/** * Whether a users capablities cover a role. * * @param string $role A valid Wordpress rolename * @param array $user_role_caps The users capabilities. Should be accumulated from all roles a user has. Use `wpaa_get_user_role_caps()` to get them. If `null` the current users capabilities will be used. * @return string */ function wpaa_user_can_role($role, $user_role_caps = null) { global $wp_roles; if (is_null($user_role_caps)) { $user_role_caps = wpaa_get_user_role_caps(); } if ($wp_roles->is_role($role)) { return 0 == count(array_diff_assoc($wp_roles->get_role($role)->capabilities, $user_role_caps)); } return false; }
static function select_default_caps() { $option_values = get_option('wpaa_default_caps'); $post_types = get_post_types(array('show_ui' => true)); global $wp_roles; $roles = $wp_roles->get_names(); $user_role_caps = wpaa_get_user_role_caps(); $rolenames = array(); $edit_rolenames = array(); foreach ($roles as $role => $rolename) { $rolenames[$role] = $rolename; } $groups = UndisclosedUserlabel::get_label_array(); ?> <table class="wp-list-table widefat set-default-caps"><?php ?> <thead><?php ?> <tr><?php ?> <th class="manage-column"><?php _e('Post Type', 'wp-access-areas'); ?> </th><?php ?> <th class="manage-column"><?php _e('Reading'); ?> </th><?php ?> <th class="manage-column"><?php _e('Edit'); ?> </th><?php ?> <th class="manage-column"><?php _e('Post Comment'); ?> </th><?php ?> </tr><?php ?> </thead><?php ?> <tfoot><?php ?> <tr><?php ?> <th class="manage-column"><?php _e('Post Type', 'wp-access-areas'); ?> </th><?php ?> <th class="manage-column"><?php _e('Reading'); ?> </th><?php ?> <th class="manage-column"><?php _e('Edit'); ?> </th><?php ?> <th class="manage-column"><?php _e('Post Comment'); ?> </th><?php ?> </tr><?php ?> </tfoot><?php ?> <tbody><?php $alternate = false; foreach ($post_types as $post_type) { $post_type_object = get_post_type_object($post_type); $editing_cap = $post_type_object->cap->edit_posts; $alternate = !$alternate; $edit_rolenames = array(); foreach ($roles as $role => $rolename) { if (get_role($role)->has_cap($editing_cap)) { $edit_rolenames[$role] = $rolename; } } ?> <tr class="post-select <?php if ($alternate) { echo "alternate"; } ?> "><?php ?> <th><?php echo $post_type_object->labels->name; ?> </th><?php ?> <td><?php $action = 'post_view_cap'; $cap = isset($option_values[$post_type][$action]) ? $option_values[$post_type][$action] : 'exist'; if ($post_type != 'attachment' && ($post_type_object->public || $post_type_object->show_ui)) { UndisclosedEditPost::access_area_dropdown($roles, $groups, wpaa_sanitize_access_cap($cap), "wpaa_default_caps[{$post_type}][{$action}]"); } ?> </td><?php ?> <td><?php $action = 'post_edit_cap'; $cap = isset($option_values[$post_type][$action]) ? $option_values[$post_type][$action] : 'exist'; UndisclosedEditPost::access_area_dropdown($edit_rolenames, $groups, wpaa_sanitize_access_cap($cap), "wpaa_default_caps[{$post_type}][{$action}]"); ?> </td><?php ?> <td><?php $action = 'post_comment_cap'; $cap = isset($option_values[$post_type][$action]) ? $option_values[$post_type][$action] : 'exist'; if (post_type_supports($post_type, 'comments')) { UndisclosedEditPost::access_area_dropdown($roles, $groups, wpaa_sanitize_access_cap($cap), "wpaa_default_caps[{$post_type}][{$action}]"); } ?> </td><?php ?> </tr><?php } ?> </tbody><?php ?> </table><?php }
private static function _edit_fields($column_name, $post_type, $post = null, $first_item_value = -1) { global $wp_roles; if ($column_name == 'view_cap') { $view_cap = !is_null($post) ? $post->post_view_cap : false; $edit_cap = !is_null($post) ? $post->post_edit_cap : false; $comment_cap = !is_null($post) ? $post->post_comment_cap : false; $post_type_object = get_post_type_object($post_type); $editing_cap = $post_type_object->cap->edit_posts; $current_user = wp_get_current_user(); $roles = $wp_roles->get_names(); $groups = UndisclosedUserlabel::get_label_array(); $user_role_caps = wpaa_get_user_role_caps(); $rolenames = array(); $edit_rolenames = array(); foreach ($roles as $role => $rolename) { if (wpaa_user_can_role($role, $user_role_caps)) { $rolenames[$role] = $rolename; if (get_role($role)->has_cap($editing_cap)) { $edit_rolenames[$role] = $rolename; } } } ?> <fieldset class="inline-edit-col-access-areas inline-edit-col-left"> <h3><?php _e('Access', 'wp-access-areas'); ?> </h3> <div class="inline-edit-col"><?php if (self::can_edit_view_cap($post_type, $post_type_object)) { ?> <div class="inline-edit-group"> <label> <span class="title"><?php _e('Read:', 'wp-access-areas'); ?> </span> <?php self::access_area_dropdown($rolenames, $groups, $view_cap, 'post_view_cap', $first_item_value, __('— No Change —')); ?> </label> </div><?php } if (self::can_edit_edit_cap()) { ?> <div class="inline-edit-group"> <label> <span class="title"><?php _e('Edit:', 'wp-access-areas'); ?> </span> <?php self::access_area_dropdown($edit_rolenames, $groups, $edit_cap, 'post_edit_cap', $first_item_value, __('— No Change —')); ?> </label> </div><?php } if (self::can_edit_comment_cap($post_type)) { ?> <div class="inline-edit-group"> <label> <span class="title"><?php _e('Comment:', 'wp-access-areas'); ?> </span> <?php self::access_area_dropdown($rolenames, $groups, $comment_cap, 'post_comment_cap', $first_item_value, __('— No Change —')); ?> </label> </div><?php } ?> </div> </fieldset><?php } }