Untitled diff
1 removal
39 lines
2 additions
40 lines
public function has_cap( $cap ) {
public function has_cap( $cap ) {
if ( is_numeric( $cap ) ) {
if ( is_numeric( $cap ) ) {
_deprecated_argument( __FUNCTION__, '2.0', __('Usage of user levels by plugins and themes is deprecated. Use roles and capabilities instead.') );
_deprecated_argument( __FUNCTION__, '2.0', __('Usage of user levels by plugins and themes is deprecated. Use roles and capabilities instead.') );
$cap = $this->translate_level_to_cap( $cap );
$cap = $this->translate_level_to_cap( $cap );
}
}
$args = array_slice( func_get_args(), 1 );
$args = array_slice( func_get_args(), 1 );
$args = array_merge( array( $cap, $this->ID ), $args );
$args = array_merge( array( $cap, $this->ID ), $args );
$caps = call_user_func_array( 'map_meta_cap', $args );
$caps = call_user_func_array( 'map_meta_cap', $args );
if(!in_array($cap,$caps)) return false;
// Multisite super admin has all caps by definition, Unless specifically denied.
// Multisite super admin has all caps by definition, Unless specifically denied.
if ( is_multisite() && is_super_admin( $this->ID ) ) {
if ( is_multisite() && is_super_admin( $this->ID ) ) {
if ( in_array('do_not_allow', $caps) )
if ( in_array('do_not_allow', $caps) )
return false;
return false;
return true;
return true;
}
}
/**
/**
* Dynamically filter a user's capabilities.
* Dynamically filter a user's capabilities.
*
*
* @since 2.0.0
* @since 2.0.0
* @since 3.7.0 Added the user object.
* @since 3.7.0 Added the user object.
*
*
* @param array $allcaps An array of all the role's capabilities.
* @param array $allcaps An array of all the role's capabilities.
* @param array $caps Actual capabilities for meta capability.
* @param array $caps Actual capabilities for meta capability.
* @param array $args Optional parameters passed to has_cap(), typically object ID.
* @param array $args Optional parameters passed to has_cap(), typically object ID.
* @param WP_User $user The user object.
* @param WP_User $user The user object.
*/
*/
// Must have ALL requested caps
// Must have ALL requested caps
$capabilities = apply_filters( 'user_has_cap', $this->allcaps, $caps, $args, $this );
$capabilities = apply_filters( 'user_has_cap', $this->allcaps, $caps, $args, $this );
$capabilities['exist'] = true; // Everyone is allowed to exist
$capabilities['exist'] = true; // Everyone is allowed to exist
if(empty((array)$caps)) return false;
foreach ( (array) $caps as $cap ) {
foreach ( (array) $caps as $cap ) {
if ( empty( $capabilities[ $cap ] ) )
if ( empty( $capabilities[ $cap ] ) )
return false;
return false;
}
}
return true;
return true;
}
}