PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.2.17
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.2.17
1.2.72 1.2.71 1.2.70 1.2.69 1.2.68 1.2.67 1.2.66 1.2.65 1.2.64 1.2.63 trunk 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 1.0.22 1.0.23 All 172 releases
userswp / admin / class-admin.php

class-admin.php in UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP 1.2.17, at admin/class-admin.php

1,026 lines 36.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The admin-specific functionality of the plugin.
4 *
5 * @link http://wpgeodirectory.com
6 * @since 1.0.0
7 *
8 * @package userswp
9 * @subpackage userswp/admin
10 */
11
12 /**
13 * The admin-specific functionality of the plugin.
14 *
15 * Defines the plugin name, version, and two examples hooks for how to
16 * enqueue the admin-specific stylesheet and JavaScript.
17 *
18 * @package userswp
19 * @subpackage userswp/admin
20 * @author GeoDirectory Team <info@wpgeodirectory.com>
21 */
22 class UsersWP_Admin {
23
24 /**
25 * Register all of the hooks related to the admin area functionality
26 * of the plugin.
27 *
28 * @since 1.0.0
29 */
30 public function __construct() {
31 add_action( 'admin_init', array( $this, 'activation_redirect' ) );
32 add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) );
33 add_action( 'admin_init', array( $this, 'prevent_admin_access' ) );
34 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_styles' ) );
35 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
36 add_action( 'admin_notices', array( $this, 'show_update_messages' ) );
37 add_action( 'admin_footer', array( $this, 'admin_only_script' ) );
38 add_action( 'user_profile_picture_description', array( $this, 'user_profile_picture_description' ) );
39 add_action( 'admin_body_class', array( $this, 'admin_body_class' ) );
40 add_action( 'admin_init', array( $this, 'preview_emails' ) );
41
42 add_filter( 'views_users', array( $this, 'request_views_users' ) );
43 add_filter( 'pre_user_query', array( $this, 'request_users_filter' ) );
44 add_action( 'edit_user_profile', array( $this, 'get_profile_extra_edit' ), 10, 1 );
45 add_action( 'show_user_profile', array( $this, 'get_profile_extra_edit' ), 10, 1 );
46 add_filter( 'user_row_actions', array( $this, 'user_row_actions' ), 10, 2 );
47 add_action( 'bulk_actions-users', array( $this, 'users_bulk_actions' ) );
48 add_action( 'handle_bulk_actions-users', array( $this, 'handle_users_bulk_actions' ), 10, 3 );
49 add_filter( 'init', array( $this, 'process_user_actions' ) );
50 add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 2 );
51 add_filter( 'aui_screen_ids', array( $this, 'add_aui_screens' ), 20, 1 );
52
53 add_action( 'wp_ajax_uwp_ajax_create_register', array( $this, 'process_create_register_form' ) );
54 add_action( 'wp_ajax_uwp_ajax_update_register', array( $this, 'process_update_register_form' ) );
55 add_action( 'wp_ajax_uwp_ajax_remove_register', array( $this, 'process_remove_register_form' ) );
56
57 // Register with the deactivation survey class.
58 if(class_exists('AyeCode_Deactivation_Survey')){
59 AyeCode_Deactivation_Survey::instance(array(
60 'slug' => 'userswp',
61 'version' => USERSWP_VERSION,
62 'support_url'=> 'https://userswp.io/support/',
63 'documentation_url'=> 'https://docs.userswp.io/',
64 'activated' => get_option('uwp_installed_on', 0)
65 ));
66 }
67 }
68
69 /**
70 * Redirects to UsersWP info page after plugin activation.
71 *
72 * @return void
73 * @package userswp
74 * @since 1.0.0
75 */
76 public function activation_redirect() {
77 if ( get_option( 'uwp_activation_redirect', false ) ) {
78 delete_option( 'uwp_activation_redirect' );
79 update_option( "uwp_setup_wizard_notice", 1 );
80 wp_redirect( admin_url( 'index.php?page=uwp-setup' ) );
81 exit;
82 }
83
84 if ( ! empty( $_GET['force_sync_data'] ) && ! empty( $_GET['_nonce'] ) && wp_verify_nonce( sanitize_text_field( $_GET['_nonce'] ), 'force_sync_data' ) && current_user_can( 'manage_options' ) ) {
85 $blog_id = get_current_blog_id();
86 do_action( 'wp_' . $blog_id . '_uwp_updater_cron' );
87 wp_safe_redirect( admin_url( 'admin.php?page=userswp' ) );
88 exit;
89 }
90 }
91
92 /**
93 * Maybe show the AyeCode Connect Notice.
94 */
95 public function init_ayecode_connect_helper() {
96 // AyeCode Connect notice
97 if ( is_admin() ) {
98 // set the strings so they can be translated
99 $strings = array(
100 'connect_title' => __( "UsersWP - an AyeCode product!", "userswp" ),
101 'connect_external' => __( "Please confirm you wish to connect your site?", "userswp" ),
102 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s", "userswp" ), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", "</a>" ),
103 'connect_button' => __( "Connect Site", "userswp" ),
104 'connecting_button' => __( "Connecting...", "userswp" ),
105 'error_localhost' => __( "This service will only work with a live domain, not a localhost.", "userswp" ),
106 'error' => __( "Something went wrong, please refresh and try again.", "userswp" ),
107 );
108 new AyeCode_Connect_Helper( $strings, array( 'uwp-addons' ) );
109 }
110 }
111
112 /**
113 * Restrict the wp-admin area from specific user roles if set to do so.
114 */
115 public function prevent_admin_access() {
116 $restricted_roles = (array) uwp_get_option( 'admin_blocked_roles', array() );
117
118 // Checking action in request to allow ajax request go through
119 if ( ! empty ( $restricted_roles ) && is_user_logged_in() && ! wp_doing_ajax() && ! wp_doing_cron() ) {
120 $roles = wp_get_current_user()->roles;
121
122 $prevent = false;
123
124 // Always allow administrator role.
125 if ( ! ( ! empty( $roles ) && in_array( 'administrator', $roles ) ) ) {
126 foreach( $restricted_roles as $role ) {
127 if ( in_array( $role, $roles ) ) {
128 $prevent = true;
129 break;
130 }
131 }
132 }
133
134 /*
135 * Check and prevent admin access based on user role.
136 *
137 * @param bool $prevent True to prevent admin access.
138 */
139 $prevent = apply_filters( 'uwp_prevent_wp_admin_access', $prevent );
140
141 if ( $prevent ) {
142 wp_safe_redirect( home_url() );
143 exit;
144 }
145 }
146 }
147
148 /**
149 * Register the stylesheets for the admin area.
150 *
151 * @param $hook_suffix
152 *
153 * @since 1.0.0
154 */
155 public function enqueue_styles( $hook_suffix ) {
156 $screen = get_current_screen();
157 $screen_id = $screen ? $screen->id : '';
158
159 if ( $hook_suffix == 'profile.php' || $hook_suffix == 'user-edit.php' ) {
160 wp_register_style( 'jquery-ui', USERSWP_PLUGIN_URL . 'assets/css/jquery-ui.css' );
161 wp_enqueue_style( 'jquery-ui' );
162 wp_enqueue_style( 'jcrop' );
163 wp_enqueue_style( "uwp-country-select", USERSWP_PLUGIN_URL . 'assets/css/countryselect.css', array(), USERSWP_VERSION, 'all' );
164 wp_enqueue_style( "userswp", USERSWP_PLUGIN_URL . 'assets/css/users-wp.css', array(), USERSWP_VERSION, 'all' );
165 wp_enqueue_style( "uwp_timepicker_css", USERSWP_PLUGIN_URL . 'assets/css/jquery.ui.timepicker.css', array(), USERSWP_VERSION, 'all' );
166 }
167
168 if ( false !== strpos($hook_suffix, 'page_uwp_tools' )) {
169 wp_enqueue_style( "userswp", USERSWP_PLUGIN_URL . 'assets/css/users-wp.css', array(), USERSWP_VERSION, 'all' );
170 }
171
172 if ( false !== strpos($hook_suffix, 'page_uwp_form_builder' )) {
173 wp_enqueue_style( "uwp_form_builder", USERSWP_PLUGIN_URL . 'admin/assets/css/uwp-form-builder.css', array(), USERSWP_VERSION, 'all' );
174 }
175
176 if ( $hook_suffix == 'toplevel_page_userswp' ) {
177 wp_enqueue_style( 'wp-color-picker' );
178 }
179
180 if ( in_array( $screen_id, uwp_get_screen_ids() ) ) {
181 wp_enqueue_style( "userswp_admin_css", USERSWP_PLUGIN_URL . 'admin/assets/css/users-wp-admin.css', array(), USERSWP_VERSION, 'all' );
182 }
183
184 }
185
186 /**
187 * Register the JavaScript for the admin area.
188 *
189 * @param $hook_suffix
190 *
191 * @since 1.0.0
192 */
193 public function enqueue_scripts( $hook_suffix ) {
194
195 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
196 $screen = get_current_screen();
197 $screen_id = $screen ? $screen->id : '';
198
199 if ( $hook_suffix == 'profile.php' || $hook_suffix == 'user-edit.php' ) {
200
201 wp_enqueue_script( 'jquery-ui-datepicker', array( 'jquery' ) );
202 wp_enqueue_script( "uwp_timepicker", USERSWP_PLUGIN_URL . 'assets/js/jquery.ui.timepicker.min.js', array(
203 'jquery',
204 'jquery-ui-datepicker',
205 'jquery-ui-core'
206 ), USERSWP_VERSION );
207 wp_enqueue_script( "userswp", USERSWP_PLUGIN_URL . 'assets/js/users-wp' . $suffix . '.js', array( 'jquery' ), USERSWP_VERSION, false );
208 $uwp_localize_data = uwp_get_localize_data();
209 wp_localize_script( 'userswp', 'uwp_localize_data', $uwp_localize_data );
210 wp_enqueue_script( 'jquery-ui-progressbar', array( 'jquery' ) );
211 wp_enqueue_script( 'jcrop', array( 'jquery' ) );
212 wp_enqueue_script( "country-select", USERSWP_PLUGIN_URL . 'assets/js/countrySelect' . $suffix . '.js', array( 'jquery' ), USERSWP_VERSION );
213
214 $country_data = uwp_get_country_data();
215 wp_localize_script( USERSWP_NAME, 'uwp_country_data', $country_data );
216 }
217
218 if ( false !== strpos($hook_suffix, 'page_uwp_tools' )) {
219 wp_enqueue_script( 'jquery-ui-progressbar', array( 'jquery' ) );
220 }
221
222 if ( false !== strpos($hook_suffix, 'page_uwp_status' )) {
223 wp_enqueue_script( "uwp_status", USERSWP_PLUGIN_URL . 'admin/assets/js/system-status.js', array( 'jquery' ), USERSWP_VERSION, true );
224 }
225
226 if ( false !== strpos($hook_suffix, 'page_uwp_form_builder' )) {
227 wp_enqueue_script( 'jquery-ui-sortable' );
228 wp_enqueue_script( 'uwp-nestable-script', USERSWP_PLUGIN_URL . 'admin/assets/js/jquery.nestable' . $suffix . '.js', array( 'jquery-ui-sortable' ), USERSWP_VERSION );
229 wp_enqueue_script( "uwp_form_builder", USERSWP_PLUGIN_URL . 'admin/assets/js/uwp-form-builder' . $suffix . '.js', array(), USERSWP_VERSION, 'all' );
230 }
231
232 if ( in_array( $screen_id, uwp_get_screen_ids() ) ) {
233 wp_enqueue_script( "userswp_admin", USERSWP_PLUGIN_URL . 'admin/assets/js/users-wp-admin' . $suffix . '.js', array( 'jquery' ), USERSWP_VERSION, false );
234
235 wp_enqueue_script( "jquery-ui-tooltip" );
236 wp_enqueue_script( 'wp-color-picker' );
237
238 $ajax_cons_data = array(
239 'url' => admin_url( 'admin-ajax.php' ),
240 'custom_field_not_blank_var' => __( 'Field key must not be blank', 'userswp' ),
241 'custom_field_options_not_blank_var' => __( 'Option Values must not be blank', 'userswp' ),
242 'custom_field_not_special_char' => __( 'Please do not use special character and spaces in field key.', 'userswp' ),
243 'custom_field_unique_name' => __( 'Field key should be a unique name.', 'userswp' ),
244 'custom_field_delete' => __( 'Are you sure you wish to delete this field?', 'userswp' ),
245 'custom_field_id_required' => __( 'This field is required.', 'userswp' ),
246 'img_spacer' => admin_url( 'images/media-button-image.gif' ),
247 'txt_choose_image' => __( 'Choose an image', 'userswp' ),
248 'txt_use_image' => __( 'Use image', 'userswp' ),
249 'delete_register_form' => __( 'Are you sure you wish to delete this form?', 'userswp' ),
250 'ask_register_form_title' => __( 'Enter register form title', 'userswp' ),
251 'form_updated_msg' => __( 'Updated! Reloading page...', 'userswp' )
252 );
253 wp_localize_script( "userswp_admin", 'uwp_admin_ajax', $ajax_cons_data );
254 }
255
256 }
257
258 public function get_screen_ids(){
259 return uwp_get_screen_ids();
260 }
261
262 /**
263 * Displays update messages
264 */
265 public function show_update_messages() {
266 if ( ! isset( $_REQUEST['update'] ) ) {
267 return;
268 }
269
270 $update = sanitize_text_field( $_REQUEST['update'] );
271 $messages = array();
272
273 switch ( $update ) {
274 case 'uwp_resend':
275 $messages['msg'] = __( 'Activation email has been sent!', 'userswp' );
276 break;
277 case 'err_uwp_resend':
278 $messages['err_msg'] = __( 'Error while sending activation email. Please try again.', 'userswp' );
279 break;
280 case 'uwp_activate_user':
281 $messages['msg'] = __( 'User(s) has been activated!', 'userswp' );
282 break;
283 }
284
285 if ( ! empty( $messages ) ) {
286 if ( isset( $messages['err_msg'] ) ) {
287 echo '<div class="notice notice-error"><p>' . esc_html( $messages['err_msg'] ) . '</p></div>';
288 } else {
289 echo '<div class="notice notice-success is-dismissible"><p>' . esc_html( $messages['msg'] ) . '</p></div>';
290 }
291 }
292 }
293
294 /**
295 * Adds UsersWP JS to admin area.
296 *
297 * @return void
298 * @package userswp
299 *
300 * @since 1.0.0
301 */
302 public function admin_only_script() {
303
304 // check page is userswp or not.
305 if ( ! empty( $_GET['page'] ) && 'userswp' == $_GET['page']) {
306
307 // check tab is general or not.
308 if ( ! empty( $_GET['tab'] ) && 'general' == $_GET['tab']) {
309
310 // check for login section.
311 if ( ! empty( $_GET['section'] ) && 'login' == $_GET['section'] ) {
312 ?>
313 <script type="text/javascript">
314 jQuery(document).ready(function () {
315 var login_redirect_to = jQuery('#login_redirect_to');
316 login_redirect_to.on('change', function () {
317 var value = jQuery(this).val();
318 var login_redirect_custom_obj = jQuery('#login_redirect_custom_url');
319
320 if ('-2' === value) {
321 login_redirect_custom_obj.parent().parent().show();
322 } else {
323 login_redirect_custom_obj.parent().parent().hide();
324 }
325 }).change();
326 });
327 </script>
328 <?php
329 }
330 }
331
332 }
333
334 if(! empty( $_GET['page'] ) && 'uwp_form_builder' == $_GET['page']) {
335 ?>
336 <script type="text/javascript">
337 jQuery(document).ready(function () {
338 var uwp_registration_action = jQuery('#uwp_registration_action');
339 uwp_registration_action.on('change', function () {
340 var value = jQuery(this).val();
341 var register_redirect_obj = jQuery('#register_redirect_to');
342
343 if ('auto_approve_login' === value) {
344 register_redirect_obj.parent().parent().show();
345 } else {
346 register_redirect_obj.parent().parent().hide();
347 }
348 }).change();
349
350 var register_redirect_to = jQuery('#register_redirect_to');
351 register_redirect_to.on('change', function () {
352 var value = jQuery(this).val();
353 var register_redirect_custom_obj = jQuery('#register_redirect_custom_url');
354
355 if ('-2' === value) {
356 register_redirect_custom_obj.parent().show();
357 register_redirect_custom_obj.parent().prev().show();
358 } else {
359 register_redirect_custom_obj.parent().hide();
360 register_redirect_custom_obj.parent().prev().hide();
361 }
362 }).change();
363 });
364 </script>
365 <?php
366 }
367
368 }
369
370 /**
371 * Filters the user profile picture description displayed under the Gravatar.
372 *
373 * @param string $description Profile picture description.
374 *
375 * @return string Modified description.
376 * @since 1.0.0
377 * @package userswp
378 *
379 */
380 public function user_profile_picture_description( $description ) {
381 if ( is_admin() && IS_PROFILE_PAGE ) {
382 $user_id = get_current_user_id();
383 $avatar = uwp_get_usermeta( $user_id, 'avatar_thumb', '' );
384
385 if ( ! empty( $avatar ) ) {
386 $description = sprintf( __( 'You can change your profile picture on your <a href="%s">Profile Page</a>.', 'userswp' ),
387 uwp_build_profile_tab_url( $user_id ) );
388 }
389
390 }
391
392 return $description;
393 }
394
395 public function admin_body_class( $classes ) {
396 $screen = get_current_screen();
397 if ( 'profile' == $screen->base || 'user-edit' == $screen->base ) {
398 $classes .= ' uwp_page';
399 }
400
401 // Add original UsersWP page class when UsersWP screen is translated.
402 if ( ! empty( $_GET['page'] ) && in_array( $_GET['page'], array( 'uwp_form_builder', 'uwp_tools', 'uwp_status', 'uwp-addons' ) ) ) {
403 $uwp_screen_id = sanitize_title( __( 'UsersWP', 'userswp' ) );
404
405 if ( $uwp_screen_id != 'userswp' ) {
406 $classes .= ' userswp_page_' . esc_attr( sanitize_text_field( $_GET['page'] ) );
407 }
408 }
409
410 // Add body class for admin pages.
411 $screen = get_current_screen();
412 $screen_id = $screen ? $screen->id : '';
413
414 if ( $screen_id && in_array( $screen_id, uwp_get_screen_ids() ) ) {
415 $classes .= ' uwp-admin-page uwp-admin-page-' . sanitize_key( $screen_id );
416 }
417
418 return $classes;
419 }
420
421 /**
422 * Preview email template for UWP emails.
423 */
424 public function preview_emails() {
425 if ( isset( $_GET['uwp_preview_mail'] ) ) {
426 if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'uwp-preview-mail' ) ) {
427 die( 'Security check failed.' );
428 }
429
430 $email_name = 'preview_mail';
431 $email_vars = array();
432 $plain_text = UsersWP_Mails::get_email_type() != 'html' ? true : false;
433
434 // Get the preview email content.
435 ob_start();
436 include( 'views/html-email-template-preview.php' );
437 $message = ob_get_clean();
438
439 $message = UsersWP_Mails::email_wrap_message( $message, $email_name, $email_vars, '', $plain_text );
440 $message = UsersWP_Mails::style_body( $message, $email_name, $email_vars );
441 $message = apply_filters( 'uwp_mail_content', $message, $email_name, $email_vars );
442
443 // Print the preview email content.
444 if ( $plain_text ) {
445 echo '<div style="white-space:pre-wrap;font-family:sans-serif">';
446 }
447 echo $message; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
448 if ( $plain_text ) {
449 echo '</div>';
450 }
451 exit;
452 }
453 }
454
455 /**
456 * Returns user views filter
457 *
458 * @return array User views.
459 */
460 public function request_views_users( $views ) {
461
462 $current = '';
463
464 if ( isset( $_REQUEST['uwp_status'] ) && $_REQUEST['uwp_status'] == 'pending-email-activate' ) {
465 $views['all'] = str_replace( 'current', '', $views['all'] );
466 $current = 'current';
467 }
468
469 $views['pending-email-activate'] = '<a href="' . admin_url( 'users.php' ) . '?uwp_status=pending-email-activate" class="' . $current . '">' . __( 'Pending Email Activation', 'userswp' ) . ' <span class="count">(' . $this->uwp_pending_email_count() . ')</span></a>';
470
471 return $views;
472 }
473
474 /**
475 * Returns pending email activation user counts
476 *
477 * @return int User count
478 */
479 public function uwp_pending_email_count() {
480
481 $args = array(
482 'fields' => 'ID',
483 'number' => 0,
484 'meta_query' => array(
485 array(
486 'key' => 'uwp_mod',
487 'value' => 'email_unconfirmed',
488 'compare' => '='
489 )
490 )
491 );
492 $users = new WP_User_Query( $args );
493
494 return isset( $users->results ) ? (int) count( $users->results ) : 0;
495 }
496
497 /**
498 * Filter to modify the user query
499 *
500 * @return object User query.
501 */
502 public function request_users_filter( $query ) {
503
504 global $wpdb, $pagenow;
505
506 if ( is_admin() && $pagenow == 'users.php' && isset( $_GET['uwp_status'] ) && $_GET['uwp_status'] != '' ) {
507
508 do_action('uwp_users_show_pending_email_activation', $query);
509
510 $status = sanitize_text_field( urldecode( $_GET['uwp_status'] ) );
511
512 if ( $status == 'pending-email-activate' ) {
513 $query->query_where = str_replace( 'WHERE 1=1',
514 "WHERE 1=1 AND {$wpdb->users}.ID IN (
515 SELECT {$wpdb->usermeta}.user_id FROM $wpdb->usermeta
516 WHERE {$wpdb->usermeta}.meta_key = 'uwp_mod'
517 AND {$wpdb->usermeta}.meta_value = 'email_unconfirmed')",
518 $query->query_where
519 );
520 }
521 }
522
523 return $query;
524 }
525
526 /**
527 * Gets UsersWP fields in WP-Admin Users Edit page.
528 *
529 * @param object $user User Object.
530 *
531 * @package userswp
532 * @since 1.0.0
533 */
534 public function get_profile_extra_edit( $user ) {
535 global $wpdb;
536 $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
537 $form_id = uwp_get_register_form_id( $user->ID );
538 $excluded_fields = apply_filters( 'uwp_exclude_edit_profile_fields', array('bio', 'register_gdpr', 'register_tos', 'uwp_language', 'multisite_site_title', 'multisite_site_address') );
539 $query = $wpdb->prepare("SELECT * FROM " . $table_name . " WHERE form_type = 'account' AND is_default = '0' AND form_id = %d", $form_id);
540 if ( is_array( $excluded_fields ) && count( $excluded_fields ) > 0 ) {
541 $query .= " AND htmlvar_name NOT IN ('" . implode( "','", $excluded_fields ) . "')";
542 }
543 $query .= ' ORDER BY sort_order ASC';
544 $fields = $wpdb->get_results( $query ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
545
546 $this->edit_profile_banner_fields( $user ); // Displays avatar and banner fields
547
548 if ( $fields ) {
549 ?>
550 <div class="uwp-profile-extra">
551 <table class="uwp-profile-extra-table form-table bsui">
552 <?php
553 foreach ( $fields as $field ) {
554
555 if(isset($field->css_class) && !empty($field->css_class)){
556 $field->css_class = $field->css_class.' w-50';
557 } else {
558 $field->css_class = 'w-50';
559 }
560
561 if ( $field->field_type == 'fieldset' ) {
562 ?>
563 <tr style="margin: 0; padding: 0">
564 <th class="uwp-profile-extra-key" style="margin: 0; padding: 0"><h3
565 style="margin: 10px 0;"><?php echo esc_html( $field->site_title ); ?></h3></th>
566 <td></td>
567 </tr>
568 <?php
569 } else { ?>
570 <tr>
571 <th class="uwp-profile-extra-key"><?php echo esc_html( $field->site_title ); ?></th>
572 <td class="uwp-profile-extra-value">
573 <?php
574 $templates_obj = new UsersWP_Templates();
575 $templates_obj->template_fields_html( $field, 'account', $user->ID ); ?>
576 </td>
577 </tr>
578 <?php
579 }
580 }
581 ?>
582 </table>
583 </div>
584 <?php
585 }
586 }
587
588 /**
589 * Adds avatar and banner fields in admin side.
590 *
591 * @param object $user User object.
592 *
593 * @return void
594 * @since 1.0.0
595 * @package userswp
596 *
597 */
598 public function edit_profile_banner_fields( $user ) {
599 global $wpdb;
600
601 $file_obj = new UsersWP_Files();
602
603 $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
604 $fields = $wpdb->get_results( "SELECT * FROM " . $table_name . " WHERE (form_type = 'avatar' OR form_type = 'banner') ORDER BY sort_order ASC" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
605 if ( $fields ) {
606 ?>
607 <div class="uwp-profile-extra uwp_page">
608 <?php do_action( 'uwp_admin_profile_edit', $user ); ?>
609 <h2><?php esc_html_e('UsersWP Account Details', 'userswp'); ?></h2>
610 <table class="uwp-profile-extra-table form-table">
611 <?php
612 foreach ( $fields as $field ) {
613
614 if ( $field->field_type == 'fieldset' ) {
615 ?>
616 <tr style="margin: 0; padding: 0">
617 <th class="uwp-profile-extra-key" style="margin: 0; padding: 0"><h3
618 style="margin: 10px 0;">
619 <?php echo esc_html( $field->site_title ); ?></h3></th>
620 <td></td>
621 </tr>
622 <?php
623 } else { ?>
624 <tr>
625 <th class="uwp-profile-extra-key"><?php echo esc_html( $field->site_title ); ?></th>
626 <td class="uwp-profile-extra-value">
627 <?php
628 if ( $field->htmlvar_name == "avatar" ) {
629 $value = uwp_get_usermeta( $user->ID, "avatar_thumb", "" );
630 } elseif ( $field->htmlvar_name == "banner" ) {
631 $value = uwp_get_usermeta( $user->ID, "banner_thumb", "" );
632 } else {
633 $value = "";
634 }
635
636 echo $file_obj->file_upload_preview( $field, $value ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
637
638 if ( $field->htmlvar_name == "avatar" ) {
639 if ( ! empty( $value ) ) {
640 $label = __( "Change Avatar", "userswp" );
641 } else {
642 $label = __( "Upload Avatar", "userswp" );
643 }
644 ?>
645 <a onclick="uwp_profile_image_change('avatar');return false;" href="#"
646 class="uwp-banner-change-icon-admin">
647 <?php echo esc_html( $label ); ?>
648 </a>
649 <?php
650 } elseif ( $field->htmlvar_name == "banner" ) {
651 if ( ! empty( $value ) ) {
652 $label = __( "Change Banner", "userswp" );
653 } else {
654 $label = __( "Upload Banner", "userswp" );
655 } ?>
656 <a onclick="uwp_profile_image_change('banner');return false;" href="#"
657 class="uwp-banner-change-icon-admin">
658 <?php echo esc_html( $label ); ?>
659 </a>
660 <?php
661 }
662 ?>
663 </td>
664 </tr>
665 <?php
666 }
667 }
668 ?>
669 </table>
670 </div>
671 <?php
672 }
673 }
674
675 /**
676 * Returns user row actions
677 *
678 * @param array $actions Date string.
679 * @param object $user_object The User ID.
680 *
681 * @return array Row actions.
682 * @package userswp
683 *
684 */
685 public function user_row_actions( $actions, $user_object ) {
686 $user_id = $user_object->ID;
687 $mod_value = get_user_meta( $user_id, 'uwp_mod', true );
688 $resend_link = add_query_arg(
689 array(
690 'user_id' => $user_id,
691 'action' => 'uwp_resend',
692 '_nonce' => wp_create_nonce( 'uwp_resend' ),
693 'uwp_is_admin' => 1,
694 ),
695 admin_url( 'users.php' )
696 );
697
698 $activate_link = add_query_arg(
699 array(
700 'user_id' => $user_id,
701 'action' => 'uwp_activate_user',
702 '_nonce' => wp_create_nonce( 'uwp_activate_user' ),
703 'uwp_is_admin' => 1,
704 ),
705 admin_url( 'users.php' )
706 );
707
708 if ( $mod_value == 'email_unconfirmed' ) {
709 $actions['uwp_resend_activation'] = "<a class='' href='" . $resend_link . "'>" . __( 'Resend Activation', 'userswp' ) . "</a>";
710 $actions['uwp_auto_activate'] = "<a class='' href='" . $activate_link . "'>" . __( 'Activate User', 'userswp' ) . "</a>";
711 }
712
713 return $actions;
714 }
715
716 /**
717 * Returns users bulk actions
718 *
719 * @param array $bulk_actions Bulk actions.
720 *
721 * @return array Bulk actions.
722 * @package userswp
723 *
724 */
725 public function users_bulk_actions( $bulk_actions ) {
726 $bulk_actions['uwp_resend'] = __( 'Resend Activation', 'userswp' );
727 $bulk_actions['uwp_activate_user'] = __( 'Activate Users', 'userswp' );
728
729 return $bulk_actions;
730 }
731
732 /**
733 * Handles users bulk actions
734 *
735 * @param string $redirect_to Bulk actions.
736 * @param string $doaction Current action.
737 * @param array $user_ids User IDs to process.
738 *
739 * @return string Redirect URL.
740 * @package userswp
741 *
742 */
743 public function handle_users_bulk_actions( $redirect_to, $doaction, $user_ids ) {
744 if ( 'uwp_resend' == $doaction ) {
745 foreach ( $user_ids as $user_id ) {
746 uwp_resend_activation_mail( $user_id );
747 }
748
749 $redirect_to = add_query_arg( 'update', 'uwp_resend', $redirect_to );
750 } elseif ( 'uwp_activate_user' == $doaction ) {
751 foreach ( $user_ids as $user_id ) {
752 $this->activate_user( $user_id );
753 }
754 $redirect_to = add_query_arg( 'update', 'uwp_activate_user', $redirect_to );
755 }
756
757 return $redirect_to;
758 }
759
760 /**
761 * Activates user
762 *
763 * @param int $user_id User ID
764 *
765 * @return bool
766 */
767 public function activate_user( $user_id = 0 ) {
768 if ( ! $user_id ) {
769 return false;
770 }
771
772 $uwp_mode = get_user_meta( $user_id, 'uwp_mod', true );
773 if ( 'email_unconfirmed' == $uwp_mode ) {
774 delete_user_meta( $user_id, 'uwp_mod' );
775 do_action( 'uwp_email_activation_success', $user_id );
776 }
777
778 return true;
779 }
780
781 /**
782 * Processes user action
783 *
784 * @return mixed
785 * @package userswp
786 *
787 */
788 public function process_user_actions() {
789 $user_id = isset( $_REQUEST['user_id'] ) ? (int) $_REQUEST['user_id'] : 0;
790 $action = isset( $_REQUEST['action'] ) ? sanitize_text_field($_REQUEST['action']) : false;
791 $nonce = isset( $_REQUEST['_nonce'] ) ? sanitize_text_field($_REQUEST['_nonce']) : false;
792 $is_admin = isset( $_REQUEST['uwp_is_admin'] ) ? sanitize_text_field($_REQUEST['uwp_is_admin']) : false;
793
794 if ( $user_id && 'uwp_resend' == $action && !empty($nonce) && wp_verify_nonce( $nonce, 'uwp_resend' ) ) {
795 uwp_resend_activation_mail( $user_id );
796 if ( isset($is_admin) && $is_admin ) {
797 wp_redirect( add_query_arg( 'update', 'uwp_resend', admin_url( 'users.php' ) ) );
798 exit();
799 } else {
800 global $uwp_notices;
801 $message = __( 'Activation email has been sent!', 'userswp' );
802 $uwp_notices[] = aui()->alert( array(
803 'type' => 'success',
804 'content' => $message
805 ) );
806 }
807 } elseif ( $user_id && 'uwp_activate_user' == $action && wp_verify_nonce( $nonce, 'uwp_activate_user' ) ) {
808 if ( isset($is_admin) && $is_admin && current_user_can( 'edit_users' ) ) {
809 $this->activate_user( $user_id );
810 wp_redirect( add_query_arg( 'update', 'uwp_activate_user', admin_url( 'users.php' ) ) );
811 }
812 }
813 }
814
815 /**
816 * Show row meta on the plugin screen.
817 *
818 * @param mixed $links Plugin Row Meta
819 * @param mixed $file Plugin Base file
820 * @return array
821 */
822 public static function plugin_row_meta( $links, $file ) {
823 if ( USERSWP_PLUGIN_BASENAME == $file ) {
824 $row_meta = array(
825 'docs' => '<a href="' . esc_url( 'https://docs.userswp.io/' ) . '" aria-label="' . esc_attr__( 'View UsersWP Documentation', 'userswp' ) . '">' . esc_html__( 'Docs', 'userswp' ) . '</a>',
826 'support' => '<a href="' . esc_url( 'https://userswp.io/support/' ) . '" aria-label="' . esc_attr__( 'Visit UsersWP support', 'userswp' ) . '">' . esc_html__( 'Support', 'userswp' ) . '</a>',
827 'translation' => '<a href="' . esc_url( 'https://userswp.io/translate/projects' ) . '" aria-label="' . esc_attr__( 'View translations', 'userswp' ) . '">' . esc_html__( 'Translations', 'userswp' ) . '</a>',
828 );
829
830 return array_merge( $links, $row_meta );
831 }
832
833 return (array) $links;
834 }
835
836 public function process_create_register_form() {
837
838 if ( ! current_user_can( 'manage_options' ) ) {
839 wp_die( -1 );
840 }
841
842 $type = ! empty( $_POST['type'] ) ? sanitize_text_field($_POST['type']) : '';
843 $form_title = ! empty( $_POST['form_title'] ) ? sanitize_title_with_dashes($_POST['form_title']) : '';
844 $nonce = ! empty( $_POST['nonce'] ) ? sanitize_text_field($_POST['nonce']) : '';
845
846 $status = false;
847 $message = __( 'Something went wrong. Please try again.', 'userswp' );
848 $redirect = '';
849 if ( ! empty( $type ) && $type == 'create' && ! empty( $nonce ) && wp_verify_nonce( $nonce, 'uwp-create-register-form-nonce' ) ) {
850
851 $get_register_forms = uwp_get_option( 'multiple_registration_forms' );
852 $new_form_id = uwp_get_next_register_form_id();
853
854 if ( ! empty( $new_form_id ) ) {
855
856 $get_register_forms[] = array(
857 'id' => $new_form_id,
858 'title' => ! empty( $form_title ) ? sanitize_text_field( $form_title ) : sprintf( __( 'Form %d', 'userswp' ), $new_form_id ),
859 );
860
861 uwp_update_option( 'multiple_registration_forms', $get_register_forms );
862
863 $fields = UsersWP_Activator::uwp_default_custom_fields_account();
864 $form_builder = new UsersWP_Form_Builder();
865
866 if(isset($fields) && count($fields) > 0){
867 foreach ($fields as $field_index => $field) {
868 $field['form_id'] = $new_form_id;
869 $form_builder->admin_form_field_save($field);
870 }
871 }
872
873 UsersWP_Activator::insert_form_extras($new_form_id);
874
875 do_action('uwp_create_register_form', $new_form_id);
876
877 $status = true;
878 $redirect = admin_url( 'admin.php?page=uwp_form_builder&tab=account&form=' . $new_form_id );
879 }
880 }
881
882 $response = array(
883 'status' => $status,
884 'message' => $message,
885 'redirect' => $redirect,
886 );
887
888 echo json_encode( $response );
889 wp_die();
890 }
891
892 public function process_update_register_form() {
893
894 check_ajax_referer( 'uwp-update-register-form-nonce', 'uwp_update_register_form_nonce' );
895
896 if ( ! current_user_can( 'manage_options' ) ) {
897 wp_die( -1 );
898 }
899
900 $type = ! empty( $_POST['type'] ) ? sanitize_text_field($_POST['type']) : '';
901 $form_id = ! empty( $_POST['manage_field_form_id'] ) ? (int)$_POST['manage_field_form_id'] : '';
902 $form_title = ! empty( $_POST['form_title'] ) ? sanitize_text_field($_POST['form_title']) : __( 'Form', 'userswp' );
903 $user_role = ! empty( $_POST['user_role'] ) ? sanitize_text_field($_POST['user_role']) : '';
904 $action = ! empty( $_POST['reg_action'] ) ? sanitize_text_field($_POST['reg_action']) : uwp_get_option( 'uwp_registration_action', 'auto_approve' );
905 $redirect_to = (int) $_POST['redirect_to'];
906 $custom_url = ! empty( $_POST['custom_url'] ) ? sanitize_text_field($_POST['custom_url']) : '';
907 $gdpr_page = ! empty( $_POST['gdpr_page'] ) ? (int)$_POST['gdpr_page'] : (int)uwp_get_option('register_gdpr_page', false);
908 $tos_page = ! empty( $_POST['tos_page'] ) ? (int)$_POST['tos_page'] : (int)uwp_get_option('register_terms_page', false);
909
910 $status = false;
911 $message = __( 'Something went wrong. Please try again.', 'userswp' );
912 if ( ! empty( $type ) && ! empty( $form_id ) && $type === 'update' ) {
913
914 $register_forms = uwp_get_option( 'multiple_registration_forms' );
915
916 if ( ! empty( $register_forms ) && is_array( $register_forms ) ) {
917
918 foreach ( $register_forms as $key => $register_form ) {
919
920 if ( ! empty( $register_form['id'] ) && $register_form['id'] == $form_id ) {
921 $status = true;
922 $register_forms[ $key ]['title'] = $form_title;
923 $register_forms[ $key ]['user_role'] = $user_role;
924 $register_forms[ $key ]['reg_action'] = $action;
925 $register_forms[ $key ]['redirect_to'] = $redirect_to;
926 $register_forms[ $key ]['custom_url'] = $custom_url;
927 $register_forms[ $key ]['gdpr_page'] = $gdpr_page;
928 $register_forms[ $key ]['tos_page'] = $tos_page;
929 }
930 }
931 }
932
933 $register_forms = array_values( $register_forms );
934 $register_forms = apply_filters('uwp_multiple_registration_forms_update', $register_forms);
935 uwp_update_option( 'multiple_registration_forms', $register_forms );
936 }
937
938 $response = array(
939 'status' => $status,
940 'message' => $message,
941 );
942
943 echo json_encode( $response );
944 wp_die();
945 }
946
947 public function process_remove_register_form() {
948
949 check_ajax_referer( 'uwp-delete-register-form-nonce', 'nonce' );
950
951 if ( ! current_user_can( 'manage_options' ) ) {
952 wp_die( -1 );
953 }
954
955 global $wpdb;
956 $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
957
958 $type = ! empty( $_POST['type'] ) ? sanitize_text_field($_POST['type']) : '';
959 $form_id = ! empty( $_POST['form_id'] ) ? (int)$_POST['form_id'] : '';
960
961 $status = false;
962 $message = __( 'Security nonce failed. Please try again.', 'userswp' );
963 $redirect = '';
964 if ( ! empty( $type ) && ! empty( $form_id ) && $type === 'remove' ) {
965
966 $register_forms = uwp_get_option( 'multiple_registration_forms' );
967 $form_builder = new UsersWP_Form_Builder();
968
969 if ( ! empty( $register_forms ) && is_array( $register_forms ) ) {
970
971 foreach ( $register_forms as $key => $register_form ) {
972
973 if ( ! empty( $register_form['id'] ) && $register_form['id'] == $form_id ) {
974 $status = true;
975 unset( $register_forms[ $key ] );
976 $fields = $wpdb->get_results( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
977 $wpdb->prepare(
978 "select id from " . $table_name . " where form_type = %s AND form_id = %d order by sort_order asc",
979 array('account', $form_id)
980 )
981 );
982
983 if (!empty($fields)) {
984 foreach ($fields as $field) {
985 $form_builder->admin_form_field_delete($field->id, false, $form_id);
986 }
987 }
988 }
989 }
990 }
991
992 $register_forms = array_values( $register_forms );
993 uwp_update_option( 'multiple_registration_forms', $register_forms );
994 $redirect = admin_url( 'admin.php?page=uwp_form_builder&tab=account' );
995 }
996
997 $response = array(
998 'status' => $status,
999 'message' => $message,
1000 'redirect' => $redirect,
1001 );
1002
1003 echo json_encode( $response );
1004 wp_die();
1005 }
1006
1007 /**
1008 * Tell AyeCode UI to load on certain admin pages.
1009 *
1010 * @since 1.2.3.22
1011 *
1012 * @param array $screen_ids Screen IDs.
1013 * @return array Screen IDs.
1014 */
1015 public function add_aui_screens( $screen_ids ) {
1016 // Load on these pages if set
1017 if ( is_admin() && ! wp_doing_ajax() ) {
1018 $screen_ids = array_merge( $screen_ids, uwp_get_screen_ids() );
1019 }
1020
1021 // AUI is also needed for setup wizard.
1022 $screen_ids[] = 'uwp-setup';
1023
1024 return $screen_ids;
1025 }
1026 }