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

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