X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/af50974463450c98503e763a7836a50e260461a9..refs/tags/wordpress-4.2.3:/wp-includes/capabilities.php diff --git a/wp-includes/capabilities.php b/wp-includes/capabilities.php index 894a149e..8a3d3350 100644 --- a/wp-includes/capabilities.php +++ b/wp-includes/capabilities.php @@ -90,7 +90,10 @@ class WP_Roles { * @return mixed|bool Return value of the callback, false otherwise. */ public function __call( $name, $arguments ) { - return call_user_func_array( array( $this, $name ), $arguments ); + if ( '_init' === $name ) { + return call_user_func_array( array( $this, $name ), $arguments ); + } + return false; } /** @@ -415,16 +418,31 @@ class WP_Role { * @since 2.0.0 * @package WordPress * @subpackage User + * + * @property string $nickname + * @property string $user_description + * @property string $user_firstname + * @property string $user_lastname + * @property string $user_login + * @property string $user_pass + * @property string $user_nicename + * @property string $user_email + * @property string $user_url + * @property string $user_registered + * @property string $user_activation_key + * @property string $user_status + * @property string $display_name + * @property string $spam + * @property string $deleted */ class WP_User { /** * User data container. * * @since 2.0.0 - * @access private - * @var array + * @var object */ - var $data; + public $data; /** * The user's ID. @@ -493,7 +511,6 @@ class WP_User { * @param int|string|stdClass|WP_User $id User's ID, a WP_User object, or a user object from the DB. * @param string $name Optional. User's username * @param int $blog_id Optional Blog ID, defaults to current blog. - * @return WP_User */ public function __construct( $id = 0, $name = '', $blog_id = '' ) { if ( ! isset( self::$back_compat_keys ) ) { @@ -508,7 +525,7 @@ class WP_User { ); } - if ( is_a( $id, 'WP_User' ) ) { + if ( $id instanceof WP_User ) { $this->init( $id->data, $blog_id ); return; } elseif ( is_object( $id ) ) { @@ -521,13 +538,17 @@ class WP_User { $id = 0; } - if ( $id ) + if ( $id ) { $data = self::get_data_by( 'id', $id ); - else + } else { $data = self::get_data_by( 'login', $name ); + } - if ( $data ) + if ( $data ) { $this->init( $data, $blog_id ); + } else { + $this->data = new stdClass; + } } /** @@ -550,7 +571,7 @@ class WP_User { * * @param string $field The field to query against: 'id', 'slug', 'email' or 'login' * @param string|int $value The field value - * @return object Raw user object + * @return object|false Raw user object */ public static function get_data_by( $field, $value ) { global $wpdb; @@ -918,6 +939,8 @@ class WP_User { public function add_cap( $cap, $grant = true ) { $this->caps[$cap] = $grant; update_user_meta( $this->ID, $this->cap_key, $this->caps ); + $this->get_role_caps(); + $this->update_user_level_from_caps(); } /** @@ -929,10 +952,13 @@ class WP_User { * @param string $cap Capability name. */ public function remove_cap( $cap ) { - if ( ! isset( $this->caps[$cap] ) ) + if ( ! isset( $this->caps[ $cap ] ) ) { return; - unset( $this->caps[$cap] ); + } + unset( $this->caps[ $cap ] ); update_user_meta( $this->ID, $this->cap_key, $this->caps ); + $this->get_role_caps(); + $this->update_user_level_from_caps(); } /** @@ -985,7 +1011,7 @@ class WP_User { * @since 2.0.0 * @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 user's capabilities. * @param array $caps Actual capabilities for meta capability. * @param array $args Optional parameters passed to has_cap(), typically object ID. * @param WP_User $user The user object. @@ -1117,8 +1143,10 @@ function map_meta_cap( $cap, $user_id ) { case 'edit_post': case 'edit_page': $post = get_post( $args[0] ); - if ( empty( $post ) ) + if ( empty( $post ) ) { + $caps[] = 'do_not_allow'; break; + } if ( 'revision' == $post->post_type ) { $post = get_post( $post->post_parent ); @@ -1319,6 +1347,9 @@ function map_meta_cap( $cap, $user_id ) { case 'customize' : $caps[] = 'edit_theme_options'; break; + case 'delete_site': + $caps[] = 'manage_options'; + break; default: // Handle meta capabilities for custom post types. $post_type_meta_caps = _post_type_meta_capabilities(); @@ -1374,21 +1405,25 @@ function current_user_can( $capability ) { * @return bool */ function current_user_can_for_blog( $blog_id, $capability ) { - if ( is_multisite() ) - switch_to_blog( $blog_id ); + $switched = is_multisite() ? switch_to_blog( $blog_id ) : false; $current_user = wp_get_current_user(); - if ( empty( $current_user ) ) + if ( empty( $current_user ) ) { + if ( $switched ) { + restore_current_blog(); + } return false; + } $args = array_slice( func_get_args(), 2 ); $args = array_merge( array( $capability ), $args ); $can = call_user_func_array( array( $current_user, 'has_cap' ), $args ); - if ( is_multisite() ) + if ( $switched ) { restore_current_blog(); + } return $can; }