Move the optimization done to get_user_by() in [21376] higher up the stack, into map_meta_cap() and is_super_admin().
This provides nearly the same benefits without possibly receiving a stale object from get_userdata(), which could affect authentication, and introduce side effects for plugins. see #21120. git-svn-id: https://develop.svn.wordpress.org/trunk@21563 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
c4e51487e5
commit
d41d58d128
|
@ -1016,12 +1016,13 @@ function map_meta_cap( $cap, $user_id ) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( '' != $post->post_author ) {
|
$post_author_id = $post->post_author;
|
||||||
$post_author_data = get_userdata( $post->post_author );
|
|
||||||
} else {
|
// If no author set yet, default to current user for cap checks.
|
||||||
// No author set yet, so default to current user for cap checks.
|
if ( ! $post_author_id )
|
||||||
$post_author_data = get_userdata( $user_id );
|
$post_author_id = $user_id;
|
||||||
}
|
|
||||||
|
$post_author_data = $post_author_id == get_current_user_id() ? wp_get_current_user() : get_userdata( $post_author_id );
|
||||||
|
|
||||||
// If the user is the author...
|
// If the user is the author...
|
||||||
if ( is_object( $post_author_data ) && $user_id == $post_author_data->ID ) {
|
if ( is_object( $post_author_data ) && $user_id == $post_author_data->ID ) {
|
||||||
|
@ -1065,14 +1066,14 @@ function map_meta_cap( $cap, $user_id ) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( '' != $post->post_author ) {
|
$post_author_id = $post->post_author;
|
||||||
$post_author_data = get_userdata( $post->post_author );
|
|
||||||
} else {
|
// If no author set yet, default to current user for cap checks.
|
||||||
// No author set yet, so default to current user for cap checks.
|
if ( ! $post_author_id )
|
||||||
$post_author_data = get_userdata( $user_id );
|
$post_author_id = $user_id;
|
||||||
}
|
|
||||||
|
$post_author_data = $post_author_id == get_current_user_id() ? wp_get_current_user() : get_userdata( $post_author_id );
|
||||||
|
|
||||||
//echo "current user id : $user_id, post author id: " . $post_author_data->ID . "<br />";
|
|
||||||
// If the user is the author...
|
// If the user is the author...
|
||||||
if ( is_object( $post_author_data ) && $user_id == $post_author_data->ID ) {
|
if ( is_object( $post_author_data ) && $user_id == $post_author_data->ID ) {
|
||||||
// If the post is published...
|
// If the post is published...
|
||||||
|
@ -1119,12 +1120,13 @@ function map_meta_cap( $cap, $user_id ) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( '' != $post->post_author ) {
|
$post_author_id = $post->post_author;
|
||||||
$post_author_data = get_userdata( $post->post_author );
|
|
||||||
} else {
|
// If no author set yet, default to current user for cap checks.
|
||||||
// No author set yet, so default to current user for cap checks.
|
if ( ! $post_author_id )
|
||||||
$post_author_data = get_userdata( $user_id );
|
$post_author_id = $user_id;
|
||||||
}
|
|
||||||
|
$post_author_data = $post_author_id == get_current_user_id() ? wp_get_current_user() : get_userdata( $post_author_id );
|
||||||
|
|
||||||
if ( is_object( $post_author_data ) && $user_id == $post_author_data->ID )
|
if ( is_object( $post_author_data ) && $user_id == $post_author_data->ID )
|
||||||
$caps[] = $post_type->cap->read;
|
$caps[] = $post_type->cap->read;
|
||||||
|
@ -1423,10 +1425,12 @@ function get_super_admins() {
|
||||||
* @return bool True if the user is a site admin.
|
* @return bool True if the user is a site admin.
|
||||||
*/
|
*/
|
||||||
function is_super_admin( $user_id = false ) {
|
function is_super_admin( $user_id = false ) {
|
||||||
if ( ! $user_id )
|
if ( ! $user_id || $user_id == get_current_user_id() )
|
||||||
$user_id = get_current_user_id();
|
$user = wp_get_current_user();
|
||||||
|
else
|
||||||
|
$user = get_userdata( $user_id );
|
||||||
|
|
||||||
if ( ! $user = get_userdata( $user_id ) )
|
if ( ! $user || ! $user->exists() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if ( is_multisite() ) {
|
if ( is_multisite() ) {
|
||||||
|
|
|
@ -133,9 +133,6 @@ if ( !function_exists('get_user_by') ) :
|
||||||
* @return bool|object False on failure, WP_User object on success
|
* @return bool|object False on failure, WP_User object on success
|
||||||
*/
|
*/
|
||||||
function get_user_by( $field, $value ) {
|
function get_user_by( $field, $value ) {
|
||||||
if ( 'id' === $field && (int) $value && get_current_user_id() === (int) $value )
|
|
||||||
return wp_get_current_user();
|
|
||||||
|
|
||||||
$userdata = WP_User::get_data_by( $field, $value );
|
$userdata = WP_User::get_data_by( $field, $value );
|
||||||
|
|
||||||
if ( !$userdata )
|
if ( !$userdata )
|
||||||
|
|
Loading…
Reference in New Issue