| @@ -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 | /** |
| @@ -87,21 +73,23 @@ | ||
| 87 | 73 | * @package userswp |
| 88 | 74 | * @since 1.0.0 |
| 89 | 75 | */ |
| 90 | 76 | public function activation_redirect() { |
| 77 | + | |
| 91 | 78 | if ( get_option( 'uwp_activation_redirect', false ) ) { |
| 92 | 79 | delete_option( 'uwp_activation_redirect' ); |
| 93 | - update_option( 'uwp_setup_wizard_notice', 1 ); | |
| 80 | + update_option( "uwp_setup_wizard_notice", 1 ); | |
| 94 | 81 | wp_redirect( admin_url( 'index.php?page=uwp-setup' ) ); |
| 95 | 82 | exit; |
| 96 | 83 | } |
| 97 | 84 | |
| 98 | - if ( ! empty( $_GET['force_sync_data'] ) && ! empty( $_GET['_nonce'] ) && wp_verify_nonce( sanitize_text_field( $_GET['_nonce'] ), 'force_sync_data' ) && current_user_can( 'manage_options' ) ) { | |
| 85 | + if ( ! empty( $_GET['force_sync_data'] ) ) { | |
| 99 | 86 | $blog_id = get_current_blog_id(); |
| 100 | 87 | do_action( 'wp_' . $blog_id . '_uwp_updater_cron' ); |
| 101 | 88 | wp_safe_redirect( admin_url( 'admin.php?page=userswp' ) ); |
| 102 | 89 | exit; |
| 103 | 90 | } |
| 91 | + | |
| 104 | 92 | } |
| 105 | 93 | |
| 106 | 94 | /** |
| 107 | 95 | * Maybe show the AyeCode Connect Notice. |
| @@ -110,15 +98,15 @@ | ||
| 110 | 98 | // AyeCode Connect notice |
| 111 | 99 | if ( is_admin() ) { |
| 112 | 100 | // set the strings so they can be translated |
| 113 | 101 | $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' ), | |
| 102 | + 'connect_title' => __( "UsersWP - an AyeCode product!", "userswp" ), | |
| 103 | + 'connect_external' => __( "Please confirm you wish to connect your site?", "userswp" ), | |
| 104 | + '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>" ), | |
| 105 | + 'connect_button' => __( "Connect Site", "userswp" ), | |
| 106 | + 'connecting_button' => __( "Connecting...", "userswp" ), | |
| 107 | + 'error_localhost' => __( "This service will only work with a live domain, not a localhost.", "userswp" ), | |
| 108 | + 'error' => __( "Something went wrong, please refresh and try again.", "userswp" ), | |
| 121 | 109 | ); |
| 122 | 110 | new AyeCode_Connect_Helper( $strings, array( 'uwp-addons' ) ); |
| 123 | 111 | } |
| 124 | 112 | } |
| @@ -129,18 +117,9 @@ | ||
| 129 | 117 | public function prevent_admin_access() { |
| 130 | 118 | $restricted_roles = (array) uwp_get_option( 'admin_blocked_roles', array() ); |
| 131 | 119 | |
| 132 | 120 | // 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 | - | |
| 121 | + if ( ! empty ( $restricted_roles ) && is_user_logged_in() && ! wp_doing_ajax() && ! wp_doing_cron() ) { | |
| 143 | 122 | $roles = wp_get_current_user()->roles; |
| 144 | 123 | |
| 145 | 124 | $prevent = false; |
| 146 | 125 | |
| @@ -145,9 +124,9 @@ | ||
| 145 | 124 | $prevent = false; |
| 146 | 125 | |
| 147 | 126 | // Always allow administrator role. |
| 148 | 127 | if ( ! ( ! empty( $roles ) && in_array( 'administrator', $roles ) ) ) { |
| 149 | - foreach ( $restricted_roles as $role ) { | |
| 128 | + foreach( $restricted_roles as $role ) { | |
| 150 | 129 | if ( in_array( $role, $roles ) ) { |
| 151 | 130 | $prevent = true; |
| 152 | 131 | break; |
| 153 | 132 | } |
| @@ -182,19 +161,19 @@ | ||
| 182 | 161 | if ( $hook_suffix == 'profile.php' || $hook_suffix == 'user-edit.php' ) { |
| 183 | 162 | wp_register_style( 'jquery-ui', USERSWP_PLUGIN_URL . 'assets/css/jquery-ui.css' ); |
| 184 | 163 | wp_enqueue_style( 'jquery-ui' ); |
| 185 | 164 | 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' ); | |
| 165 | + wp_enqueue_style( "uwp-country-select", USERSWP_PLUGIN_URL . 'assets/css/countryselect.css', array(), USERSWP_VERSION, 'all' ); | |
| 166 | + wp_enqueue_style( "userswp", USERSWP_PLUGIN_URL . 'assets/css/users-wp.css', array(), USERSWP_VERSION, 'all' ); | |
| 167 | + wp_enqueue_style( "uwp_timepicker_css", USERSWP_PLUGIN_URL . 'assets/css/jquery.ui.timepicker.css', array(), USERSWP_VERSION, 'all' ); | |
| 189 | 168 | } |
| 190 | 169 | |
| 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' ); | |
| 170 | + if ( false !== strpos($hook_suffix, 'page_uwp_tools' )) { | |
| 171 | + wp_enqueue_style( "userswp", USERSWP_PLUGIN_URL . 'assets/css/users-wp.css', array(), USERSWP_VERSION, 'all' ); | |
| 193 | 172 | } |
| 194 | 173 | |
| 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' ); | |
| 174 | + if ( false !== strpos($hook_suffix, 'page_uwp_form_builder' )) { | |
| 175 | + wp_enqueue_style( "uwp_form_builder", USERSWP_PLUGIN_URL . 'admin/assets/css/uwp-form-builder.css', array(), USERSWP_VERSION, 'all' ); | |
| 197 | 176 | } |
| 198 | 177 | |
| 199 | 178 | if ( $hook_suffix == 'toplevel_page_userswp' ) { |
| 200 | 179 | wp_enqueue_style( 'wp-color-picker' ); |
| @@ -200,10 +179,11 @@ | ||
| 200 | 179 | wp_enqueue_style( 'wp-color-picker' ); |
| 201 | 180 | } |
| 202 | 181 | |
| 203 | 182 | 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' ); | |
| 183 | + wp_enqueue_style( "userswp_admin_css", USERSWP_PLUGIN_URL . 'admin/assets/css/users-wp-admin.css', array(), USERSWP_VERSION, 'all' ); | |
| 205 | 184 | } |
| 185 | + | |
| 206 | 186 | } |
| 207 | 187 | |
| 208 | 188 | /** |
| 209 | 189 | * Register the JavaScript for the admin area. |
| @@ -220,59 +200,46 @@ | ||
| 220 | 200 | |
| 221 | 201 | if ( $hook_suffix == 'profile.php' || $hook_suffix == 'user-edit.php' ) { |
| 222 | 202 | |
| 223 | 203 | 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 ); | |
| 204 | + wp_enqueue_script( "uwp_timepicker", USERSWP_PLUGIN_URL . 'assets/js/jquery.ui.timepicker.min.js', array( | |
| 205 | + 'jquery', | |
| 206 | + 'jquery-ui-datepicker', | |
| 207 | + 'jquery-ui-core' | |
| 208 | + ), USERSWP_VERSION ); | |
| 209 | + wp_enqueue_script( "userswp", USERSWP_PLUGIN_URL . 'assets/js/users-wp' . $suffix . '.js', array( 'jquery' ), USERSWP_VERSION, false ); | |
| 235 | 210 | $uwp_localize_data = uwp_get_localize_data(); |
| 236 | 211 | wp_localize_script( 'userswp', 'uwp_localize_data', $uwp_localize_data ); |
| 237 | 212 | wp_enqueue_script( 'jquery-ui-progressbar', array( 'jquery' ) ); |
| 238 | 213 | wp_enqueue_script( 'jcrop', array( 'jquery' ) ); |
| 239 | - wp_enqueue_script( 'country-select', USERSWP_PLUGIN_URL . 'assets/js/countrySelect' . $suffix . '.js', array( 'jquery' ), USERSWP_VERSION ); | |
| 214 | + wp_enqueue_script( "country-select", USERSWP_PLUGIN_URL . 'assets/js/countrySelect' . $suffix . '.js', array( 'jquery' ), USERSWP_VERSION ); | |
| 240 | 215 | |
| 241 | 216 | $country_data = uwp_get_country_data(); |
| 242 | 217 | wp_localize_script( USERSWP_NAME, 'uwp_country_data', $country_data ); |
| 243 | 218 | } |
| 244 | 219 | |
| 245 | - if ( false !== strpos( $hook_suffix, 'page_uwp_tools' ) ) { | |
| 220 | + if ( false !== strpos($hook_suffix, 'page_uwp_tools' )) { | |
| 246 | 221 | wp_enqueue_script( 'jquery-ui-progressbar', array( 'jquery' ) ); |
| 247 | 222 | } |
| 248 | 223 | |
| 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 ); | |
| 224 | + if ( false !== strpos($hook_suffix, 'page_uwp_status' )) { | |
| 225 | + wp_enqueue_script( "uwp_status", USERSWP_PLUGIN_URL . 'admin/assets/js/system-status.js', array( 'jquery' ), USERSWP_VERSION, true ); | |
| 251 | 226 | } |
| 252 | 227 | |
| 253 | - if ( false !== strpos( $hook_suffix, 'page_uwp_form_builder' ) ) { | |
| 228 | + if ( false !== strpos($hook_suffix, 'page_uwp_form_builder' )) { | |
| 254 | 229 | wp_enqueue_script( 'jquery-ui-sortable' ); |
| 255 | 230 | 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' ); | |
| 231 | + wp_enqueue_script( "uwp_form_builder", USERSWP_PLUGIN_URL . 'admin/assets/js/uwp-form-builder' . $suffix . '.js', array(), USERSWP_VERSION, 'all' ); | |
| 257 | 232 | } |
| 258 | 233 | |
| 259 | 234 | 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 ); | |
| 235 | + wp_enqueue_script( "userswp_admin", USERSWP_PLUGIN_URL . 'admin/assets/js/users-wp-admin' . $suffix . '.js', array( 'jquery' ), USERSWP_VERSION, false ); | |
| 261 | 236 | |
| 262 | - wp_enqueue_script( 'jquery-ui-tooltip' ); | |
| 237 | + wp_enqueue_script( "jquery-ui-tooltip" ); | |
| 263 | 238 | wp_enqueue_script( 'wp-color-picker' ); |
| 264 | 239 | |
| 265 | - if ( 'userswp_page_uwp_user_types' === $screen_id ) { | |
| 266 | - wp_enqueue_script( 'jquery-ui-sortable' ); | |
| 267 | - } | |
| 268 | - | |
| 269 | 240 | $ajax_cons_data = array( |
| 270 | 241 | '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 | 242 | 'custom_field_not_blank_var' => __( 'Field key must not be blank', 'userswp' ), |
| 276 | 243 | 'custom_field_options_not_blank_var' => __( 'Option Values must not be blank', 'userswp' ), |
| 277 | 244 | 'custom_field_not_special_char' => __( 'Please do not use special character and spaces in field key.', 'userswp' ), |
| 278 | 245 | 'custom_field_unique_name' => __( 'Field key should be a unique name.', 'userswp' ), |
| @@ -279,26 +246,19 @@ | ||
| 279 | 246 | 'custom_field_delete' => __( 'Are you sure you wish to delete this field?', 'userswp' ), |
| 280 | 247 | 'custom_field_id_required' => __( 'This field is required.', 'userswp' ), |
| 281 | 248 | 'img_spacer' => admin_url( 'images/media-button-image.gif' ), |
| 282 | 249 | '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' ), | |
| 250 | + 'txt_use_image' => __( 'Use image', 'userswp' ), | |
| 291 | 251 | 'delete_register_form' => __( 'Are you sure you wish to delete this form?', 'userswp' ), |
| 292 | 252 | 'ask_register_form_title' => __( 'Enter register form title', 'userswp' ), |
| 293 | - 'form_updated_msg' => __( 'Updated! Reloading page...', 'userswp' ), | |
| 253 | + 'form_updated_msg' => __( 'Updated! Reloading page...', 'userswp' ) | |
| 294 | 254 | ); |
| 255 | + wp_localize_script( "userswp_admin", 'uwp_admin_ajax', $ajax_cons_data ); | |
| 256 | + } | |
| 295 | 257 | |
| 296 | - wp_localize_script( 'userswp_admin', 'uwp_admin_ajax', $ajax_cons_data ); | |
| 297 | - } | |
| 298 | 258 | } |
| 299 | 259 | |
| 300 | - public function get_screen_ids() { | |
| 260 | + public function get_screen_ids(){ | |
| 301 | 261 | return uwp_get_screen_ids(); |
| 302 | 262 | } |
| 303 | 263 | |
| 304 | 264 | /** |
| @@ -343,12 +303,12 @@ | ||
| 343 | 303 | */ |
| 344 | 304 | public function admin_only_script() { |
| 345 | 305 | |
| 346 | 306 | // check page is userswp or not. |
| 347 | - if ( ! empty( $_GET['page'] ) && 'userswp' == $_GET['page'] ) { | |
| 307 | + if ( ! empty( $_GET['page'] ) && 'userswp' == $_GET['page']) { | |
| 348 | 308 | |
| 349 | 309 | // check tab is general or not. |
| 350 | - if ( ! empty( $_GET['tab'] ) && 'general' == $_GET['tab'] ) { | |
| 310 | + if ( ! empty( $_GET['tab'] ) && 'general' == $_GET['tab']) { | |
| 351 | 311 | |
| 352 | 312 | // check for login section. |
| 353 | 313 | if ( ! empty( $_GET['section'] ) && 'login' == $_GET['section'] ) { |
| 354 | 314 | ?> |
| @@ -369,11 +329,12 @@ | ||
| 369 | 329 | </script> |
| 370 | 330 | <?php |
| 371 | 331 | } |
| 372 | 332 | } |
| 333 | + | |
| 373 | 334 | } |
| 374 | 335 | |
| 375 | - if ( ! empty( $_GET['page'] ) && 'uwp_user_types' == $_GET['page'] ) { | |
| 336 | + if(! empty( $_GET['page'] ) && 'uwp_form_builder' == $_GET['page']) { | |
| 376 | 337 | ?> |
| 377 | 338 | <script type="text/javascript"> |
| 378 | 339 | jQuery(document).ready(function () { |
| 379 | 340 | var uwp_registration_action = jQuery('#uwp_registration_action'); |
| @@ -380,9 +341,13 @@ | ||
| 380 | 341 | uwp_registration_action.on('change', function () { |
| 381 | 342 | var value = jQuery(this).val(); |
| 382 | 343 | var register_redirect_obj = jQuery('#register_redirect_to'); |
| 383 | 344 | |
| 384 | - register_redirect_obj.parents('tr').toggle(value === 'auto_approve_login'); | |
| 345 | + if ('auto_approve_login' === value) { | |
| 346 | + register_redirect_obj.parent().parent().show(); | |
| 347 | + } else { | |
| 348 | + register_redirect_obj.parent().parent().hide(); | |
| 349 | + } | |
| 385 | 350 | }).change(); |
| 386 | 351 | |
| 387 | 352 | var register_redirect_to = jQuery('#register_redirect_to'); |
| 388 | 353 | register_redirect_to.on('change', function () { |
| @@ -387,14 +352,22 @@ | ||
| 387 | 352 | var register_redirect_to = jQuery('#register_redirect_to'); |
| 388 | 353 | register_redirect_to.on('change', function () { |
| 389 | 354 | var value = jQuery(this).val(); |
| 390 | 355 | var register_redirect_custom_obj = jQuery('#register_redirect_custom_url'); |
| 391 | - register_redirect_custom_obj.parents('tr').toggle(value === '-2'); | |
| 356 | + | |
| 357 | + if ('-2' === value) { | |
| 358 | + register_redirect_custom_obj.parent().show(); | |
| 359 | + register_redirect_custom_obj.parent().prev().show(); | |
| 360 | + } else { | |
| 361 | + register_redirect_custom_obj.parent().hide(); | |
| 362 | + register_redirect_custom_obj.parent().prev().hide(); | |
| 363 | + } | |
| 392 | 364 | }).change(); |
| 393 | 365 | }); |
| 394 | 366 | </script> |
| 395 | 367 | <?php |
| 396 | 368 | } |
| 369 | + | |
| 397 | 370 | } |
| 398 | 371 | |
| 399 | 372 | /** |
| 400 | 373 | * Filters the user profile picture description displayed under the Gravatar. |
| @@ -411,15 +384,14 @@ | ||
| 411 | 384 | $user_id = get_current_user_id(); |
| 412 | 385 | $avatar = uwp_get_usermeta( $user_id, 'avatar_thumb', '' ); |
| 413 | 386 | |
| 414 | 387 | 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 | - ); | |
| 388 | + $description = sprintf( __( 'You can change your profile picture on your <a href="%s">Profile Page</a>.', 'userswp' ), | |
| 389 | + uwp_build_profile_tab_url( $user_id ) ); | |
| 419 | 390 | } |
| 420 | -} | |
| 421 | 391 | |
| 392 | + } | |
| 393 | + | |
| 422 | 394 | return $description; |
| 423 | 395 | } |
| 424 | 396 | |
| 425 | 397 | public function admin_body_class( $classes ) { |
| @@ -462,9 +434,9 @@ | ||
| 462 | 434 | $plain_text = UsersWP_Mails::get_email_type() != 'html' ? true : false; |
| 463 | 435 | |
| 464 | 436 | // Get the preview email content. |
| 465 | 437 | ob_start(); |
| 466 | - include 'views/html-email-template-preview.php'; | |
| 438 | + include( 'views/html-email-template-preview.php' ); | |
| 467 | 439 | $message = ob_get_clean(); |
| 468 | 440 | |
| 469 | 441 | $message = UsersWP_Mails::email_wrap_message( $message, $email_name, $email_vars, '', $plain_text ); |
| 470 | 442 | $message = UsersWP_Mails::style_body( $message, $email_name, $email_vars ); |
| @@ -514,11 +486,11 @@ | ||
| 514 | 486 | 'meta_query' => array( |
| 515 | 487 | array( |
| 516 | 488 | 'key' => 'uwp_mod', |
| 517 | 489 | 'value' => 'email_unconfirmed', |
| 518 | - 'compare' => '=', | |
| 519 | - ), | |
| 520 | - ), | |
| 490 | + 'compare' => '=' | |
| 491 | + ) | |
| 492 | + ) | |
| 521 | 493 | ); |
| 522 | 494 | $users = new WP_User_Query( $args ); |
| 523 | 495 | |
| 524 | 496 | return isset( $users->results ) ? (int) count( $users->results ) : 0; |
| @@ -534,15 +506,14 @@ | ||
| 534 | 506 | global $wpdb, $pagenow; |
| 535 | 507 | |
| 536 | 508 | if ( is_admin() && $pagenow == 'users.php' && isset( $_GET['uwp_status'] ) && $_GET['uwp_status'] != '' ) { |
| 537 | 509 | |
| 538 | - do_action( 'uwp_users_show_pending_email_activation', $query ); | |
| 510 | + do_action('uwp_users_show_pending_email_activation', $query); | |
| 539 | 511 | |
| 540 | 512 | $status = sanitize_text_field( urldecode( $_GET['uwp_status'] ) ); |
| 541 | 513 | |
| 542 | 514 | if ( $status == 'pending-email-activate' ) { |
| 543 | - $query->query_where = str_replace( | |
| 544 | - 'WHERE 1=1', | |
| 515 | + $query->query_where = str_replace( 'WHERE 1=1', | |
| 545 | 516 | "WHERE 1=1 AND {$wpdb->users}.ID IN ( |
| 546 | 517 | SELECT {$wpdb->usermeta}.user_id FROM $wpdb->usermeta |
| 547 | 518 | WHERE {$wpdb->usermeta}.meta_key = 'uwp_mod' |
| 548 | 519 | AND {$wpdb->usermeta}.meta_value = 'email_unconfirmed')", |
| @@ -565,10 +536,10 @@ | ||
| 565 | 536 | public function get_profile_extra_edit( $user ) { |
| 566 | 537 | global $wpdb; |
| 567 | 538 | $table_name = uwp_get_table_prefix() . 'uwp_form_fields'; |
| 568 | 539 | $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 ); | |
| 540 | + $excluded_fields = apply_filters( 'uwp_exclude_edit_profile_fields', array('bio', 'register_gdpr', 'register_tos', 'uwp_language', 'multisite_site_title', 'multisite_site_address') ); | |
| 541 | + $query = $wpdb->prepare("SELECT * FROM " . $table_name . " WHERE form_type = 'account' AND is_default = '0' AND form_id = %d", $form_id); | |
| 571 | 542 | if ( is_array( $excluded_fields ) && count( $excluded_fields ) > 0 ) { |
| 572 | 543 | $query .= " AND htmlvar_name NOT IN ('" . implode( "','", $excluded_fields ) . "')"; |
| 573 | 544 | } |
| 574 | 545 | $query .= ' ORDER BY sort_order ASC'; |
| @@ -578,14 +549,14 @@ | ||
| 578 | 549 | |
| 579 | 550 | if ( $fields ) { |
| 580 | 551 | ?> |
| 581 | 552 | <div class="uwp-profile-extra"> |
| 582 | - <table class="uwp-profile-extra-table form-table"> | |
| 553 | + <table class="uwp-profile-extra-table form-table bsui"> | |
| 583 | 554 | <?php |
| 584 | 555 | foreach ( $fields as $field ) { |
| 585 | 556 | |
| 586 | - if ( isset( $field->css_class ) && ! empty( $field->css_class ) ) { | |
| 587 | - $field->css_class = $field->css_class . ' w-50'; | |
| 557 | + if(isset($field->css_class) && !empty($field->css_class)){ | |
| 558 | + $field->css_class = $field->css_class.' w-50'; | |
| 588 | 559 | } else { |
| 589 | 560 | $field->css_class = 'w-50'; |
| 590 | 561 | } |
| 591 | 562 | |
| @@ -590,24 +561,21 @@ | ||
| 590 | 561 | } |
| 591 | 562 | |
| 592 | 563 | if ( $field->field_type == 'fieldset' ) { |
| 593 | 564 | ?> |
| 594 | - <tr> | |
| 595 | - <th class="uwp-profile-extra-key"> | |
| 596 | - <h2><?php echo esc_html( $field->site_title ); ?></h2> | |
| 597 | - </th> | |
| 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 esc_html( $field->site_title ); ?></h3></th> | |
| 598 | 568 | <td></td> |
| 599 | 569 | </tr> |
| 600 | 570 | <?php |
| 601 | - } else { | |
| 602 | - ?> | |
| 571 | + } else { ?> | |
| 603 | 572 | <tr> |
| 604 | 573 | <th class="uwp-profile-extra-key"><?php echo esc_html( $field->site_title ); ?></th> |
| 605 | - <td class="uwp-profile-extra-value bsui"> | |
| 574 | + <td class="uwp-profile-extra-value"> | |
| 606 | 575 | <?php |
| 607 | 576 | $templates_obj = new UsersWP_Templates(); |
| 608 | - $templates_obj->template_fields_html( $field, 'account', $user->ID ); | |
| 609 | - ?> | |
| 577 | + $templates_obj->template_fields_html( $field, 'account', $user->ID ); ?> | |
| 610 | 578 | </td> |
| 611 | 579 | </tr> |
| 612 | 580 | <?php |
| 613 | 581 | } |
| @@ -634,14 +602,14 @@ | ||
| 634 | 602 | |
| 635 | 603 | $file_obj = new UsersWP_Files(); |
| 636 | 604 | |
| 637 | 605 | $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 | |
| 606 | + $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 | 607 | if ( $fields ) { |
| 640 | 608 | ?> |
| 641 | 609 | <div class="uwp-profile-extra uwp_page"> |
| 642 | 610 | <?php do_action( 'uwp_admin_profile_edit', $user ); ?> |
| 643 | - <h2><?php esc_html_e( 'UsersWP Account Details', 'userswp' ); ?></h2> | |
| 611 | + <h2><?php esc_html_e('UsersWP Account Details', 'userswp'); ?></h2> | |
| 644 | 612 | <table class="uwp-profile-extra-table form-table"> |
| 645 | 613 | <?php |
| 646 | 614 | foreach ( $fields as $field ) { |
| 647 | 615 | |
| @@ -646,52 +614,50 @@ | ||
| 646 | 614 | foreach ( $fields as $field ) { |
| 647 | 615 | |
| 648 | 616 | if ( $field->field_type == 'fieldset' ) { |
| 649 | 617 | ?> |
| 650 | - <tr> | |
| 651 | - <th class="uwp-profile-extra-key"> | |
| 652 | - <h2><?php echo esc_html( $field->site_title ); ?></h2> | |
| 653 | - </th> | |
| 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 esc_html( $field->site_title ); ?></h3></th> | |
| 654 | 622 | <td></td> |
| 655 | 623 | </tr> |
| 656 | 624 | <?php |
| 657 | - } else { | |
| 658 | - ?> | |
| 625 | + } else { ?> | |
| 659 | 626 | <tr> |
| 660 | 627 | <th class="uwp-profile-extra-key"><?php echo esc_html( $field->site_title ); ?></th> |
| 661 | - <td class="uwp-profile-extra-value bsui"> | |
| 628 | + <td class="uwp-profile-extra-value"> | |
| 662 | 629 | <?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', '' ); | |
| 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", "" ); | |
| 667 | 634 | } else { |
| 668 | - $value = ''; | |
| 635 | + $value = ""; | |
| 669 | 636 | } |
| 670 | 637 | |
| 671 | 638 | echo $file_obj->file_upload_preview( $field, $value ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 672 | 639 | |
| 673 | - if ( $field->htmlvar_name == 'avatar' ) { | |
| 640 | + if ( $field->htmlvar_name == "avatar" ) { | |
| 674 | 641 | if ( ! empty( $value ) ) { |
| 675 | - $label = __( 'Change Avatar', 'userswp' ); | |
| 642 | + $label = __( "Change Avatar", "userswp" ); | |
| 676 | 643 | } else { |
| 677 | - $label = __( 'Upload Avatar', 'userswp' ); | |
| 644 | + $label = __( "Upload Avatar", "userswp" ); | |
| 678 | 645 | } |
| 679 | 646 | ?> |
| 680 | 647 | <a onclick="uwp_profile_image_change('avatar');return false;" href="#" |
| 681 | - class="uwp-banner-change-icon-admin"> | |
| 648 | + class="uwp-banner-change-icon-admin"> | |
| 682 | 649 | <?php echo esc_html( $label ); ?> |
| 683 | 650 | </a> |
| 684 | 651 | <?php |
| 685 | - } elseif ( $field->htmlvar_name == 'banner' ) { | |
| 652 | + } elseif ( $field->htmlvar_name == "banner" ) { | |
| 686 | 653 | if ( ! empty( $value ) ) { |
| 687 | - $label = __( 'Change Banner', 'userswp' ); | |
| 654 | + $label = __( "Change Banner", "userswp" ); | |
| 688 | 655 | } else { |
| 689 | - $label = __( 'Upload Banner', 'userswp' ); | |
| 690 | - } | |
| 691 | - ?> | |
| 656 | + $label = __( "Upload Banner", "userswp" ); | |
| 657 | + } ?> | |
| 692 | 658 | <a onclick="uwp_profile_image_change('banner');return false;" href="#" |
| 693 | - class="uwp-banner-change-icon-admin"> | |
| 659 | + class="uwp-banner-change-icon-admin"> | |
| 694 | 660 | <?php echo esc_html( $label ); ?> |
| 695 | 661 | </a> |
| 696 | 662 | <?php |
| 697 | 663 | } |
| @@ -722,12 +688,12 @@ | ||
| 722 | 688 | $user_id = $user_object->ID; |
| 723 | 689 | $mod_value = get_user_meta( $user_id, 'uwp_mod', true ); |
| 724 | 690 | $resend_link = add_query_arg( |
| 725 | 691 | array( |
| 726 | - 'user_id' => $user_id, | |
| 727 | - 'action' => 'uwp_resend', | |
| 728 | - '_nonce' => wp_create_nonce( 'uwp_resend' ), | |
| 729 | - 'uwp_is_admin' => 1, | |
| 692 | + 'user_id' => $user_id, | |
| 693 | + 'action' => 'uwp_resend', | |
| 694 | + '_nonce' => wp_create_nonce( 'uwp_resend' ), | |
| 695 | + 'uwp_is_admin' => 1, | |
| 730 | 696 | ), |
| 731 | 697 | admin_url( 'users.php' ) |
| 732 | 698 | ); |
| 733 | 699 | |
| @@ -732,19 +698,19 @@ | ||
| 732 | 698 | ); |
| 733 | 699 | |
| 734 | 700 | $activate_link = add_query_arg( |
| 735 | 701 | array( |
| 736 | - 'user_id' => $user_id, | |
| 737 | - 'action' => 'uwp_activate_user', | |
| 738 | - '_nonce' => wp_create_nonce( 'uwp_activate_user' ), | |
| 739 | - 'uwp_is_admin' => 1, | |
| 702 | + 'user_id' => $user_id, | |
| 703 | + 'action' => 'uwp_activate_user', | |
| 704 | + '_nonce' => wp_create_nonce( 'uwp_activate_user' ), | |
| 705 | + 'uwp_is_admin' => 1, | |
| 740 | 706 | ), |
| 741 | 707 | admin_url( 'users.php' ) |
| 742 | 708 | ); |
| 743 | 709 | |
| 744 | 710 | 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>'; | |
| 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>"; | |
| 747 | 713 | } |
| 748 | 714 | |
| 749 | 715 | return $actions; |
| 750 | 716 | } |
| @@ -822,29 +788,27 @@ | ||
| 822 | 788 | * |
| 823 | 789 | */ |
| 824 | 790 | public function process_user_actions() { |
| 825 | 791 | $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; | |
| 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; | |
| 829 | 795 | |
| 830 | - if ( $user_id && 'uwp_resend' == $action && ! empty( $nonce ) && wp_verify_nonce( $nonce, 'uwp_resend' ) ) { | |
| 796 | + if ( $user_id && 'uwp_resend' == $action && !empty($nonce) && wp_verify_nonce( $nonce, 'uwp_resend' ) ) { | |
| 831 | 797 | uwp_resend_activation_mail( $user_id ); |
| 832 | - if ( isset( $is_admin ) && $is_admin ) { | |
| 798 | + if ( isset($is_admin) && $is_admin ) { | |
| 833 | 799 | wp_redirect( add_query_arg( 'update', 'uwp_resend', admin_url( 'users.php' ) ) ); |
| 834 | 800 | exit(); |
| 835 | 801 | } else { |
| 836 | 802 | global $uwp_notices; |
| 837 | 803 | $message = __( 'Activation email has been sent!', 'userswp' ); |
| 838 | - $uwp_notices[] = aui()->alert( | |
| 839 | - array( | |
| 840 | - 'type' => 'success', | |
| 841 | - 'content' => $message, | |
| 842 | - ) | |
| 843 | - ); | |
| 804 | + $uwp_notices[] = aui()->alert( array( | |
| 805 | + 'type' => 'success', | |
| 806 | + 'content' => $message | |
| 807 | + ) ); | |
| 844 | 808 | } |
| 845 | 809 | } 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' ) ) { | |
| 810 | + if ( isset($is_admin) && $is_admin && current_user_can( 'edit_users' ) ) { | |
| 847 | 811 | $this->activate_user( $user_id ); |
| 848 | 812 | wp_redirect( add_query_arg( 'update', 'uwp_activate_user', admin_url( 'users.php' ) ) ); |
| 849 | 813 | } |
| 850 | 814 | } |
| @@ -852,17 +816,17 @@ | ||
| 852 | 816 | |
| 853 | 817 | /** |
| 854 | 818 | * Show row meta on the plugin screen. |
| 855 | 819 | * |
| 856 | - * @param mixed $links Plugin Row Meta | |
| 857 | - * @param mixed $file Plugin Base file | |
| 858 | - * @return array | |
| 820 | + * @param mixed $links Plugin Row Meta | |
| 821 | + * @param mixed $file Plugin Base file | |
| 822 | + * @return array | |
| 859 | 823 | */ |
| 860 | 824 | public static function plugin_row_meta( $links, $file ) { |
| 861 | 825 | if ( USERSWP_PLUGIN_BASENAME == $file ) { |
| 862 | 826 | $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>', | |
| 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>', | |
| 865 | 829 | 'translation' => '<a href="' . esc_url( 'https://userswp.io/translate/projects' ) . '" aria-label="' . esc_attr__( 'View translations', 'userswp' ) . '">' . esc_html__( 'Translations', 'userswp' ) . '</a>', |
| 866 | 830 | ); |
| 867 | 831 | |
| 868 | 832 | return array_merge( $links, $row_meta ); |
| @@ -870,271 +834,179 @@ | ||
| 870 | 834 | |
| 871 | 835 | return (array) $links; |
| 872 | 836 | } |
| 873 | 837 | |
| 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' ); | |
| 838 | + public function process_create_register_form() { | |
| 882 | 839 | |
| 883 | - if ( ! current_user_can( 'manage_options' ) ) { | |
| 884 | - wp_die( -1 ); | |
| 885 | - } | |
| 840 | + if ( ! current_user_can( 'manage_options' ) ) { | |
| 841 | + wp_die( -1 ); | |
| 842 | + } | |
| 886 | 843 | |
| 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 ); | |
| 844 | + $type = ! empty( $_POST['type'] ) ? sanitize_text_field($_POST['type']) : ''; | |
| 845 | + $form_title = ! empty( $_POST['form_title'] ) ? sanitize_title_with_dashes($_POST['form_title']) : ''; | |
| 846 | + $nonce = ! empty( $_POST['nonce'] ) ? sanitize_text_field($_POST['nonce']) : ''; | |
| 894 | 847 | |
| 895 | - if ( empty( $form_title ) ) { | |
| 896 | - wp_send_json_error( | |
| 897 | - array( | |
| 898 | - 'message' => esc_html__( 'Form title is required.', 'userswp' ), | |
| 899 | - ) | |
| 900 | - ); | |
| 901 | - } | |
| 848 | + $status = false; | |
| 849 | + $message = __( 'Something went wrong. Please try again.', 'userswp' ); | |
| 850 | + $redirect = ''; | |
| 851 | + if ( ! empty( $type ) && $type == 'create' && ! empty( $nonce ) && wp_verify_nonce( $nonce, 'uwp-create-register-form-nonce' ) ) { | |
| 902 | 852 | |
| 903 | - $status = false; | |
| 904 | - $redirect = ''; | |
| 853 | + $get_register_forms = uwp_get_option( 'multiple_registration_forms' ); | |
| 854 | + $new_form_id = uwp_get_next_register_form_id(); | |
| 905 | 855 | |
| 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 | - ); | |
| 856 | + if ( ! empty( $new_form_id ) ) { | |
| 916 | 857 | |
| 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 | - ); | |
| 858 | + $get_register_forms[] = array( | |
| 859 | + 'id' => $new_form_id, | |
| 860 | + 'title' => ! empty( $form_title ) ? sanitize_text_field( $form_title ) : sprintf( __( 'Form %d', 'userswp' ), $new_form_id ), | |
| 861 | + ); | |
| 928 | 862 | |
| 929 | - $register_forms = array_values( $register_forms ); | |
| 930 | - $register_forms = apply_filters( 'uwp_multiple_registration_forms_update', $register_forms, $new_form_id ); | |
| 863 | + uwp_update_option( 'multiple_registration_forms', $get_register_forms ); | |
| 931 | 864 | |
| 932 | - uwp_update_option( 'multiple_registration_forms', $register_forms ); | |
| 865 | + $fields = UsersWP_Activator::uwp_default_custom_fields_account(); | |
| 866 | + $form_builder = new UsersWP_Form_Builder(); | |
| 933 | 867 | |
| 934 | - $fields = UsersWP_Activator::uwp_default_custom_fields_account(); | |
| 935 | - $form_builder = new UsersWP_Form_Builder(); | |
| 868 | + if(isset($fields) && count($fields) > 0){ | |
| 869 | + foreach ($fields as $field_index => $field) { | |
| 870 | + $field['form_id'] = $new_form_id; | |
| 871 | + $form_builder->admin_form_field_save($field); | |
| 872 | + } | |
| 873 | + } | |
| 936 | 874 | |
| 937 | - foreach ( $fields as $field ) { | |
| 938 | - $field['form_id'] = $new_form_id; | |
| 939 | - $form_builder->admin_form_field_save( $field ); | |
| 940 | - } | |
| 875 | + UsersWP_Activator::insert_form_extras($new_form_id); | |
| 941 | 876 | |
| 942 | - UsersWP_Activator::insert_form_extras( $new_form_id ); | |
| 877 | + do_action('uwp_create_register_form', $new_form_id); | |
| 943 | 878 | |
| 944 | - do_action( 'uwp_create_register_form', $new_form_id ); | |
| 879 | + $status = true; | |
| 880 | + $redirect = admin_url( 'admin.php?page=uwp_form_builder&tab=account&form=' . $new_form_id ); | |
| 881 | + } | |
| 882 | + } | |
| 945 | 883 | |
| 946 | - $status = true; | |
| 947 | - $redirect = admin_url( sprintf( 'admin.php?page=uwp_user_types&form=%d', $new_form_id ) ); | |
| 948 | - } | |
| 884 | + $response = array( | |
| 885 | + 'status' => $status, | |
| 886 | + 'message' => $message, | |
| 887 | + 'redirect' => $redirect, | |
| 888 | + ); | |
| 949 | 889 | |
| 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 | - } | |
| 890 | + echo json_encode( $response ); | |
| 891 | + wp_die(); | |
| 892 | + } | |
| 958 | 893 | |
| 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' ); | |
| 894 | + public function process_update_register_form() { | |
| 967 | 895 | |
| 968 | - if ( ! current_user_can( 'manage_options' ) ) { | |
| 969 | - wp_die( -1 ); | |
| 970 | - } | |
| 896 | + check_ajax_referer( 'uwp-update-register-form-nonce', 'uwp_update_register_form_nonce' ); | |
| 971 | 897 | |
| 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 ); | |
| 898 | + if ( ! current_user_can( 'manage_options' ) ) { | |
| 899 | + wp_die( -1 ); | |
| 900 | + } | |
| 980 | 901 | |
| 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 | - } | |
| 902 | + $type = ! empty( $_POST['type'] ) ? sanitize_text_field($_POST['type']) : ''; | |
| 903 | + $form_id = ! empty( $_POST['manage_field_form_id'] ) ? (int)$_POST['manage_field_form_id'] : ''; | |
| 904 | + $form_title = ! empty( $_POST['form_title'] ) ? sanitize_text_field($_POST['form_title']) : __( 'Form', 'userswp' ); | |
| 905 | + $user_role = ! empty( $_POST['user_role'] ) ? sanitize_text_field($_POST['user_role']) : ''; | |
| 906 | + $action = ! empty( $_POST['reg_action'] ) ? sanitize_text_field($_POST['reg_action']) : uwp_get_option( 'uwp_registration_action', 'auto_approve' ); | |
| 907 | + $redirect_to = (int) $_POST['redirect_to']; | |
| 908 | + $custom_url = ! empty( $_POST['custom_url'] ) ? sanitize_text_field($_POST['custom_url']) : ''; | |
| 909 | + $gdpr_page = ! empty( $_POST['gdpr_page'] ) ? (int)$_POST['gdpr_page'] : (int)uwp_get_option('register_gdpr_page', false); | |
| 910 | + $tos_page = ! empty( $_POST['tos_page'] ) ? (int)$_POST['tos_page'] : (int)uwp_get_option('register_terms_page', false); | |
| 988 | 911 | |
| 989 | - $redirect = ''; | |
| 990 | - $status = false; | |
| 912 | + $status = false; | |
| 913 | + $message = __( 'Something went wrong. Please try again.', 'userswp' ); | |
| 914 | + if ( ! empty( $type ) && ! empty( $form_id ) && $type === 'update' ) { | |
| 991 | 915 | |
| 992 | - $register_forms = (array) uwp_get_option( 'multiple_registration_forms', array() ); | |
| 916 | + $register_forms = uwp_get_option( 'multiple_registration_forms' ); | |
| 993 | 917 | |
| 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 | - } | |
| 918 | + if ( ! empty( $register_forms ) && is_array( $register_forms ) ) { | |
| 1007 | 919 | |
| 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 | - } | |
| 920 | + foreach ( $register_forms as $key => $register_form ) { | |
| 1020 | 921 | |
| 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 | - } | |
| 922 | + if ( ! empty( $register_form['id'] ) && $register_form['id'] == $form_id ) { | |
| 923 | + $status = true; | |
| 924 | + $register_forms[ $key ]['title'] = $form_title; | |
| 925 | + $register_forms[ $key ]['user_role'] = $user_role; | |
| 926 | + $register_forms[ $key ]['reg_action'] = $action; | |
| 927 | + $register_forms[ $key ]['redirect_to'] = $redirect_to; | |
| 928 | + $register_forms[ $key ]['custom_url'] = $custom_url; | |
| 929 | + $register_forms[ $key ]['gdpr_page'] = $gdpr_page; | |
| 930 | + $register_forms[ $key ]['tos_page'] = $tos_page; | |
| 931 | + } | |
| 932 | + } | |
| 933 | + } | |
| 1028 | 934 | |
| 1029 | - public function reorder_user_types() { | |
| 1030 | - check_ajax_referer( 'uwp_reorder_user_types', 'nonce' ); | |
| 935 | + $register_forms = array_values( $register_forms ); | |
| 936 | + $register_forms = apply_filters('uwp_multiple_registration_forms_update', $register_forms); | |
| 937 | + uwp_update_option( 'multiple_registration_forms', $register_forms ); | |
| 938 | + } | |
| 1031 | 939 | |
| 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 | - } | |
| 940 | + $response = array( | |
| 941 | + 'status' => $status, | |
| 942 | + 'message' => $message, | |
| 943 | + ); | |
| 1035 | 944 | |
| 1036 | - $order = isset( $_POST['order'] ) ? array_map( 'absint', $_POST['order'] ) : array(); | |
| 945 | + echo json_encode( $response ); | |
| 946 | + wp_die(); | |
| 947 | + } | |
| 1037 | 948 | |
| 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 | 949 | public function process_remove_register_form() { |
| 1060 | 950 | |
| 1061 | - check_ajax_referer( 'uwp_delete_user_types', 'nonce' ); | |
| 951 | + check_ajax_referer( 'uwp-delete-register-form-nonce', 'nonce' ); | |
| 1062 | 952 | |
| 1063 | 953 | if ( ! current_user_can( 'manage_options' ) ) { |
| 1064 | 954 | wp_die( -1 ); |
| 1065 | 955 | } |
| 1066 | 956 | |
| 1067 | - $type = ! empty( $_POST['type'] ) ? sanitize_text_field( $_POST['type'] ) : ''; | |
| 1068 | - $form_id = ! empty( $_POST['form_id'] ) ? (int) $_POST['form_id'] : ''; | |
| 957 | + global $wpdb; | |
| 958 | + $table_name = uwp_get_table_prefix() . 'uwp_form_fields'; | |
| 1069 | 959 | |
| 960 | + $type = ! empty( $_POST['type'] ) ? sanitize_text_field($_POST['type']) : ''; | |
| 961 | + $form_id = ! empty( $_POST['form_id'] ) ? (int)$_POST['form_id'] : ''; | |
| 962 | + | |
| 1070 | 963 | $status = false; |
| 1071 | 964 | $message = __( 'Security nonce failed. Please try again.', 'userswp' ); |
| 1072 | 965 | $redirect = ''; |
| 1073 | - | |
| 1074 | 966 | 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 | 967 | |
| 1079 | - wp_send_json( | |
| 1080 | - array( | |
| 1081 | - 'status' => $status, | |
| 1082 | - 'message' => $message, | |
| 1083 | - 'redirect' => $redirect, | |
| 1084 | - ) | |
| 1085 | - ); | |
| 1086 | - } | |
| 968 | + $register_forms = uwp_get_option( 'multiple_registration_forms' ); | |
| 969 | + $form_builder = new UsersWP_Form_Builder(); | |
| 1087 | 970 | |
| 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; | |
| 971 | + if ( ! empty( $register_forms ) && is_array( $register_forms ) ) { | |
| 1098 | 972 | |
| 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(); | |
| 973 | + foreach ( $register_forms as $key => $register_form ) { | |
| 1103 | 974 | |
| 1104 | - if ( empty( $register_forms ) || ! is_array( $register_forms ) ) { | |
| 1105 | - return $status; | |
| 1106 | - } | |
| 975 | + if ( ! empty( $register_form['id'] ) && $register_form['id'] == $form_id ) { | |
| 976 | + $status = true; | |
| 977 | + unset( $register_forms[ $key ] ); | |
| 978 | + $fields = $wpdb->get_results( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 979 | + $wpdb->prepare( | |
| 980 | + "select id from " . $table_name . " where form_type = %s AND form_id = %d order by sort_order asc", | |
| 981 | + array('account', $form_id) | |
| 982 | + ) | |
| 983 | + ); | |
| 1107 | 984 | |
| 1108 | - foreach ( $register_forms as $key => $register_form ) { | |
| 1109 | - if ( empty( $register_form['id'] ) || (int) $register_form['id'] !== $form_id ) { | |
| 1110 | - continue; | |
| 1111 | - } | |
| 985 | + if (!empty($fields)) { | |
| 986 | + foreach ($fields as $field) { | |
| 987 | + $form_builder->admin_form_field_delete($field->id, false, $form_id); | |
| 988 | + } | |
| 989 | + } | |
| 990 | + } | |
| 991 | + } | |
| 992 | + } | |
| 1112 | 993 | |
| 1113 | - $status = true; | |
| 1114 | - unset( $register_forms[ $key ] ); | |
| 994 | + $register_forms = array_values( $register_forms ); | |
| 995 | + uwp_update_option( 'multiple_registration_forms', $register_forms ); | |
| 996 | + $redirect = admin_url( 'admin.php?page=uwp_form_builder&tab=account' ); | |
| 997 | + } | |
| 1115 | 998 | |
| 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 | - ); | |
| 999 | + $response = array( | |
| 1000 | + 'status' => $status, | |
| 1001 | + 'message' => $message, | |
| 1002 | + 'redirect' => $redirect, | |
| 1003 | + ); | |
| 1123 | 1004 | |
| 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 | - } | |
| 1005 | + echo json_encode( $response ); | |
| 1006 | + wp_die(); | |
| 1007 | + } | |
| 1130 | 1008 | |
| 1131 | - $register_forms = array_values( $register_forms ); | |
| 1132 | - uwp_update_option( 'multiple_registration_forms', $register_forms ); | |
| 1133 | - | |
| 1134 | - return $status; | |
| 1135 | - } | |
| 1136 | - | |
| 1137 | 1009 | /** |
| 1138 | 1010 | * Tell AyeCode UI to load on certain admin pages. |
| 1139 | 1011 | * |
| 1140 | 1012 | * @since 1.2.3.22 |
| @@ -1152,264 +1024,5 @@ | ||
| 1152 | 1024 | $screen_ids[] = 'uwp-setup'; |
| 1153 | 1025 | |
| 1154 | 1026 | return $screen_ids; |
| 1155 | 1027 | } |
| 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 '—'; | |
| 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 | -} | |
| 1028 | +} | |