Add magic get/set/isset methods to WP_User to avoid data duplication. Standardize on WP_User::ID. Props scribu. see #15458
git-svn-id: http://svn.automattic.com/wordpress/trunk@18504 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
6e3e6da9bd
commit
6c81d023bb
|
@ -255,7 +255,7 @@ function get_editable_user_ids( $user_id, $exclude_zeros = true, $post_type = 'p
|
||||||
|
|
||||||
if ( ! $user->has_cap($post_type_obj->cap->edit_others_posts) ) {
|
if ( ! $user->has_cap($post_type_obj->cap->edit_others_posts) ) {
|
||||||
if ( $user->has_cap($post_type_obj->cap->edit_posts) || ! $exclude_zeros )
|
if ( $user->has_cap($post_type_obj->cap->edit_posts) || ! $exclude_zeros )
|
||||||
return array($user->id);
|
return array($user->ID);
|
||||||
else
|
else
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
|
@ -250,7 +250,7 @@ function send_confirmation_on_profile_email() {
|
||||||
if ( ! is_object($errors) )
|
if ( ! is_object($errors) )
|
||||||
$errors = new WP_Error();
|
$errors = new WP_Error();
|
||||||
|
|
||||||
if ( $current_user->id != $_POST['user_id'] )
|
if ( $current_user->ID != $_POST['user_id'] )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if ( $current_user->user_email != $_POST['email'] ) {
|
if ( $current_user->user_email != $_POST['email'] ) {
|
||||||
|
|
|
@ -17,7 +17,7 @@ if ( ! current_user_can('read') )
|
||||||
|
|
||||||
$action = isset( $_POST['action'] ) ? $_POST['action'] : 'splash';
|
$action = isset( $_POST['action'] ) ? $_POST['action'] : 'splash';
|
||||||
|
|
||||||
$blogs = get_blogs_of_user( $current_user->id );
|
$blogs = get_blogs_of_user( $current_user->ID );
|
||||||
|
|
||||||
if ( empty( $blogs ) )
|
if ( empty( $blogs ) )
|
||||||
wp_die( __( 'You must be a member of at least one site to use this page.' ) );
|
wp_die( __( 'You must be a member of at least one site to use this page.' ) );
|
||||||
|
@ -28,7 +28,7 @@ if ( 'updateblogsettings' == $action && isset( $_POST['primary_blog'] ) ) {
|
||||||
|
|
||||||
$blog = get_blog_details( (int) $_POST['primary_blog'] );
|
$blog = get_blog_details( (int) $_POST['primary_blog'] );
|
||||||
if ( $blog && isset( $blog->domain ) ) {
|
if ( $blog && isset( $blog->domain ) ) {
|
||||||
update_user_option( $current_user->id, 'primary_blog', (int) $_POST['primary_blog'], true );
|
update_user_option( $current_user->ID, 'primary_blog', (int) $_POST['primary_blog'], true );
|
||||||
$updated = true;
|
$updated = true;
|
||||||
} else {
|
} else {
|
||||||
wp_die( __( 'The primary site you chose does not exist.' ) );
|
wp_die( __( 'The primary site you chose does not exist.' ) );
|
||||||
|
|
|
@ -216,7 +216,7 @@ case 'doremove':
|
||||||
$update = 'remove';
|
$update = 'remove';
|
||||||
foreach ( $userids as $id ) {
|
foreach ( $userids as $id ) {
|
||||||
$id = (int) $id;
|
$id = (int) $id;
|
||||||
if ( $id == $current_user->id && !is_super_admin() ) {
|
if ( $id == $current_user->ID && !is_super_admin() ) {
|
||||||
$update = 'err_admin_remove';
|
$update = 'err_admin_remove';
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -269,7 +269,7 @@ case 'remove':
|
||||||
foreach ( $userids as $id ) {
|
foreach ( $userids as $id ) {
|
||||||
$id = (int) $id;
|
$id = (int) $id;
|
||||||
$user = new WP_User($id);
|
$user = new WP_User($id);
|
||||||
if ( $id == $current_user->id && !is_super_admin() ) {
|
if ( $id == $current_user->ID && !is_super_admin() ) {
|
||||||
echo "<li>" . sprintf(__('ID #%1s: %2s <strong>The current user will not be removed.</strong>'), $id, $user->user_login) . "</li>\n";
|
echo "<li>" . sprintf(__('ID #%1s: %2s <strong>The current user will not be removed.</strong>'), $id, $user->user_login) . "</li>\n";
|
||||||
} elseif ( !current_user_can('remove_user', $id) ) {
|
} elseif ( !current_user_can('remove_user', $id) ) {
|
||||||
echo "<li>" . sprintf(__('ID #%1s: %2s <strong>You don\'t have permission to remove this user.</strong>'), $id, $user->user_login) . "</li>\n";
|
echo "<li>" . sprintf(__('ID #%1s: %2s <strong>You don\'t have permission to remove this user.</strong>'), $id, $user->user_login) . "</li>\n";
|
||||||
|
|
|
@ -360,8 +360,6 @@ class WP_User {
|
||||||
/**
|
/**
|
||||||
* User data container.
|
* User data container.
|
||||||
*
|
*
|
||||||
* This will be set as properties of the object.
|
|
||||||
*
|
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
* @access private
|
* @access private
|
||||||
* @var array
|
* @var array
|
||||||
|
@ -377,17 +375,6 @@ class WP_User {
|
||||||
*/
|
*/
|
||||||
var $ID = 0;
|
var $ID = 0;
|
||||||
|
|
||||||
/**
|
|
||||||
* The deprecated user's ID.
|
|
||||||
*
|
|
||||||
* @since 2.0.0
|
|
||||||
* @access public
|
|
||||||
* @deprecated Use WP_User::$ID
|
|
||||||
* @see WP_User::$ID
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
var $id = 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The individual capabilities the user has been given.
|
* The individual capabilities the user has been given.
|
||||||
*
|
*
|
||||||
|
@ -471,7 +458,6 @@ class WP_User {
|
||||||
* @return WP_User
|
* @return WP_User
|
||||||
*/
|
*/
|
||||||
function __construct( $id, $name = '', $blog_id = '' ) {
|
function __construct( $id, $name = '', $blog_id = '' ) {
|
||||||
|
|
||||||
if ( empty( $id ) && empty( $name ) )
|
if ( empty( $id ) && empty( $name ) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -488,12 +474,40 @@ class WP_User {
|
||||||
if ( empty( $this->data->ID ) )
|
if ( empty( $this->data->ID ) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
foreach ( get_object_vars( $this->data ) as $key => $value ) {
|
$this->ID = $this->data->ID;
|
||||||
$this->{$key} = $value;
|
$this->for_blog( $blog_id );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Magic method for checking the existance of a certain custom field
|
||||||
|
*
|
||||||
|
* @since 3.3.0
|
||||||
|
*/
|
||||||
|
function __isset( $key ) {
|
||||||
|
return isset( $this->data->$key );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Magic method for accessing custom fields
|
||||||
|
*
|
||||||
|
* @since 3.3.0
|
||||||
|
*/
|
||||||
|
function __get( $key ) {
|
||||||
|
if ( 'id' == $key ) {
|
||||||
|
_deprecated_argument( 'WP_User->id', '2.1', __( 'Use <code>WP_User->ID</code> instead.' ) );
|
||||||
|
return $this->ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->id = $this->ID;
|
return $this->data->$key;
|
||||||
$this->for_blog( $blog_id );
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Magic method for setting custom fields
|
||||||
|
*
|
||||||
|
* @since 3.3.0
|
||||||
|
*/
|
||||||
|
function __set( $key, $value ) {
|
||||||
|
$this->data->$key = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -511,13 +525,16 @@ class WP_User {
|
||||||
*/
|
*/
|
||||||
function _init_caps( $cap_key = '' ) {
|
function _init_caps( $cap_key = '' ) {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
if ( empty($cap_key) )
|
if ( empty($cap_key) )
|
||||||
$this->cap_key = $wpdb->prefix . 'capabilities';
|
$this->cap_key = $wpdb->prefix . 'capabilities';
|
||||||
else
|
else
|
||||||
$this->cap_key = $cap_key;
|
$this->cap_key = $cap_key;
|
||||||
$this->caps = &$this->{$this->cap_key};
|
|
||||||
|
$this->caps = &$this->data->{$this->cap_key};
|
||||||
if ( ! is_array( $this->caps ) )
|
if ( ! is_array( $this->caps ) )
|
||||||
$this->caps = array();
|
$this->caps = array();
|
||||||
|
|
||||||
$this->get_role_caps();
|
$this->get_role_caps();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1080,7 +1097,7 @@ function current_user_can_for_blog( $blog_id, $capability ) {
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Create new object to avoid stomping the global current_user.
|
// Create new object to avoid stomping the global current_user.
|
||||||
$user = new WP_User( $current_user->id) ;
|
$user = new WP_User( $current_user->ID) ;
|
||||||
|
|
||||||
// Set the blog id. @todo add blog id arg to WP_User constructor?
|
// Set the blog id. @todo add blog id arg to WP_User constructor?
|
||||||
$user->for_blog( $blog_id );
|
$user->for_blog( $blog_id );
|
||||||
|
@ -1225,7 +1242,7 @@ function is_super_admin( $user_id = false ) {
|
||||||
else
|
else
|
||||||
$user = wp_get_current_user();
|
$user = wp_get_current_user();
|
||||||
|
|
||||||
if ( empty( $user->id ) )
|
if ( empty( $user->ID ) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if ( is_multisite() ) {
|
if ( is_multisite() ) {
|
||||||
|
|
|
@ -783,7 +783,7 @@ if ( !function_exists('is_user_logged_in') ) :
|
||||||
function is_user_logged_in() {
|
function is_user_logged_in() {
|
||||||
$user = wp_get_current_user();
|
$user = wp_get_current_user();
|
||||||
|
|
||||||
if ( $user->id == 0 )
|
if ( $user->ID == 0 )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -1308,7 +1308,7 @@ if ( !function_exists('wp_verify_nonce') ) :
|
||||||
*/
|
*/
|
||||||
function wp_verify_nonce($nonce, $action = -1) {
|
function wp_verify_nonce($nonce, $action = -1) {
|
||||||
$user = wp_get_current_user();
|
$user = wp_get_current_user();
|
||||||
$uid = (int) $user->id;
|
$uid = (int) $user->ID;
|
||||||
|
|
||||||
$i = wp_nonce_tick();
|
$i = wp_nonce_tick();
|
||||||
|
|
||||||
|
@ -1334,7 +1334,7 @@ if ( !function_exists('wp_create_nonce') ) :
|
||||||
*/
|
*/
|
||||||
function wp_create_nonce($action = -1) {
|
function wp_create_nonce($action = -1) {
|
||||||
$user = wp_get_current_user();
|
$user = wp_get_current_user();
|
||||||
$uid = (int) $user->id;
|
$uid = (int) $user->ID;
|
||||||
|
|
||||||
$i = wp_nonce_tick();
|
$i = wp_nonce_tick();
|
||||||
|
|
||||||
|
|
|
@ -1566,7 +1566,7 @@ function wp_update_user($userdata) {
|
||||||
|
|
||||||
// Update the cookies if the password changed.
|
// Update the cookies if the password changed.
|
||||||
$current_user = wp_get_current_user();
|
$current_user = wp_get_current_user();
|
||||||
if ( $current_user->id == $ID ) {
|
if ( $current_user->ID == $ID ) {
|
||||||
if ( isset($plaintext_pass) ) {
|
if ( isset($plaintext_pass) ) {
|
||||||
wp_clear_auth_cookie();
|
wp_clear_auth_cookie();
|
||||||
wp_set_auth_cookie($ID);
|
wp_set_auth_cookie($ID);
|
||||||
|
|
|
@ -586,10 +586,10 @@ default:
|
||||||
|
|
||||||
if ( ( empty( $redirect_to ) || $redirect_to == 'wp-admin/' || $redirect_to == admin_url() ) ) {
|
if ( ( empty( $redirect_to ) || $redirect_to == 'wp-admin/' || $redirect_to == admin_url() ) ) {
|
||||||
// If the user doesn't belong to a blog, send them to user admin. If the user can't edit posts, send them to their profile.
|
// If the user doesn't belong to a blog, send them to user admin. If the user can't edit posts, send them to their profile.
|
||||||
if ( is_multisite() && !get_active_blog_for_user($user->id) && !is_super_admin( $user->id ) )
|
if ( is_multisite() && !get_active_blog_for_user($user->ID) && !is_super_admin( $user->ID ) )
|
||||||
$redirect_to = user_admin_url();
|
$redirect_to = user_admin_url();
|
||||||
elseif ( is_multisite() && !$user->has_cap('read') )
|
elseif ( is_multisite() && !$user->has_cap('read') )
|
||||||
$redirect_to = get_dashboard_url( $user->id );
|
$redirect_to = get_dashboard_url( $user->ID );
|
||||||
elseif ( !$user->has_cap('edit_posts') )
|
elseif ( !$user->has_cap('edit_posts') )
|
||||||
$redirect_to = admin_url('profile.php');
|
$redirect_to = admin_url('profile.php');
|
||||||
}
|
}
|
||||||
|
|
|
@ -213,7 +213,7 @@ function validate_another_blog_signup() {
|
||||||
$meta = apply_filters( 'signup_create_blog_meta', array( 'lang_id' => 1, 'public' => $public ) ); // deprecated
|
$meta = apply_filters( 'signup_create_blog_meta', array( 'lang_id' => 1, 'public' => $public ) ); // deprecated
|
||||||
$meta = apply_filters( 'add_signup_meta', $meta );
|
$meta = apply_filters( 'add_signup_meta', $meta );
|
||||||
|
|
||||||
wpmu_create_blog( $domain, $path, $blog_title, $current_user->id, $meta, $wpdb->siteid );
|
wpmu_create_blog( $domain, $path, $blog_title, $current_user->ID, $meta, $wpdb->siteid );
|
||||||
confirm_another_blog_signup($domain, $path, $blog_title, $current_user->user_login, $current_user->user_email, $meta);
|
confirm_another_blog_signup($domain, $path, $blog_title, $current_user->user_login, $current_user->user_email, $meta);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue