class-affiliates-settings.php
7.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
<?php
/**
* class-affiliates-settings.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;
}
/**
* @var string options form nonce name
*/
define( 'AFFILIATES_ADMIN_SETTINGS_NONCE', 'affiliates-admin-nonce' );
/**
* @var string generator nonce
*/
define( 'AFFILIATES_ADMIN_SETTINGS_GEN_NONCE', 'affiliates-admin-gen-nonce' );
/**
* Settings admin section.
*/
class Affiliates_Settings {
static $sections = null;
/**
* Settings initialization.
*/
public static function init() {
add_action( 'admin_init', array( __CLASS__, 'admin_init' ) );
}
/**
* Settings sections.
*
* @return array
*/
public static function init_sections() {
self::$sections = apply_filters(
'affiliates_settings_sections',
array(
'general' => __( 'General', AFFILIATES_PLUGIN_DOMAIN ),
'registration' => __( 'Registration', AFFILIATES_PLUGIN_DOMAIN ),
'pages' => __( 'Pages', AFFILIATES_PLUGIN_DOMAIN ),
'referrals' => __( 'Referrals', AFFILIATES_PLUGIN_DOMAIN ),
'integrations' => __( 'Integrations', AFFILIATES_PLUGIN_DOMAIN )
)
);
}
/**
* Registers an admin_notices action.
*/
public static function admin_init() {
wp_register_style( 'affiliates-admin-settings', AFFILIATES_PLUGIN_URL . 'css/affiliates_admin_settings.css' );
wp_register_script( 'affiliates-field-choice', AFFILIATES_PLUGIN_URL . 'js/affiliates-field-choice.js', array( 'jquery' ), AFFILIATES_CORE_VERSION, true );
if ( current_user_can( AFFILIATES_ADMINISTER_OPTIONS ) ) {
if ( isset( $_REQUEST['aff_setup_hide'] ) ) {
if ( wp_verify_nonce( $_REQUEST['aff_setup_nonce'], 'aff_setup_hide' ) ) {
add_option( 'aff_setup_hide', 'yes', '', 'no' );
}
}
if ( !get_option( 'aff_setup_hide' ) ) {
add_action( 'admin_notices', array( __CLASS__, 'setup_notice' ) );
}
}
}
/**
* Prints setup notices.
*/
public static function setup_notice() {
echo '<style type="text/css">';
echo '.affiliates-welcome a.button-primary { margin: 0 4px 4px 0; }';
echo '</style>';
echo '<div class="updated affiliates-welcome">';
// render the welcome header and a brief explanation
echo '<p>';
echo
sprintf(
__( '<strong>Welcome to %s</strong>', AFFILIATES_PLUGIN_DOMAIN ),
ucwords( str_replace('-', ' ', AFFILIATES_PLUGIN_NAME ) )
);
echo '</p>';
echo '<p>';
echo __( 'Please review the following suggested steps to set up the affiliate system.', AFFILIATES_PLUGIN_DOMAIN );
echo ' ';
echo __( 'This is intended as a guidance and you can safely hide this message when finished.', AFFILIATES_PLUGIN_DOMAIN );
echo ' ';
echo sprintf(
__( 'Use the <a href="%s">Settings</a> section to review or adjust the system anytime.', AFFILIATES_PLUGIN_DOMAIN ),
admin_url( 'admin.php?page=affiliates-admin-settings' )
);
echo '</p>';
$buttons = apply_filters(
'affiliates_setup_buttons',
array(
'general' => sprintf(
'<a href="%s" class="button-primary">%s</a>',
add_query_arg( 'section', 'general', admin_url( 'admin.php?page=affiliates-admin-settings' ) ),
__( 'Review General Settings', AFFILIATES_PLUGIN_DOMAIN )
),
'registration' => sprintf (
'<a href="%s" class="button-primary">%s</a>',
add_query_arg( 'section', 'registration', admin_url( 'admin.php?page=affiliates-admin-settings' ) ),
__( 'Enable Affiliate Registration', AFFILIATES_PLUGIN_DOMAIN )
),
'pages' => sprintf (
'<a href="%s" class="button-primary">%s</a>',
add_query_arg( 'section', 'pages', admin_url( 'admin.php?page=affiliates-admin-settings' ) ),
__( 'Create an Affiliate Area', AFFILIATES_PLUGIN_DOMAIN )
),
'integrations' => sprintf (
'<a href="%s" class="button-primary">%s</a>',
add_query_arg( 'section', 'integrations', admin_url( 'admin.php?page=affiliates-admin-settings' ) ),
__( 'Install an Integration', AFFILIATES_PLUGIN_DOMAIN )
)
)
);
// render the buttons
echo '<p class="submit">';
echo implode( ' ', $buttons );
echo ' ';
printf( '<a class="hide button" href="%s">%s</a>',
wp_nonce_url(
add_query_arg( 'aff_setup_hide', 'true', admin_url( 'admin.php?page=affiliates-admin-settings' ) ),
'aff_setup_hide',
'aff_setup_nonce'
),
__( 'Hide this', AFFILIATES_PLUGIN_DOMAIN )
);
echo '</p>';
echo '</div>';
}
/**
* Settings admin section.
*/
public static function admin_settings() {
global $wp, $wpdb, $affiliates_options, $wp_roles;
if ( !current_user_can( AFFILIATES_ADMINISTER_OPTIONS ) ) {
wp_die( __( 'Access denied.', AFFILIATES_PLUGIN_DOMAIN ) );
}
wp_enqueue_style( 'affiliates-admin-settings' );
wp_enqueue_script( 'affiliates-field-choice' );
self::init_sections();
$section = isset( $_REQUEST['section'] ) ? $_REQUEST['section'] : null;
if ( !key_exists( $section, self::$sections ) ) {
$section = 'general';
}
$section_title = self::$sections[$section];
echo
'<h1>' .
__( 'Settings', AFFILIATES_PLUGIN_DOMAIN ) .
'</h1>';
$section_links = array();
foreach( self::$sections as $sec => $title ) {
$section_links[] = sprintf(
'<a class="section-link %s" href="%s">%s</a>',
$section == $sec ? 'active' : '',
esc_url( add_query_arg( 'section', $sec, admin_url( 'admin.php?page=affiliates-admin-settings' ) ) ),
$title
);
}
echo '<div class="section-links">';
echo implode( ' | ', $section_links );
echo '</div>';
echo
'<h2>' .
$section_title .
'</h2>';
switch( $section ) {
case 'integrations' :
require_once AFFILIATES_CORE_LIB . '/class-affiliates-settings-integrations.php';
Affiliates_Settings_Integrations::section();
break;
case 'pages' :
require_once AFFILIATES_CORE_LIB . '/class-affiliates-settings-pages.php';
Affiliates_Settings_Pages::section();
break;
case 'referrals' :
require_once AFFILIATES_CORE_LIB . '/class-affiliates-settings-referrals.php';
Affiliates_Settings_Referrals::section();
break;
case 'registration' :
require_once AFFILIATES_CORE_LIB . '/class-affiliates-settings-registration.php';
Affiliates_Settings_Registration::section();
break;
case 'general' :
require_once AFFILIATES_CORE_LIB . '/class-affiliates-settings-general.php';
Affiliates_Settings_General::section();
break;
default :
do_action( 'affiliates_settings_section', $section );
}
}
/**
* Outputs a note to confirm settings have been saved.
*/
protected static function settings_saved_notice() {
echo '<div class="updated">';
echo __( 'Settings saved.', AFFILIATES_PLUGIN_DOMAIN );
echo '</div>';
}
}
Affiliates_Settings::init();