| 1 |
<?php |
| 2 |
/** |
| 3 |
* Functions related to capabilities. |
| 4 |
* |
| 5 |
* @package Members |
| 6 |
* @subpackage Includes |
| 7 |
* @author The MemberPress Team |
| 8 |
* @copyright Copyright (c) 2009 - 2018, The MemberPress Team |
| 9 |
* @link https://members-plugin.com/ |
| 10 |
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
| 11 |
*/ |
| 12 |
if (!defined('ABSPATH')) { |
| 13 |
die('You are not allowed to call this page directly.'); |
| 14 |
} |
| 15 |
|
| 16 |
# Register capabilities. |
| 17 |
add_action( 'init', 'members_register_caps', 95 ); |
| 18 |
add_action( 'members_register_caps', 'members_register_default_caps', 5 ); |
| 19 |
|
| 20 |
# Disables the old user levels from capabilities array. |
| 21 |
add_filter( 'members_get_capabilities', 'members_remove_old_levels' ); |
| 22 |
add_filter( 'members_get_capabilities', 'members_remove_hidden_caps' ); |
| 23 |
|
| 24 |
/** |
| 25 |
* Fires the action hook for registering capabilities. |
| 26 |
* |
| 27 |
* @since 2.0.0 |
| 28 |
* @access public |
| 29 |
* @return void |
| 30 |
*/ |
| 31 |
function members_register_caps() { |
| 32 |
|
| 33 |
do_action( 'members_register_caps' ); |
| 34 |
|
| 35 |
// The following is a quick way to register capabilities that technically |
| 36 |
// exist (i.e., caps that have been added to a role). These are caps that |
| 37 |
// we don't know about because they haven't been registered. |
| 38 |
|
| 39 |
$role_caps = array_values( members_get_role_capabilities() ); |
| 40 |
$unregistered = array_diff( $role_caps, array_keys( members_get_caps() ) ); |
| 41 |
|
| 42 |
foreach ( $unregistered as $cap ) |
| 43 |
members_register_cap( $cap, array( 'label' => $cap ) ); |
| 44 |
|
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Registers all of our default caps. In particular, the plugin registers its own caps plus core |
| 49 |
* WP's caps. |
| 50 |
* |
| 51 |
* @since 2.0.0 |
| 52 |
* @access public |
| 53 |
* @return void |
| 54 |
*/ |
| 55 |
function members_register_default_caps() { |
| 56 |
|
| 57 |
$caps = array(); |
| 58 |
|
| 59 |
// General caps. |
| 60 |
$caps['edit_dashboard'] = array( 'label' => __( 'Edit Dashboard', 'members' ), 'group' => 'general' ); |
| 61 |
$caps['edit_files'] = array( 'label' => __( 'Edit Files', 'members' ), 'group' => 'general' ); |
| 62 |
$caps['export'] = array( 'label' => __( 'Export', 'members' ), 'group' => 'general' ); |
| 63 |
$caps['import'] = array( 'label' => __( 'Import', 'members' ), 'group' => 'general' ); |
| 64 |
$caps['manage_links'] = array( 'label' => __( 'Manage Links', 'members' ), 'group' => 'general' ); |
| 65 |
$caps['manage_options'] = array( 'label' => __( 'Manage Options', 'members' ), 'group' => 'general' ); |
| 66 |
$caps['moderate_comments'] = array( 'label' => __( 'Moderate Comments', 'members' ), 'group' => 'general' ); |
| 67 |
$caps['read'] = array( 'label' => __( 'Read', 'members' ), 'group' => 'general' ); |
| 68 |
$caps['unfiltered_html'] = array( 'label' => __( 'Unfiltered HTML', 'members' ), 'group' => 'general' ); |
| 69 |
$caps['update_core'] = array( 'label' => __( 'Update Core', 'members' ), 'group' => 'general' ); |
| 70 |
|
| 71 |
// Post caps. |
| 72 |
$caps['delete_others_posts'] = array( 'label' => __( "Delete Others' Posts", 'members' ), 'group' => 'type-post' ); |
| 73 |
$caps['delete_posts'] = array( 'label' => __( 'Delete Posts', 'members' ), 'group' => 'type-post' ); |
| 74 |
$caps['delete_private_posts'] = array( 'label' => __( 'Delete Private Posts', 'members' ), 'group' => 'type-post' ); |
| 75 |
$caps['delete_published_posts'] = array( 'label' => __( 'Delete Published Posts', 'members' ), 'group' => 'type-post' ); |
| 76 |
$caps['edit_others_posts'] = array( 'label' => __( "Edit Others' Posts", 'members' ), 'group' => 'type-post' ); |
| 77 |
$caps['edit_posts'] = array( 'label' => __( 'Edit Posts', 'members' ), 'group' => 'type-post' ); |
| 78 |
$caps['edit_private_posts'] = array( 'label' => __( 'Edit Private Posts', 'members' ), 'group' => 'type-post' ); |
| 79 |
$caps['edit_published_posts'] = array( 'label' => __( 'Edit Published Posts', 'members' ), 'group' => 'type-post' ); |
| 80 |
$caps['publish_posts'] = array( 'label' => __( 'Publish Posts', 'members' ), 'group' => 'type-post' ); |
| 81 |
$caps['read_private_posts'] = array( 'label' => __( 'Read Private Posts', 'members' ), 'group' => 'type-post' ); |
| 82 |
|
| 83 |
// Page caps. |
| 84 |
$caps['delete_others_pages'] = array( 'label' => __( "Delete Others' Pages", 'members' ), 'group' => 'type-page' ); |
| 85 |
$caps['delete_pages'] = array( 'label' => __( 'Delete Pages', 'members' ), 'group' => 'type-page' ); |
| 86 |
$caps['delete_private_pages'] = array( 'label' => __( 'Delete Private Pages', 'members' ), 'group' => 'type-page' ); |
| 87 |
$caps['delete_published_pages'] = array( 'label' => __( 'Delete Published Pages', 'members' ), 'group' => 'type-page' ); |
| 88 |
$caps['edit_others_pages'] = array( 'label' => __( "Edit Others' Pages", 'members' ), 'group' => 'type-page' ); |
| 89 |
$caps['edit_pages'] = array( 'label' => __( 'Edit Pages', 'members' ), 'group' => 'type-page' ); |
| 90 |
$caps['edit_private_pages'] = array( 'label' => __( 'Edit Private Pages', 'members' ), 'group' => 'type-page' ); |
| 91 |
$caps['edit_published_pages'] = array( 'label' => __( 'Edit Published Pages', 'members' ), 'group' => 'type-page' ); |
| 92 |
$caps['publish_pages'] = array( 'label' => __( 'Publish Pages', 'members' ), 'group' => 'type-page' ); |
| 93 |
$caps['read_private_pages'] = array( 'label' => __( 'Read Private Pages', 'members' ), 'group' => 'type-page' ); |
| 94 |
|
| 95 |
// Attachment caps. |
| 96 |
$caps['upload_files'] = array( 'label' => __( 'Upload Files', 'members' ), 'group' => 'type-attachment' ); |
| 97 |
|
| 98 |
// Taxonomy caps. |
| 99 |
$caps['manage_categories'] = array( 'label' => __( 'Manage Categories', 'members' ), 'group' => 'taxonomy' ); |
| 100 |
|
| 101 |
// Theme caps. |
| 102 |
$caps['delete_themes'] = array( 'label' => __( 'Delete Themes', 'members' ), 'group' => 'theme' ); |
| 103 |
$caps['edit_theme_options'] = array( 'label' => __( 'Edit Theme Options', 'members' ), 'group' => 'theme' ); |
| 104 |
$caps['edit_themes'] = array( 'label' => __( 'Edit Themes', 'members' ), 'group' => 'theme' ); |
| 105 |
$caps['install_themes'] = array( 'label' => __( 'Install Themes', 'members' ), 'group' => 'theme' ); |
| 106 |
$caps['switch_themes'] = array( 'label' => __( 'Switch Themes', 'members' ), 'group' => 'theme' ); |
| 107 |
$caps['update_themes'] = array( 'label' => __( 'Update Themes', 'members' ), 'group' => 'theme' ); |
| 108 |
|
| 109 |
// Plugin caps. |
| 110 |
$caps['activate_plugins'] = array( 'label' => __( 'Activate Plugins', 'members' ), 'group' => 'plugin' ); |
| 111 |
$caps['delete_plugins'] = array( 'label' => __( 'Delete Plugins', 'members' ), 'group' => 'plugin' ); |
| 112 |
$caps['edit_plugins'] = array( 'label' => __( 'Edit Plugins', 'members' ), 'group' => 'plugin' ); |
| 113 |
$caps['install_plugins'] = array( 'label' => __( 'Install Plugins', 'members' ), 'group' => 'plugin' ); |
| 114 |
$caps['update_plugins'] = array( 'label' => __( 'Update Plugins', 'members' ), 'group' => 'plugin' ); |
| 115 |
|
| 116 |
// User caps. |
| 117 |
$caps['create_roles'] = array( 'label' => __( 'Create Roles', 'members' ), 'group' => 'user' ); |
| 118 |
$caps['create_users'] = array( 'label' => __( 'Create Users', 'members' ), 'group' => 'user' ); |
| 119 |
$caps['delete_roles'] = array( 'label' => __( 'Delete Roles', 'members' ), 'group' => 'user' ); |
| 120 |
$caps['delete_users'] = array( 'label' => __( 'Delete Users', 'members' ), 'group' => 'user' ); |
| 121 |
$caps['edit_roles'] = array( 'label' => __( 'Edit Roles', 'members' ), 'group' => 'user' ); |
| 122 |
$caps['edit_users'] = array( 'label' => __( 'Edit Users', 'members' ), 'group' => 'user' ); |
| 123 |
$caps['list_roles'] = array( 'label' => __( 'List Roles', 'members' ), 'group' => 'user' ); |
| 124 |
$caps['list_users'] = array( 'label' => __( 'List Users', 'members' ), 'group' => 'user' ); |
| 125 |
$caps['promote_users'] = array( 'label' => __( 'Promote Users', 'members' ), 'group' => 'user' ); |
| 126 |
$caps['remove_users'] = array( 'label' => __( 'Remove Users', 'members' ), 'group' => 'user' ); |
| 127 |
|
| 128 |
// Custom caps. |
| 129 |
$caps['restrict_content'] = array( 'label' => __( 'Restrict Content', 'members' ), 'group' => 'custom' ); |
| 130 |
|
| 131 |
// Register each of the capabilities. |
| 132 |
foreach ( $caps as $name => $args ) |
| 133 |
members_register_cap( $name, $args ); |
| 134 |
|
| 135 |
// === Category and Tag caps. === |
| 136 |
// These are mapped to `manage_categories` in a default WP install. However, it's possible |
| 137 |
// for another plugin to map these differently and handle them correctly. So, we're only |
| 138 |
// going to register the caps if they've been assigned to a role. There's no other way |
| 139 |
// to reliably detect if they've been mapped. |
| 140 |
|
| 141 |
$role_caps = array_values( members_get_role_capabilities() ); |
| 142 |
$tax_caps = array(); |
| 143 |
|
| 144 |
$tax_caps['assign_categories'] = array( 'label' => __( 'Assign Categories', 'members' ), 'group' => 'taxonomy' ); |
| 145 |
$tax_caps['edit_categories'] = array( 'label' => __( 'Edit Categories', 'members' ), 'group' => 'taxonomy' ); |
| 146 |
$tax_caps['delete_categories'] = array( 'label' => __( 'Delete Categories', 'members' ), 'group' => 'taxonomy' ); |
| 147 |
$tax_caps['assign_post_tags'] = array( 'label' => __( 'Assign Post Tags', 'members' ), 'group' => 'taxonomy' ); |
| 148 |
$tax_caps['edit_post_tags'] = array( 'label' => __( 'Edit Post Tags', 'members' ), 'group' => 'taxonomy' ); |
| 149 |
$tax_caps['delete_post_tags'] = array( 'label' => __( 'Delete Post Tags', 'members' ), 'group' => 'taxonomy' ); |
| 150 |
$tax_caps['manage_post_tags'] = array( 'label' => __( 'Manage Post Tags', 'members' ), 'group' => 'taxonomy' ); |
| 151 |
|
| 152 |
foreach ( $tax_caps as $tax_cap => $args ) { |
| 153 |
|
| 154 |
if ( in_array( $tax_cap, $role_caps ) ) |
| 155 |
members_register_cap( $tax_cap, $args ); |
| 156 |
} |
| 157 |
} |
| 158 |
|
| 159 |
/** |
| 160 |
* Returns the instance of the capability registry. |
| 161 |
* |
| 162 |
* @since 2.0.0 |
| 163 |
* @access public |
| 164 |
* @return object |
| 165 |
*/ |
| 166 |
function members_capability_registry() { |
| 167 |
|
| 168 |
return \Members\Registry::get_instance( 'cap' ); |
| 169 |
} |
| 170 |
|
| 171 |
/** |
| 172 |
* Returns all registered caps. |
| 173 |
* |
| 174 |
* @since 2.0.0 |
| 175 |
* @access public |
| 176 |
* @return array |
| 177 |
*/ |
| 178 |
function members_get_caps() { |
| 179 |
|
| 180 |
return members_capability_registry()->get_collection(); |
| 181 |
} |
| 182 |
|
| 183 |
/** |
| 184 |
* Registers a capability. |
| 185 |
* |
| 186 |
* @since 2.0.0 |
| 187 |
* @access public |
| 188 |
* @param string $name |
| 189 |
* @param array $args |
| 190 |
* @return void |
| 191 |
*/ |
| 192 |
function members_register_cap( $name, $args = array() ) { |
| 193 |
|
| 194 |
members_capability_registry()->register( $name, new \Members\Capability( $name, $args ) ); |
| 195 |
} |
| 196 |
|
| 197 |
/** |
| 198 |
* Unregisters a capability. |
| 199 |
* |
| 200 |
* @since 2.0.0 |
| 201 |
* @access public |
| 202 |
* @param string $name |
| 203 |
* @return void |
| 204 |
*/ |
| 205 |
function members_unregister_cap( $name ) { |
| 206 |
|
| 207 |
members_capability_registry()->unregister( $name ); |
| 208 |
} |
| 209 |
|
| 210 |
/** |
| 211 |
* Returns a capability object. |
| 212 |
* |
| 213 |
* @since 2.0.0 |
| 214 |
* @access public |
| 215 |
* @param string $name |
| 216 |
* @return object |
| 217 |
*/ |
| 218 |
function members_get_cap( $name ) { |
| 219 |
|
| 220 |
return members_capability_registry()->get( $name ); |
| 221 |
} |
| 222 |
|
| 223 |
/** |
| 224 |
* Checks if a capability object exists. |
| 225 |
* |
| 226 |
* @note In 2.0.0, the function was changed to only check from registered caps. |
| 227 |
* |
| 228 |
* @since 1.0.0 |
| 229 |
* @access public |
| 230 |
* @param string $name |
| 231 |
* @return bool |
| 232 |
*/ |
| 233 |
function members_cap_exists( $name ) { |
| 234 |
|
| 235 |
return members_capability_registry()->exists( $name ); |
| 236 |
} |
| 237 |
|
| 238 |
/** |
| 239 |
* Function for sanitizing a capability. |
| 240 |
* |
| 241 |
* @since 1.0.0 |
| 242 |
* @access public |
| 243 |
* @param string $cap |
| 244 |
* @return string |
| 245 |
*/ |
| 246 |
function members_sanitize_cap( $cap ) { |
| 247 |
|
| 248 |
return apply_filters( 'members_sanitize_cap', sanitize_key( $cap ) ); |
| 249 |
} |
| 250 |
|
| 251 |
/** |
| 252 |
* Checks if a capability is editable. A capability is editable if it's not one of the core WP |
| 253 |
* capabilities and doesn't belong to an uneditable role. |
| 254 |
* |
| 255 |
* @since 1.0.0 |
| 256 |
* @access public |
| 257 |
* @param string $cap |
| 258 |
* @return bool |
| 259 |
*/ |
| 260 |
function members_is_cap_editable( $cap ) { |
| 261 |
|
| 262 |
$uneditable = array_keys( members_get_uneditable_roles() ); |
| 263 |
|
| 264 |
return ! in_array( $cap, members_get_wp_capabilities() ) && ! array_intersect( $uneditable, members_get_cap_roles( $cap ) ); |
| 265 |
} |
| 266 |
|
| 267 |
/** |
| 268 |
* Returns an array of roles that have a capability. |
| 269 |
* |
| 270 |
* @since 1.0.0 |
| 271 |
* @access public |
| 272 |
* @param string $cap |
| 273 |
* @return array |
| 274 |
*/ |
| 275 |
function members_get_cap_roles( $cap ) { |
| 276 |
global $wp_roles; |
| 277 |
|
| 278 |
$_roles = array(); |
| 279 |
|
| 280 |
foreach ( $wp_roles->role_objects as $role ) { |
| 281 |
|
| 282 |
if ( $role->has_cap( $cap ) ) |
| 283 |
$_roles[] = $role->name; |
| 284 |
} |
| 285 |
|
| 286 |
return $_roles; |
| 287 |
} |
| 288 |
|
| 289 |
/** |
| 290 |
* The function that makes this plugin what it is. It returns all of our capabilities in a |
| 291 |
* nicely-formatted, alphabetized array with no duplicate capabilities. It pulls from three |
| 292 |
* different functions to make sure we get all of the capabilities that we need for use in the |
| 293 |
* plugin components. |
| 294 |
* |
| 295 |
* @since 0.1.0 |
| 296 |
* @access public |
| 297 |
* @return array |
| 298 |
*/ |
| 299 |
function members_get_capabilities() { |
| 300 |
|
| 301 |
// Apply filters to the array of capabilities. |
| 302 |
$capabilities = apply_filters( 'members_get_capabilities', array_keys( members_get_caps() ) ); |
| 303 |
|
| 304 |
// Sort the capabilities alphabetically. |
| 305 |
sort( $capabilities ); |
| 306 |
|
| 307 |
// Discard duplicates and return. |
| 308 |
return array_unique( $capabilities ); |
| 309 |
} |
| 310 |
|
| 311 |
/** |
| 312 |
* Gets an array of capabilities according to each user role. Each role will return its caps, |
| 313 |
* which are then added to the overall `$capabilities` array. |
| 314 |
* |
| 315 |
* Note that if no role has the capability, it technically no longer exists. Since this could be |
| 316 |
* a problem with folks accidentally deleting the default WordPress capabilities, the |
| 317 |
* `members_get_plugin_capabilities()` will return all the defaults. |
| 318 |
* |
| 319 |
* @since 0.1.0 |
| 320 |
* @global object $wp_roles |
| 321 |
* @return array |
| 322 |
*/ |
| 323 |
function members_get_role_capabilities() { |
| 324 |
global $wp_roles; |
| 325 |
|
| 326 |
// Set up an empty capabilities array. |
| 327 |
$capabilities = array(); |
| 328 |
|
| 329 |
// Loop through each role object because we need to get the caps. |
| 330 |
foreach ( $wp_roles->role_objects as $key => $role ) { |
| 331 |
|
| 332 |
// Make sure that the role has caps. |
| 333 |
if ( is_array( $role->capabilities ) ) { |
| 334 |
|
| 335 |
// Add each of the role's caps (both granted and denied) to the array. |
| 336 |
foreach ( $role->capabilities as $cap => $grant ) |
| 337 |
$capabilities[ $cap ] = $cap; |
| 338 |
} |
| 339 |
} |
| 340 |
|
| 341 |
// Return the capabilities array, making sure there are no duplicates. |
| 342 |
return array_unique( $capabilities ); |
| 343 |
} |
| 344 |
|
| 345 |
/** |
| 346 |
* Checks if a specific capability has been given to at least one role. If it has, return true. |
| 347 |
* Else, return false. |
| 348 |
* |
| 349 |
* @since 0.1.0 |
| 350 |
* @access public |
| 351 |
* @param string $cap |
| 352 |
* @return bool |
| 353 |
*/ |
| 354 |
function members_check_for_cap( $cap = '' ) { |
| 355 |
|
| 356 |
// Without a capability, we have nothing to check for. Just return false. |
| 357 |
if ( ! $cap ) |
| 358 |
return false; |
| 359 |
|
| 360 |
// Check if the cap is assigned to any role. |
| 361 |
return in_array( $cap, members_get_role_capabilities() ); |
| 362 |
} |
| 363 |
|
| 364 |
/** |
| 365 |
* Return an array of capabilities that are not allowed on this installation. |
| 366 |
* |
| 367 |
* @since 1.0.0 |
| 368 |
* @access public |
| 369 |
* @return array |
| 370 |
*/ |
| 371 |
function members_get_hidden_caps() { |
| 372 |
|
| 373 |
$caps = array(); |
| 374 |
|
| 375 |
// This is always a hidden cap and should never be added to the caps list. |
| 376 |
$caps[] = 'do_not_allow'; |
| 377 |
|
| 378 |
// Network-level caps. |
| 379 |
// These shouldn't show on single-site installs anyway. |
| 380 |
// On multisite installs, they should be handled by a network-specific role manager. |
| 381 |
$caps[] = 'create_sites'; |
| 382 |
$caps[] = 'delete_sites'; |
| 383 |
$caps[] = 'manage_network'; |
| 384 |
$caps[] = 'manage_sites'; |
| 385 |
$caps[] = 'manage_network_users'; |
| 386 |
$caps[] = 'manage_network_plugins'; |
| 387 |
$caps[] = 'manage_network_themes'; |
| 388 |
$caps[] = 'manage_network_options'; |
| 389 |
$caps[] = 'upgrade_network'; |
| 390 |
|
| 391 |
// This cap is needed on single site to set up a multisite network. |
| 392 |
if ( is_multisite() ) |
| 393 |
$caps[] = 'setup_network'; |
| 394 |
|
| 395 |
// Unfiltered uploads. |
| 396 |
if ( is_multisite() || ! defined( 'ALLOW_UNFILTERED_UPLOADS' ) || ! ALLOW_UNFILTERED_UPLOADS ) |
| 397 |
$caps[] = 'unfiltered_upload'; |
| 398 |
|
| 399 |
// Unfiltered HTML. |
| 400 |
if ( is_multisite() || ( defined( 'DISALLOW_UNFILTERED_HTML' ) && DISALLOW_UNFILTERED_HTML ) ) |
| 401 |
$caps[] = 'unfiltered_html'; |
| 402 |
|
| 403 |
// File editing. |
| 404 |
if ( is_multisite() || ( defined( 'DISALLOW_FILE_EDIT' ) && DISALLOW_FILE_EDIT ) ) { |
| 405 |
$caps[] = 'edit_files'; |
| 406 |
$caps[] = 'edit_plugins'; |
| 407 |
$caps[] = 'edit_themes'; |
| 408 |
} |
| 409 |
|
| 410 |
// File mods. |
| 411 |
if ( is_multisite() || ( defined( 'DISALLOW_FILE_MODS' ) && DISALLOW_FILE_MODS ) ) { |
| 412 |
$caps[] = 'edit_files'; |
| 413 |
$caps[] = 'edit_plugins'; |
| 414 |
$caps[] = 'edit_themes'; |
| 415 |
$caps[] = 'update_plugins'; |
| 416 |
$caps[] = 'delete_plugins'; |
| 417 |
$caps[] = 'install_plugins'; |
| 418 |
$caps[] = 'upload_plugins'; |
| 419 |
$caps[] = 'update_themes'; |
| 420 |
$caps[] = 'delete_themes'; |
| 421 |
$caps[] = 'install_themes'; |
| 422 |
$caps[] = 'upload_themes'; |
| 423 |
$caps[] = 'update_core'; |
| 424 |
} |
| 425 |
|
| 426 |
return array_values( array_unique( $caps ) ); |
| 427 |
} |
| 428 |
|
| 429 |
/** |
| 430 |
* Get rid of hidden capabilities. |
| 431 |
* |
| 432 |
* @since 1.0.0 |
| 433 |
* @access public |
| 434 |
* @param array $caps |
| 435 |
* @return array |
| 436 |
*/ |
| 437 |
function members_remove_hidden_caps( $caps ) { |
| 438 |
|
| 439 |
return apply_filters( 'members_remove_hidden_caps', true ) ? array_diff( $caps, members_get_hidden_caps() ) : $caps; |
| 440 |
} |
| 441 |
|
| 442 |
/** |
| 443 |
* Old WordPress levels system. This is mostly useful for filtering out the levels when shown |
| 444 |
* in admin screen. Plugins shouldn't rely on these levels to create permissions for users. |
| 445 |
* They should move to the newer system of checking for a specific capability instead. |
| 446 |
* |
| 447 |
* @since 0.1.0 |
| 448 |
* @access public |
| 449 |
* @return array |
| 450 |
*/ |
| 451 |
function members_get_old_levels() { |
| 452 |
|
| 453 |
return array( |
| 454 |
'level_0', |
| 455 |
'level_1', |
| 456 |
'level_2', |
| 457 |
'level_3', |
| 458 |
'level_4', |
| 459 |
'level_5', |
| 460 |
'level_6', |
| 461 |
'level_7', |
| 462 |
'level_8', |
| 463 |
'level_9', |
| 464 |
'level_10' |
| 465 |
); |
| 466 |
} |
| 467 |
|
| 468 |
/** |
| 469 |
* Get rid of levels since these are mostly useless in newer versions of WordPress. Devs should |
| 470 |
* add the `__return_false` filter to the `members_remove_old_levels` hook to utilize user levels. |
| 471 |
* |
| 472 |
* @since 0.1.0 |
| 473 |
* @access public |
| 474 |
* @param array $caps |
| 475 |
* @return array |
| 476 |
*/ |
| 477 |
function members_remove_old_levels( $caps ) { |
| 478 |
|
| 479 |
return apply_filters( 'members_remove_old_levels', true ) ? array_diff( $caps, members_get_old_levels() ) : $caps; |
| 480 |
} |
| 481 |
|
| 482 |
/** |
| 483 |
* Returns an array of capabilities that should be set on the New Role admin screen. By default, |
| 484 |
* the only capability checked is 'read' because it's needed for users of the role to view their |
| 485 |
* profile in the admin. |
| 486 |
* |
| 487 |
* @since 0.1.0 |
| 488 |
* @access public |
| 489 |
* @return array |
| 490 |
*/ |
| 491 |
function members_new_role_default_capabilities() { |
| 492 |
|
| 493 |
return apply_filters( 'members_new_role_default_capabilities', array( 'read' ) ); |
| 494 |
} |
| 495 |
|
| 496 |
/** |
| 497 |
* Returns an array of capabilities that should be set on the New Role admin screen. By default, |
| 498 |
* the only capability checked is 'read' because it's needed for users of the role to view their |
| 499 |
* profile in the admin. |
| 500 |
* |
| 501 |
* @since 1.0.0 |
| 502 |
* @access public |
| 503 |
* @return array |
| 504 |
*/ |
| 505 |
function members_new_role_default_caps() { |
| 506 |
|
| 507 |
return apply_filters( 'members_new_role_default_caps', array( 'read' => true ) ); |
| 508 |
} |
| 509 |
|