class-affiliates-settings-pages.php
4.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
/**
* class-affiliates-settings-pages.php
*
* Copyright (c) 2010 - 2015 "kento" Karim Rahimpur www.itthinx.com
*
* This code is released under the GNU General Public License.
* See COPYRIGHT.txt and LICENSE.txt.
*
* This code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This header and all notices must be kept intact.
*
* @author Karim Rahimpur
* @package affiliates
* @since affiliates 2.8.0
*/
if ( !defined( 'ABSPATH' ) ) {
exit;
}
/**
* Integration section.
*/
class Affiliates_Settings_Pages extends Affiliates_Settings {
/**
* Renders the generator form and handles page
* generation form submission.
*/
public static function section() {
$pages_generated_info = '';
//
// handle page generation form submission
//
if ( isset( $_POST['generate'] ) ) {
if ( wp_verify_nonce( $_POST[AFFILIATES_ADMIN_SETTINGS_GEN_NONCE], 'admin' ) ) {
require_once( AFFILIATES_CORE_LIB . '/class-affiliates-generator.php' );
$post_ids = Affiliates_Generator::setup_pages();
foreach ( $post_ids as $post_id ) {
$link = '<a href="' . get_permalink( $post_id ) . '" target="_blank">' . get_the_title( $post_id ) . '</a>';
$pages_generated_info .= '<div class="info">' . __( sprintf( 'The %s page has been created.', $link ), AFFILIATES_PLUGIN_DOMAIN ) . '</div>';
}
}
}
echo '<h3>' . __( 'Generator', AFFILIATES_PLUGIN_DOMAIN ) . '</h3>';
//
// Generator form
//
echo
'<form action="" name="options" method="post">' .
'<div>' .
'<p>' .
__( 'Press the button to generate a default affiliate area.', AFFILIATES_PLUGIN_DOMAIN ) .
' ' .
'<input class="generate button" name="generate" type="submit" value="' . __( 'Generate', AFFILIATES_PLUGIN_DOMAIN ) .'" />' .
wp_nonce_field( 'admin', AFFILIATES_ADMIN_SETTINGS_GEN_NONCE, true, false ) .
'</p>' .
$pages_generated_info.
'</div>' .
'</form>';
echo '<p>';
echo __( 'The generated page contains Affiliates shortcodes and can be used as an out-of-the-box affiliate area or as a framework for customized affiliate areas and pages.', AFFILIATES_PLUGIN_DOMAIN );
echo '</p>';
//
// Pages containing affiliates shortcodes
//
echo '<h3>' . __( 'Pages', AFFILIATES_PLUGIN_DOMAIN ) . '</h3>';
global $wpdb;
$post_options = '';
$post_ids = array();
// We also have [referrer_id] and [referrer_user] but these are not essential in
// determining whether an affiliate page has been set up.
$posts = $wpdb->get_results( "SELECT ID FROM $wpdb->posts WHERE post_content LIKE '%[affiliates_%' AND post_status = 'publish'" );
foreach( $posts as $post ) {
$post_ids[] = $post->ID;
}
if ( count( $posts ) == 0 ) {
echo '<p>';
echo __( 'It seems that you do not have any pages set up for your affiliates yet.', AFFILIATES_PLUGIN_DOMAIN );
echo '</p>';
echo '<p>';
echo __( 'You can use the page generation option to create the default affiliate area for your affiliates.', AFFILIATES_PLUGIN_DOMAIN );
echo '</p>';
} else {
echo '<p>';
echo _n(
'This page containing Affiliates shortcodes has been detected :',
'These pages containing Affiliates shortcodes have been detected :',
count( $posts ),
AFFILIATES_PLUGIN_DOMAIN
);
echo '</p>';
$post_list = '<ul>';
foreach( $post_ids as $post_id ) {
$post_title = get_the_title( $post_id );
$post_list .= sprintf(
'<li><a href="%s">%s</a></li>',
get_permalink( $post_id ),
esc_html( $post_title )
);
}
$post_list .= '</ul>';
echo $post_list;
}
echo '<p>';
_e( 'You can modify the default affiliate area and also create customized pages for your affiliates using shortcodes.', AFFILIATES_PLUGIN_DOMAIN );
echo '</p>';
echo '<p>';
_e( 'Please refer to the <a href="http://docs.itthinx.com/document/affiliates/">Documentation</a> for more details.', AFFILIATES_PLUGIN_DOMAIN );
echo '</p>';
affiliates_footer();
}
}