| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 3 |
|
| 4 |
class WPPB_Roles_Editor { |
| 5 |
|
| 6 |
function __construct() { |
| 7 |
|
| 8 |
// Create Roles Editor CPT |
| 9 |
add_action( 'init', array( $this, 'create_roles_editor_cpt' ) ); |
| 10 |
|
| 11 |
// Add User Roles entry under PB menu as well |
| 12 |
add_action( 'init', array( $this, 'submenu_page' ), 25 ); |
| 13 |
|
| 14 |
add_action( 'admin_init', array( $this, 'redirect_to_roles_editor' ), 25 ); |
| 15 |
|
| 16 |
// Create a Roles Editor CPT post for every existing role |
| 17 |
add_action( 'current_screen', array( $this, 'create_post_for_role' ) ); |
| 18 |
|
| 19 |
// Edit CPT page |
| 20 |
add_filter( 'manage_wppb-roles-editor_posts_columns', array( $this, 'add_extra_column_for_roles_editor_cpt' ) ); |
| 21 |
add_action( 'manage_wppb-roles-editor_posts_custom_column', array( $this, 'custom_column_content_for_roles_editor_cpt' ), 10, 2 ); |
| 22 |
|
| 23 |
// Add and remove meta boxes |
| 24 |
add_action( 'add_meta_boxes', array( $this, 'register_meta_boxes' ), 1 ); |
| 25 |
|
| 26 |
// Edit Publish meta box |
| 27 |
add_action( 'post_submitbox_misc_actions', array( $this, 'edit_publish_meta_box' ) ); |
| 28 |
|
| 29 |
// Enqueue scripts and styles |
| 30 |
add_action( 'admin_enqueue_scripts', array( $this, 'scripts_admin' ) ); |
| 31 |
|
| 32 |
// Add role slug to the created post |
| 33 |
add_action( 'save_post', array( $this, 'add_post_meta' ), 10, 2 ); |
| 34 |
|
| 35 |
add_filter( 'wp_insert_post_data', array( $this, 'modify_post_title'), '99', 1 ); |
| 36 |
|
| 37 |
add_action( 'wp_ajax_delete_capability_permanently', array( $this, 'delete_capability_permanently' ) ); |
| 38 |
add_action( 'wp_ajax_update_role_capabilities', array( $this, 'update_role_capabilities' ) ); |
| 39 |
add_action( 'wp_ajax_get_role_capabilities', array( $this, 'get_role_capabilities' ) ); |
| 40 |
|
| 41 |
add_filter( 'months_dropdown_results', array( $this, 'remove_filter_by_month_dropdown' ), 10, 2 ); |
| 42 |
add_filter( 'post_row_actions', array( $this, 'modify_list_row_actions' ), 10, 2 ); |
| 43 |
|
| 44 |
add_action( 'before_delete_post', array( $this, 'delete_role_permanently' ), 10 ); |
| 45 |
|
| 46 |
add_filter( 'bulk_actions-edit-wppb-roles-editor', '__return_empty_array' ); |
| 47 |
add_filter( 'views_edit-wppb-roles-editor', array( $this, 'edit_cpt_quick_links' ) ); |
| 48 |
|
| 49 |
add_filter( 'enter_title_here', array( $this, 'change_title_text' ) ); |
| 50 |
add_filter( 'post_updated_messages', array( $this, 'change_post_updated_messages' ) ); |
| 51 |
|
| 52 |
// Add multiple roles checkbox to back-end Add / Edit User (as admin) |
| 53 |
add_action( 'load-user-new.php', array( $this, 'actions_on_user_new' ) ); |
| 54 |
add_action( 'load-user-edit.php', array( $this, 'actions_on_user_edit' ) ); |
| 55 |
|
| 56 |
} |
| 57 |
|
| 58 |
function submenu_page(){ |
| 59 |
|
| 60 |
$args = array( |
| 61 |
'menu_title' => __( 'Roles Editor', 'profile-builder' ), |
| 62 |
'page_title' => __( 'Roles Editor', 'profile-builder' ), |
| 63 |
'menu_slug' => 'wppb-roles-editor', |
| 64 |
'page_type' => 'submenu_page', |
| 65 |
'capability' => 'delete_users', |
| 66 |
'priority' => 12, |
| 67 |
'parent_slug' => 'profile-builder' |
| 68 |
); |
| 69 |
|
| 70 |
if( class_exists( 'WCK_Page_Creator_PB' ) ) { |
| 71 |
new WCK_Page_Creator_PB( $args ); |
| 72 |
} |
| 73 |
|
| 74 |
} |
| 75 |
|
| 76 |
function redirect_to_roles_editor(){ |
| 77 |
if( isset( $_GET['page'] ) && $_GET['page'] == 'wppb-roles-editor' ){ |
| 78 |
wp_redirect( admin_url( 'edit.php?post_type=wppb-roles-editor' ) ); |
| 79 |
die(); |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
function scripts_admin() { |
| 84 |
|
| 85 |
global $post_type; |
| 86 |
global $current_screen; |
| 87 |
global $post; |
| 88 |
global $wp_scripts; |
| 89 |
global $wp_styles; |
| 90 |
|
| 91 |
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 |
wp_enqueue_script( 'wppb_select2_js', WPPB_PLUGIN_URL .'assets/js/select2/select2.min.js', array( 'jquery' ), PROFILE_BUILDER_VERSION ); |
| 109 |
wp_enqueue_style( 'wppb_select2_css', WPPB_PLUGIN_URL .'assets/css/select2/select2.min.css', array(), PROFILE_BUILDER_VERSION ); |
| 110 |
|
| 111 |
wp_enqueue_script( 'wppb_roles_editor_js', plugin_dir_url( __FILE__ ) .'assets/js/roles-editor.js', array( 'jquery', 'wppb_select2_js' ), PROFILE_BUILDER_VERSION ); |
| 112 |
wp_enqueue_style( 'wppb_roles_editor_css', plugin_dir_url( __FILE__ ) .'assets/css/roles-editor.css', array(), PROFILE_BUILDER_VERSION ); |
| 113 |
|
| 114 |
if( $current_screen->id == 'wppb-roles-editor' ) { |
| 115 |
$role_slug = $this->sanitize_role( get_post_meta( $post->ID, 'wppb_role_slug', true ) ); |
| 116 |
$current_role = get_role( $role_slug ); |
| 117 |
$current_user = wp_get_current_user(); |
| 118 |
|
| 119 |
if( isset( $current_role ) && is_array( $current_role->capabilities ) ) { |
| 120 |
$role_capabilities = $current_role->capabilities; |
| 121 |
|
| 122 |
// True if current user got this role |
| 123 |
if( isset( $role_slug ) && in_array( $role_slug, $current_user->roles ) ) { |
| 124 |
$current_user_role = TRUE; |
| 125 |
} else { |
| 126 |
$current_user_role = FALSE; |
| 127 |
} |
| 128 |
|
| 129 |
// Get current role users count |
| 130 |
$current_role_users_count = $this->count_role_users( $current_role->name ); |
| 131 |
} else { |
| 132 |
$role_capabilities = NULL; |
| 133 |
$current_role_users_count = NULL; |
| 134 |
$current_user_role = FALSE; |
| 135 |
} |
| 136 |
} else { |
| 137 |
$role_capabilities = NULL; |
| 138 |
$current_role_users_count = NULL; |
| 139 |
$current_user_role = FALSE; |
| 140 |
} |
| 141 |
|
| 142 |
// Remove old WordPress levels system |
| 143 |
// Use filter and return FALSE if you need the old levels capability system |
| 144 |
$remove_old_levels = apply_filters( 'wppb_remove_old_levels', TRUE ); |
| 145 |
if( $remove_old_levels === TRUE ) { |
| 146 |
$role_capabilities = $this->remove_old_labels( $role_capabilities ); |
| 147 |
} |
| 148 |
|
| 149 |
$admin_capabilities = array( |
| 150 |
'manage_options', |
| 151 |
'activate_plugins', |
| 152 |
'delete_plugins', |
| 153 |
'install_plugins', |
| 154 |
'manage_network_options', |
| 155 |
'manage_network', |
| 156 |
'manage_network_plugins', |
| 157 |
'upload_plugins' |
| 158 |
); |
| 159 |
|
| 160 |
$group_capabilities = $this->group_capabilities(); |
| 161 |
$hidden_capabilities = NULL; |
| 162 |
|
| 163 |
$remove_hidden_capabilities = apply_filters( 'wppb_re_remove_hidden_caps', TRUE ); |
| 164 |
if( $remove_hidden_capabilities === TRUE ) { |
| 165 |
$group_capabilities['general']['capabilities'] = array_diff( $group_capabilities['general']['capabilities'], $this->get_hidden_capabilities() ); |
| 166 |
$group_capabilities['appearance']['capabilities'] = array_diff( $group_capabilities['appearance']['capabilities'], $this->get_hidden_capabilities() ); |
| 167 |
$group_capabilities['plugins']['capabilities'] = array_diff( $group_capabilities['plugins']['capabilities'], $this->get_hidden_capabilities() ); |
| 168 |
$group_capabilities['post_types']['attachment']['capabilities'] = array_diff( $group_capabilities['post_types']['attachment']['capabilities'], $this->get_hidden_capabilities() ); |
| 169 |
|
| 170 |
if( $role_capabilities !== NULL ) { |
| 171 |
$role_capabilities = array_diff_key( $role_capabilities, $this->get_hidden_capabilities() ); |
| 172 |
} |
| 173 |
|
| 174 |
$hidden_capabilities = $this->get_hidden_capabilities(); |
| 175 |
if( empty( $hidden_capabilities ) ) { |
| 176 |
$hidden_capabilities = NULL; |
| 177 |
} |
| 178 |
} |
| 179 |
|
| 180 |
$all_capabilities = $this->get_all_capabilities(); |
| 181 |
|
| 182 |
$custom_capabilities = get_option( 'wppb_roles_editor_capabilities', 'not_set' ); |
| 183 |
if( $custom_capabilities != 'not_set' && ! empty( $custom_capabilities['custom']['capabilities'] ) ) { |
| 184 |
foreach( $custom_capabilities['custom']['capabilities'] as $custom_capability_key => $custom_capability ) { |
| 185 |
if( ! in_array( $custom_capability, $all_capabilities ) ) { |
| 186 |
$all_capabilities[$custom_capability] = $custom_capability; |
| 187 |
} |
| 188 |
} |
| 189 |
} |
| 190 |
|
| 191 |
$vars_array = array( |
| 192 |
'ajaxUrl' => admin_url( 'admin-ajax.php' ), |
| 193 |
'current_screen_action' => $current_screen->action, |
| 194 |
'capabilities' => $group_capabilities, |
| 195 |
'current_role_capabilities' => $role_capabilities, |
| 196 |
'current_role_users_count' => $current_role_users_count, |
| 197 |
'all_capabilities' => $all_capabilities, |
| 198 |
'current_user_role' => $current_user_role, |
| 199 |
'admin_capabilities' => $admin_capabilities, |
| 200 |
'hidden_capabilities' => $hidden_capabilities, |
| 201 |
'default_role_text' => esc_html__( 'Default Role', 'profile-builder' ), |
| 202 |
'your_role_text' => esc_html__( 'Your Role', 'profile-builder' ), |
| 203 |
'role_name_required_error_text' => esc_html__( 'Role name is required.', 'profile-builder' ), |
| 204 |
'no_capabilities_found_text' => esc_html__( 'No capabilities found.', 'profile-builder' ), |
| 205 |
'select2_placeholder_text' => esc_html__( 'Select capabilities', 'profile-builder' ), |
| 206 |
'delete_permanently_text' => esc_html__( 'Delete Permanently', 'profile-builder' ), |
| 207 |
'capability_perm_delete_text' => esc_html__( "This will permanently delete the capability from your site and from every user role.\n\nIt can't be undone!", 'profile-builder' ), |
| 208 |
'new_cap_update_title_text' => esc_html__( 'This capability is not saved until you click Update!', 'profile-builder' ), |
| 209 |
'new_cap_publish_title_text' => esc_html__( 'This capability is not saved until you click Publish!', 'profile-builder' ), |
| 210 |
'delete_text' => esc_html__( 'Delete', 'profile-builder' ), |
| 211 |
'cancel_text' => esc_html__( 'Cancel', 'profile-builder' ), |
| 212 |
'add_new_capability_text' => esc_html__( 'Add New Capability', 'profile-builder' ), |
| 213 |
'capability_text' => esc_html__( 'Capability', 'profile-builder' ), |
| 214 |
'cap_no_delete_text' => esc_html__( 'You can\'t delete this capability from your role.', 'profile-builder' ) |
| 215 |
); |
| 216 |
|
| 217 |
wp_localize_script( 'wppb_roles_editor_js', 'wppb_roles_editor_data', $vars_array ); |
| 218 |
} |
| 219 |
|
| 220 |
} |
| 221 |
|
| 222 |
function count_role_users( $current_role_name ) { |
| 223 |
|
| 224 |
// Get current role users count |
| 225 |
$user_count = count_users(); |
| 226 |
|
| 227 |
if( isset( $user_count['avail_roles'][$current_role_name] ) ) { |
| 228 |
$current_role_users_count = $user_count['avail_roles'][$current_role_name]; |
| 229 |
} else { |
| 230 |
$current_role_users_count = NULL; |
| 231 |
} |
| 232 |
|
| 233 |
return $current_role_users_count; |
| 234 |
} |
| 235 |
|
| 236 |
function get_role_capabilities() { |
| 237 |
|
| 238 |
if( ! current_user_can( 'delete_users' ) ) { |
| 239 |
die(); |
| 240 |
} |
| 241 |
|
| 242 |
check_ajax_referer( 'wppb-re-ajax-nonce', 'security' ); |
| 243 |
|
| 244 |
$role = isset( $_POST['role'] ) ? get_role( sanitize_text_field( $_POST['role'] ) ) : null; |
| 245 |
|
| 246 |
if( isset( $role ) && ! empty( $role->capabilities ) ) { |
| 247 |
$role_capabilities = $role->capabilities; |
| 248 |
|
| 249 |
// Remove old WordPress levels system |
| 250 |
// Use filter and return FALSE if you need the old levels capability system |
| 251 |
$remove_old_levels = apply_filters( 'wppb_remove_old_levels', TRUE ); |
| 252 |
if( $remove_old_levels === TRUE ) { |
| 253 |
$role_capabilities = $this->remove_old_labels( $role_capabilities ); |
| 254 |
} |
| 255 |
|
| 256 |
die( json_encode( $role_capabilities ) ); |
| 257 |
} |
| 258 |
|
| 259 |
die( 'no_caps' ); |
| 260 |
} |
| 261 |
|
| 262 |
function edit_cpt_quick_links( $views ) { |
| 263 |
|
| 264 |
$edited_views = array(); |
| 265 |
$edited_views['all'] = $views['all']; |
| 266 |
|
| 267 |
return $edited_views; |
| 268 |
|
| 269 |
} |
| 270 |
|
| 271 |
function create_roles_editor_cpt(){ |
| 272 |
|
| 273 |
if( is_admin() && current_user_can( 'delete_users' ) ) { |
| 274 |
$labels = array( |
| 275 |
'name' => esc_html__( 'Roles Editor', 'profile-builder' ), |
| 276 |
'singular_name' => esc_html__( 'Roles Editor', 'profile-builder' ), |
| 277 |
'add_new' => esc_html__( 'Add New Role', 'profile-builder' ), |
| 278 |
'add_new_item' => esc_html__( 'Add New Role', 'profile-builder' ), |
| 279 |
'edit_item' => esc_html__( 'Edit Role', 'profile-builder' ), |
| 280 |
'new_item' => esc_html__( 'New Role', 'profile-builder' ), |
| 281 |
'all_items' => esc_html__( 'Roles Editor', 'profile-builder' ), |
| 282 |
'view_item' => esc_html__( 'View Role', 'profile-builder' ), |
| 283 |
'search_items' => esc_html__( 'Search the Roles Editor', 'profile-builder' ), |
| 284 |
'not_found' => esc_html__( 'No roles found', 'profile-builder' ), |
| 285 |
'not_found_in_trash' => esc_html__( 'No roles found in trash', 'profile-builder' ), |
| 286 |
'name_admin_bar' => esc_html__( 'Role', 'profile-builder' ), |
| 287 |
'parent_item_colon' => '', |
| 288 |
'menu_name' => esc_html__( 'Roles Editor', 'profile-builder' ) |
| 289 |
); |
| 290 |
|
| 291 |
$args = array( |
| 292 |
'labels' => $labels, |
| 293 |
'public' => false, |
| 294 |
'publicly_queryable' => false, |
| 295 |
'show_ui' => true, |
| 296 |
'query_var' => true, |
| 297 |
'show_in_menu' => 'users.php', |
| 298 |
'has_archive' => false, |
| 299 |
'hierarchical' => false, |
| 300 |
'capability_type' => 'post', |
| 301 |
'supports' => array( 'title' ) |
| 302 |
); |
| 303 |
|
| 304 |
register_post_type( 'wppb-roles-editor', $args ); |
| 305 |
} |
| 306 |
|
| 307 |
} |
| 308 |
|
| 309 |
function change_title_text( $title ) { |
| 310 |
|
| 311 |
$screen = get_current_screen(); |
| 312 |
|
| 313 |
if( $screen->post_type == 'wppb-roles-editor' ) { |
| 314 |
$title = esc_html__( 'Enter role name here', 'profile-builder' ); |
| 315 |
} |
| 316 |
|
| 317 |
return $title; |
| 318 |
|
| 319 |
} |
| 320 |
|
| 321 |
function change_post_updated_messages( $messages ) { |
| 322 |
|
| 323 |
global $post; |
| 324 |
|
| 325 |
$messages['wppb-roles-editor'] = array( |
| 326 |
0 => '', |
| 327 |
1 => esc_html__( 'Role updated.', 'profile-builder' ), |
| 328 |
2 => esc_html__( 'Custom field updated.', 'profile-builder' ), |
| 329 |
3 => esc_html__( 'Custom field deleted.', 'profile-builder' ), |
| 330 |
4 => esc_html__( 'Role updated.', 'profile-builder' ), |
| 331 |
5 => isset( $_GET['revision'] ) ? sprintf( esc_html__( 'Role restored to revision from %s', 'profile-builder' ), wp_post_revision_title( (int) sanitize_text_field( $_GET['revision'] ), false ) ) : false, |
| 332 |
6 => esc_html__( 'Role created.', 'profile-builder' ), |
| 333 |
7 => esc_html__( 'Role saved.', 'profile-builder' ), |
| 334 |
8 => esc_html__( 'Role submitted.', 'profile-builder' ), |
| 335 |
9 => sprintf( esc_html__( 'Role scheduled for: <strong>%1$s</strong>', 'profile-builder' ), date_i18n( __( 'M j, Y @ G:i', 'profile-builder' ), strtotime( $post->post_date ) ) ), |
| 336 |
10 => esc_html__( 'Role draft updated.', 'profile-builder' ), |
| 337 |
); |
| 338 |
|
| 339 |
return $messages; |
| 340 |
|
| 341 |
} |
| 342 |
|
| 343 |
function create_post_for_role() { |
| 344 |
|
| 345 |
$screen = get_current_screen(); |
| 346 |
|
| 347 |
if( $screen->id == 'edit-wppb-roles-editor' ) { |
| 348 |
global $wpdb; |
| 349 |
global $wp_roles; |
| 350 |
|
| 351 |
$added_posts = array(); |
| 352 |
|
| 353 |
$args = array( |
| 354 |
'numberposts' => -1, |
| 355 |
'post_type' => 'wppb-roles-editor' |
| 356 |
); |
| 357 |
$posts = get_posts( $args ); |
| 358 |
|
| 359 |
foreach( $posts as $key => $value ) { |
| 360 |
$post_id = intval( $value->ID ); |
| 361 |
$role_slug_meta = $this->sanitize_role( get_post_meta( $post_id, 'wppb_role_slug', true ) ); |
| 362 |
if( ! empty( $role_slug_meta ) ) { |
| 363 |
if( ! array_key_exists( $role_slug_meta, $wp_roles->role_names ) ) { |
| 364 |
$post_meta = get_post_meta( $post_id ); |
| 365 |
foreach( $post_meta as $post_meta_key => $post_meta_value ) { |
| 366 |
delete_post_meta( $post_id, $post_meta_key ); |
| 367 |
} |
| 368 |
|
| 369 |
$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->posts WHERE post_type = %s AND ID = %d", "wppb-roles-editor", $post_id ) ); |
| 370 |
} else { |
| 371 |
$added_posts[] = $role_slug_meta; |
| 372 |
} |
| 373 |
} |
| 374 |
} |
| 375 |
|
| 376 |
foreach( $wp_roles->role_names as $role_slug => $role_display_name ) { |
| 377 |
if( ! in_array( $role_slug, $added_posts ) ) { |
| 378 |
$id = wp_insert_post( array( |
| 379 |
'post_title' => $role_display_name, |
| 380 |
'post_type' => 'wppb-roles-editor', |
| 381 |
'post_content' => '', |
| 382 |
'post_status' => 'publish' |
| 383 |
) ); |
| 384 |
|
| 385 |
update_post_meta( $id, 'wppb_role_slug', $role_slug ); |
| 386 |
} |
| 387 |
} |
| 388 |
} |
| 389 |
|
| 390 |
} |
| 391 |
|
| 392 |
function add_extra_column_for_roles_editor_cpt( $columns ) { |
| 393 |
|
| 394 |
$columns = array( |
| 395 |
'title' => esc_html__( 'Role Name', 'profile-builder' ), |
| 396 |
'role' => esc_html__( 'Role Slug', 'profile-builder' ), |
| 397 |
'capabilities' => esc_html__( 'Capabilities', 'profile-builder' ), |
| 398 |
'users' => esc_html__( 'Users', 'profile-builder' ) |
| 399 |
); |
| 400 |
|
| 401 |
return apply_filters( 'wppb_manage_roles_columns', $columns ); |
| 402 |
|
| 403 |
} |
| 404 |
|
| 405 |
function custom_column_content_for_roles_editor_cpt( $column_name, $post_id ) { |
| 406 |
|
| 407 |
$role_slug = $this->sanitize_role( get_post_meta( $post_id, 'wppb_role_slug', true ) ); |
| 408 |
|
| 409 |
if( isset( $role_slug ) ) { |
| 410 |
$role = get_role( $role_slug ); |
| 411 |
|
| 412 |
if( $column_name == 'role' ) { |
| 413 |
echo '<input readonly spellcheck="false" type="text" class="wppb-role-slug-input input" value="'. esc_attr( $role_slug ) .'" />'; |
| 414 |
} |
| 415 |
|
| 416 |
if( $column_name == 'capabilities' && isset( $role ) ) { |
| 417 |
// Remove old WordPress levels system |
| 418 |
// Use filter and return FALSE if you need the old levels capability system |
| 419 |
$remove_old_levels = apply_filters( 'wppb_remove_old_levels', TRUE ); |
| 420 |
if( $remove_old_levels === TRUE ) { |
| 421 |
$role_capabilities = $this->remove_old_labels( $role->capabilities ); |
| 422 |
} else { |
| 423 |
$role_capabilities = $role->capabilities; |
| 424 |
} |
| 425 |
|
| 426 |
echo count( $role_capabilities ); |
| 427 |
} |
| 428 |
|
| 429 |
if( $column_name == 'users' && isset( $role ) ) { |
| 430 |
$role_users_count = $this->count_role_users( $role->name ); |
| 431 |
|
| 432 |
if( ! isset( $role_users_count ) ) { |
| 433 |
$role_users_count = 0; |
| 434 |
} |
| 435 |
|
| 436 |
echo esc_html( $role_users_count ); |
| 437 |
} |
| 438 |
} |
| 439 |
} |
| 440 |
|
| 441 |
function register_meta_boxes() { |
| 442 |
|
| 443 |
remove_meta_box( 'slugdiv', 'wppb-roles-editor', 'normal' ); |
| 444 |
add_meta_box( 'wppb_edit_role_capabilities', esc_html__( 'Edit Role Capabilities', 'profile-builder' ), array( $this, 'edit_role_capabilities_meta_box_callback' ), 'wppb-roles-editor', 'normal', 'high' ); |
| 445 |
|
| 446 |
} |
| 447 |
|
| 448 |
function edit_role_capabilities_meta_box_callback() { |
| 449 |
|
| 450 |
?> |
| 451 |
<div id="wppb-role-edit-caps-div" style="margin: 15px 0 5px; 0;"> |
| 452 |
<div id="wppb-role-edit-add-caps " class="cozmoslabs-form-field-wrapper"> |
| 453 |
<select style="width: 40%; display: none;" class="wppb-capabilities-select" multiple="multiple"></select> |
| 454 |
|
| 455 |
<input class="wppb-add-new-cap-input" type="text" placeholder="<?php esc_html_e( 'Add a new capability', 'profile-builder' ) ?>"> |
| 456 |
|
| 457 |
<a href="javascript:void(0)" class="button-primary" onclick="wppb_re_add_capability()"> |
| 458 |
<span><?php esc_html_e( 'Add Capability', 'profile-builder' ) ?></span> |
| 459 |
</a> |
| 460 |
|
| 461 |
<div id="wppb-add-new-cap-link"> |
| 462 |
<a class="wppb-add-new-cap-link" href="javascript:void(0)"><?php esc_html_e( 'Add New Capability', 'profile-builder' ) ?></a> |
| 463 |
</div> |
| 464 |
|
| 465 |
<span id="wppb-add-capability-error"><?php esc_html_e( 'Please select an existing capability or add a new one!', 'profile-builder' ) ?></span> |
| 466 |
<span id="wppb-hidden-capability-error"><?php esc_html_e( 'You can\'t add a hidden capability!', 'profile-builder' ) ?></span> |
| 467 |
<span id="wppb-duplicate-capability-error"><?php esc_html_e( 'This capability already exists!', 'profile-builder' ) ?></span> |
| 468 |
</div> |
| 469 |
|
| 470 |
<div class="wppb-role-edit-caps"> |
| 471 |
<ul id="wppb-capabilities-tabs"> |
| 472 |
<li class="wppb-role-editor-tab-title wppb-role-editor-tab-active"> |
| 473 |
<a href="javascript:void(0)" class="wppb-role-editor-tab wppb-role-editor-all" data-wppb-re-tab="all"><i class="dashicons dashicons-plus"></i> <span class="wppb-role-editor-tab-label"><?php esc_html_e( 'All', 'profile-builder' ) ?></span></a> |
| 474 |
</li> |
| 475 |
|
| 476 |
<li class="wppb-role-editor-tab-title"> |
| 477 |
<a href="javascript:void(0)" class="wppb-role-editor-tab wppb-role-editor-general" data-wppb-re-tab="general"><i class="dashicons dashicons-wordpress"></i> <span class="wppb-role-editor-tab-label"><?php esc_html_e( 'General', 'profile-builder' ) ?></span></a> |
| 478 |
</li> |
| 479 |
|
| 480 |
<li class="wppb-role-editor-tab-title"> |
| 481 |
<a href="javascript:void(0)" class="wppb-role-editor-tab wppb-role-editor-posts" data-wppb-re-tab="post"><i class="dashicons dashicons-admin-post"></i> <span class="wppb-role-editor-tab-label"><?php esc_html_e( 'Posts', 'profile-builder' ) ?></span></a> |
| 482 |
</li> |
| 483 |
|
| 484 |
<li class="wppb-role-editor-tab-title"> |
| 485 |
<a href="javascript:void(0)" class="wppb-role-editor-tab wppb-role-editor-pages" data-wppb-re-tab="page"><i class="dashicons dashicons-admin-page"></i> <span class="wppb-role-editor-tab-label"><?php esc_html_e( 'Pages', 'profile-builder' ) ?></span></a> |
| 486 |
</li> |
| 487 |
|
| 488 |
<li class="wppb-role-editor-tab-title"> |
| 489 |
<a href="javascript:void(0)" class="wppb-role-editor-tab wppb-role-editor-media" data-wppb-re-tab="attachment"><i class="dashicons dashicons-admin-media"></i> <span class="wppb-role-editor-tab-label"><?php esc_html_e( 'Media', 'profile-builder' ) ?></span></a> |
| 490 |
</li> |
| 491 |
|
| 492 |
<li class="wppb-role-editor-tab-title"> |
| 493 |
<a href="javascript:void(0)" class="wppb-role-editor-tab wppb-role-editor-taxonomies" data-wppb-re-tab="taxonomies"><i class="dashicons dashicons-tag"></i> <span class="wppb-role-editor-tab-label"><?php esc_html_e( 'Taxonomies', 'profile-builder' ) ?></span></a> |
| 494 |
</li> |
| 495 |
|
| 496 |
<li class="wppb-role-editor-tab-title"> |
| 497 |
<a href="javascript:void(0)" class="wppb-role-editor-tab wppb-role-editor-appearance" data-wppb-re-tab="appearance"><i class="dashicons dashicons-admin-appearance"></i> <span class="wppb-role-editor-tab-label"><?php esc_html_e( 'Appearance', 'profile-builder' ) ?></span></a> |
| 498 |
</li> |
| 499 |
|
| 500 |
<li class="wppb-role-editor-tab-title"> |
| 501 |
<a href="javascript:void(0)" class="wppb-role-editor-tab wppb-role-editor-plugins" data-wppb-re-tab="plugins"><i class="dashicons dashicons-admin-plugins"></i> <span class="wppb-role-editor-tab-label"><?php esc_html_e( 'Plugins', 'profile-builder' ) ?></span></a> |
| 502 |
</li> |
| 503 |
|
| 504 |
<li class="wppb-role-editor-tab-title"> |
| 505 |
<a href="javascript:void(0)" class="wppb-role-editor-tab wppb-role-editor-users" data-wppb-re-tab="users"><i class="dashicons dashicons-admin-users"></i> <span class="wppb-role-editor-tab-label"><?php esc_html_e( 'Users', 'profile-builder' ) ?></span></a> |
| 506 |
</li> |
| 507 |
|
| 508 |
<li class="wppb-role-editor-tab-title"> |
| 509 |
<a href="javascript:void(0)" class="wppb-role-editor-tab wppb-role-editor-custom" data-wppb-re-tab="custom"><i class="dashicons dashicons-admin-generic"></i> <span class="wppb-role-editor-tab-label"><?php esc_html_e( 'Custom', 'profile-builder' ) ?></span></a> |
| 510 |
</li> |
| 511 |
</ul> |
| 512 |
|
| 513 |
<div id="wppb-role-edit-table"> |
| 514 |
<div class="wppb-re-spinner-container"><i class="icon-wppb-re-spinner wppb-re-spin"></i></div> |
| 515 |
<div id="wppb-role-edit-caps-clear"></div> |
| 516 |
</div> |
| 517 |
<div id="wppb-role-edit-divs-clear"></div> |
| 518 |
</div> |
| 519 |
|
| 520 |
<input type="hidden" id="wppb-role-slug-hidden" name="wppb-role-slug-hidden" value=""> |
| 521 |
<input type="hidden" name="wppb-re-ajax-nonce" id="wppb-re-ajax-nonce" value="<?php echo esc_attr( wp_create_nonce( 'wppb-re-ajax-nonce' ) ) ?>" /> |
| 522 |
</div> |
| 523 |
<?php |
| 524 |
|
| 525 |
} |
| 526 |
|
| 527 |
function edit_publish_meta_box( $post ) { |
| 528 |
|
| 529 |
global $current_screen; |
| 530 |
|
| 531 |
$post_type = 'wppb-roles-editor'; |
| 532 |
|
| 533 |
if( $post->post_type == $post_type ) { |
| 534 |
$role_slug = $this->sanitize_role( get_post_meta( $post->ID, 'wppb_role_slug', true ) ); |
| 535 |
|
| 536 |
?> |
| 537 |
<style type="text/css"> |
| 538 |
.misc-pub-section.misc-pub-post-status, |
| 539 |
.misc-pub-section.misc-pub-visibility, |
| 540 |
.misc-pub-section.curtime.misc-pub-curtime, |
| 541 |
#minor-publishing-actions, |
| 542 |
#major-publishing-actions #delete-action { |
| 543 |
display: none; |
| 544 |
} |
| 545 |
</style> |
| 546 |
|
| 547 |
<div class="misc-pub-section misc-pub-section-users"> |
| 548 |
<i class="icon-wppb-re-users"></i> |
| 549 |
<span><?php esc_html_e( 'Users', 'profile-builder' ) ?>: <strong>0</strong></span> |
| 550 |
</div> |
| 551 |
|
| 552 |
<div class="misc-pub-section misc-pub-section-capabilities"> |
| 553 |
<i class="icon-wppb-re-caps"></i> |
| 554 |
<span><?php esc_html_e( 'Capabilities', 'profile-builder' ) ?>: <strong>0</strong></span> |
| 555 |
</div> |
| 556 |
|
| 557 |
<div class="misc-pub-section misc-pub-section-edit-slug"> |
| 558 |
<i class="icon-wppb-re-slug"></i> |
| 559 |
<span> |
| 560 |
<label for="wppb-role-slug"><?php esc_html_e( 'Role Slug', 'profile-builder' ) ?>: </label> |
| 561 |
<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 |
</span> |
| 563 |
</div> |
| 564 |
<?php |
| 565 |
} |
| 566 |
|
| 567 |
} |
| 568 |
|
| 569 |
function remove_old_labels( $capabilities ) { |
| 570 |
|
| 571 |
$old_levels = array( 'level_0', 'level_1', 'level_2', 'level_3', 'level_4', 'level_5', 'level_6', 'level_7', 'level_8', 'level_9', 'level_10' ); |
| 572 |
|
| 573 |
foreach( $old_levels as $key => $value ) { |
| 574 |
unset( $capabilities[$value] ); |
| 575 |
} |
| 576 |
|
| 577 |
return $capabilities; |
| 578 |
|
| 579 |
} |
| 580 |
|
| 581 |
function modify_post_title( $data ) { |
| 582 |
|
| 583 |
if( 'wppb-roles-editor' != $data['post_type'] || $data['post_status'] == 'auto-draft' ) { |
| 584 |
return $data; |
| 585 |
} |
| 586 |
|
| 587 |
if( ! current_user_can( 'delete_users' ) ) { |
| 588 |
return $data; |
| 589 |
} |
| 590 |
|
| 591 |
if( isset( $data['post_title'] ) ) { |
| 592 |
$data['post_title'] = wp_strip_all_tags( $data['post_title'] ); |
| 593 |
} |
| 594 |
|
| 595 |
return $data; |
| 596 |
|
| 597 |
} |
| 598 |
|
| 599 |
function add_post_meta( $post_id, $post ) { |
| 600 |
|
| 601 |
$post_type = get_post_type( $post_id ); |
| 602 |
|
| 603 |
if( 'wppb-roles-editor' != $post_type || $post->post_status == 'auto-draft' ) { |
| 604 |
return; |
| 605 |
} |
| 606 |
|
| 607 |
if( ! current_user_can( 'delete_users' ) ) { |
| 608 |
return; |
| 609 |
} |
| 610 |
|
| 611 |
if( !isset( $_POST['wppb-re-ajax-nonce'] ) || !wp_verify_nonce( sanitize_text_field( $_POST['wppb-re-ajax-nonce'] ), 'wppb-re-ajax-nonce' ) ) |
| 612 |
return; |
| 613 |
|
| 614 |
if( isset( $_POST['wppb-role-slug-hidden'] ) ) { |
| 615 |
$role_slug = $this->sanitize_role( trim( $_POST['wppb-role-slug-hidden'] ) ); /* phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized */ |
| 616 |
|
| 617 |
update_post_meta( $post_id, 'wppb_role_slug', $role_slug ); |
| 618 |
} |
| 619 |
|
| 620 |
} |
| 621 |
|
| 622 |
function update_role_capabilities() { |
| 623 |
|
| 624 |
if( ! current_user_can( 'delete_users' ) ) { |
| 625 |
die(); |
| 626 |
} |
| 627 |
|
| 628 |
check_ajax_referer( 'wppb-re-ajax-nonce', 'security' ); |
| 629 |
|
| 630 |
$role_slug = isset( $_POST['role'] ) ? $this->sanitize_role( $_POST['role'] ) : ''; /* phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized */ |
| 631 |
|
| 632 |
$role = get_role( $role_slug ); |
| 633 |
|
| 634 |
if( $role ) { |
| 635 |
if( isset( $_POST['new_capabilities'] ) ) { |
| 636 |
foreach( $_POST['new_capabilities'] as $key => $value ) { /* phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized */ |
| 637 |
$role->add_cap( sanitize_text_field( $key ) ); |
| 638 |
} |
| 639 |
} |
| 640 |
|
| 641 |
if( isset( $_POST['capabilities_to_delete'] ) ) { |
| 642 |
foreach( $_POST['capabilities_to_delete'] as $key => $value ) { /* phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized */ |
| 643 |
$role->remove_cap( sanitize_text_field( $key ) ); |
| 644 |
} |
| 645 |
} |
| 646 |
} else { |
| 647 |
$capabilities = array(); |
| 648 |
|
| 649 |
if( isset( $_POST['all_capabilities'] ) ) { |
| 650 |
foreach( $_POST['all_capabilities'] as $key => $value ) { /* phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized */ |
| 651 |
$capabilities[sanitize_text_field( $key )] = true; |
| 652 |
}; |
| 653 |
} |
| 654 |
|
| 655 |
$role_display_name = isset( $_POST['role_display_name'] ) ? sanitize_text_field( $_POST['role_display_name'] ) : ''; |
| 656 |
|
| 657 |
add_role( $role_slug, $role_display_name, $capabilities ); |
| 658 |
} |
| 659 |
|
| 660 |
die( 'role_capabilities_updated' ); |
| 661 |
|
| 662 |
} |
| 663 |
|
| 664 |
function group_capabilities() { |
| 665 |
|
| 666 |
$capabilities = get_option( 'wppb_roles_editor_capabilities', 'not_set' ); |
| 667 |
|
| 668 |
if( $capabilities == 'not_set' ) { |
| 669 |
// We remove non-custom capabilities from this array later on |
| 670 |
$custom_capabilities = $this->get_all_capabilities(); |
| 671 |
$custom_capabilities = $this->remove_old_labels( $custom_capabilities ); |
| 672 |
|
| 673 |
// General capabilities |
| 674 |
$general_capabilities = array( |
| 675 |
'label' => 'General', |
| 676 |
'icon' => 'dashicons-wordpress', |
| 677 |
'capabilities' => array( 'edit_dashboard', 'edit_files', 'export', 'import', 'manage_links', 'manage_options', 'moderate_comments', 'read', 'unfiltered_html', 'update_core' ) |
| 678 |
); |
| 679 |
|
| 680 |
// Themes management capabilities |
| 681 |
$appearance_capabilities = array( |
| 682 |
'label' => 'Appearance', |
| 683 |
'icon' => 'dashicons-admin-appearance', |
| 684 |
'capabilities' => array( 'delete_themes', 'edit_theme_options', 'edit_themes', 'install_themes', 'switch_themes', 'update_themes' ) |
| 685 |
); |
| 686 |
|
| 687 |
// Plugins management capabilities |
| 688 |
$plugins_capabilities = array( |
| 689 |
'label' => 'Plugins', |
| 690 |
'icon' => 'dashicons-admin-plugins', |
| 691 |
'capabilities' => array( 'activate_plugins', 'delete_plugins', 'edit_plugins', 'install_plugins', 'update_plugins' ) |
| 692 |
); |
| 693 |
|
| 694 |
// Users management capabilities |
| 695 |
$users_capabilities = array( |
| 696 |
'label' => 'Users', |
| 697 |
'icon' => 'dashicons-admin-users', |
| 698 |
'capabilities' => array( 'add_users', 'create_roles', 'create_users', 'delete_roles', 'delete_users', 'edit_roles', 'edit_users', 'list_roles', 'list_users', 'promote_users', 'remove_users' ) |
| 699 |
); |
| 700 |
|
| 701 |
// Taxonomies capabilities - part 1 |
| 702 |
$taxonomies_capabilities = array(); |
| 703 |
$taxonomies = get_taxonomies( array(), 'objects' ); |
| 704 |
foreach( $taxonomies as $taxonomy ) { |
| 705 |
$taxonomies_capabilities = array_merge( $taxonomies_capabilities, array_values( (array) $taxonomy->cap ) ); |
| 706 |
} |
| 707 |
|
| 708 |
// Post types capabilities |
| 709 |
$post_types_capabilities = array(); |
| 710 |
foreach( get_post_types( array(), 'objects' ) as $type ) { |
| 711 |
|
| 712 |
if( in_array( $type->name, array( 'revision', 'nav_menu_item', 'custom_css', 'customize_changeset', 'wppb-rf-cpt', 'wppb-epf-cpt', 'wppb-roles-editor' ) ) ) { |
| 713 |
continue; |
| 714 |
} |
| 715 |
|
| 716 |
$post_type_capabilities = $this->post_type_group_capabilities( $type->name ); |
| 717 |
if( empty( $post_type_capabilities ) ) { |
| 718 |
continue; |
| 719 |
} |
| 720 |
|
| 721 |
$post_type_icon = $type->hierarchical ? 'dashicons-admin-page' : 'dashicons-admin-post'; |
| 722 |
if( is_string( $type->menu_icon ) && preg_match( '/dashicons-/i', $type->menu_icon ) ) { |
| 723 |
$post_type_icon = $type->menu_icon; |
| 724 |
} else if( 'attachment' === $type->name ) { |
| 725 |
$post_type_icon = 'dashicons-admin-media'; |
| 726 |
} else if( 'download' === $type->name ) { |
| 727 |
$post_type_icon = 'dashicons-download'; |
| 728 |
} else if( 'product' === $type->name ) { |
| 729 |
$post_type_icon = 'dashicons-cart'; |
| 730 |
} |
| 731 |
|
| 732 |
$post_types_capabilities[$type->name] = array( |
| 733 |
'label' => $type->labels->name, |
| 734 |
'icon' => $post_type_icon, |
| 735 |
'capabilities' => $post_type_capabilities |
| 736 |
); |
| 737 |
|
| 738 |
$taxonomies_capabilities = array_diff( $taxonomies_capabilities, $post_type_capabilities ); |
| 739 |
$custom_capabilities = array_diff( $custom_capabilities, $post_type_capabilities ); |
| 740 |
} |
| 741 |
|
| 742 |
// Taxonomies capabilities - part 2 |
| 743 |
$taxonomies_capabilities = array_diff( $taxonomies_capabilities, $general_capabilities['capabilities'], $appearance_capabilities['capabilities'], $plugins_capabilities['capabilities'], $users_capabilities['capabilities'] ); |
| 744 |
$taxonomies_capabilities = array( |
| 745 |
'label' => 'Taxonomies', |
| 746 |
'icon' => '', |
| 747 |
'capabilities' => array_unique( $taxonomies_capabilities ) |
| 748 |
); |
| 749 |
|
| 750 |
// Custom capabilities |
| 751 |
$custom_capabilities = array_diff( $custom_capabilities, $general_capabilities['capabilities'], $appearance_capabilities['capabilities'], $appearance_capabilities['capabilities'], $plugins_capabilities['capabilities'], $users_capabilities['capabilities'], $taxonomies_capabilities['capabilities'] ); |
| 752 |
$custom_capabilities = array_values( $custom_capabilities ); |
| 753 |
$custom_capabilities = array( |
| 754 |
'label' => 'Custom', |
| 755 |
'icon' => '', |
| 756 |
'capabilities' => array_unique( $custom_capabilities ) |
| 757 |
); |
| 758 |
|
| 759 |
// Create capabilities array |
| 760 |
$capabilities = array( |
| 761 |
'general' => $general_capabilities, |
| 762 |
'post_types' => $post_types_capabilities, |
| 763 |
'taxonomies' => $taxonomies_capabilities, |
| 764 |
'appearance' => $appearance_capabilities, |
| 765 |
'plugins' => $plugins_capabilities, |
| 766 |
'users' => $users_capabilities, |
| 767 |
'custom' => $custom_capabilities |
| 768 |
); |
| 769 |
|
| 770 |
update_option( 'wppb_roles_editor_capabilities', $capabilities ); |
| 771 |
} else { |
| 772 |
$custom_capabilities = $this->get_all_capabilities(); |
| 773 |
$custom_capabilities = $this->remove_old_labels( $custom_capabilities ); |
| 774 |
|
| 775 |
foreach( $capabilities['post_types'] as $key => $value ) { |
| 776 |
$custom_capabilities = array_diff( $custom_capabilities, $value['capabilities'] ); |
| 777 |
} |
| 778 |
|
| 779 |
foreach( $capabilities as $key => $value ) { |
| 780 |
if( $key != 'post_types' && $key != 'custom' ) { |
| 781 |
$custom_capabilities = array_diff( $custom_capabilities, $value['capabilities'] ); |
| 782 |
} |
| 783 |
} |
| 784 |
|
| 785 |
$custom_capabilities = array_values( $custom_capabilities ); |
| 786 |
$custom_capabilities = array_unique( $custom_capabilities ); |
| 787 |
$custom_capabilities = array_diff( $custom_capabilities, $capabilities['custom']['capabilities'] ); |
| 788 |
|
| 789 |
if( ! empty( $custom_capabilities ) ) { |
| 790 |
$capabilities['custom']['capabilities'] = array_merge( $capabilities['custom']['capabilities'], $custom_capabilities ); |
| 791 |
|
| 792 |
update_option( 'wppb_roles_editor_capabilities', $capabilities ); |
| 793 |
} |
| 794 |
} |
| 795 |
|
| 796 |
return $capabilities; |
| 797 |
|
| 798 |
} |
| 799 |
|
| 800 |
function post_type_group_capabilities( $post_type = 'post' ) { |
| 801 |
|
| 802 |
$capabilities = (array) get_post_type_object( $post_type )->cap; |
| 803 |
|
| 804 |
unset( $capabilities['edit_post'] ); |
| 805 |
unset( $capabilities['read_post'] ); |
| 806 |
unset( $capabilities['delete_post'] ); |
| 807 |
|
| 808 |
$capabilities = array_values( $capabilities ); |
| 809 |
|
| 810 |
if( ! in_array( $post_type, array( 'post', 'page' ) ) ) { |
| 811 |
// Get the post and page capabilities |
| 812 |
$post_caps = array_values( (array) get_post_type_object( 'post' )->cap ); |
| 813 |
$page_caps = array_values( (array) get_post_type_object( 'page' )->cap ); |
| 814 |
|
| 815 |
// Remove post/page capabilities from the current post type capabilities |
| 816 |
$capabilities = array_diff( $capabilities, $post_caps, $page_caps ); |
| 817 |
} |
| 818 |
|
| 819 |
if( 'attachment' === $post_type ) { |
| 820 |
$capabilities[] = 'unfiltered_upload'; |
| 821 |
} |
| 822 |
|
| 823 |
return array_unique( $capabilities ); |
| 824 |
|
| 825 |
} |
| 826 |
|
| 827 |
function get_all_capabilities() { |
| 828 |
|
| 829 |
global $wp_roles; |
| 830 |
|
| 831 |
$capabilities = array(); |
| 832 |
|
| 833 |
foreach( $wp_roles->role_objects as $key => $role ) { |
| 834 |
if( is_array( $role->capabilities ) ) { |
| 835 |
foreach( $role->capabilities as $capability => $granted ) { |
| 836 |
$capabilities[$capability] = $capability; |
| 837 |
} |
| 838 |
} |
| 839 |
} |
| 840 |
|
| 841 |
return array_unique( $capabilities ); |
| 842 |
|
| 843 |
} |
| 844 |
|
| 845 |
function delete_capability_permanently() { |
| 846 |
|
| 847 |
if( ! current_user_can( 'delete_users' ) ) { |
| 848 |
die(); |
| 849 |
} |
| 850 |
|
| 851 |
check_ajax_referer( 'wppb-re-ajax-nonce', 'security' ); |
| 852 |
|
| 853 |
global $wp_roles; |
| 854 |
|
| 855 |
if( !empty( $_POST['capability'] ) ) { |
| 856 |
|
| 857 |
foreach ($wp_roles->role_names as $role_slug => $role_display_name) { |
| 858 |
$role = get_role($role_slug); |
| 859 |
$role->remove_cap(sanitize_text_field($_POST['capability'])); |
| 860 |
} |
| 861 |
|
| 862 |
$capabilities = get_option('wppb_roles_editor_capabilities', 'not_set'); |
| 863 |
|
| 864 |
if ($capabilities != 'not_set' && ($key = array_search(sanitize_text_field($_POST['capability']), $capabilities['custom']['capabilities'])) !== false) { |
| 865 |
unset($capabilities['custom']['capabilities'][$key]); |
| 866 |
$capabilities['custom']['capabilities'] = array_values($capabilities['custom']['capabilities']); |
| 867 |
|
| 868 |
update_option('wppb_roles_editor_capabilities', $capabilities); |
| 869 |
} |
| 870 |
} |
| 871 |
|
| 872 |
die(); |
| 873 |
|
| 874 |
} |
| 875 |
|
| 876 |
function remove_filter_by_month_dropdown( $months, $post_type = NULL ) { |
| 877 |
|
| 878 |
if( isset( $post_type ) && $post_type == 'wppb-roles-editor' ) { |
| 879 |
return __return_empty_array(); |
| 880 |
} else { |
| 881 |
return $months; |
| 882 |
} |
| 883 |
|
| 884 |
} |
| 885 |
|
| 886 |
function modify_list_row_actions( $actions, $post ) { |
| 887 |
global $wp_roles; |
| 888 |
|
| 889 |
if( $post->post_type == 'wppb-roles-editor' ) { |
| 890 |
$current_user = wp_get_current_user(); |
| 891 |
$default_role = get_option( 'default_role' ); |
| 892 |
$role_slug = get_post_meta( $post->ID, 'wppb_role_slug', true ); |
| 893 |
|
| 894 |
$url = admin_url( 'post.php?post=' . $post->ID ); |
| 895 |
|
| 896 |
$edit_link = add_query_arg( array( 'action' => 'edit' ), $url ); |
| 897 |
|
| 898 |
$actions = array( |
| 899 |
'edit' => sprintf( |
| 900 |
'<a href="%1$s">%2$s</a>', |
| 901 |
esc_url( $edit_link ), |
| 902 |
esc_html__( 'Edit', 'profile-builder' ) |
| 903 |
) |
| 904 |
); |
| 905 |
|
| 906 |
$clone_url = admin_url( 'post-new.php?post_type=wppb-roles-editor' ); |
| 907 |
$clone_link = add_query_arg( array( 'action' => 'wppb_re_clone', 'wppb_re_clone' => $this->sanitize_role( $role_slug ) ), $clone_url ); |
| 908 |
|
| 909 |
$actions = array_merge( $actions, array( |
| 910 |
'clone' => sprintf( |
| 911 |
'<a href="%1$s">%2$s</a>', |
| 912 |
esc_url( $clone_link ), |
| 913 |
esc_html__( 'Clone', 'profile-builder' ) |
| 914 |
) |
| 915 |
) |
| 916 |
); |
| 917 |
|
| 918 |
if( in_array( $role_slug, $current_user->roles ) && ( ! is_multisite() || ( is_multisite() && ! is_super_admin() ) ) && ( !empty( $wp_roles->roles[$role_slug]['capabilities'] ) && array_key_exists( 'manage_options', $wp_roles->roles[$role_slug]['capabilities'] ) ) ) { |
| 919 |
$actions = array_merge( $actions, array( |
| 920 |
'delete_notify your_role' => '<span title="'. esc_html__( 'You can\'t delete your role.', 'profile-builder' ) .'">'. esc_html__( 'Delete', 'profile-builder' ) .'</span>' |
| 921 |
) |
| 922 |
); |
| 923 |
} elseif( $role_slug == $default_role ) { |
| 924 |
$actions = array_merge( $actions, array( |
| 925 |
'default_role' => sprintf( |
| 926 |
'<a href="%s">%s</a>', |
| 927 |
esc_url( admin_url( 'options-general.php#default_role' ) ), |
| 928 |
esc_html__( 'Change Default', 'profile-builder' ) ), |
| 929 |
'delete_notify' => '<span title="'. esc_html__( 'You can\'t delete the default role. Change it first.', 'profile-builder' ) .'">'. esc_html__( 'Delete', 'profile-builder' ) .'</span>' |
| 930 |
) |
| 931 |
); |
| 932 |
} else { |
| 933 |
$delete_link = wp_nonce_url( add_query_arg( array( 'action' => 'delete' ), $url ), 'delete-post_'. $post->ID ); |
| 934 |
|
| 935 |
$actions = array_merge( $actions, array( |
| 936 |
'delete' => sprintf( |
| 937 |
'<a href="%1$s" onclick="return confirm( \'%2$s\' );">%3$s</a>', |
| 938 |
esc_url( $delete_link ), |
| 939 |
esc_html__( 'Are you sure?\nThis will permanently delete the role and cannot be undone!\nUsers assigned only on this role will be moved to the default role.', 'profile-builder' ), |
| 940 |
esc_html__( 'Delete', 'profile-builder' ) |
| 941 |
) |
| 942 |
) |
| 943 |
); |
| 944 |
} |
| 945 |
} |
| 946 |
|
| 947 |
return $actions; |
| 948 |
|
| 949 |
} |
| 950 |
|
| 951 |
function sanitize_role( $role ) { |
| 952 |
|
| 953 |
$role = strtolower( $role ); |
| 954 |
$role = wp_strip_all_tags( $role ); |
| 955 |
$role = preg_replace( '/[^a-z0-9_\-\s]/', '', $role ); |
| 956 |
$role = str_replace( ' ', '_', $role ); |
| 957 |
$role = sanitize_text_field( $role ); |
| 958 |
|
| 959 |
return $role; |
| 960 |
|
| 961 |
} |
| 962 |
|
| 963 |
function delete_role_permanently( $post_id ) { |
| 964 |
|
| 965 |
global $post_type; |
| 966 |
if( $post_type != 'wppb-roles-editor' ) { |
| 967 |
return; |
| 968 |
} |
| 969 |
|
| 970 |
check_admin_referer( 'delete-post_'. $post_id ); |
| 971 |
|
| 972 |
$role_slug = get_post_meta( $post_id, 'wppb_role_slug', true ); |
| 973 |
$role_slug = $this->sanitize_role( $role_slug ); |
| 974 |
|
| 975 |
$default_role = get_option( 'default_role' ); |
| 976 |
|
| 977 |
if( $role_slug == $default_role ) { |
| 978 |
return; |
| 979 |
} |
| 980 |
|
| 981 |
$users = get_users( array( 'role' => $role_slug ) ); |
| 982 |
|
| 983 |
if( is_array( $users ) ) { |
| 984 |
foreach( $users as $user ) { |
| 985 |
if( $user->has_cap( $role_slug ) && count( $user->roles ) <= 1 ) { |
| 986 |
$user->set_role( $default_role ); |
| 987 |
} elseif( $user->has_cap( $role_slug ) ) { |
| 988 |
$user->remove_role( $role_slug ); |
| 989 |
} |
| 990 |
} |
| 991 |
} |
| 992 |
|
| 993 |
remove_role( $role_slug ); |
| 994 |
|
| 995 |
} |
| 996 |
|
| 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 |
function get_hidden_capabilities() { |
| 1053 |
|
| 1054 |
$capabilities = array(); |
| 1055 |
|
| 1056 |
if( is_multisite() || ! defined( 'ALLOW_UNFILTERED_UPLOADS' ) || ! ALLOW_UNFILTERED_UPLOADS ) { |
| 1057 |
$capabilities['unfiltered_upload'] = 'unfiltered_upload'; |
| 1058 |
} |
| 1059 |
|
| 1060 |
if( is_multisite() || ( defined( 'DISALLOW_UNFILTERED_HTML' ) && DISALLOW_UNFILTERED_HTML ) ) { |
| 1061 |
$capabilities['unfiltered_html'] = 'unfiltered_html'; |
| 1062 |
} |
| 1063 |
|
| 1064 |
if( is_multisite() || ( defined( 'DISALLOW_FILE_EDIT' ) && DISALLOW_FILE_EDIT ) ) { |
| 1065 |
$capabilities['edit_files'] = 'edit_files'; |
| 1066 |
$capabilities['edit_plugins'] = 'edit_plugins'; |
| 1067 |
$capabilities['edit_themes'] = 'edit_themes'; |
| 1068 |
} |
| 1069 |
|
| 1070 |
if( is_multisite() || ( defined( 'DISALLOW_FILE_MODS' ) && DISALLOW_FILE_MODS ) ) { |
| 1071 |
$capabilities['edit_files'] = 'edit_files'; |
| 1072 |
$capabilities['edit_plugins'] = 'edit_plugins'; |
| 1073 |
$capabilities['edit_themes'] = 'edit_themes'; |
| 1074 |
$capabilities['update_plugins'] = 'update_plugins'; |
| 1075 |
$capabilities['delete_plugins'] = 'delete_plugins'; |
| 1076 |
$capabilities['install_plugins'] = 'install_plugins'; |
| 1077 |
$capabilities['upload_plugins'] = 'upload_plugins'; |
| 1078 |
$capabilities['update_themes'] = 'update_themes'; |
| 1079 |
$capabilities['delete_themes'] = 'delete_themes'; |
| 1080 |
$capabilities['install_themes'] = 'install_themes'; |
| 1081 |
$capabilities['upload_themes'] = 'upload_themes'; |
| 1082 |
$capabilities['update_core'] = 'update_core'; |
| 1083 |
} |
| 1084 |
|
| 1085 |
return array_unique( $capabilities ); |
| 1086 |
|
| 1087 |
} |
| 1088 |
|
| 1089 |
// Add actions on Add User back-end page |
| 1090 |
function actions_on_user_new() { |
| 1091 |
|
| 1092 |
$this->scripts_and_styles_actions( 'user_new' ); |
| 1093 |
|
| 1094 |
add_action( 'user_new_form', array( $this, 'roles_field_user_new' ) ); |
| 1095 |
|
| 1096 |
add_action( 'user_register', array( $this, 'roles_update_user_new' ) ); |
| 1097 |
|
| 1098 |
} |
| 1099 |
|
| 1100 |
// Add actions on Edit User back-end page |
| 1101 |
function actions_on_user_edit() { |
| 1102 |
|
| 1103 |
$this->scripts_and_styles_actions( 'user_edit' ); |
| 1104 |
|
| 1105 |
add_action( 'personal_options', array( $this, 'roles_field_user_edit' ) ); |
| 1106 |
|
| 1107 |
add_action( 'profile_update', array( $this, 'roles_update_user_edit' ), 10, 2 ); |
| 1108 |
|
| 1109 |
} |
| 1110 |
|
| 1111 |
// Roles Edit checkboxes for Add User back-end page |
| 1112 |
function roles_field_user_new() { |
| 1113 |
|
| 1114 |
if( ! current_user_can( 'promote_users' ) ) { |
| 1115 |
return; |
| 1116 |
} |
| 1117 |
|
| 1118 |
$user_roles = apply_filters( 'wppb_default_user_roles', array( get_option( 'default_role' ) ) ); |
| 1119 |
|
| 1120 |
if( isset( $_POST['createuser'] ) && ! empty( $_POST['wppb_re_user_roles'] ) ) { |
| 1121 |
$user_roles = array_map( array( $this, 'sanitize_role' ), $_POST['wppb_re_user_roles'] );// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 1122 |
} |
| 1123 |
|
| 1124 |
wp_nonce_field( 'new_user_roles', 'wppb_re_new_user_roles_nonce' ); |
| 1125 |
|
| 1126 |
if( apply_filters( 'wppb_backend_allow_multiple_user_roles_selection', true ) ) { |
| 1127 |
$this->roles_field_display( $user_roles ); |
| 1128 |
} |
| 1129 |
|
| 1130 |
} |
| 1131 |
|
| 1132 |
// Roles Edit checkboxes for Edit User back-end page |
| 1133 |
function roles_field_user_edit( $user ) { |
| 1134 |
|
| 1135 |
if( ! current_user_can( 'promote_users' ) || ! current_user_can( 'edit_user', $user->ID ) ) { |
| 1136 |
return; |
| 1137 |
} |
| 1138 |
|
| 1139 |
$user_roles = (array) $user->roles; |
| 1140 |
|
| 1141 |
wp_nonce_field( 'new_user_roles', 'wppb_re_new_user_roles_nonce' ); |
| 1142 |
|
| 1143 |
if( apply_filters( 'wppb_backend_allow_multiple_user_roles_selection', true ) ) { |
| 1144 |
$this->roles_field_display( $user_roles ); |
| 1145 |
} |
| 1146 |
} |
| 1147 |
|
| 1148 |
// Output roles edit checkboxes |
| 1149 |
function roles_field_display( $user_roles ) { |
| 1150 |
|
| 1151 |
$wppb_roles = get_editable_roles(); |
| 1152 |
|
| 1153 |
?> |
| 1154 |
<table class="form-table"> |
| 1155 |
<tr class="wppb-re-edit-user"> |
| 1156 |
<th><?php esc_html_e( 'Edit User Roles', 'profile-builder' ); ?></th> |
| 1157 |
|
| 1158 |
<td> |
| 1159 |
<div> |
| 1160 |
<ul style="margin: 5px 0;"> |
| 1161 |
<?php foreach( $wppb_roles as $role_slug => $role_details ) { ?> |
| 1162 |
<li> |
| 1163 |
<label> |
| 1164 |
<input type="checkbox" name="wppb_re_user_roles[]" value="<?php echo esc_attr( $role_slug ); ?>" <?php checked( in_array( $role_slug, $user_roles ) ); ?> /> |
| 1165 |
<?php echo esc_html( translate_user_role( $role_details['name'] ) ); ?> |
| 1166 |
</label> |
| 1167 |
</li> |
| 1168 |
<?php } ?> |
| 1169 |
</ul> |
| 1170 |
</div> |
| 1171 |
</td> |
| 1172 |
</tr> |
| 1173 |
</table> |
| 1174 |
|
| 1175 |
<?php |
| 1176 |
} |
| 1177 |
|
| 1178 |
function roles_update_user_edit( $user_id, $old_user_data ) { |
| 1179 |
|
| 1180 |
if( ! current_user_can( 'promote_users' ) || ! current_user_can( 'edit_user', $user_id ) ) { |
| 1181 |
return; |
| 1182 |
} |
| 1183 |
|
| 1184 |
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' ) ) { |
| 1185 |
return; |
| 1186 |
} |
| 1187 |
|
| 1188 |
$this->roles_update_user_new_and_edit( $old_user_data ); |
| 1189 |
|
| 1190 |
} |
| 1191 |
|
| 1192 |
function roles_update_user_new( $user_id ) { |
| 1193 |
|
| 1194 |
if( ! current_user_can( 'promote_users' ) ) { |
| 1195 |
return; |
| 1196 |
} |
| 1197 |
|
| 1198 |
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' ) ) { |
| 1199 |
return; |
| 1200 |
} |
| 1201 |
|
| 1202 |
$user = new \WP_User( $user_id ); |
| 1203 |
|
| 1204 |
$this->roles_update_user_new_and_edit( $user ); |
| 1205 |
|
| 1206 |
} |
| 1207 |
|
| 1208 |
function roles_update_user_new_and_edit( $user ) { |
| 1209 |
|
| 1210 |
if( ! empty( $_POST['wppb_re_user_roles'] ) || !empty( $_POST['role'] ) ) { |
| 1211 |
|
| 1212 |
$old_roles = (array) $user->roles; |
| 1213 |
|
| 1214 |
if( isset( $_POST['wppb_re_user_roles'] ) ) |
| 1215 |
$new_roles = array_map( array( $this, 'sanitize_role' ), $_POST['wppb_re_user_roles'] );//phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 1216 |
else |
| 1217 |
$new_roles = array( $this->sanitize_role( $_POST['role'] ) ); //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 1218 |
|
| 1219 |
foreach( $new_roles as $new_role ) { |
| 1220 |
if( ! in_array( $new_role, (array) $user->roles ) ) { |
| 1221 |
$user->add_role( $new_role ); |
| 1222 |
} |
| 1223 |
} |
| 1224 |
|
| 1225 |
foreach( $old_roles as $old_role ) { |
| 1226 |
if( ! in_array( $old_role, $new_roles ) ) { |
| 1227 |
$user->remove_role( $old_role ); |
| 1228 |
} |
| 1229 |
} |
| 1230 |
} else { |
| 1231 |
foreach( (array) $user->roles as $old_role ) { |
| 1232 |
$user->remove_role( $old_role ); |
| 1233 |
} |
| 1234 |
} |
| 1235 |
|
| 1236 |
} |
| 1237 |
|
| 1238 |
function scripts_and_styles_actions( $location ) { |
| 1239 |
|
| 1240 |
// Enqueue jQuery on both Add User and Edit User back-end pages |
| 1241 |
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_jquery' ) ); |
| 1242 |
|
| 1243 |
// Actions for Add User back-end page |
| 1244 |
if( $location == 'user_new' && apply_filters( 'wppb_backend_allow_multiple_user_roles_selection', true ) ) { |
| 1245 |
add_action( 'admin_footer', array( $this, 'print_scripts_user_new' ), 25 ); |
| 1246 |
} |
| 1247 |
|
| 1248 |
// Actions for Edit User back-end page |
| 1249 |
if( $location == 'user_edit' && apply_filters( 'wppb_backend_allow_multiple_user_roles_selection', true ) ) { |
| 1250 |
add_action( 'admin_head', array( $this, 'print_styles_user_edit' ) ); |
| 1251 |
add_action( 'admin_footer', array( $this, 'print_scripts_user_edit' ), 25 ); |
| 1252 |
} |
| 1253 |
|
| 1254 |
} |
| 1255 |
|
| 1256 |
// Enqueue jQuery where needed (use action) |
| 1257 |
function enqueue_jquery() { |
| 1258 |
|
| 1259 |
wp_enqueue_script( 'jquery' ); |
| 1260 |
|
| 1261 |
} |
| 1262 |
|
| 1263 |
// Print scripts on Add User back-end page |
| 1264 |
function print_scripts_user_new() { |
| 1265 |
|
| 1266 |
?> |
| 1267 |
<script> |
| 1268 |
jQuery( document ).ready( function() { |
| 1269 |
// Remove WordPress default Role Select |
| 1270 |
var roles_dropdown = jQuery( 'select#role' ); |
| 1271 |
roles_dropdown.closest( 'tr' ).remove(); |
| 1272 |
} ); |
| 1273 |
</script> |
| 1274 |
|
| 1275 |
<?php |
| 1276 |
} |
| 1277 |
|
| 1278 |
// Print scripts on Edit User back-end page |
| 1279 |
function print_scripts_user_edit() { |
| 1280 |
|
| 1281 |
?> |
| 1282 |
<script> |
| 1283 |
jQuery( document ).ready( |
| 1284 |
// Remove WordPress default Role Select |
| 1285 |
function() { |
| 1286 |
jQuery( '.user-role-wrap' ).remove(); |
| 1287 |
} |
| 1288 |
); |
| 1289 |
</script> |
| 1290 |
|
| 1291 |
<?php |
| 1292 |
} |
| 1293 |
|
| 1294 |
// Print scripts on Edit User back-end page |
| 1295 |
function print_styles_user_edit() { |
| 1296 |
|
| 1297 |
?> |
| 1298 |
<style type="text/css"> |
| 1299 |
/* Hide WordPress default Role Select */ |
| 1300 |
.user-role-wrap { |
| 1301 |
display: none !important; |
| 1302 |
} |
| 1303 |
</style> |
| 1304 |
|
| 1305 |
<?php |
| 1306 |
} |
| 1307 |
|
| 1308 |
} |
| 1309 |
|
| 1310 |
$wppb_generalSettings = get_option( 'wppb_general_settings', 'not_found' ); |
| 1311 |
if( $wppb_generalSettings != 'not_found' ) { |
| 1312 |
if( ! empty( $wppb_generalSettings['rolesEditor'] ) && ( $wppb_generalSettings['rolesEditor'] == 'yes' ) ) { |
| 1313 |
$wppb_role_editor_instance = new WPPB_Roles_Editor(); |
| 1314 |
} |
| 1315 |
} |
| 1316 |
|