Make WordPress Core

Ticket #15458: 15458.diff

File 15458.diff, 2.8 KB (added by scribu, 14 years ago)
  • wp-includes/capabilities.php

     
    360360        /**
    361361         * User data container.
    362362         *
    363          * This will be set as properties of the object.
    364          *
    365363         * @since 2.0.0
    366364         * @access private
    367365         * @var array
     
    378376        var $ID = 0;
    379377
    380378        /**
    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;
    390 
    391         /**
    392379         * The individual capabilities the user has been given.
    393380         *
    394381         * @since 2.0.0
     
    471458         * @return WP_User
    472459         */
    473460        function __construct( $id, $name = '', $blog_id = '' ) {
    474 
    475461                if ( empty( $id ) && empty( $name ) )
    476462                        return;
    477463
     
    488474                if ( empty( $this->data->ID ) )
    489475                        return;
    490476
    491                 foreach ( get_object_vars( $this->data ) as $key => $value ) {
    492                         $this->{$key} = $value;
     477                $this->ID = $this->data->ID;
     478                $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;
    493499                }
    494500
    495                 $this->id = $this->ID;
    496                 $this->for_blog( $blog_id );
     501                return $this->data->$key;
    497502        }
    498503
    499504        /**
     505         * Magic method for setting custom fields
     506         *
     507         * @since 3.3.0
     508         */
     509        function __set( $key, $value ) {
     510                $this->data->$key = $value;
     511        }
     512
     513        /**
    500514         * Set up capability object properties.
    501515         *
    502516         * Will set the value for the 'cap_key' property to current database table
     
    511525         */
    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        }
    523540
     
    956973        case 'add_post_meta':
    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 ); 
     976                $caps = map_meta_cap( $post_type_object->cap->edit_post, $user_id, $post->ID );
    960977
    961                 $meta_key = isset( $args[ 1 ] ) ? $args[ 1 ] : false; 
    962                        
     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 );
    965982                        if ( ! $allowed )