| @@ -52,8 +52,16 @@ | ||
| 52 | 52 | // Add multiple roles checkbox to back-end Add / Edit User (as admin) |
| 53 | 53 | add_action( 'load-user-new.php', array( $this, 'actions_on_user_new' ) ); |
| 54 | 54 | add_action( 'load-user-edit.php', array( $this, 'actions_on_user_edit' ) ); |
| 55 | 55 | |
| 56 | + add_action( 'load-profile.php', array( $this, 'actions_on_user_new' ) ); | |
| 57 | + add_action( 'load-profile.php', array( $this, 'actions_on_user_edit' ) ); | |
| 58 | + | |
| 59 | + // Intercept account activation on multisites | |
| 60 | + if ( is_multisite() ) { | |
| 61 | + // Add the user to the blog | |
| 62 | + add_action( 'add_user_to_blog', array( $this, 'ms_add_user_to_blog' ), 10, 3 ); | |
| 63 | + } | |
| 56 | 64 | } |
| 57 | 65 | |
| 58 | 66 | function submenu_page(){ |
| 59 | 67 | |
| @@ -84,28 +92,10 @@ | ||
| 84 | 92 | |
| 85 | 93 | global $post_type; |
| 86 | 94 | global $current_screen; |
| 87 | 95 | global $post; |
| 88 | - global $wp_scripts; | |
| 89 | - global $wp_styles; | |
| 90 | 96 | |
| 91 | 97 | if( $post_type == 'wppb-roles-editor' ) { |
| 92 | - $wp_default_scripts = $this->wp_default_scripts(); | |
| 93 | - $scripts_exceptions = array( 'wppb-sitewide', 'acf-field-group', 'acf-pro-field-group', 'acf-input', 'acf-pro-input', 'query-monitor' ); | |
| 94 | - foreach( $wp_scripts->registered as $key => $value ) { | |
| 95 | - if( ! in_array( $key, $wp_default_scripts ) && ! in_array( $key, $scripts_exceptions ) ) { | |
| 96 | - wp_deregister_script( $key ); | |
| 97 | - } | |
| 98 | - } | |
| 99 | - | |
| 100 | - $wp_default_styles = $this->wp_default_styles(); | |
| 101 | - $styles_exceptions = array( 'wppb-serial-notice-css', 'acf-global', 'wppb-back-end-style', 'wppb-new-back-end-style', 'query-monitor' ); | |
| 102 | - foreach( $wp_styles->registered as $key => $value ) { | |
| 103 | - if( ! in_array( $key, $wp_default_styles ) && ! in_array( $key, $styles_exceptions ) ) { | |
| 104 | - wp_deregister_style( $key ); | |
| 105 | - } | |
| 106 | - } | |
| 107 | - | |
| 108 | 98 | wp_enqueue_script( 'wppb_select2_js', WPPB_PLUGIN_URL .'assets/js/select2/select2.min.js', array( 'jquery' ), PROFILE_BUILDER_VERSION ); |
| 109 | 99 | wp_enqueue_style( 'wppb_select2_css', WPPB_PLUGIN_URL .'assets/css/select2/select2.min.css', array(), PROFILE_BUILDER_VERSION ); |
| 110 | 100 | |
| 111 | 101 | wp_enqueue_script( 'wppb_roles_editor_js', plugin_dir_url( __FILE__ ) .'assets/js/roles-editor.js', array( 'jquery', 'wppb_select2_js' ), PROFILE_BUILDER_VERSION ); |
| @@ -560,9 +550,9 @@ | ||
| 560 | 550 | <label for="wppb-role-slug"><?php esc_html_e( 'Role Slug', 'profile-builder' ) ?>: </label> |
| 561 | 551 | <input type="text" id="wppb-role-slug" value="<?php echo $current_screen->action == 'add' ? '' : esc_attr( $role_slug ) ?>" <?php echo $current_screen->action == 'add' ? '' : 'disabled'; ?>> |
| 562 | 552 | </span> |
| 563 | 553 | </div> |
| 564 | - <?php | |
| 554 | + <?php | |
| 565 | 555 | } |
| 566 | 556 | |
| 567 | 557 | } |
| 568 | 558 | |
| @@ -654,8 +644,11 @@ | ||
| 654 | 644 | |
| 655 | 645 | $role_display_name = isset( $_POST['role_display_name'] ) ? sanitize_text_field( $_POST['role_display_name'] ) : ''; |
| 656 | 646 | |
| 657 | 647 | add_role( $role_slug, $role_display_name, $capabilities ); |
| 648 | + | |
| 649 | + do_action( 'wppb_user_role_added', $role_slug, $role_display_name, $capabilities ); | |
| 650 | + | |
| 658 | 651 | } |
| 659 | 652 | |
| 660 | 653 | die( 'role_capabilities_updated' ); |
| 661 | 654 | |
| @@ -766,9 +759,9 @@ | ||
| 766 | 759 | 'users' => $users_capabilities, |
| 767 | 760 | 'custom' => $custom_capabilities |
| 768 | 761 | ); |
| 769 | 762 | |
| 770 | - update_option( 'wppb_roles_editor_capabilities', $capabilities ); | |
| 763 | + update_option( 'wppb_roles_editor_capabilities', $capabilities, false ); | |
| 771 | 764 | } else { |
| 772 | 765 | $custom_capabilities = $this->get_all_capabilities(); |
| 773 | 766 | $custom_capabilities = $this->remove_old_labels( $custom_capabilities ); |
| 774 | 767 | |
| @@ -788,9 +781,9 @@ | ||
| 788 | 781 | |
| 789 | 782 | if( ! empty( $custom_capabilities ) ) { |
| 790 | 783 | $capabilities['custom']['capabilities'] = array_merge( $capabilities['custom']['capabilities'], $custom_capabilities ); |
| 791 | 784 | |
| 792 | - update_option( 'wppb_roles_editor_capabilities', $capabilities ); | |
| 785 | + update_option( 'wppb_roles_editor_capabilities', $capabilities, false ); | |
| 793 | 786 | } |
| 794 | 787 | } |
| 795 | 788 | |
| 796 | 789 | return $capabilities; |
| @@ -858,15 +851,15 @@ | ||
| 858 | 851 | $role = get_role($role_slug); |
| 859 | 852 | $role->remove_cap(sanitize_text_field($_POST['capability'])); |
| 860 | 853 | } |
| 861 | 854 | |
| 862 | - $capabilities = get_option('wppb_roles_editor_capabilities', 'not_set'); | |
| 855 | + $capabilities = get_option( 'wppb_roles_editor_capabilities', 'not_set' ); | |
| 863 | 856 | |
| 864 | 857 | if ($capabilities != 'not_set' && ($key = array_search(sanitize_text_field($_POST['capability']), $capabilities['custom']['capabilities'])) !== false) { |
| 865 | 858 | unset($capabilities['custom']['capabilities'][$key]); |
| 866 | 859 | $capabilities['custom']['capabilities'] = array_values($capabilities['custom']['capabilities']); |
| 867 | 860 | |
| 868 | - update_option('wppb_roles_editor_capabilities', $capabilities); | |
| 861 | + update_option( 'wppb_roles_editor_capabilities', $capabilities, false ); | |
| 869 | 862 | } |
| 870 | 863 | } |
| 871 | 864 | |
| 872 | 865 | die(); |
| @@ -993,63 +986,8 @@ | ||
| 993 | 986 | remove_role( $role_slug ); |
| 994 | 987 | |
| 995 | 988 | } |
| 996 | 989 | |
| 997 | - function wp_default_scripts() { | |
| 998 | - | |
| 999 | - $wp_default_scripts = array( | |
| 1000 | - 'jquery', 'jquery-core', 'jquery-migrate', 'jquery-ui-core', 'jquery-ui-accordion', | |
| 1001 | - 'jquery-ui-autocomplete', 'jquery-ui-button', 'jquery-ui-datepicker', 'jquery-ui-dialog', | |
| 1002 | - 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-menu', 'jquery-ui-mouse', | |
| 1003 | - 'jquery-ui-position', 'jquery-ui-progressbar', 'jquery-ui-resizable', 'jquery-ui-selectable', | |
| 1004 | - 'jquery-ui-slider', 'jquery-ui-sortable', 'jquery-ui-spinner', 'jquery-ui-tabs', | |
| 1005 | - 'jquery-ui-tooltip', 'jquery-ui-widget', 'underscore', 'backbone', 'utils', 'common', | |
| 1006 | - 'wp-a11y', 'sack', 'quicktags', 'colorpicker', 'editor', 'wp-fullscreen-stub', 'wp-ajax-response', | |
| 1007 | - 'wp-pointer', 'heartbeat', 'wp-auth-check', 'wp-lists', 'prototype', 'scriptaculous-root', | |
| 1008 | - 'scriptaculous-builder', 'scriptaculous-dragdrop', 'scriptaculous-effects', 'scriptaculous-slider', | |
| 1009 | - 'scriptaculous-sound', 'scriptaculous-controls', 'scriptaculous', 'cropper', 'jquery-effects-core', | |
| 1010 | - 'jquery-effects-blind', 'jquery-effects-bounce', 'jquery-effects-clip', 'jquery-effects-drop', | |
| 1011 | - 'jquery-effects-explode', 'jquery-effects-fade', 'jquery-effects-fold', 'jquery-effects-highlight', | |
| 1012 | - 'jquery-effects-puff', 'jquery-effects-pulsate', 'jquery-effects-scale', 'jquery-effects-shake', | |
| 1013 | - 'jquery-effects-size', 'jquery-effects-slide', 'jquery-effects-transfer', 'jquery-ui-selectmenu', | |
| 1014 | - 'jquery-form', 'jquery-color', 'schedule', 'jquery-query', 'jquery-serialize-object', 'jquery-hotkeys', | |
| 1015 | - 'jquery-table-hotkeys', 'jquery-touch-punch', 'suggest', 'imagesloaded', 'masonry', 'jquery-masonry', | |
| 1016 | - 'thickbox', 'jcrop', 'swfobject', 'plupload', 'plupload-all', 'plupload-html5', 'plupload-flash', | |
| 1017 | - 'plupload-silverlight', 'plupload-html4', 'plupload-handlers', 'wp-plupload', 'swfupload', 'swfupload-swfobject', | |
| 1018 | - 'swfupload-queue', 'swfupload-speed', 'swfupload-all', 'swfupload-handlers', 'comment-reply', 'json2', | |
| 1019 | - 'underscore', 'backbone', 'wp-util', 'wp-backbone', 'revisions', 'imgareaselect', 'mediaelement', | |
| 1020 | - 'wp-mediaelement', 'froogaloop', 'wp-playlist', 'zxcvbn-async', 'password-strength-meter', 'user-profile', | |
| 1021 | - 'language-chooser', 'user-suggest', 'admin-bar', 'wplink', 'wpdialogs', 'word-count', 'media-upload', | |
| 1022 | - 'hoverIntent', 'customize-base', 'customize-loader', 'customize-preview', 'customize-models', 'customize-views', | |
| 1023 | - 'customize-controls', 'customize-selective-refresh', 'customize-widgets', 'customize-preview-widgets', | |
| 1024 | - 'customize-preview-nav-menus', 'wp-custom-header', 'accordion', 'shortcode', 'media-models', 'wp-embed', | |
| 1025 | - 'media-views', 'media-editor', 'media-audiovideo', 'mce-view', 'wp-api', 'admin-tags', 'admin-comments', 'xfn', | |
| 1026 | - 'postbox', 'tags-box', 'tags-suggest', 'post', 'press-this', 'editor-expand', 'link', 'comment', 'admin-gallery', | |
| 1027 | - 'admin-widgets', 'theme', 'inline-edit-post', 'inline-edit-tax', 'plugin-install', 'updates', 'farbtastic', 'iris', | |
| 1028 | - 'wp-color-picker', 'dashboard', 'list-revisions', 'media-grid', 'media', 'image-edit', 'set-post-thumbnail', | |
| 1029 | - 'nav-menu', 'custom-header', 'custom-background', 'media-gallery', 'svg-painter', 'customize-nav-menus', | |
| 1030 | - ); | |
| 1031 | - | |
| 1032 | - return $wp_default_scripts; | |
| 1033 | - | |
| 1034 | - } | |
| 1035 | - | |
| 1036 | - function wp_default_styles() { | |
| 1037 | - | |
| 1038 | - $wp_default_styles = array( | |
| 1039 | - 'admin-bar', 'colors', 'ie', 'wp-auth-check', 'wp-jquery-ui-dialog', 'wppb-serial-notice-css', | |
| 1040 | - 'common', 'forms', 'admin-menu', 'dashboard', 'list-tables', 'edit', 'revisions', 'media', | |
| 1041 | - 'themes', 'about', 'nav-menus', 'widgets', 'site-icon', 'l10n', 'wp-admin', 'login', 'install', | |
| 1042 | - 'wp-color-picker', 'customize-controls', 'customize-widgets', 'customize-nav-menus', 'press-this', | |
| 1043 | - 'buttons', 'dashicons', 'editor-buttons', 'media-views', 'wp-pointer', 'customize-preview', | |
| 1044 | - 'wp-embed-template-ie', 'imgareaselect', 'mediaelement', 'wp-mediaelement', 'thickbox', | |
| 1045 | - 'deprecated-media', 'farbtastic', 'jcrop', 'colors-fresh', 'open-sans', | |
| 1046 | - ); | |
| 1047 | - | |
| 1048 | - return $wp_default_styles; | |
| 1049 | - | |
| 1050 | - } | |
| 1051 | - | |
| 1052 | 990 | function get_hidden_capabilities() { |
| 1053 | 991 | |
| 1054 | 992 | $capabilities = array(); |
| 1055 | 993 | |
| @@ -1092,10 +1030,17 @@ | ||
| 1092 | 1030 | $this->scripts_and_styles_actions( 'user_new' ); |
| 1093 | 1031 | |
| 1094 | 1032 | add_action( 'user_new_form', array( $this, 'roles_field_user_new' ) ); |
| 1095 | 1033 | |
| 1096 | - add_action( 'user_register', array( $this, 'roles_update_user_new' ) ); | |
| 1034 | + if ( is_multisite() ) { | |
| 1035 | + // Set up the wp-signups for new users that will receive confirmation emails | |
| 1036 | + add_filter( 'signup_user_meta', array( $this, 'ms_signup_user_meta' ) ); | |
| 1097 | 1037 | |
| 1038 | + // Intercept the invite for existing users that will receive confirmation emails | |
| 1039 | + add_action( 'invite_user', array( $this, 'ms_invite_user' ), 10, 3 ); | |
| 1040 | + } else { | |
| 1041 | + add_action( 'user_register', array( $this, 'roles_update_user_new' ) ); | |
| 1042 | + } | |
| 1098 | 1043 | } |
| 1099 | 1044 | |
| 1100 | 1045 | // Add actions on Edit User back-end page |
| 1101 | 1046 | function actions_on_user_edit() { |
| @@ -1170,10 +1115,9 @@ | ||
| 1170 | 1115 | </div> |
| 1171 | 1116 | </td> |
| 1172 | 1117 | </tr> |
| 1173 | 1118 | </table> |
| 1174 | - | |
| 1175 | - <?php | |
| 1119 | + <?php | |
| 1176 | 1120 | } |
| 1177 | 1121 | |
| 1178 | 1122 | function roles_update_user_edit( $user_id, $old_user_data ) { |
| 1179 | 1123 | |
| @@ -1234,8 +1178,117 @@ | ||
| 1234 | 1178 | } |
| 1235 | 1179 | |
| 1236 | 1180 | } |
| 1237 | 1181 | |
| 1182 | + // Add the user roles to the signup meta for new users that will receive confirmation emails | |
| 1183 | + public function ms_signup_user_meta( $meta ) { | |
| 1184 | + if ( ! current_user_can( 'promote_users' ) ) { | |
| 1185 | + return; | |
| 1186 | + } | |
| 1187 | + | |
| 1188 | + if ( ! isset( $_POST['wppb_re_new_user_roles_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( $_POST['wppb_re_new_user_roles_nonce'] ), 'new_user_roles' ) ) { | |
| 1189 | + return; | |
| 1190 | + } | |
| 1191 | + | |
| 1192 | + if ( ! empty( $_POST['wppb_re_user_roles'] ) ) { | |
| 1193 | + $new_roles = array_map( array( $this, 'sanitize_role' ), $_POST['wppb_re_user_roles'] );// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 1194 | + | |
| 1195 | + $meta['wppb_re_user_roles'] = array(); | |
| 1196 | + | |
| 1197 | + foreach ( $new_roles as $new_role ) { | |
| 1198 | + $meta['wppb_re_user_roles'][] = $new_role; | |
| 1199 | + } | |
| 1200 | + | |
| 1201 | + // Having a single role is required to set up the user signup. | |
| 1202 | + // Any extra roles will be added when the account is activated. | |
| 1203 | + if ( empty( $_REQUEST['role'] ) || ! $meta['new_role'] && isset( $meta['wppb_re_user_roles'][0] ) ) { | |
| 1204 | + $meta['new_role'] = $meta['wppb_re_user_roles'][0]; | |
| 1205 | + } | |
| 1206 | + } | |
| 1207 | + | |
| 1208 | + return $meta; | |
| 1209 | + } | |
| 1210 | + | |
| 1211 | + // Add the user roles to the usermeta for existing users that will receive confirmation emails | |
| 1212 | + public function ms_invite_user( $user_id, $role, $newuser_key ) { | |
| 1213 | + if ( ! current_user_can( 'promote_users' ) || ! current_user_can( 'edit_user', $user_id ) ) { | |
| 1214 | + return; | |
| 1215 | + } | |
| 1216 | + | |
| 1217 | + if ( ! isset( $_POST['wppb_re_new_user_roles_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( $_POST['wppb_re_new_user_roles_nonce'] ), 'new_user_roles' ) ) { | |
| 1218 | + return; | |
| 1219 | + } | |
| 1220 | + | |
| 1221 | + if ( ! empty( $_POST['wppb_re_user_roles'] ) ) { | |
| 1222 | + update_user_meta($user_id, 'wppb_subsite_' . get_current_blog_id() . '_user_roles', array_map( array( $this, 'sanitize_role' ), $_POST['wppb_re_user_roles'] ));// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 1223 | + } | |
| 1224 | + } | |
| 1225 | + | |
| 1226 | + // Add the extra roles to the user when they are added to the blog | |
| 1227 | + public function ms_add_user_to_blog( $user_id, $role, $blog_id ) { | |
| 1228 | + | |
| 1229 | + $user = new \WP_User( $user_id ); | |
| 1230 | + | |
| 1231 | + if ( empty( $_POST['wppb_re_user_roles'] ) ) { | |
| 1232 | + | |
| 1233 | + // Add New User - Confirmation Email | |
| 1234 | + | |
| 1235 | + global $wpdb; | |
| 1236 | + $key = $wpdb->get_var( $wpdb->prepare( "SELECT activation_key FROM {$wpdb->signups} WHERE user_login = %s", $user->data->user_login ) ); | |
| 1237 | + if ( $key ) { | |
| 1238 | + $signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE activation_key = %s", $key ) ); | |
| 1239 | + if ( $signup ) { | |
| 1240 | + $meta = maybe_unserialize( $signup->meta ); | |
| 1241 | + $this->update_roles( $user, $meta['wppb_re_user_roles'] ); | |
| 1242 | + return; | |
| 1243 | + } | |
| 1244 | + } | |
| 1245 | + | |
| 1246 | + // Add Existing User - Confirmation Email | |
| 1247 | + | |
| 1248 | + $meta_key = 'wppb_subsite_' . get_current_blog_id() . '_user_roles'; | |
| 1249 | + $roles = get_user_meta( $user_id, $meta_key, true ); | |
| 1250 | + delete_user_meta( $user_id, $meta_key ); | |
| 1251 | + $this->update_roles( $user, $roles ); | |
| 1252 | + return; | |
| 1253 | + } | |
| 1254 | + | |
| 1255 | + // Add New User & Add Existing User - Skip Confirmation Email | |
| 1256 | + // In these cases the user role data can be found in $_POST['wppb_re_user_roles'] | |
| 1257 | + | |
| 1258 | + if ( ! current_user_can( 'promote_users' ) || ! current_user_can( 'edit_user', $user_id ) ) { | |
| 1259 | + return; | |
| 1260 | + } | |
| 1261 | + | |
| 1262 | + if ( ! isset( $_POST['wppb_re_new_user_roles_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( $_POST['wppb_re_new_user_roles_nonce'] ), 'new_user_roles' ) ) { | |
| 1263 | + return; | |
| 1264 | + } | |
| 1265 | + | |
| 1266 | + $this->roles_update_user_new_and_edit( $user ); | |
| 1267 | + } | |
| 1268 | + | |
| 1269 | + function update_roles( $user, $roles ) { | |
| 1270 | + if ( !empty( $roles ) ) { | |
| 1271 | + $old_roles = (array) $user->roles; | |
| 1272 | + | |
| 1273 | + $new_roles = array_map( array( $this, 'sanitize_role' ), $roles ); | |
| 1274 | + | |
| 1275 | + foreach ( $new_roles as $new_role ) { | |
| 1276 | + // Add the missing roles. | |
| 1277 | + if ( ! in_array( $new_role, (array) $user->roles ) ) { | |
| 1278 | + $user->add_role( $new_role ); | |
| 1279 | + } | |
| 1280 | + } | |
| 1281 | + | |
| 1282 | + foreach ( $old_roles as $old_role ) { | |
| 1283 | + // Remove the extra roles. | |
| 1284 | + if ( ! in_array( $old_role, $new_roles ) ) { | |
| 1285 | + $user->remove_role( $old_role ); | |
| 1286 | + } | |
| 1287 | + } | |
| 1288 | + } | |
| 1289 | + } | |
| 1290 | + | |
| 1238 | 1291 | function scripts_and_styles_actions( $location ) { |
| 1239 | 1292 | |
| 1240 | 1293 | // Enqueue jQuery on both Add User and Edit User back-end pages |
| 1241 | 1294 | add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_jquery' ) ); |
| @@ -1262,8 +1315,72 @@ | ||
| 1262 | 1315 | |
| 1263 | 1316 | // Print scripts on Add User back-end page |
| 1264 | 1317 | function print_scripts_user_new() { |
| 1265 | 1318 | |
| 1319 | + if ( ! is_multisite() ) { | |
| 1320 | + ?> | |
| 1321 | + <script> | |
| 1322 | + jQuery( document ).ready( function() { | |
| 1323 | + // Remove WordPress default Role Select | |
| 1324 | + var roles_dropdown = jQuery( 'select#role' ); | |
| 1325 | + roles_dropdown.closest( 'tr' ).remove(); | |
| 1326 | + } ); | |
| 1327 | + </script> | |
| 1328 | + <?php | |
| 1329 | + } else { | |
| 1330 | + ?> | |
| 1331 | + <script> | |
| 1332 | + jQuery( document ).ready( function() { | |
| 1333 | + wppb_multisite_re_checkboxes( 'select#adduser-role' ); | |
| 1334 | + wppb_multisite_re_checkboxes( 'select#role' ); | |
| 1335 | + | |
| 1336 | + function wppb_multisite_re_checkboxes( selector ) { | |
| 1337 | + var roles_dropdown_new = jQuery( selector ); | |
| 1338 | + | |
| 1339 | + if ( roles_dropdown_new.length ) { | |
| 1340 | + // Hide WordPress default Role Select | |
| 1341 | + roles_dropdown_new.closest('tr').hide(); | |
| 1342 | + | |
| 1343 | + var checkboxes_new = roles_dropdown_new.closest('form').find('input[name="wppb_re_user_roles[]"]'); | |
| 1344 | + var selectedCheckboxes_new = checkboxes_new.filter(':checked'); | |
| 1345 | + | |
| 1346 | + // At least one role must be selected | |
| 1347 | + if (selectedCheckboxes_new.length === 1) { | |
| 1348 | + selectedCheckboxes_new.prop('disabled', true); | |
| 1349 | + } | |
| 1350 | + | |
| 1351 | + // Detect selected checkboxes on change | |
| 1352 | + checkboxes_new.on('change', function() { | |
| 1353 | + selectedCheckboxes_new = checkboxes_new.filter(':checked'); | |
| 1354 | + | |
| 1355 | + if (selectedCheckboxes_new.length === 1) { | |
| 1356 | + selectedCheckboxes_new.prop('disabled', true); | |
| 1357 | + } else { | |
| 1358 | + checkboxes_new.prop('disabled', false); | |
| 1359 | + } | |
| 1360 | + | |
| 1361 | + // Select a role in the hidden default dropdown | |
| 1362 | + selectedCheckboxes_new.each(function() { | |
| 1363 | + var selectedRoleNew = jQuery(this).val(); | |
| 1364 | + roles_dropdown_new.find('option').each(function() { | |
| 1365 | + if (jQuery(this).val() === selectedRoleNew) { | |
| 1366 | + jQuery(this).prop('selected', true); | |
| 1367 | + //return false; // Break the loop after selecting the first match | |
| 1368 | + } | |
| 1369 | + }); | |
| 1370 | + }); | |
| 1371 | + }); | |
| 1372 | + } | |
| 1373 | + } | |
| 1374 | + } ); | |
| 1375 | + </script> | |
| 1376 | + <?php | |
| 1377 | + } | |
| 1378 | + } | |
| 1379 | + | |
| 1380 | + // Print scripts on Add Existing User back-end page | |
| 1381 | + function print_scripts_user_existing() { | |
| 1382 | + | |
| 1266 | 1383 | ?> |
| 1267 | 1384 | <script> |
| 1268 | 1385 | jQuery( document ).ready( function() { |
| 1269 | 1386 | // Remove WordPress default Role Select |
| @@ -1271,9 +1388,9 @@ | ||
| 1271 | 1388 | roles_dropdown.closest( 'tr' ).remove(); |
| 1272 | 1389 | } ); |
| 1273 | 1390 | </script> |
| 1274 | 1391 | |
| 1275 | - <?php | |
| 1392 | + <?php | |
| 1276 | 1393 | } |
| 1277 | 1394 | |
| 1278 | 1395 | // Print scripts on Edit User back-end page |
| 1279 | 1396 | function print_scripts_user_edit() { |
| @@ -1287,9 +1404,9 @@ | ||
| 1287 | 1404 | } |
| 1288 | 1405 | ); |
| 1289 | 1406 | </script> |
| 1290 | 1407 | |
| 1291 | - <?php | |
| 1408 | + <?php | |
| 1292 | 1409 | } |
| 1293 | 1410 | |
| 1294 | 1411 | // Print scripts on Edit User back-end page |
| 1295 | 1412 | function print_styles_user_edit() { |
| @@ -1301,9 +1418,9 @@ | ||
| 1301 | 1418 | display: none !important; |
| 1302 | 1419 | } |
| 1303 | 1420 | </style> |
| 1304 | 1421 | |
| 1305 | - <?php | |
| 1422 | + <?php | |
| 1306 | 1423 | } |
| 1307 | 1424 | |
| 1308 | 1425 | } |
| 1309 | 1426 | |