PluginProbe
WP-Members Membership Plugin / trunk
WP-Members Membership Plugin vtrunk
trunk 3.3.9 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.4.2 3.4.5 3.4.6 3.4.7 3.4.8 3.4.9 3.4.9.1 3.4.9.2 3.4.9.3 3.4.9.4 3.4.9.5 3.4.9.6 3.4.9.7 3.5.0 3.5.1 3.5.2 3.5.3 3.5.4 All 34 releases
wp-members / includes / admin / class-wp-members-admin-api.php

class-wp-members-admin-api.php in WP-Members Membership Plugin trunk, at includes/admin/class-wp-members-admin-api.php

768 lines 29.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The WP_Members Admin API Class.
4 *
5 * @package WP-Members
6 * @subpackage WP_Members Admin API Object Class
7 * @since 3.1.0
8 */
9
10 // Exit if accessed directly.
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit();
13 }
14
15 class WP_Members_Admin_API {
16
17 /**
18 * Container for tabs.
19 *
20 * @since 3.1.0
21 * @access public
22 * @var array
23 */
24 public $tabs = array();
25
26 /**
27 * Container for emails.
28 *
29 * @since 3.1.0
30 * @access public
31 * @var array
32 */
33 public $emails = array();
34
35 /**
36 * Container for dialogs.
37 *
38 * @since 3.1.1
39 * @access public
40 * @var array
41 */
42 public $dialogs = array();
43
44 /**
45 * Container for user search.
46 *
47 * @since 3.4.7
48 * @access public
49 */
50 public $user_search;
51
52 public $current_form;
53 public $current_form_fields;
54
55 /**
56 * Plugin initialization function.
57 *
58 * @since 3.1.0
59 */
60 function __construct() {
61
62 global $wpmem;
63
64 if ( 'finalize' == wpmem_get( 'wpmem_onboarding_action' ) ) {
65 require_once( $wpmem->path . 'includes/install.php' );
66 wpmem_onboarding_init( array( 'finalize' ) );
67 wpmem_onboarding_finalize();
68 }
69
70 if ( 'new_install' == $wpmem->install_state ) {
71 require_once( $wpmem->path . 'includes/install.php' );
72 wpmem_onboarding_new_install( $wpmem->path, $wpmem->version );
73 }
74
75 if ( 'update_pending' == $wpmem->install_state ) {
76 require_once( $wpmem->path . 'includes/install.php' );
77 wpmem_onboarding_pending_update( $wpmem->path, $wpmem->version );
78 }
79
80 // Load dependencies.
81 $this->load_dependencies();
82
83 // Load admin hooks.
84 $this->load_hooks();
85
86 // The following is only needed if we are on the WP-Members settings screen.
87 $is_wpmem_admin = wpmem_get( 'page', false, 'get' );
88 if ( false !== $is_wpmem_admin && 'wpmem-settings' == $is_wpmem_admin ) {
89 $this->default_tabs(); // Load default tabs.
90 $this->default_emails(); // Load default emails.
91 $this->default_dialogs(); // Load default dialogs.
92 }
93
94 if ( wpmem_is_enabled( 'enable_products' ) ) {
95 $wpmem->membership->admin = new WP_Members_Products_Admin();
96 }
97 }
98
99 /**
100 * Load dependencies.
101 *
102 * @since 3.1.0
103 * @since 3.1.1 Added tab-about.php.
104 * @since 3.1.7 Loads all admin dependent files.
105 * @since 3.2.9 Removed tab-about.php until we can re-do it.
106 *
107 * @global object $wpmem
108 */
109 function load_dependencies() {
110
111 global $wpmem;
112
113 include_once( $wpmem->path . 'includes/admin/admin.php' );
114 include_once( $wpmem->path . 'includes/admin/class-wp-members-admin-users.php' );
115 include_once( $wpmem->path . 'includes/admin/class-wp-members-admin-posts.php' );
116 include_once( $wpmem->path . 'includes/admin/class-wp-members-products-admin.php' );
117 include_once( $wpmem->path . 'includes/admin/class-wp-members-user-search.php' );
118 include_once( $wpmem->path . 'includes/admin/dialogs.php' );
119 include_once( $wpmem->path . 'includes/admin/api.php' );
120 include_once( $wpmem->path . 'includes/admin/tabs/class-wp-members-admin-tab-fields.php' ); // Fields tab is used for field reorder (which is ! wpmem-settings).
121 if ( 'wpmem-settings' == wpmem_get( 'page', false, 'get' ) ) {
122 include_once( $wpmem->path . 'includes/admin/tabs/class-wp-members-admin-tab-options.php' );
123 include_once( $wpmem->path . 'includes/admin/tabs/class-wp-members-admin-tab-emails.php' );
124 include_once( $wpmem->path . 'includes/admin/tabs/class-wp-members-admin-tab-captcha.php' );
125 include_once( $wpmem->path . 'includes/admin/tabs/class-wp-members-admin-tab-about.php' );
126 include_once( $wpmem->path . 'includes/admin/tabs/class-wp-members-admin-tab-dialogs.php' );
127 include_once( $wpmem->path . 'includes/admin/tabs/class-wp-members-admin-tab-dropins.php' );
128 include_once( $wpmem->path . 'includes/admin/tabs/class-wp-members-admin-tab-shortcodes.php' );
129 if ( ! class_exists( 'WP_List_Table' ) ) {
130 require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
131 }
132 include_once( $wpmem->path . 'includes/admin/tabs/class-wp-members-fields-table.php' );
133 }
134 }
135
136 /**
137 * Load admin.
138 *
139 * @since 3.1.0
140 * @since 3.1.7 Loads all admin hooks.
141 *
142 * @global object $wpmem
143 */
144 function load_hooks() {
145
146 global $wpmem;
147
148 add_action( 'admin_menu', array( $this, 'add_options_page' ) ); // Adds admin menu
149 add_action( 'admin_enqueue_scripts', array( $this, 'dashboard_enqueue_scripts' ) );
150 add_filter( 'plugin_action_links', array( $this, 'plugin_links' ), 10, 2 );
151
152 add_action( 'user_new_form', array( $wpmem->forms, 'wp_newuser_form' ) );
153 // add_filter( 'wpmem_admin_tabs', 'wpmem_add_about_tab' );
154
155 add_action( 'wp_ajax_wpmem_do_field_reorder', array( 'WP_Members_Admin_Tab_Fields', 'do_field_reorder' ) );
156
157 add_action( 'wpmem_admin_do_tab', array( 'WP_Members_Admin_Tab_Options', 'do_tab' ), 1 );
158 add_action( 'wpmem_admin_do_tab', array( 'WP_Members_Admin_Tab_Fields', 'do_tab' ), 5 );
159 add_action( 'wpmem_admin_do_tab', array( 'WP_Members_Admin_Tab_Dialogs', 'do_tab' ), 10 );
160 add_action( 'wpmem_admin_do_tab', array( 'WP_Members_Admin_Tab_Emails', 'do_tab' ), 15 );
161 add_action( 'wpmem_admin_do_tab', array( 'WP_Members_Admin_Tab_Shortcodes', 'do_tab' ), 16 );
162 add_action( 'wpmem_admin_do_tab', array( 'WP_Members_Admin_Tab_About', 'do_tab' ), 99 );
163
164 // If user has a role that cannot edit users, set profile actions for non-admins.
165
166 // User actions and filters.
167 add_action( 'user_edit_form_tag', array( 'WP_Members_User_Profile', 'add_multipart' ) );
168 add_action( 'show_user_profile', array( 'WP_Members_User_Profile', 'profile' ) );
169 add_action( 'edit_user_profile', array( 'WP_Members_User_Profile', 'profile' ) );
170 add_action( 'profile_update', array( 'WP_Members_User_Profile', 'update' ) );
171 add_action( 'edit_user_profile', array( 'WP_Members_User_Profile', '_profile_tabs' ), 99 );
172 add_action( 'show_user_profile', array( 'WP_Members_User_Profile', '_profile_tabs' ), 99 );
173
174 if ( current_user_can( 'list_users' ) ) {
175 add_action( 'admin_footer-users.php', array( 'WP_Members_Admin_Users', 'bulk_user_action' ) );
176 add_action( 'load-users.php', array( 'WP_Members_Admin_Users', 'page_load' ) );
177 add_action( 'admin_notices', array( 'WP_Members_Admin_Users', 'admin_notices' ) );
178 add_filter( 'views_users', array( 'WP_Members_Admin_Users', 'views' ) );
179 add_filter( 'manage_users_columns', array( 'WP_Members_Admin_Users', 'add_user_column' ) );
180 add_filter( 'manage_users_custom_column', array( 'WP_Members_Admin_Users', 'add_user_column_content' ), 10, 3 );
181 add_action( 'wpmem_user_activated', array( 'WP_Members_Admin_Users', 'set_activated_user' ) );
182 add_action( 'wpmem_user_deactivated', array( 'WP_Members_Admin_Users', 'set_deactivated_user' ) );
183 add_filter( 'user_row_actions', array( 'WP_Members_Admin_Users', 'insert_hover_links' ), 10, 2 );
184 add_action( 'wpmem_admin_after_profile', array( 'WP_Members_User_Profile', '_show_activate' ), 7 );
185 add_action( 'wpmem_admin_after_profile', array( 'WP_Members_User_Profile', '_show_expiration' ), 8 );
186 add_action( 'wpmem_admin_after_profile', array( 'WP_Members_User_Profile', '_show_ip' ), 9 );
187 if ( wpmem_is_enabled( 'enable_products' ) ) {
188 //add_action( 'wpmem_admin_after_profile', array( 'WP_Members_User_Profile', '_show_product' ), 10 );
189 }
190 if ( wpmem_is_enabled( 'mod_reg' ) || wpmem_is_enabled( 'act_link' ) ) {
191 include_once $wpmem->path . 'includes/admin/class-wp-members-user-utilities.php';
192 add_action( 'admin_menu', array( 'WP_Members_User_Utilities', 'admin_menu' ) );
193 }
194 }
195
196 // If user has a role that can edit posts, add the block/unblock meta boxes and custom post/page columns.
197 if ( current_user_can( 'edit_posts' ) ) {
198 // Post actions and filters.
199 add_action( 'add_meta_boxes', array( 'WP_Members_Admin_Posts', 'block_meta_add' ) );
200 add_action( 'save_post', array( 'WP_Members_Admin_Posts', 'block_meta_save' ) );
201 add_filter( 'manage_posts_columns', array( 'WP_Members_Admin_Posts', 'columns' ) );
202 add_action( 'manage_posts_custom_column', array( 'WP_Members_Admin_Posts', 'columns_content' ), 10, 2 );
203 add_filter( 'manage_pages_columns', array( 'WP_Members_Admin_Posts', 'columns' ) );
204 add_action( 'manage_pages_custom_column', array( 'WP_Members_Admin_Posts', 'columns_content' ), 10, 2 );
205 add_action( 'restrict_manage_posts', array( 'WP_Members_Admin_Posts', 'filter_by_restriction' ) );
206 add_action( 'pre_get_posts', array( 'WP_Members_Admin_Posts', 'restriction_filter' ) );
207 add_action( 'admin_footer-edit.php', array( 'WP_Members_Admin_Posts', 'bulk_action' ) );
208 add_action( 'load-edit.php', array( 'WP_Members_Admin_Posts', 'page_load' ) );
209 add_action( 'admin_notices', array( 'WP_Members_Admin_Posts', 'notices' ) );
210 add_action( 'load-post.php', array( 'WP_Members_Admin_Posts', 'load_tinymce' ) );
211 add_action( 'load-post-new.php', array( 'WP_Members_Admin_Posts', 'load_tinymce' ) );
212 }
213
214 if ( ! is_multisite() && current_user_can( 'manage_options' ) ) {
215 add_action('wp_dashboard_setup', 'butlerblog_dashboard_widget');
216 }
217
218 add_action( 'wpmem_after_admin_init', array( 'WP_Members_Admin_Tab_Fields', 'update' ) );
219 add_action( 'admin_print_styles', array( 'WP_Members_Admin_Tab_Fields', 'enqueue_scripts' ) );
220 add_action( 'admin_footer', array( 'WP_Members_Admin_Tab_Fields', 'bulk_actions' ) );
221
222 if ( current_user_can( 'manage_options' ) ) {
223 add_action( 'admin_notices', array( $this, 'do_admin_notices' ) );
224 }
225
226 add_action( 'current_screen', array( $this, 'check_user_folders_for_index' ) );
227
228 // Check for any upgrade notices.
229 add_filter( 'wpmem_admin_notices', array( $this, 'check_for_upgrade_notices' ) );
230
231 } // End of load_hooks()
232
233 /**
234 * Adds the plugin options page and JavaScript.
235 *
236 * @since 2.5.2
237 * @since 3.4.4 Moved from wp-members.php/wpmem_admin_options() to main admin object.
238 */
239 function add_options_page() {
240 if ( ! is_multisite() || ( is_multisite() && current_user_can( 'edit_theme_options' ) ) ) {
241 $plugin_page = add_options_page( 'WP-Members', 'WP-Members', 'manage_options', 'wpmem-settings', 'wpmem_admin' );
242 }
243 }
244
245 /**
246 * Add admin notices.
247 *
248 * @since 3.3.0
249 */
250 function do_admin_notices() {
251 global $wpmem;
252 /**
253 * Filter admin notices.
254 *
255 * @since 3.5.5
256 *
257 * @param array $wpmem->admin_notices Array of admin notices to display.
258 */
259 $wpmem->admin_notices = apply_filters( 'wpmem_admin_notices', $wpmem->admin_notices );
260 if ( $wpmem->admin_notices ) {
261 foreach ( $wpmem->admin_notices as $key => $value ) {
262 echo '<div class="notice notice-' . esc_attr( $value['type'] ) . ' is-dismissible">
263 <p><strong>' . wp_kses_post( $value['notice'] ) . '</strong></p>
264 </div>';
265
266 }
267 }
268 }
269
270 /**
271 * Display admin tabs.
272 *
273 * @since 3.1.0
274 *
275 * @param string $current The current tab being displayed (default: options).
276 */
277 function do_tabs( $current = 'options' ) {
278
279 /**
280 * Filter the admin tabs for the plugin settings page.
281 *
282 * @since 2.8.0
283 *
284 * @param array $tabs An array of the tabs to be displayed on the plugin settings page.
285 */
286 $this->tabs = apply_filters( 'wpmem_admin_tabs', $this->tabs );
287
288 $links = array();
289 foreach ( $this->tabs as $tab => $name ) {
290 $link_args = array( 'page' => 'wpmem-settings', 'tab' => $tab );
291 $link = add_query_arg( $link_args, admin_url( 'options-general.php' ) );
292 $class = ( $tab == $current ) ? 'nav-tab nav-tab-active' : 'nav-tab';
293 $links[] = sprintf( '<a class="%s" href="%s">%s</a>', esc_attr( $class ), esc_url( $link ), esc_attr( $name ) );
294 }
295
296 echo '<h2 class="nav-tab-wrapper">';
297 foreach ( $links as $link ) {
298 echo $link;
299 }
300 echo '</h2>';
301 }
302
303 /**
304 * Handles custom email settings.
305 *
306 * @since 3.1.0
307 *
308 * @param array $args Settings array for the email.
309 * @return array $args
310 */
311 function add_email( $args ) {
312
313 // Get saved settings (or defaults).
314 $settings = wpmem_get_email_settings( $args['name'] );;
315
316 $defaults = array(
317 'name' => $args['name'],
318 'heading' => esc_html__( 'Custom email', 'wp-members' ),
319 'subject_label' => esc_html__( 'Subject', 'wp-members' ),
320 'subject_input' => $args['name'] . '_subject',
321 'subject_value' => ( $settings ) ? $settings['subj'] : esc_html__( 'Subject', 'wp-members' ),
322 'body_label' => esc_html__( 'Body', 'wp-members' ),
323 'body_input' => $args['name'] . '_body',
324 'body_value' => ( $settings ) ? $settings['body'] : esc_html__( 'Your custom email message content.', 'wp-members' ),
325 );
326
327 // Merge args with settings.
328 $args = wp_parse_args( $args, $defaults );
329
330 $this->emails[ $args['name'] ] = $args;
331
332 return $args;
333 }
334
335 /**
336 * Adds dialogs to the Dialogs tab.
337 *
338 * @since 3.1.1
339 *
340 * @param array $args Settings array for the dialog.
341 */
342 function do_dialog_input( $args ) { ?>
343 <tr valign="top">
344 <th scope="row"><?php echo esc_html( $args['label'] ); ?></th>
345 <td><textarea name="<?php echo esc_attr( $args['name'] . "_dialog" ); ?>" rows="3" cols="50" id="" class="large-text code"><?php echo esc_textarea( wp_unslash( $args['value'] ) ); ?></textarea></td>
346 </tr><?php
347 }
348
349 /**
350 * Saves custom dialog settings.
351 *
352 * @since 3.1.1
353 */
354 function dialog_update() {
355 $settings = $this->dialogs;
356 foreach ( $settings as $dialog ) {
357 if ( isset( $_POST[ $dialog['name'] . '_dialog' ] ) ) {
358 $settings[ $dialog['name'] ] = wp_kses( $_POST[ $dialog['name'] . '_dialog' ], 'post' );
359 }
360 }
361
362 update_option( 'wpmembers_dialogs', $settings, false );
363 // Refresh settings
364 $this->default_dialogs();
365 return;
366 }
367
368 /**
369 * Handles custom dialog settings.
370 *
371 * @since 3.1.1
372 *
373 * @param array $args Settings array for the dialog.
374 * @return array $args
375 */
376 function add_dialog( $args ) {
377 global $wpmem;
378 if ( is_array( $args ) && isset( $args['label'] ) ) {
379 $defaults = array(
380 'name' => $args['name'],
381 'label' => $args['label'],
382 //'input' => $args['name'] . '_dialog',
383 'value' => $args['value'],
384 //'value' => ( $args['value'] ) ? $args['value'] : wpmem_get_text( $key ),
385 );
386
387 // Merge args with settings.
388 $args = wp_parse_args( $args, $defaults );
389
390 $this->dialogs[ $args['name'] ] = $args;
391 }
392
393 //return $args;
394 }
395
396 /**
397 * Settings for default tabs.
398 *
399 * @since 3.1.0
400 */
401 function default_tabs() {
402 $this->tabs = array(
403 'options' => 'WP-Members ' . esc_html__( 'Options', 'wp-members' ),
404 'fields' => esc_html__( 'Fields', 'wp-members' ),
405 'dialogs' => esc_html__( 'Dialogs', 'wp-members' ),
406 'emails' => esc_html__( 'Emails', 'wp-members' ),
407 'shortcodes' => esc_html__( 'Shortcodes', 'wp-members' ),
408 );
409 }
410
411 /**
412 * Settings for default emails.
413 *
414 * @since 3.1.0
415 */
416 function default_emails() {
417
418 if ( ! wpmem_is_enabled( 'mod_reg' ) ) {
419
420 $this->add_email( array(
421 'name' => 'wpmembers_email_newreg',
422 'heading' => esc_html__( "New Registration", 'wp-members' ),
423 'subject_input' => 'wpmembers_email_newreg_subj',
424 'body_input' => 'wpmembers_email_newreg_body',
425 ) );
426
427 if ( wpmem_is_enabled( 'act_link' ) ) {
428 $this->add_email( array(
429 'name' => 'wpmembers_email_validated',
430 'heading' => esc_html__( "User email validated", 'wp-members' ),
431 'subject_input' => 'wpmembers_email_validated_subj',
432 'body_input' => 'wpmembers_email_validated_body',
433 ) );
434 }
435
436 } else {
437
438 $this->add_email( array(
439 'name' => 'wpmembers_email_newmod',
440 'heading' => esc_html__( "Registration is Moderated", 'wp-members' ),
441 'subject_input' => 'wpmembers_email_newmod_subj',
442 'body_input' => 'wpmembers_email_newmod_body',
443 ) );
444
445 if ( wpmem_is_enabled( 'act_link' ) ) {
446 $this->add_email( array(
447 'name' => 'wpmembers_email_validated',
448 'heading' => esc_html__( "User email validated", 'wp-members' ),
449 'subject_input' => 'wpmembers_email_validated_subj',
450 'body_input' => 'wpmembers_email_validated_body',
451 ) );
452 }
453
454 $this->add_email( array(
455 'name' => 'wpmembers_email_appmod',
456 'heading' => esc_html__( "Registration is Moderated, User is Approved", 'wp-members' ),
457 'subject_input' => 'wpmembers_email_appmod_subj',
458 'body_input' => 'wpmembers_email_appmod_body',
459 ) );
460 }
461
462 $this->add_email( array(
463 'name' => 'wpmembers_email_repass',
464 'heading' => esc_html__( "Password Reset", 'wp-members' ),
465 'subject_input' => 'wpmembers_email_repass_subj',
466 'body_input' => 'wpmembers_email_repass_body',
467 ) );
468
469 $this->add_email( array(
470 'name' => 'wpmembers_email_getuser',
471 'heading' => esc_html__( "Retrieve Username", 'wp-members' ),
472 'subject_input' => 'wpmembers_email_getuser_subj',
473 'body_input' => 'wpmembers_email_getuser_body',
474 ) );
475
476 if ( wpmem_is_enabled( 'notify' ) ) {
477 $this->add_email( array(
478 'name' => 'wpmembers_email_notify',
479 'heading' => esc_html__( "Admin Notification", 'wp-members' ),
480 'subject_input' => 'wpmembers_email_notify_subj',
481 'body_input' => 'wpmembers_email_notify_body',
482 ) );
483 }
484
485 }
486
487 /**
488 * Settings for default dialogs.
489 *
490 * @since 3.1.1
491 */
492 function default_dialogs() {
493
494 global $wpmem;
495
496 /**
497 * Filter the dialog array to add custom dialogs.
498 *
499 * @since 3.1.1
500 *
501 * @param array $dialog_array
502 */
503 $dialogs = apply_filters( 'wpmem_dialogs', get_option( 'wpmembers_dialogs' ) );
504
505 $dialog_labels = array(
506 'restricted_msg' => esc_html__( "Restricted post (or page), displays above the login/registration form", 'wp-members' ),
507 'user' => esc_html__( "Username is taken", 'wp-members' ),
508 'email' => esc_html__( "Email is registered", 'wp-members' ),
509 'success' => esc_html__( "Registration completed", 'wp-members' ),
510 'editsuccess' => esc_html__( "User update", 'wp-members' ),
511 'pwdchangerr' => esc_html__( "Passwords did not match", 'wp-members' ),
512 'pwdchangesuccess' => esc_html__( "Password changes", 'wp-members' ),
513 'pwdreseterr' => esc_html__( "Username or email do not exist when trying to reset forgotten password", 'wp-members' ),
514 'pwdresetsuccess' => esc_html__( "Password reset", 'wp-members' ),
515 );
516
517 // @todo Are we using deprecated dialogs? This will be used to remove them from display in the tab - maybe 3.5.4?
518 // $deprecated_dialogs = ( 1 == get_option( 'wpmem_legacy_dialogs' ) ) ? $wpmem->dialogs->get_deprecated_dialogs() : array();
519
520 foreach ( $dialogs as $key => $val ) {
521 if ( array_key_exists( $key, $dialog_labels ) ) {
522 $dialogs[ $key ] = array(
523 'name' => $key,
524 'label' => $dialog_labels[ $key ],
525 'value' => $dialogs[ $key ],
526 );
527 }
528 }
529
530 foreach ( $dialogs as $val ) {
531 $this->add_dialog( $val );
532 }
533 }
534
535
536 /**
537 * Get the current form.
538 *
539 * @since 3.1.2
540 *
541 * @todo Work on multi-form project, no current milestone.
542 */
543 function get_form( $form = 'default' ) {
544 /*
545 $current_form = ( isset( $_GET['form'] ) ) ? $_GET['form'] : $form;
546 $wpmem_forms = get_option( 'wpmembers_forms' );
547 $fields = $wpmem_forms[ $current_form ];
548 $this->current_form = $current_form;
549 $this->current_form_fields = $fields;
550 */
551 $this->current_form = sanitize_text_field( wpmem_get( 'form', $form, 'get' ) ); //( isset( $_GET['form'] ) ) ? $_GET['form'] : $form;
552 //global $wpmem;
553 // Add numeric array form fields as associative
554 //foreach( $wpmem->fields as $field ) {
555 // $wpmem->fields[ $field[2] ] = $field;
556 //}
557 $this->current_form_fields = wpmem_fields();
558 }
559
560 /**
561 * Build admin panel form action url.
562 *
563 * @since 3.1.8
564 *
565 * @global string $pagenow
566 * @global string $plugin_page
567 * @global object $wpmem The WP_Members Object.
568 * @param mixed $args Array of additional arguments|boolean. Default: false.
569 * @return string $url
570 */
571 function form_post_url( $args = false ) {
572 global $pagenow, $plugin_page, $wpmem;
573 $tab = sanitize_text_field( wpmem_get( 'tab', false, 'get' ) );
574 $params = array( 'page' => $plugin_page );
575 if ( $tab ) {
576 $params['tab'] = $tab;
577 }
578 if ( $args ) {
579 foreach( $args as $key => $val ) {
580 $params[ $key ] = $val;
581 }
582 }
583 $url = add_query_arg( $params, admin_url( $pagenow ) );
584 return esc_url( $url );
585 }
586
587 /**
588 * Enqueues the admin javascript and css files.
589 *
590 * Replaces wpmem_admin_enqueue_scripts().
591 * Only loads the js and css on admin screens that use them.
592 *
593 * @since 3.1.7
594 * @since 3.2.0 Moved into admin object, renamed dashboard_enqueue_scripts().
595 * @since 3.2.1 Load js for post.php hook.
596 * @since 3.3.0 Everything loads from /assets/ folder.
597 *
598 * @global object $current_screen
599 * @param string $hook The admin screen hook being loaded.
600 */
601 function dashboard_enqueue_scripts( $hook ) {
602 global $current_screen;
603 if ( 'edit.php' == $hook
604 || 'post.php' == $hook
605 || 'post-new.php' == $hook
606 || 'user-new.php' == $hook
607 || 'user-edit.php' == $hook
608 || 'profile.php' == $hook
609 || 'users.php' == $hook
610 || 'settings_page_wpmem-settings' == $hook ) {
611 wp_enqueue_style( 'wpmem-admin', wpmem_get_plugin_url() . 'assets/css/admin' . wpmem_get_suffix() . '.css', '', wpmem_get_plugin_version() );
612 }
613 if ( 'settings_page_wpmem-settings' == $hook || 'post.php' == $hook || 'post-new.php' == $hook ) {
614 wp_enqueue_script( 'jquery-ui-dialog' ); // enqueue jQuery UI Dialog dependency
615 wp_register_script( 'wpmem-admin', wpmem_get_plugin_url() . 'assets/js/admin' . wpmem_get_suffix() . '.js', 'jquery', wpmem_get_plugin_version(), true );
616 $ajax_url = admin_url( 'admin-ajax.php' );
617 $wpmem_settings_nonce = wp_create_nonce( 'wpmem_settings_nonce' );
618 $translation_array = array(
619 'close_btn' => esc_html__( 'Close', 'wp-members' ),
620 'ajax_url' => $ajax_url,
621 'nonce' => $wpmem_settings_nonce,
622 );
623 wp_localize_script( 'wpmem-admin', 'wpmem_get_settings_vars', $translation_array );
624 wp_enqueue_script( 'wpmem-admin' );
625 }
626 if ( ( ( 'post.php' == $hook || 'post-new.php' == $hook ) && wpmem_is_enabled( 'enable_products' ) )
627 || ( 'wpmem_product' == get_post_type() )
628 || ( 'user-edit' == $current_screen->id || 'profile' == $current_screen->id )
629 || ( 'settings_page_wpmem-settings' == $hook ) ) {
630 wp_enqueue_script( 'jquery' );
631 wp_enqueue_script( 'jquery-ui-core' ); // enqueue jQuery UI Core
632 wp_enqueue_script( 'jquery-ui-datepicker' ); // enqueue jQuery UI Datepicker
633 if ( ! wp_style_is( 'jquery-ui-style', 'enqueued' ) ) {
634 wp_register_style( 'jquery-ui-style', wpmem_get_plugin_url() . 'includes/vendor/jquery-ui/css/jquery-ui' . wpmem_get_suffix() . '.css' );
635 }
636 wp_enqueue_style( 'jquery-ui-style' );
637 }
638 if ( ( 'post.php' == $hook || 'post-new.php' == $hook ) && wpmem_is_enabled( 'enable_products' ) ) {
639 if ( ! wp_script_is( 'select2', 'enqueued' ) ) {
640 wp_register_style( 'select2-style', wpmem_get_plugin_url() . 'includes/vendor/select2/css/select2' . wpmem_get_suffix() . '.css', false, '4.0.5', 'all' );
641 wp_register_script( 'select2', wpmem_get_plugin_url() . 'includes/vendor/select2/js/select2' . wpmem_get_suffix() . '.js', array( 'jquery' ), '4.0.5', true );
642 wp_enqueue_style( 'select2-style' );
643 wp_enqueue_script( 'select2' );
644 }
645 }
646 if ( 'user-edit' == $current_screen->id || 'profile' == $current_screen->id ) {
647 wp_enqueue_script( 'jquery-ui-tabs' ); // enqueue jQuery UI Tabs
648 }
649 }
650
651 /**
652 * Filter to add link to settings from plugin panel.
653 *
654 * @since 2.4.0
655 * @since 3.2.0 Moved to admin API class, renamed from wpmem_admin_plugin_links().
656 *
657 * @global object $wpmem
658 *
659 * @param array $links
660 * @param string $file
661 * @return array $links
662 */
663 function plugin_links( $links, $file ) {
664 global $wpmem;
665 static $wpmem_plugin;
666 if ( ! $wpmem_plugin ) {
667 $wpmem_plugin = plugin_basename( $wpmem->path . '/wp-members.php' );
668 }
669 if ( $file == $wpmem_plugin ) {
670 $settings_link = '<a href="' . esc_url( add_query_arg( 'page', 'wpmem-settings', 'options-general.php' ) ) . '">' . esc_html__( 'Settings', 'wp-members' ) . '</a>';
671 $links = array_merge( array( $settings_link ), $links );
672 }
673 return $links;
674 }
675
676 /**
677 * Returns an array of WordPress reserved terms.
678 *
679 * @since 3.0.2
680 * @since 3.2.3 Moved to WP_Members_Admin_API class.
681 *
682 * @return array An array of WordPress reserved terms.
683 */
684 function wp_reserved_terms() {
685 $reserved_terms = array( 'attachment', 'attachment_id', 'author', 'author_name', 'calendar', 'cat', 'category', 'category__and', 'category__in', 'category__not_in', 'category_name', 'comments_per_page', 'comments_popup', 'customize_messenger_channel', 'customized', 'cpage', 'day', 'debug', 'error', 'exact', 'feed', 'fields', 'hour', 'link_category', 'm', 'minute', 'monthnum', 'more', 'name', 'nav_menu', 'nonce', 'nopaging', 'offset', 'order', 'orderby', 'p', 'page', 'page_id', 'paged', 'pagename', 'pb', 'perm', 'post', 'post__in', 'post__not_in', 'post_format', 'post_mime_type', 'post_status', 'post_tag', 'post_type', 'posts', 'posts_per_archive_page', 'posts_per_page', 'preview', 'robots', 'role', 's', 'search', 'second', 'sentence', 'showposts', 'static', 'subpost', 'subpost_id', 'tag', 'tag__and', 'tag__in', 'tag__not_in', 'tag_id', 'tag_slug__and', 'tag_slug__in', 'taxonomy', 'tb', 'term', 'theme', 'type', 'w', 'withcomments', 'withoutcomments', 'year' );
686
687 /**
688 * Filter the array of reserved terms.
689 *
690 * @since 3.0.2
691 *
692 * @param array $reserved_terms
693 */
694 $reserved_terms = apply_filters( 'wpmem_wp_reserved_terms', $reserved_terms );
695
696 return $reserved_terms;
697 }
698
699 function post_types() {
700 return get_post_types( array( 'public' => true, '_builtin' => false ), 'names', 'and' );
701 }
702
703 function check_user_folders_for_index() {
704 global $current_screen, $wpmem;
705 if ( 'user-edit' == $current_screen->id
706 || 'profile' == $current_screen->id
707 || 'dashboard' == $current_screen->id
708 || 'plugins' == $current_screen->id
709 || 'update-core' == $current_screen->id
710 || 'settings_page_wpmem-settings' == $current_screen->id ) {
711
712 $upload_vars = wp_upload_dir( null, false );
713 $wpmem_base_dir = trailingslashit( trailingslashit( $upload_vars['basedir'] ) . wpmem_get_upload_base() );
714 $wpmem_user_files_dir = $wpmem_base_dir . trailingslashit( wpmem_get_file_dir_hash() );
715
716 if ( file_exists( $wpmem_user_files_dir ) ) {
717 // If there is a user file dir, check/self-heal htaccess/index files.
718 wpmem_create_file( array(
719 'path' => $wpmem_user_files_dir,
720 'name' => '.htaccess',
721 'contents' => "Options -Indexes"
722 ) );
723 wpmem_create_file( array(
724 'path' => $wpmem_base_dir,
725 'name' => 'index.php',
726 'contents' => "<?php // Silence is golden."
727 ) );
728 wpmem_create_file( array(
729 'path' => $wpmem_user_files_dir,
730 'name' => 'index.php',
731 'contents' => "<?php // Silence is golden."
732 ) );
733 }
734 }
735 }
736
737 function check_for_upgrade_notices( $notices ) {
738
739 // Check for deprecated folder system.
740 $uploads = wp_upload_dir();
741 $deprecated_folder = trailingslashit( $uploads['basedir'] ) . 'wpmembers/user_files';
742 if ( is_dir( $deprecated_folder ) ) {
743 $notice_dismissed = get_option( 'wpmem_dismiss_filesystem_upgrade_notice' );
744 if ( ! $notice_dismissed ) {
745 $notices['deprecated_foldersystem'] = array(
746 'notice' => __( 'The /wpmembers/user_files/ folder is deprecated. Please <a href="' . esc_url( trailingslashit( admin_url() ) . 'options-general.php?page=wpmem-settings&tab=filesystem-upgrade' ) . '">go to the settings page</a> to either upgrade or permanently remove this message.', 'wp-members' ),
747 'type' => 'warning',
748 );
749 }
750 if ( 'update_filesystem' == wpmem_get( 'wpmem_admin_a' ) ) {
751 if ( false == wpmem_get( 'wpmem_dismiss_filesystem_upgrade_notice' ) ) {
752 $notices['deprecated_foldersystem'] = array(
753 'notice' => __( 'The /wpmembers/user_files/ folder is deprecated. Please <a href="' . esc_url( trailingslashit( admin_url() ) . 'options-general.php?page=wpmem-settings&tab=filesystem-upgrade' ) . '">go to the settings page</a> to either upgrade or permanently remove this message.', 'wp-members' ),
754 'type' => 'warning',
755 );
756 } elseif ( 1 == wpmem_get( 'wpmem_dismiss_filesystem_upgrade_notice' ) ) {
757 unset( $notices['deprecated_foldersystem'] );
758 }
759 }
760 }
761
762 // Return any notices.
763 return $notices;
764 }
765
766 } // End of WP_Members_Admin_API class.
767
768 // End of file.