Make WordPress Core

Changeset 18504


Ignore:
Timestamp:
08/04/2011 03:09:27 AM (15 years ago)
Author:
ryan
Message:

Add magic get/set/isset methods to WP_User to avoid data duplication. Standardize on WP_User::ID. Props scribu. see #15458

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/deprecated.php

    r18498 r18504  
    256256        if ( ! $user->has_cap($post_type_obj->cap->edit_others_posts) ) {
    257257                if ( $user->has_cap($post_type_obj->cap->edit_posts) || ! $exclude_zeros )
    258                         return array($user->id);
     258                        return array($user->ID);
    259259                else
    260260                        return array();
  • trunk/wp-admin/includes/ms.php

    r18337 r18504  
    251251                $errors = new WP_Error();
    252252
    253         if ( $current_user->id != $_POST['user_id'] )
     253        if ( $current_user->ID != $_POST['user_id'] )
    254254                return false;
    255255
  • trunk/wp-admin/my-sites.php

    r17748 r18504  
    1818$action = isset( $_POST['action'] ) ? $_POST['action'] : 'splash';
    1919
    20 $blogs = get_blogs_of_user( $current_user->id );
     20$blogs = get_blogs_of_user( $current_user->ID );
    2121
    2222if ( empty( $blogs ) )
    … …  
    2929        $blog = get_blog_details( (int) $_POST['primary_blog'] );
    3030        if ( $blog && isset( $blog->domain ) ) {
    31                 update_user_option( $current_user->id, 'primary_blog', (int) $_POST['primary_blog'], true );
     31                update_user_option( $current_user->ID, 'primary_blog', (int) $_POST['primary_blog'], true );
    3232                $updated = true;
    3333        } else {
  • trunk/wp-admin/users.php

    r17977 r18504  
    217217        foreach ( $userids as $id ) {
    218218                $id = (int) $id;
    219                 if ( $id == $current_user->id && !is_super_admin() ) {
     219                if ( $id == $current_user->ID && !is_super_admin() ) {
    220220                        $update = 'err_admin_remove';
    221221                        continue;
    … …  
    270270                $id = (int) $id;
    271271                $user = new WP_User($id);
    272                 if ( $id == $current_user->id && !is_super_admin() ) {
     272                if ( $id == $current_user->ID && !is_super_admin() ) {
    273273                        echo "<li>" . sprintf(__('ID #%1s: %2s <strong>The current user will not be removed.</strong>'), $id, $user->user_login) . "</li>\n";
    274274                } elseif ( !current_user_can('remove_user', $id) ) {
  • trunk/wp-includes/capabilities.php

    r18476 r18504  
    361361         * User data container.
    362362         *
    363          * This will be set as properties of the object.
    364          *
    365363         * @since 2.0.0
    366364         * @access private
    … …  
    377375         */
    378376        var $ID = 0;
    379 
    380         /**
    381          * The deprecated user's ID.
    382          *
    383          * @since 2.0.0
    384          * @access public
    385          * @deprecated Use WP_User::$ID
    386          * @see WP_User::$ID
    387          * @var int
    388          */
    389         var $id = 0;
    390377
    391378        /**
    … …  
    472459         */
    473460        function __construct( $id, $name = '', $blog_id = '' ) {
    474 
    475461                if ( empty( $id ) && empty( $name ) )
    476462                        return;
    … …  
    489475                        return;
    490476
    491                 foreach ( get_object_vars( $this->data ) as $key => $value ) {
    492                         $this->{$key} = $value;
    493                 }
    494 
    495                 $this->id = $this->ID;
     477                $this->ID = $this->data->ID;
    496478                $this->for_blog( $blog_id );
     479        }
     480
     481        /**
     482         * Magic method for checking the existance of a certain custom field
     483         *
     484         * @since 3.3.0
     485         */
     486        function __isset( $key ) {
     487                return isset( $this->data->$key );
     488        }
     489
     490        /**
     491         * Magic method for accessing custom fields
     492         *
     493         * @since 3.3.0
     494         */
     495        function __get( $key ) {
     496                if ( 'id' == $key ) {
     497                        _deprecated_argument( 'WP_User->id', '2.1', __( 'Use <code>WP_User->ID</code> instead.' ) );
     498                        return $this->ID;
     499                }
     500
     501                return $this->data->$key;
     502        }
     503
     504        /**
     505         * Magic method for setting custom fields
     506         *
     507         * @since 3.3.0
     508         */
     509        function __set( $key, $value ) {
     510                $this->data->$key = $value;
    497511        }
    498512
    … …  
    512526        function _init_caps( $cap_key = '' ) {
    513527                global $wpdb;
     528
    514529                if ( empty($cap_key) )
    515530                        $this->cap_key = $wpdb->prefix . 'capabilities';
    516531                else
    517532                        $this->cap_key = $cap_key;
    518                 $this->caps = &$this->{$this->cap_key};
     533
     534                $this->caps = &$this->data->{$this->cap_key};
    519535                if ( ! is_array( $this->caps ) )
    520536                        $this->caps = array();
     537
    521538                $this->get_role_caps();
    522539        }
    … …  
    957974                $post = get_post( $args[0] );
    958975                $post_type_object = get_post_type_object( $post->post_type );
    959                 $caps = map_meta_cap( $post_type_object->cap->edit_post, $user_id, $post->ID ); 
    960 
    961                 $meta_key = isset( $args[ 1 ] ) ? $args[ 1 ] : false; 
    962                        
     976                $caps = map_meta_cap( $post_type_object->cap->edit_post, $user_id, $post->ID );
     977
     978                $meta_key = isset( $args[ 1 ] ) ? $args[ 1 ] : false;
     979
    963980                if ( $meta_key && has_filter( "auth_post_meta_{$meta_key}" ) ) {
    964981                        $allowed = apply_filters( "auth_post_meta_{$meta_key}", false, $meta_key, $post->ID, $user_id, $cap, $caps );
    … …  
    10811098
    10821099        // Create new object to avoid stomping the global current_user.
    1083         $user = new WP_User( $current_user->id) ;
     1100        $user = new WP_User( $current_user->ID) ;
    10841101
    10851102        // Set the blog id.  @todo add blog id arg to WP_User constructor?
    … …  
    12261243                $user = wp_get_current_user();
    12271244
    1228         if ( empty( $user->id ) )
     1245        if ( empty( $user->ID ) )
    12291246                return false;
    12301247
  • trunk/wp-includes/pluggable.php

    r18195 r18504  
    784784        $user = wp_get_current_user();
    785785
    786         if ( $user->id == 0 )
     786        if ( $user->ID == 0 )
    787787                return false;
    788788
    … …  
    13091309function wp_verify_nonce($nonce, $action = -1) {
    13101310        $user = wp_get_current_user();
    1311         $uid = (int) $user->id;
     1311        $uid = (int) $user->ID;
    13121312
    13131313        $i = wp_nonce_tick();
    … …  
    13351335function wp_create_nonce($action = -1) {
    13361336        $user = wp_get_current_user();
    1337         $uid = (int) $user->id;
     1337        $uid = (int) $user->ID;
    13381338
    13391339        $i = wp_nonce_tick();
  • trunk/wp-includes/user.php

    r18451 r18504  
    15671567        // Update the cookies if the password changed.
    15681568        $current_user = wp_get_current_user();
    1569         if ( $current_user->id == $ID ) {
     1569        if ( $current_user->ID == $ID ) {
    15701570                if ( isset($plaintext_pass) ) {
    15711571                        wp_clear_auth_cookie();
  • trunk/wp-login.php

    r18460 r18504  
    587587                if ( ( empty( $redirect_to ) || $redirect_to == 'wp-admin/' || $redirect_to == admin_url() ) ) {
    588588                        // 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.
    589                         if ( is_multisite() && !get_active_blog_for_user($user->id) && !is_super_admin( $user->id ) )
     589                        if ( is_multisite() && !get_active_blog_for_user($user->ID) && !is_super_admin( $user->ID ) )
    590590                                $redirect_to = user_admin_url();
    591591                        elseif ( is_multisite() && !$user->has_cap('read') )
    592                                 $redirect_to = get_dashboard_url( $user->id );
     592                                $redirect_to = get_dashboard_url( $user->ID );
    593593                        elseif ( !$user->has_cap('edit_posts') )
    594594                                $redirect_to = admin_url('profile.php');
  • trunk/wp-signup.php

    r17989 r18504  
    214214        $meta = apply_filters( 'add_signup_meta', $meta );
    215215
    216         wpmu_create_blog( $domain, $path, $blog_title, $current_user->id, $meta, $wpdb->siteid );
     216        wpmu_create_blog( $domain, $path, $blog_title, $current_user->ID, $meta, $wpdb->siteid );
    217217        confirm_another_blog_signup($domain, $path, $blog_title, $current_user->user_login, $current_user->user_email, $meta);
    218218        return true;
Note: See TracChangeset for help on using the changeset viewer.