PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.2.16
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.2.16
1.2.73 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 All 173 releases
← All changes | admin/class-admin.php +257 -646 1.2.641.2.16 View file →
@@ -49,35 +49,21 @@
49 49 add_filter( 'init', array( $this, 'process_user_actions' ) );
50 50 add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 2 );
51 51 add_filter( 'aui_screen_ids', array( $this, 'add_aui_screens' ), 20, 1 );
52 52
53 - add_action( 'admin_notices', array( $this, 'add_user_type_updated_notice' ) );
54 - add_action( 'manage_users_extra_tablenav', array( $this, 'add_bulk_user_type_dropdown' ) );
55 - add_action( 'admin_init', array( $this, 'handle_bulk_user_type_change' ) );
56 - add_action( 'admin_footer', array( $this, 'add_validation_script' ) );
57 - add_filter( 'manage_users_columns', array( $this, 'add_user_type_column' ) );
58 - add_action( 'manage_users_custom_column', array( $this, 'display_user_type_column' ), 10, 3 );
59 - add_action( 'edit_user_profile', array( $this, 'display_admin_change_user_type' ), 10, 1 );
60 - add_action( 'show_user_profile', array( $this, 'display_admin_change_user_type' ), 10, 1 );
61 - add_action( 'personal_options_update', array( $this, 'update_user_type' ) );
62 - add_action( 'edit_user_profile_update', array( $this, 'update_user_type' ) );
63 -
64 53 add_action( 'wp_ajax_uwp_ajax_create_register', array( $this, 'process_create_register_form' ) );
65 54 add_action( 'wp_ajax_uwp_ajax_update_register', array( $this, 'process_update_register_form' ) );
66 - add_action( 'wp_ajax_uwp_ajax_remove_user_type', array( $this, 'process_remove_register_form' ) );
67 - add_action( 'wp_ajax_uwp_ajax_reorder_user_types', array( $this, 'reorder_user_types' ) );
55 + add_action( 'wp_ajax_uwp_ajax_remove_register', array( $this, 'process_remove_register_form' ) );
68 56
69 57 // Register with the deactivation survey class.
70 - if ( class_exists( 'AyeCode_Deactivation_Survey' ) ) {
71 - AyeCode_Deactivation_Survey::instance(
72 - array(
73 - 'slug' => 'userswp',
74 - 'version' => USERSWP_VERSION,
75 - 'support_url' => 'https://userswp.io/support/',
76 - 'documentation_url' => 'https://userswp.io/documentation/',
77 - 'activated' => get_option( 'uwp_installed_on', 0 ),
78 - )
79 - );
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 + ));
80 66 }
81 67 }
82 68
83 69 /**
@@ -89,9 +75,9 @@
89 75 */
90 76 public function activation_redirect() {
91 77 if ( get_option( 'uwp_activation_redirect', false ) ) {
92 78 delete_option( 'uwp_activation_redirect' );
93 - update_option( 'uwp_setup_wizard_notice', 1 );
79 + update_option( "uwp_setup_wizard_notice", 1 );
94 80 wp_redirect( admin_url( 'index.php?page=uwp-setup' ) );
95 81 exit;
96 82 }
97 83
@@ -110,15 +96,15 @@
110 96 // AyeCode Connect notice
111 97 if ( is_admin() ) {
112 98 // set the strings so they can be translated
113 99 $strings = array(
114 - 'connect_title' => __( 'UsersWP - an AyeCode product!', 'userswp' ),
115 - 'connect_external' => __( 'Please confirm you wish to connect your site?', 'userswp' ),
116 - 'connect' => sprintf( __( '<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %1$slearn more%2$s', 'userswp' ), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", '</a>' ),
117 - 'connect_button' => __( 'Connect Site', 'userswp' ),
118 - 'connecting_button' => __( 'Connecting...', 'userswp' ),
119 - 'error_localhost' => __( 'This service will only work with a live domain, not a localhost.', 'userswp' ),
120 - 'error' => __( 'Something went wrong, please refresh and try again.', 'userswp' ),
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" ),
121 107 );
122 108 new AyeCode_Connect_Helper( $strings, array( 'uwp-addons' ) );
123 109 }
124 110 }
@@ -129,18 +115,9 @@
129 115 public function prevent_admin_access() {
130 116 $restricted_roles = (array) uwp_get_option( 'admin_blocked_roles', array() );
131 117
132 118 // Checking action in request to allow ajax request go through
133 - if ( ! empty( $restricted_roles ) && is_user_logged_in() && ! wp_doing_ajax() && ! wp_doing_cron() ) {
134 - $action = ! empty( $_POST['action'] ) ? sanitize_text_field( wp_unslash( $_POST['action'] ) ) : '';
135 -
136 - /*
137 - * Prevent conflicts with MailPoet plugin.
138 - */
139 - if ( in_array( $action, array( 'mailpoet_subscription_update' ) ) ) {
140 - return;
141 - }
142 -
119 + if ( ! empty ( $restricted_roles ) && is_user_logged_in() && ! wp_doing_ajax() && ! wp_doing_cron() ) {
143 120 $roles = wp_get_current_user()->roles;
144 121
145 122 $prevent = false;
146 123
@@ -145,9 +122,9 @@
145 122 $prevent = false;
146 123
147 124 // Always allow administrator role.
148 125 if ( ! ( ! empty( $roles ) && in_array( 'administrator', $roles ) ) ) {
149 - foreach ( $restricted_roles as $role ) {
126 + foreach( $restricted_roles as $role ) {
150 127 if ( in_array( $role, $roles ) ) {
151 128 $prevent = true;
152 129 break;
153 130 }
@@ -182,19 +159,19 @@
182 159 if ( $hook_suffix == 'profile.php' || $hook_suffix == 'user-edit.php' ) {
183 160 wp_register_style( 'jquery-ui', USERSWP_PLUGIN_URL . 'assets/css/jquery-ui.css' );
184 161 wp_enqueue_style( 'jquery-ui' );
185 162 wp_enqueue_style( 'jcrop' );
186 - wp_enqueue_style( 'uwp-country-select', USERSWP_PLUGIN_URL . 'assets/css/countryselect.css', array(), USERSWP_VERSION, 'all' );
187 - wp_enqueue_style( 'userswp', USERSWP_PLUGIN_URL . 'assets/css/users-wp.css', array(), USERSWP_VERSION, 'all' );
188 - wp_enqueue_style( 'uwp_timepicker_css', USERSWP_PLUGIN_URL . 'assets/css/jquery.ui.timepicker.css', array(), USERSWP_VERSION, 'all' );
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' );
189 166 }
190 167
191 - if ( false !== strpos( $hook_suffix, 'page_uwp_tools' ) ) {
192 - wp_enqueue_style( 'userswp', USERSWP_PLUGIN_URL . 'assets/css/users-wp.css', array(), USERSWP_VERSION, 'all' );
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' );
193 170 }
194 171
195 - if ( false !== strpos( $hook_suffix, 'page_uwp_form_builder' ) ) {
196 - wp_enqueue_style( 'uwp_form_builder', USERSWP_PLUGIN_URL . 'admin/assets/css/uwp-form-builder.css', array(), USERSWP_VERSION, 'all' );
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' );
197 174 }
198 175
199 176 if ( $hook_suffix == 'toplevel_page_userswp' ) {
200 177 wp_enqueue_style( 'wp-color-picker' );
@@ -200,10 +177,11 @@
200 177 wp_enqueue_style( 'wp-color-picker' );
201 178 }
202 179
203 180 if ( in_array( $screen_id, uwp_get_screen_ids() ) ) {
204 - wp_enqueue_style( 'userswp_admin_css', USERSWP_PLUGIN_URL . 'admin/assets/css/users-wp-admin.css', array(), USERSWP_VERSION, 'all' );
181 + wp_enqueue_style( "userswp_admin_css", USERSWP_PLUGIN_URL . 'admin/assets/css/users-wp-admin.css', array(), USERSWP_VERSION, 'all' );
205 182 }
183 +
206 184 }
207 185
208 186 /**
209 187 * Register the JavaScript for the admin area.
@@ -220,59 +198,46 @@
220 198
221 199 if ( $hook_suffix == 'profile.php' || $hook_suffix == 'user-edit.php' ) {
222 200
223 201 wp_enqueue_script( 'jquery-ui-datepicker', array( 'jquery' ) );
224 - wp_enqueue_script(
225 - 'uwp_timepicker',
226 - USERSWP_PLUGIN_URL . 'assets/js/jquery.ui.timepicker.min.js',
227 - array(
228 - 'jquery',
229 - 'jquery-ui-datepicker',
230 - 'jquery-ui-core',
231 - ),
232 - USERSWP_VERSION
233 - );
234 - wp_enqueue_script( 'userswp', USERSWP_PLUGIN_URL . 'assets/js/users-wp' . $suffix . '.js', array( 'jquery' ), USERSWP_VERSION, false );
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 );
235 208 $uwp_localize_data = uwp_get_localize_data();
236 209 wp_localize_script( 'userswp', 'uwp_localize_data', $uwp_localize_data );
237 210 wp_enqueue_script( 'jquery-ui-progressbar', array( 'jquery' ) );
238 211 wp_enqueue_script( 'jcrop', array( 'jquery' ) );
239 - wp_enqueue_script( 'country-select', USERSWP_PLUGIN_URL . 'assets/js/countrySelect' . $suffix . '.js', array( 'jquery' ), USERSWP_VERSION );
212 + wp_enqueue_script( "country-select", USERSWP_PLUGIN_URL . 'assets/js/countrySelect' . $suffix . '.js', array( 'jquery' ), USERSWP_VERSION );
240 213
241 214 $country_data = uwp_get_country_data();
242 215 wp_localize_script( USERSWP_NAME, 'uwp_country_data', $country_data );
243 216 }
244 217
245 - if ( false !== strpos( $hook_suffix, 'page_uwp_tools' ) ) {
218 + if ( false !== strpos($hook_suffix, 'page_uwp_tools' )) {
246 219 wp_enqueue_script( 'jquery-ui-progressbar', array( 'jquery' ) );
247 220 }
248 221
249 - if ( false !== strpos( $hook_suffix, 'page_uwp_status' ) ) {
250 - wp_enqueue_script( 'uwp_status', USERSWP_PLUGIN_URL . 'admin/assets/js/system-status.js', array( 'jquery' ), USERSWP_VERSION, true );
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 );
251 224 }
252 225
253 - if ( false !== strpos( $hook_suffix, 'page_uwp_form_builder' ) ) {
226 + if ( false !== strpos($hook_suffix, 'page_uwp_form_builder' )) {
254 227 wp_enqueue_script( 'jquery-ui-sortable' );
255 228 wp_enqueue_script( 'uwp-nestable-script', USERSWP_PLUGIN_URL . 'admin/assets/js/jquery.nestable' . $suffix . '.js', array( 'jquery-ui-sortable' ), USERSWP_VERSION );
256 - wp_enqueue_script( 'uwp_form_builder', USERSWP_PLUGIN_URL . 'admin/assets/js/uwp-form-builder' . $suffix . '.js', array(), USERSWP_VERSION, 'all' );
229 + wp_enqueue_script( "uwp_form_builder", USERSWP_PLUGIN_URL . 'admin/assets/js/uwp-form-builder' . $suffix . '.js', array(), USERSWP_VERSION, 'all' );
257 230 }
258 231
259 232 if ( in_array( $screen_id, uwp_get_screen_ids() ) ) {
260 - wp_enqueue_script( 'userswp_admin', USERSWP_PLUGIN_URL . 'admin/assets/js/users-wp-admin' . $suffix . '.js', array( 'jquery' ), USERSWP_VERSION, false );
233 + wp_enqueue_script( "userswp_admin", USERSWP_PLUGIN_URL . 'admin/assets/js/users-wp-admin' . $suffix . '.js', array( 'jquery' ), USERSWP_VERSION, false );
261 234
262 - wp_enqueue_script( 'jquery-ui-tooltip' );
235 + wp_enqueue_script( "jquery-ui-tooltip" );
263 236 wp_enqueue_script( 'wp-color-picker' );
264 237
265 - if ( 'userswp_page_uwp_user_types' === $screen_id ) {
266 - wp_enqueue_script( 'jquery-ui-sortable' );
267 - }
268 -
269 238 $ajax_cons_data = array(
270 239 'url' => admin_url( 'admin-ajax.php' ),
271 - 'nonces' => array(
272 - 'uwp_delete_user_type' => wp_create_nonce( 'uwp_delete_user_types' ),
273 - 'uwp_reorder_user_types' => wp_create_nonce( 'uwp_reorder_user_types' ),
274 - ),
275 240 'custom_field_not_blank_var' => __( 'Field key must not be blank', 'userswp' ),
276 241 'custom_field_options_not_blank_var' => __( 'Option Values must not be blank', 'userswp' ),
277 242 'custom_field_not_special_char' => __( 'Please do not use special character and spaces in field key.', 'userswp' ),
278 243 'custom_field_unique_name' => __( 'Field key should be a unique name.', 'userswp' ),
@@ -279,26 +244,19 @@
279 244 'custom_field_delete' => __( 'Are you sure you wish to delete this field?', 'userswp' ),
280 245 'custom_field_id_required' => __( 'This field is required.', 'userswp' ),
281 246 'img_spacer' => admin_url( 'images/media-button-image.gif' ),
282 247 'txt_choose_image' => __( 'Choose an image', 'userswp' ),
283 - 'txt_use_image' => __( 'Use image', 'userswp' ),
284 - 'txt_save' => __( 'Save', 'userswp' ),
285 - 'txt_saved' => __( 'Saved', 'userswp' ),
286 - 'txt_delete' => __( 'Delete', 'userswp' ),
287 - 'txt_deleted' => __( 'Deleted', 'userswp' ),
288 - 'txt_cancel' => __( 'Cancel', 'userswp' ),
289 - 'txt_saving' => __( 'Saving...', 'userswp' ),
290 - 'txt_saving_error' => __( 'An error occurred while saving. Please try again.', 'userswp' ),
248 + 'txt_use_image' => __( 'Use image', 'userswp' ),
291 249 'delete_register_form' => __( 'Are you sure you wish to delete this form?', 'userswp' ),
292 250 'ask_register_form_title' => __( 'Enter register form title', 'userswp' ),
293 - 'form_updated_msg' => __( 'Updated! Reloading page...', 'userswp' ),
251 + 'form_updated_msg' => __( 'Updated! Reloading page...', 'userswp' )
294 252 );
253 + wp_localize_script( "userswp_admin", 'uwp_admin_ajax', $ajax_cons_data );
254 + }
295 255
296 - wp_localize_script( 'userswp_admin', 'uwp_admin_ajax', $ajax_cons_data );
297 - }
298 256 }
299 257
300 - public function get_screen_ids() {
258 + public function get_screen_ids(){
301 259 return uwp_get_screen_ids();
302 260 }
303 261
304 262 /**
@@ -343,12 +301,12 @@
343 301 */
344 302 public function admin_only_script() {
345 303
346 304 // check page is userswp or not.
347 - if ( ! empty( $_GET['page'] ) && 'userswp' == $_GET['page'] ) {
305 + if ( ! empty( $_GET['page'] ) && 'userswp' == $_GET['page']) {
348 306
349 307 // check tab is general or not.
350 - if ( ! empty( $_GET['tab'] ) && 'general' == $_GET['tab'] ) {
308 + if ( ! empty( $_GET['tab'] ) && 'general' == $_GET['tab']) {
351 309
352 310 // check for login section.
353 311 if ( ! empty( $_GET['section'] ) && 'login' == $_GET['section'] ) {
354 312 ?>
@@ -369,11 +327,12 @@
369 327 </script>
370 328 <?php
371 329 }
372 330 }
331 +
373 332 }
374 333
375 - if ( ! empty( $_GET['page'] ) && 'uwp_user_types' == $_GET['page'] ) {
334 + if(! empty( $_GET['page'] ) && 'uwp_form_builder' == $_GET['page']) {
376 335 ?>
377 336 <script type="text/javascript">
378 337 jQuery(document).ready(function () {
379 338 var uwp_registration_action = jQuery('#uwp_registration_action');
@@ -380,9 +339,13 @@
380 339 uwp_registration_action.on('change', function () {
381 340 var value = jQuery(this).val();
382 341 var register_redirect_obj = jQuery('#register_redirect_to');
383 342
384 - register_redirect_obj.parents('tr').toggle(value === 'auto_approve_login');
343 + if ('auto_approve_login' === value) {
344 + register_redirect_obj.parent().parent().show();
345 + } else {
346 + register_redirect_obj.parent().parent().hide();
347 + }
385 348 }).change();
386 349
387 350 var register_redirect_to = jQuery('#register_redirect_to');
388 351 register_redirect_to.on('change', function () {
@@ -387,14 +350,22 @@
387 350 var register_redirect_to = jQuery('#register_redirect_to');
388 351 register_redirect_to.on('change', function () {
389 352 var value = jQuery(this).val();
390 353 var register_redirect_custom_obj = jQuery('#register_redirect_custom_url');
391 - register_redirect_custom_obj.parents('tr').toggle(value === '-2');
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 + }
392 362 }).change();
393 363 });
394 364 </script>
395 365 <?php
396 366 }
367 +
397 368 }
398 369
399 370 /**
400 371 * Filters the user profile picture description displayed under the Gravatar.
@@ -411,15 +382,14 @@
411 382 $user_id = get_current_user_id();
412 383 $avatar = uwp_get_usermeta( $user_id, 'avatar_thumb', '' );
413 384
414 385 if ( ! empty( $avatar ) ) {
415 - $description = sprintf(
416 - __( 'You can change your profile picture on your <a href="%s">Profile Page</a>.', 'userswp' ),
417 - uwp_build_profile_tab_url( $user_id )
418 - );
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 ) );
419 388 }
420 -}
421 389
390 + }
391 +
422 392 return $description;
423 393 }
424 394
425 395 public function admin_body_class( $classes ) {
@@ -462,9 +432,9 @@
462 432 $plain_text = UsersWP_Mails::get_email_type() != 'html' ? true : false;
463 433
464 434 // Get the preview email content.
465 435 ob_start();
466 - include 'views/html-email-template-preview.php';
436 + include( 'views/html-email-template-preview.php' );
467 437 $message = ob_get_clean();
468 438
469 439 $message = UsersWP_Mails::email_wrap_message( $message, $email_name, $email_vars, '', $plain_text );
470 440 $message = UsersWP_Mails::style_body( $message, $email_name, $email_vars );
@@ -514,11 +484,11 @@
514 484 'meta_query' => array(
515 485 array(
516 486 'key' => 'uwp_mod',
517 487 'value' => 'email_unconfirmed',
518 - 'compare' => '=',
519 - ),
520 - ),
488 + 'compare' => '='
489 + )
490 + )
521 491 );
522 492 $users = new WP_User_Query( $args );
523 493
524 494 return isset( $users->results ) ? (int) count( $users->results ) : 0;
@@ -534,15 +504,14 @@
534 504 global $wpdb, $pagenow;
535 505
536 506 if ( is_admin() && $pagenow == 'users.php' && isset( $_GET['uwp_status'] ) && $_GET['uwp_status'] != '' ) {
537 507
538 - do_action( 'uwp_users_show_pending_email_activation', $query );
508 + do_action('uwp_users_show_pending_email_activation', $query);
539 509
540 510 $status = sanitize_text_field( urldecode( $_GET['uwp_status'] ) );
541 511
542 512 if ( $status == 'pending-email-activate' ) {
543 - $query->query_where = str_replace(
544 - 'WHERE 1=1',
513 + $query->query_where = str_replace( 'WHERE 1=1',
545 514 "WHERE 1=1 AND {$wpdb->users}.ID IN (
546 515 SELECT {$wpdb->usermeta}.user_id FROM $wpdb->usermeta
547 516 WHERE {$wpdb->usermeta}.meta_key = 'uwp_mod'
548 517 AND {$wpdb->usermeta}.meta_value = 'email_unconfirmed')",
@@ -565,10 +534,10 @@
565 534 public function get_profile_extra_edit( $user ) {
566 535 global $wpdb;
567 536 $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
568 537 $form_id = uwp_get_register_form_id( $user->ID );
569 - $excluded_fields = apply_filters( 'uwp_exclude_edit_profile_fields', array( 'bio', 'register_gdpr', 'register_tos', 'uwp_language', 'multisite_site_title', 'multisite_site_address' ) );
570 - $query = $wpdb->prepare( 'SELECT * FROM ' . $table_name . " WHERE form_type = 'account' AND is_default = '0' AND form_id = %d", $form_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);
571 540 if ( is_array( $excluded_fields ) && count( $excluded_fields ) > 0 ) {
572 541 $query .= " AND htmlvar_name NOT IN ('" . implode( "','", $excluded_fields ) . "')";
573 542 }
574 543 $query .= ' ORDER BY sort_order ASC';
@@ -578,14 +547,14 @@
578 547
579 548 if ( $fields ) {
580 549 ?>
581 550 <div class="uwp-profile-extra">
582 - <table class="uwp-profile-extra-table form-table">
551 + <table class="uwp-profile-extra-table form-table bsui">
583 552 <?php
584 553 foreach ( $fields as $field ) {
585 554
586 - if ( isset( $field->css_class ) && ! empty( $field->css_class ) ) {
587 - $field->css_class = $field->css_class . ' w-50';
555 + if(isset($field->css_class) && !empty($field->css_class)){
556 + $field->css_class = $field->css_class.' w-50';
588 557 } else {
589 558 $field->css_class = 'w-50';
590 559 }
591 560
@@ -590,24 +559,21 @@
590 559 }
591 560
592 561 if ( $field->field_type == 'fieldset' ) {
593 562 ?>
594 - <tr>
595 - <th class="uwp-profile-extra-key">
596 - <h2><?php echo esc_html( $field->site_title ); ?></h2>
597 - </th>
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>
598 566 <td></td>
599 567 </tr>
600 568 <?php
601 - } else {
602 - ?>
569 + } else { ?>
603 570 <tr>
604 571 <th class="uwp-profile-extra-key"><?php echo esc_html( $field->site_title ); ?></th>
605 - <td class="uwp-profile-extra-value bsui">
572 + <td class="uwp-profile-extra-value">
606 573 <?php
607 574 $templates_obj = new UsersWP_Templates();
608 - $templates_obj->template_fields_html( $field, 'account', $user->ID );
609 - ?>
575 + $templates_obj->template_fields_html( $field, 'account', $user->ID ); ?>
610 576 </td>
611 577 </tr>
612 578 <?php
613 579 }
@@ -634,14 +600,14 @@
634 600
635 601 $file_obj = new UsersWP_Files();
636 602
637 603 $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
638 - $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
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
639 605 if ( $fields ) {
640 606 ?>
641 607 <div class="uwp-profile-extra uwp_page">
642 608 <?php do_action( 'uwp_admin_profile_edit', $user ); ?>
643 - <h2><?php esc_html_e( 'UsersWP Account Details', 'userswp' ); ?></h2>
609 + <h2><?php esc_html_e('UsersWP Account Details', 'userswp'); ?></h2>
644 610 <table class="uwp-profile-extra-table form-table">
645 611 <?php
646 612 foreach ( $fields as $field ) {
647 613
@@ -646,52 +612,50 @@
646 612 foreach ( $fields as $field ) {
647 613
648 614 if ( $field->field_type == 'fieldset' ) {
649 615 ?>
650 - <tr>
651 - <th class="uwp-profile-extra-key">
652 - <h2><?php echo esc_html( $field->site_title ); ?></h2>
653 - </th>
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>
654 620 <td></td>
655 621 </tr>
656 622 <?php
657 - } else {
658 - ?>
623 + } else { ?>
659 624 <tr>
660 625 <th class="uwp-profile-extra-key"><?php echo esc_html( $field->site_title ); ?></th>
661 - <td class="uwp-profile-extra-value bsui">
626 + <td class="uwp-profile-extra-value">
662 627 <?php
663 - if ( $field->htmlvar_name == 'avatar' ) {
664 - $value = uwp_get_usermeta( $user->ID, 'avatar_thumb', '' );
665 - } elseif ( $field->htmlvar_name == 'banner' ) {
666 - $value = uwp_get_usermeta( $user->ID, 'banner_thumb', '' );
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", "" );
667 632 } else {
668 - $value = '';
633 + $value = "";
669 634 }
670 635
671 636 echo $file_obj->file_upload_preview( $field, $value ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
672 637
673 - if ( $field->htmlvar_name == 'avatar' ) {
638 + if ( $field->htmlvar_name == "avatar" ) {
674 639 if ( ! empty( $value ) ) {
675 - $label = __( 'Change Avatar', 'userswp' );
640 + $label = __( "Change Avatar", "userswp" );
676 641 } else {
677 - $label = __( 'Upload Avatar', 'userswp' );
642 + $label = __( "Upload Avatar", "userswp" );
678 643 }
679 644 ?>
680 645 <a onclick="uwp_profile_image_change('avatar');return false;" href="#"
681 - class="uwp-banner-change-icon-admin">
646 + class="uwp-banner-change-icon-admin">
682 647 <?php echo esc_html( $label ); ?>
683 648 </a>
684 649 <?php
685 - } elseif ( $field->htmlvar_name == 'banner' ) {
650 + } elseif ( $field->htmlvar_name == "banner" ) {
686 651 if ( ! empty( $value ) ) {
687 - $label = __( 'Change Banner', 'userswp' );
652 + $label = __( "Change Banner", "userswp" );
688 653 } else {
689 - $label = __( 'Upload Banner', 'userswp' );
690 - }
691 - ?>
654 + $label = __( "Upload Banner", "userswp" );
655 + } ?>
692 656 <a onclick="uwp_profile_image_change('banner');return false;" href="#"
693 - class="uwp-banner-change-icon-admin">
657 + class="uwp-banner-change-icon-admin">
694 658 <?php echo esc_html( $label ); ?>
695 659 </a>
696 660 <?php
697 661 }
@@ -722,12 +686,12 @@
722 686 $user_id = $user_object->ID;
723 687 $mod_value = get_user_meta( $user_id, 'uwp_mod', true );
724 688 $resend_link = add_query_arg(
725 689 array(
726 - 'user_id' => $user_id,
727 - 'action' => 'uwp_resend',
728 - '_nonce' => wp_create_nonce( 'uwp_resend' ),
729 - 'uwp_is_admin' => 1,
690 + 'user_id' => $user_id,
691 + 'action' => 'uwp_resend',
692 + '_nonce' => wp_create_nonce( 'uwp_resend' ),
693 + 'uwp_is_admin' => 1,
730 694 ),
731 695 admin_url( 'users.php' )
732 696 );
733 697
@@ -732,19 +696,19 @@
732 696 );
733 697
734 698 $activate_link = add_query_arg(
735 699 array(
736 - 'user_id' => $user_id,
737 - 'action' => 'uwp_activate_user',
738 - '_nonce' => wp_create_nonce( 'uwp_activate_user' ),
739 - 'uwp_is_admin' => 1,
700 + 'user_id' => $user_id,
701 + 'action' => 'uwp_activate_user',
702 + '_nonce' => wp_create_nonce( 'uwp_activate_user' ),
703 + 'uwp_is_admin' => 1,
740 704 ),
741 705 admin_url( 'users.php' )
742 706 );
743 707
744 708 if ( $mod_value == 'email_unconfirmed' ) {
745 - $actions['uwp_resend_activation'] = "<a class='' href='" . $resend_link . "'>" . __( 'Resend Activation', 'userswp' ) . '</a>';
746 - $actions['uwp_auto_activate'] = "<a class='' href='" . $activate_link . "'>" . __( 'Activate User', 'userswp' ) . '</a>';
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>";
747 711 }
748 712
749 713 return $actions;
750 714 }
@@ -822,29 +786,27 @@
822 786 *
823 787 */
824 788 public function process_user_actions() {
825 789 $user_id = isset( $_REQUEST['user_id'] ) ? (int) $_REQUEST['user_id'] : 0;
826 - $action = isset( $_REQUEST['action'] ) ? sanitize_text_field( $_REQUEST['action'] ) : false;
827 - $nonce = isset( $_REQUEST['_nonce'] ) ? sanitize_text_field( $_REQUEST['_nonce'] ) : false;
828 - $is_admin = isset( $_REQUEST['uwp_is_admin'] ) ? sanitize_text_field( $_REQUEST['uwp_is_admin'] ) : false;
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;
829 793
830 - if ( $user_id && 'uwp_resend' == $action && ! empty( $nonce ) && wp_verify_nonce( $nonce, 'uwp_resend' ) ) {
794 + if ( $user_id && 'uwp_resend' == $action && !empty($nonce) && wp_verify_nonce( $nonce, 'uwp_resend' ) ) {
831 795 uwp_resend_activation_mail( $user_id );
832 - if ( isset( $is_admin ) && $is_admin ) {
796 + if ( isset($is_admin) && $is_admin ) {
833 797 wp_redirect( add_query_arg( 'update', 'uwp_resend', admin_url( 'users.php' ) ) );
834 798 exit();
835 799 } else {
836 800 global $uwp_notices;
837 801 $message = __( 'Activation email has been sent!', 'userswp' );
838 - $uwp_notices[] = aui()->alert(
839 - array(
840 - 'type' => 'success',
841 - 'content' => $message,
842 - )
843 - );
802 + $uwp_notices[] = aui()->alert( array(
803 + 'type' => 'success',
804 + 'content' => $message
805 + ) );
844 806 }
845 807 } elseif ( $user_id && 'uwp_activate_user' == $action && wp_verify_nonce( $nonce, 'uwp_activate_user' ) ) {
846 - if ( isset( $is_admin ) && $is_admin && current_user_can( 'edit_users' ) ) {
808 + if ( isset($is_admin) && $is_admin && current_user_can( 'edit_users' ) ) {
847 809 $this->activate_user( $user_id );
848 810 wp_redirect( add_query_arg( 'update', 'uwp_activate_user', admin_url( 'users.php' ) ) );
849 811 }
850 812 }
@@ -852,17 +814,17 @@
852 814
853 815 /**
854 816 * Show row meta on the plugin screen.
855 817 *
856 - * @param mixed $links Plugin Row Meta
857 - * @param mixed $file Plugin Base file
858 - * @return array
818 + * @param mixed $links Plugin Row Meta
819 + * @param mixed $file Plugin Base file
820 + * @return array
859 821 */
860 822 public static function plugin_row_meta( $links, $file ) {
861 823 if ( USERSWP_PLUGIN_BASENAME == $file ) {
862 824 $row_meta = array(
863 - 'docs' => '<a href="' . esc_url( 'https://userswp.io/documentation/' ) . '" aria-label="' . esc_attr__( 'View UsersWP Documentation', 'userswp' ) . '">' . esc_html__( 'Docs', 'userswp' ) . '</a>',
864 - 'support' => '<a href="' . esc_url( 'https://userswp.io/support/' ) . '" aria-label="' . esc_attr__( 'Visit UsersWP support', 'userswp' ) . '">' . esc_html__( 'Support', 'userswp' ) . '</a>',
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>',
865 827 'translation' => '<a href="' . esc_url( 'https://userswp.io/translate/projects' ) . '" aria-label="' . esc_attr__( 'View translations', 'userswp' ) . '">' . esc_html__( 'Translations', 'userswp' ) . '</a>',
866 828 );
867 829
868 830 return array_merge( $links, $row_meta );
@@ -870,271 +832,179 @@
870 832
871 833 return (array) $links;
872 834 }
873 835
874 - /**
875 - * Process the creation of a new registration form.
876 - *
877 - * This method handles the AJAX request to create a new registration form,
878 - * including validation, sanitization, and database operations.
879 - */
880 - public function process_create_register_form() {
881 - check_ajax_referer( 'uwp-create-register-form-nonce', 'uwp_create_register_form_nonce' );
836 + public function process_create_register_form() {
882 837
883 - if ( ! current_user_can( 'manage_options' ) ) {
884 - wp_die( -1 );
885 - }
838 + if ( ! current_user_can( 'manage_options' ) ) {
839 + wp_die( -1 );
840 + }
886 841
887 - $form_title = isset( $_POST['form_title'] ) ? sanitize_text_field( $_POST['form_title'] ) : __( 'Form', 'userswp' );
888 - $user_role = isset( $_POST['user_role'] ) ? sanitize_text_field( $_POST['user_role'] ) : '';
889 - $action = isset( $_POST['reg_action'] ) ? sanitize_text_field( $_POST['reg_action'] ) : uwp_get_option( 'uwp_registration_action', 'auto_approve' );
890 - $redirect_to = isset( $_POST['redirect_to'] ) ? (int)$_POST['redirect_to'] : 0;
891 - $custom_url = isset( $_POST['custom_url'] ) ? sanitize_text_field( $_POST['custom_url'] ) : '';
892 - $gdpr_page = isset( $_POST['gdpr_page'] ) ? (int)$_POST['gdpr_page'] : (int)uwp_get_option( 'register_gdpr_page', false );
893 - $tos_page = isset( $_POST['tos_page'] ) ? (int)$_POST['tos_page'] : (int)uwp_get_option( 'register_terms_page', false );
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']) : '';
894 845
895 - if ( empty( $form_title ) ) {
896 - wp_send_json_error(
897 - array(
898 - 'message' => esc_html__( 'Form title is required.', 'userswp' ),
899 - )
900 - );
901 - }
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' ) ) {
902 850
903 - $status = false;
904 - $redirect = '';
851 + $get_register_forms = uwp_get_option( 'multiple_registration_forms' );
852 + $new_form_id = uwp_get_next_register_form_id();
905 853
906 - $new_form_id = uwp_get_next_register_form_id();
907 - if ( $new_form_id ) {
908 - $register_forms = (array) uwp_get_option( 'multiple_registration_forms', array() );
909 - // Filter out invalid items.
910 - $register_forms = array_filter(
911 - $register_forms,
912 - function ( $form ) {
913 - return isset( $form['id'] );
914 - }
915 - );
854 + if ( ! empty( $new_form_id ) ) {
916 855
917 - $register_forms[] = array(
918 - 'id' => $new_form_id,
919 - 'title' => ! empty( $form_title ) ? $form_title : sprintf( __( 'Form %d', 'userswp' ), $new_form_id ),
920 - 'slug' => ! empty( $form_title ) ? sanitize_title( $form_title ) : sprintf( 'form-%d', $new_form_id ),
921 - 'user_role' => $user_role,
922 - 'reg_action' => $action,
923 - 'redirect_to' => $redirect_to,
924 - 'custom_url' => $custom_url,
925 - 'gdpr_page' => $gdpr_page,
926 - 'tos_page' => $tos_page,
927 - );
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 + );
928 860
929 - $register_forms = array_values( $register_forms );
930 - $register_forms = apply_filters( 'uwp_multiple_registration_forms_update', $register_forms, $new_form_id );
861 + uwp_update_option( 'multiple_registration_forms', $get_register_forms );
931 862
932 - uwp_update_option( 'multiple_registration_forms', $register_forms );
863 + $fields = UsersWP_Activator::uwp_default_custom_fields_account();
864 + $form_builder = new UsersWP_Form_Builder();
933 865
934 - $fields = UsersWP_Activator::uwp_default_custom_fields_account();
935 - $form_builder = new UsersWP_Form_Builder();
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 + }
936 872
937 - foreach ( $fields as $field ) {
938 - $field['form_id'] = $new_form_id;
939 - $form_builder->admin_form_field_save( $field );
940 - }
873 + UsersWP_Activator::insert_form_extras($new_form_id);
941 874
942 - UsersWP_Activator::insert_form_extras( $new_form_id );
875 + do_action('uwp_create_register_form', $new_form_id);
943 876
944 - do_action( 'uwp_create_register_form', $new_form_id );
877 + $status = true;
878 + $redirect = admin_url( 'admin.php?page=uwp_form_builder&tab=account&form=' . $new_form_id );
879 + }
880 + }
945 881
946 - $status = true;
947 - $redirect = admin_url( sprintf( 'admin.php?page=uwp_user_types&form=%d', $new_form_id ) );
948 - }
882 + $response = array(
883 + 'status' => $status,
884 + 'message' => $message,
885 + 'redirect' => $redirect,
886 + );
949 887
950 - wp_send_json_success(
951 - array(
952 - 'status' => $status,
953 - 'message' => esc_html__( 'User Type added successfully.', 'userswp' ),
954 - 'redirect' => $redirect,
955 - )
956 - );
957 - }
888 + echo json_encode( $response );
889 + wp_die();
890 + }
958 891
959 - /**
960 - * Process the update of an existing registration form.
961 - *
962 - * This method handles the AJAX request to update an existing registration form,
963 - * including validation, sanitization, and database operations.
964 - */
965 - public function process_update_register_form() {
966 - check_ajax_referer( 'uwp-update-register-form-nonce', 'uwp_update_register_form_nonce' );
892 + public function process_update_register_form() {
967 893
968 - if ( ! current_user_can( 'manage_options' ) ) {
969 - wp_die( -1 );
970 - }
894 + check_ajax_referer( 'uwp-update-register-form-nonce', 'uwp_update_register_form_nonce' );
971 895
972 - $form_id = isset( $_POST['manage_field_form_id'] ) ? (int)$_POST['manage_field_form_id'] : 0;
973 - $form_title = isset( $_POST['form_title'] ) && ! empty( $_POST['form_title'] ) ? sanitize_text_field( $_POST['form_title'] ) : __( 'Form', 'userswp' );
974 - $user_role = isset( $_POST['user_role'] ) ? sanitize_text_field( $_POST['user_role'] ) : '';
975 - $action = isset( $_POST['reg_action'] ) ? sanitize_text_field( $_POST['reg_action'] ) : uwp_get_option( 'uwp_registration_action', 'auto_approve' );
976 - $redirect_to = isset( $_POST['redirect_to'] ) ? (int)$_POST['redirect_to'] : 0;
977 - $custom_url = isset( $_POST['custom_url'] ) ? sanitize_text_field( $_POST['custom_url'] ) : '';
978 - $gdpr_page = isset( $_POST['gdpr_page'] ) ? (int)$_POST['gdpr_page'] : (int)uwp_get_option( 'register_gdpr_page', false );
979 - $tos_page = isset( $_POST['tos_page'] ) ? (int)$_POST['tos_page'] : (int)uwp_get_option( 'register_terms_page', false );
896 + if ( ! current_user_can( 'manage_options' ) ) {
897 + wp_die( -1 );
898 + }
980 899
981 - if ( ! $form_id ) {
982 - wp_send_json_error(
983 - array(
984 - 'message' => esc_html__( 'Something went wrong. Please try again.', 'userswp' ),
985 - )
986 - );
987 - }
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);
988 909
989 - $redirect = '';
990 - $status = false;
910 + $status = false;
911 + $message = __( 'Something went wrong. Please try again.', 'userswp' );
912 + if ( ! empty( $type ) && ! empty( $form_id ) && $type === 'update' ) {
991 913
992 - $register_forms = (array) uwp_get_option( 'multiple_registration_forms', array() );
914 + $register_forms = uwp_get_option( 'multiple_registration_forms' );
993 915
994 - foreach ( $register_forms as &$register_form ) {
995 - if ( $register_form['id'] == $form_id ) {
996 - $register_form['title'] = $form_title;
997 - $register_form['user_role'] = $user_role;
998 - $register_form['reg_action'] = $action;
999 - $register_form['redirect_to'] = $redirect_to;
1000 - $register_form['custom_url'] = $custom_url;
1001 - $register_form['gdpr_page'] = $gdpr_page;
1002 - $register_form['tos_page'] = $tos_page;
1003 - $status = true;
1004 - break;
1005 - }
1006 - }
916 + if ( ! empty( $register_forms ) && is_array( $register_forms ) ) {
1007 917
1008 - if ( $status ) {
1009 - $register_forms = array_values( $register_forms );
1010 - $register_forms = apply_filters( 'uwp_multiple_registration_forms_update', $register_forms, $form_id );
1011 - uwp_update_option( 'multiple_registration_forms', $register_forms );
1012 - $redirect = add_query_arg(
1013 - array(
1014 - 'page' => 'uwp_user_types',
1015 - 'form' => $form_id,
1016 - ),
1017 - admin_url( 'admin.php' )
1018 - );
1019 - }
918 + foreach ( $register_forms as $key => $register_form ) {
1020 919
1021 - wp_send_json_success(
1022 - array(
1023 - 'status' => $status,
1024 - 'message' => esc_html__( 'The user type has been updated successfully.', 'userswp' ),
1025 - )
1026 - );
1027 - }
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 + }
1028 932
1029 - public function reorder_user_types() {
1030 - check_ajax_referer( 'uwp_reorder_user_types', 'nonce' );
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 + }
1031 937
1032 - if ( ! current_user_can( 'manage_options' ) ) {
1033 - wp_send_json_error( array( 'message' => __( 'You do not have permission to perform this action.', 'userswp' ) ) );
1034 - }
938 + $response = array(
939 + 'status' => $status,
940 + 'message' => $message,
941 + );
1035 942
1036 - $order = isset( $_POST['order'] ) ? array_map( 'absint', $_POST['order'] ) : array();
943 + echo json_encode( $response );
944 + wp_die();
945 + }
1037 946
1038 - if ( empty( $order ) ) {
1039 - wp_send_json_error( array( 'message' => __( 'Invalid order data.', 'userswp' ) ) );
1040 - }
1041 -
1042 - $register_forms = (array) uwp_get_option( 'multiple_registration_forms', array() );
1043 - $new_order = array();
1044 -
1045 - foreach ( $order as $id ) {
1046 - foreach ( $register_forms as $form ) {
1047 - if ( (int) $form['id'] === (int) $id ) {
1048 - $new_order[] = $form;
1049 - break;
1050 - }
1051 - }
1052 - }
1053 -
1054 - uwp_update_option( 'multiple_registration_forms', $new_order );
1055 -
1056 - wp_send_json_success( array( 'message' => __( 'User types order updated successfully.', 'userswp' ) ) );
1057 - }
1058 -
1059 947 public function process_remove_register_form() {
1060 948
1061 - check_ajax_referer( 'uwp_delete_user_types', 'nonce' );
949 + check_ajax_referer( 'uwp-delete-register-form-nonce', 'nonce' );
1062 950
1063 951 if ( ! current_user_can( 'manage_options' ) ) {
1064 952 wp_die( -1 );
1065 953 }
1066 954
1067 - $type = ! empty( $_POST['type'] ) ? sanitize_text_field( $_POST['type'] ) : '';
1068 - $form_id = ! empty( $_POST['form_id'] ) ? (int) $_POST['form_id'] : '';
955 + global $wpdb;
956 + $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
1069 957
958 + $type = ! empty( $_POST['type'] ) ? sanitize_text_field($_POST['type']) : '';
959 + $form_id = ! empty( $_POST['form_id'] ) ? (int)$_POST['form_id'] : '';
960 +
1070 961 $status = false;
1071 962 $message = __( 'Security nonce failed. Please try again.', 'userswp' );
1072 963 $redirect = '';
1073 -
1074 964 if ( ! empty( $type ) && ! empty( $form_id ) && $type === 'remove' ) {
1075 - $status = self::remove_registration_form( (int) $form_id );
1076 - $redirect = admin_url( 'admin.php?page=uwp_user_types' );
1077 - }
1078 965
1079 - wp_send_json(
1080 - array(
1081 - 'status' => $status,
1082 - 'message' => $message,
1083 - 'redirect' => $redirect,
1084 - )
1085 - );
1086 - }
966 + $register_forms = uwp_get_option( 'multiple_registration_forms' );
967 + $form_builder = new UsersWP_Form_Builder();
1087 968
1088 - /**
1089 - * Removes the registration form and its associated fields.
1090 - *
1091 - * @global wpdb $wpdb WordPress database abstraction object.
1092 - *
1093 - * @param int $form_id The form ID to remove.
1094 - * @return bool True if the form was found and removed; false otherwise.
1095 - */
1096 - public static function remove_registration_form( int $form_id ) {
1097 - global $wpdb;
969 + if ( ! empty( $register_forms ) && is_array( $register_forms ) ) {
1098 970
1099 - $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
1100 - $status = false;
1101 - $register_forms = (array) uwp_get_option( 'multiple_registration_forms', array() );
1102 - $form_builder = new UsersWP_Form_Builder();
971 + foreach ( $register_forms as $key => $register_form ) {
1103 972
1104 - if ( empty( $register_forms ) || ! is_array( $register_forms ) ) {
1105 - return $status;
1106 - }
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 + );
1107 982
1108 - foreach ( $register_forms as $key => $register_form ) {
1109 - if ( empty( $register_form['id'] ) || (int) $register_form['id'] !== $form_id ) {
1110 - continue;
1111 - }
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 + }
1112 991
1113 - $status = true;
1114 - unset( $register_forms[ $key ] );
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 + }
1115 996
1116 - $fields = $wpdb->get_results(
1117 - $wpdb->prepare(
1118 - "SELECT id FROM {$table_name} WHERE form_type = %s AND form_id = %d ORDER BY sort_order ASC",
1119 - 'account',
1120 - $form_id
1121 - )
1122 - );
997 + $response = array(
998 + 'status' => $status,
999 + 'message' => $message,
1000 + 'redirect' => $redirect,
1001 + );
1123 1002
1124 - if ( ! empty( $fields ) ) {
1125 - foreach ( $fields as $field ) {
1126 - $form_builder->admin_form_field_delete( (int) $field->id, false, $form_id );
1127 - }
1128 - }
1129 - }
1003 + echo json_encode( $response );
1004 + wp_die();
1005 + }
1130 1006
1131 - $register_forms = array_values( $register_forms );
1132 - uwp_update_option( 'multiple_registration_forms', $register_forms );
1133 -
1134 - return $status;
1135 - }
1136 -
1137 1007 /**
1138 1008 * Tell AyeCode UI to load on certain admin pages.
1139 1009 *
1140 1010 * @since 1.2.3.22
@@ -1152,264 +1022,5 @@
1152 1022 $screen_ids[] = 'uwp-setup';
1153 1023
1154 1024 return $screen_ids;
1155 1025 }
1156 -
1157 - /**
1158 - * Adds a new user type column to the users list table.
1159 - *
1160 - * @param array $columns Existing columns in the users list table.
1161 - * @return array Modified columns array with the new user type column.
1162 - */
1163 - public function add_user_type_column( array $columns ) {
1164 - $columns['uwp_user_type'] = __( 'User Type', 'userswp' );
1165 - return $columns;
1166 - }
1167 -
1168 - /**
1169 - * Displays user type in the user list column.
1170 - *
1171 - * @param string $value Current column value.
1172 - * @param string $column_name Column name being displayed.
1173 - * @param int $user_id Current user ID.
1174 - * @return string user type title.
1175 - */
1176 - public function display_user_type_column( $value, $column_name, $user_id ) {
1177 - if ( 'uwp_user_type' === $column_name ) {
1178 - $form_id = uwp_get_register_form_id( $user_id );
1179 - $uwp_user_type = uwp_get_user_register_form( $form_id );
1180 -
1181 - if ( ! isset( $uwp_user_type['id'], $uwp_user_type['title'] ) ) {
1182 - return '&mdash;';
1183 - }
1184 -
1185 - return $uwp_user_type['title'];
1186 - }
1187 -
1188 - return $value;
1189 - }
1190 -
1191 - /**
1192 - * Display user type options in the admin user edit screen.
1193 - *
1194 - * @param WP_User $user The WP user object.
1195 - * @return void
1196 - */
1197 - public function display_admin_change_user_type( $user ) {
1198 - if ( ! current_user_can( 'manage_options' ) ) {
1199 - return;
1200 - }
1201 -
1202 - $register_forms = UsersWP_User_Types::get_register_forms();
1203 - $user_type_id = (int) uwp_get_register_form_id( $user->ID );
1204 -
1205 - ob_start();
1206 - ?>
1207 - <table class="form-table">
1208 - <tbody>
1209 - <tr>
1210 - <th>
1211 - <label for="uwp_user_type_id" class="fw-semibold">
1212 - <?php esc_html_e( 'User Type', 'userswp' ); ?>
1213 - </label>
1214 - </th>
1215 - <td>
1216 - <select name="uwp_user_type_id" id="uwp_user_type_id" class="regular-text">
1217 - <?php foreach ( $register_forms as $form ) : ?>
1218 - <?php
1219 - $form_id = absint( $form['id'] );
1220 - $is_current = ( $form_id === $user_type_id );
1221 - ?>
1222 - <option value="<?php echo esc_attr( $form_id ); ?>" <?php selected( $form_id, $user_type_id ); ?>>
1223 - <?php echo esc_html( $form['title'] ); ?><?php echo $is_current ? ' (' . esc_html__( 'Active', 'userswp' ) . ')' : ''; ?>
1224 - </option>
1225 - <?php endforeach; ?>
1226 - </select>
1227 - <p class="description">
1228 - <?php esc_html_e( "Select the user type for this account.", 'userswp' ); ?>
1229 - </p>
1230 - </td>
1231 - </tr>
1232 - </tbody>
1233 - </table>
1234 - <?php
1235 -
1236 - // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1237 - echo apply_filters( 'uwp_admin_change_user_type_display', ob_get_clean(), $user );
1238 - }
1239 -
1240 - /**
1241 - * Update user membership.
1242 - *
1243 - * @param int $user_id The ID of the user to update.
1244 - * @return void
1245 - */
1246 - public function update_user_type( $user_id ) {
1247 - if ( ! current_user_can( 'manage_options' ) ) {
1248 - return;
1249 - }
1250 -
1251 - check_admin_referer( 'update-user_' . $user_id );
1252 -
1253 - if ( isset( $_POST['uwp_user_type_id'] ) && ! empty( $_POST['uwp_user_type_id'] ) ) {
1254 - $user_type_id = absint( $_POST['uwp_user_type_id'] );
1255 -
1256 - // Validate new membership.
1257 - $uwp_user_type = uwp_get_user_register_form( $user_type_id );
1258 - if ( ! $uwp_user_type ) {
1259 - return;
1260 - }
1261 -
1262 - update_user_meta( $user_id, '_uwp_register_form_id', $user_type_id );
1263 - }
1264 - }
1265 -
1266 - /**
1267 - * Adds a notice after updating user type.
1268 - */
1269 - public function add_user_type_updated_notice() {
1270 - if ( isset( $_GET['user_type_updated'] ) && 'true' === $_GET['user_type_updated'] ) {
1271 - ?>
1272 - <div class="updated notice is-dismissible">
1273 - <p><?php esc_html_e( 'User type updated successfully.', 'userswp' ); ?></p>
1274 - </div>
1275 - <?php
1276 - }
1277 - }
1278 -
1279 - /**
1280 - * Adds a bulk action dropdown for changing user types on the Users list table.
1281 - *
1282 - * @param string $which The position of the table (top or bottom).
1283 - */
1284 - public function add_bulk_user_type_dropdown( $which ) {
1285 - if ( ! is_admin() || 'users' !== get_current_screen()->id || 'top' !== $which ) {
1286 - return;
1287 - }
1288 -
1289 - $user_types = UsersWP_User_Types::get_register_forms();
1290 -
1291 - if ( empty( $user_types ) ) {
1292 - return;
1293 - }
1294 -
1295 - $options = array_map( function( $user_type ) {
1296 - return sprintf(
1297 - '<option value="%d">%s</option>',
1298 - absint( $user_type['id'] ),
1299 - esc_html( $user_type['title'] )
1300 - );
1301 - }, $user_types );
1302 -
1303 - ob_start();
1304 - ?>
1305 - <div class="alignleft actions">
1306 - <label class="screen-reader-text" for="uwp_new_user_type">
1307 - <?php esc_html_e( 'Change user type to…', 'userswp' ); ?>
1308 - </label>
1309 - <select name="uwp_new_user_type" id="uwp_new_user_type">
1310 - <option value=""><?php esc_html_e( 'Change user type to…', 'userswp' ); ?></option>
1311 - <?php echo implode( '', $options ); ?>
1312 - </select>
1313 - <input type="submit" name="uwp_change_user_type" id="uwp_change_user_type" class="button" value="<?php esc_attr_e( 'Change', 'userswp' ); ?>">
1314 - </div>
1315 - <?php
1316 -
1317 - // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1318 - echo apply_filters( 'uwp_bulk_change_user_type_display', ob_get_clean() );
1319 - }
1320 -
1321 - /**
1322 - * Handles the bulk user type change.
1323 - */
1324 - public function handle_bulk_user_type_change() {
1325 - if ( ! isset( $_GET['uwp_change_user_type'], $_GET['uwp_new_user_type'] ) ) {
1326 - return;
1327 - }
1328 -
1329 - if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( $_GET['_wpnonce'], 'bulk-users' ) ) {
1330 - wp_die( __( 'Security check failed. Please try again.' ) );
1331 - }
1332 -
1333 - if ( ! current_user_can( 'edit_users' ) ) {
1334 - wp_die( __( 'You do not have permission to perform this action.' ) );
1335 - }
1336 -
1337 - $new_user_type = absint( $_GET['uwp_new_user_type'] );
1338 -
1339 - if ( ! $new_user_type ) {
1340 - return;
1341 - }
1342 -
1343 - $users = isset( $_REQUEST['users'] ) && ! empty( $_REQUEST['users'] ) ? (array) $_REQUEST['users'] : array();
1344 -
1345 - if ( ! empty( $users ) ) {
1346 - array_map( function( $user_id ) use ( $new_user_type ) {
1347 - update_user_meta( absint( $user_id ), '_uwp_register_form_id', (int) $new_user_type );
1348 - }, $users );
1349 - }
1350 -
1351 - wp_safe_redirect( add_query_arg( 'user_type_updated', 'true', admin_url( 'users.php' ) ) );
1352 - exit;
1353 - }
1354 -
1355 - /**
1356 - * Adds JavaScript validation script.
1357 - */
1358 - public function add_validation_script() {
1359 - $screen = get_current_screen();
1360 -
1361 - if ( 'users' !== $screen->id ) {
1362 - return;
1363 - }
1364 - ?>
1365 - <script type="text/javascript">
1366 - (function($) {
1367 - $(document).ready(function() {
1368 - var $userTypeErrorNotice = $(
1369 - '<div id="no-user-type-selected" class="notice notice-error is-dismissible" style="display:none;">' +
1370 - '<p><?php esc_html_e( "Please select a user type to perform this action.", "userswp" ); ?></p>' +
1371 - '<button type="button" class="notice-dismiss"><span class="screen-reader-text"><?php esc_html_e( "Dismiss this notice.", "userswp" ); ?></span></button>' +
1372 - '</div>',
1373 - );
1374 -
1375 - var $itemSelectionErrorNotice = $(
1376 - '<div id="no-item-selected" class="notice notice-error is-dismissible" style="display:none;">' +
1377 - '<p><?php esc_html_e( "Please select at least one item to perform this action on.", "userswp" ); ?></p>' +
1378 - '<button type="button" class="notice-dismiss"><span class="screen-reader-text"><?php esc_html_e( "Dismiss this notice.", "userswp" ); ?></span></button>' +
1379 - '</div>',
1380 - );
1381 -
1382 - $("#wpbody-content").prepend($userTypeErrorNotice, $itemSelectionErrorNotice)
1383 -
1384 - $("#uwp_change_user_type").on("click", (e) => {
1385 - if ($('input[name="users[]"]:checked').length === 0) {
1386 - e.preventDefault();
1387 - showErrorNotice($itemSelectionErrorNotice);
1388 - hideErrorNotice($userTypeErrorNotice);
1389 - } else if ($("#new_user_type").val() === "") {
1390 - e.preventDefault();
1391 - showErrorNotice($userTypeErrorNotice);
1392 - hideErrorNotice($itemSelectionErrorNotice);
1393 - } else {
1394 - hideErrorNotice($userTypeErrorNotice);
1395 - hideErrorNotice($itemSelectionErrorNotice);
1396 - }
1397 - });
1398 -
1399 - $(".notice-dismiss").on("click", function () {
1400 - hideErrorNotice($(this).closest(".notice"));
1401 - })
1402 -
1403 - function showErrorNotice($notice) {
1404 - $notice.fadeIn(300);
1405 - }
1406 -
1407 - function hideErrorNotice($notice) {
1408 - $notice.fadeOut(300);
1409 - }
1410 - });
1411 - })(jQuery);
1412 - </script>
1413 - <?php
1414 - }
1415 -}
1026 +}