Make WordPress Core

Changeset 21563


Ignore:
Timestamp:
08/20/2012 09:58:34 PM (12 years ago)
Author:
nacin
Message:

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.

Location:
trunk/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/capabilities.php

    r21501 r21563  
    10171017        }
    10181018
    1019         if ( '' != $post->post_author ) {
    1020             $post_author_data = get_userdata( $post->post_author );
    1021         } else {
    1022             // No author set yet, so default to current user for cap checks.
    1023             $post_author_data = get_userdata( $user_id );
    1024         }
     1019        $post_author_id = $post->post_author;
     1020
     1021        // If no author set yet, default to current user for cap checks.
     1022        if ( ! $post_author_id )
     1023            $post_author_id = $user_id;
     1024
     1025        $post_author_data = $post_author_id == get_current_user_id() ? wp_get_current_user() : get_userdata( $post_author_id );
    10251026
    10261027        // If the user is the author...
     
    10661067        }
    10671068
    1068         if ( '' != $post->post_author ) {
    1069             $post_author_data = get_userdata( $post->post_author );
    1070         } else {
    1071             // No author set yet, so default to current user for cap checks.
    1072             $post_author_data = get_userdata( $user_id );
    1073         }
    1074 
    1075         //echo "current user id : $user_id, post author id: " . $post_author_data->ID . "<br />";
     1069        $post_author_id = $post->post_author;
     1070
     1071        // If no author set yet, default to current user for cap checks.
     1072        if ( ! $post_author_id )
     1073            $post_author_id = $user_id;
     1074
     1075        $post_author_data = $post_author_id == get_current_user_id() ? wp_get_current_user() : get_userdata( $post_author_id );
     1076
    10761077        // If the user is the author...
    10771078        if ( is_object( $post_author_data ) && $user_id == $post_author_data->ID ) {
     
    11201121        }
    11211122
    1122         if ( '' != $post->post_author ) {
    1123             $post_author_data = get_userdata( $post->post_author );
    1124         } else {
    1125             // No author set yet, so default to current user for cap checks.
    1126             $post_author_data = get_userdata( $user_id );
    1127         }
     1123        $post_author_id = $post->post_author;
     1124
     1125        // If no author set yet, default to current user for cap checks.
     1126        if ( ! $post_author_id )
     1127            $post_author_id = $user_id;
     1128
     1129        $post_author_data = $post_author_id == get_current_user_id() ? wp_get_current_user() : get_userdata( $post_author_id );
    11281130
    11291131        if ( is_object( $post_author_data ) && $user_id == $post_author_data->ID )
     
    14241426 */
    14251427function is_super_admin( $user_id = false ) {
    1426     if ( ! $user_id )
    1427         $user_id = get_current_user_id();
    1428 
    1429     if ( ! $user = get_userdata( $user_id ) )
     1428    if ( ! $user_id || $user_id == get_current_user_id() )
     1429        $user = wp_get_current_user();
     1430    else
     1431        $user = get_userdata( $user_id );
     1432
     1433    if ( ! $user || ! $user->exists() )
    14301434        return false;
    14311435
  • trunk/wp-includes/pluggable.php

    r21413 r21563  
    134134 */
    135135function get_user_by( $field, $value ) {
    136     if ( 'id' === $field && (int) $value && get_current_user_id() === (int) $value )
    137         return wp_get_current_user();
    138 
    139136    $userdata = WP_User::get_data_by( $field, $value );
    140137
Note: See TracChangeset for help on using the changeset viewer.