PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.2.3.7
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.2.3.7
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.3.7, at admin/class-admin.php

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