Make WordPress Core

Changeset 28523


Ignore:
Timestamp:
05/19/2014 06:48:56 AM (12 years ago)
Author:
wonderboymusic
Message:

Add missing access modifiers to methods in WP_Query. Add magic methods for __get(), __set(), __isset(), __unset(), and __call().

Add unit test for magic methods.

See #27881, #22234.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/query.php

    r28333 r28523  
    846846         * @var array
    847847         */
    848         var $query;
     848        public $query;
    849849
    850850        /**
    … …  
    855855         * @var array
    856856         */
    857         var $query_vars = array();
     857        public $query_vars = array();
    858858
    859859        /**
    … …  
    864864         * @var object WP_Tax_Query
    865865         */
    866         var $tax_query;
     866        public $tax_query;
    867867
    868868        /**
    … …  
    873873         * @var object WP_Meta_Query
    874874         */
    875         var $meta_query = false;
     875        public $meta_query = false;
    876876
    877877        /**
    … …  
    882882         * @var object WP_Date_Query
    883883         */
    884         var $date_query = false;
     884        public $date_query = false;
    885885
    886886        /**
    … …  
    893893         * @var object|array
    894894         */
    895         var $queried_object;
     895        public $queried_object;
    896896
    897897        /**
    … …  
    902902         * @var int
    903903         */
    904         var $queried_object_id;
     904        public $queried_object_id;
    905905
    906906        /**
    … …  
    911911         * @var string
    912912         */
    913         var $request;
     913        public $request;
    914914
    915915        /**
    … …  
    920920         * @var array
    921921         */
    922         var $posts;
     922        public $posts;
    923923
    924924        /**
    … …  
    929929         * @var int
    930930         */
    931         var $post_count = 0;
     931        public $post_count = 0;
    932932
    933933        /**
    … …  
    938938         * @var int
    939939         */
    940         var $current_post = -1;
     940        public $current_post = -1;
    941941
    942942        /**
    … …  
    947947         * @var bool
    948948         */
    949         var $in_the_loop = false;
     949        public $in_the_loop = false;
    950950
    951951        /**
    … …  
    956956         * @var WP_Post
    957957         */
    958         var $post;
     958        public $post;
    959959
    960960        /**
    … …  
    965965         * @var array
    966966         */
    967         var $comments;
     967        public $comments;
    968968
    969969        /**
    … …  
    974974         * @var int
    975975         */
    976         var $comment_count = 0;
     976        public $comment_count = 0;
    977977
    978978        /**
    … …  
    983983         * @var int
    984984         */
    985         var $current_comment = -1;
     985        public $current_comment = -1;
    986986
    987987        /**
    … …  
    992992         * @var int
    993993         */
    994         var $comment;
     994        public $comment;
    995995
    996996        /**
    … …  
    10031003         * @var int
    10041004         */
    1005         var $found_posts = 0;
     1005        public $found_posts = 0;
    10061006
    10071007        /**
    … …  
    10121012         * @var int
    10131013         */
    1014         var $max_num_pages = 0;
     1014        public $max_num_pages = 0;
    10151015
    10161016        /**
    … …  
    10211021         * @var int
    10221022         */
    1023         var $max_num_comment_pages = 0;
     1023        public $max_num_comment_pages = 0;
    10241024
    10251025        /**
    … …  
    10301030         * @var bool
    10311031         */
    1032         var $is_single = false;
     1032        public $is_single = false;
    10331033
    10341034        /**
    … …  
    10391039         * @var bool
    10401040         */
    1041         var $is_preview = false;
     1041        public $is_preview = false;
    10421042
    10431043        /**
    … …  
    10481048         * @var bool
    10491049         */
    1050         var $is_page = false;
     1050        public $is_page = false;
    10511051
    10521052        /**
    … …  
    10571057         * @var bool
    10581058         */
    1059         var $is_archive = false;
     1059        public $is_archive = false;
    10601060
    10611061        /**
    … …  
    10661066         * @var bool
    10671067         */
    1068         var $is_date = false;
     1068        public $is_date = false;
    10691069
    10701070        /**
    … …  
    10751075         * @var bool
    10761076         */
    1077         var $is_year = false;
     1077        public $is_year = false;
    10781078
    10791079        /**
    … …  
    10841084         * @var bool
    10851085         */
    1086         var $is_month = false;
     1086        public $is_month = false;
    10871087
    10881088        /**
    … …  
    10931093         * @var bool
    10941094         */
    1095         var $is_day = false;
     1095        public $is_day = false;
    10961096
    10971097        /**
    … …  
    11021102         * @var bool
    11031103         */
    1104         var $is_time = false;
     1104        public $is_time = false;
    11051105
    11061106        /**
    … …  
    11111111         * @var bool
    11121112         */
    1113         var $is_author = false;
     1113        public $is_author = false;
    11141114
    11151115        /**
    … …  
    11201120         * @var bool
    11211121         */
    1122         var $is_category = false;
     1122        public $is_category = false;
    11231123
    11241124        /**
    … …  
    11291129         * @var bool
    11301130         */
    1131         var $is_tag = false;
     1131        public $is_tag = false;
    11321132
    11331133        /**
    … …  
    11381138         * @var bool
    11391139         */
    1140         var $is_tax = false;
     1140        public $is_tax = false;
    11411141
    11421142        /**
    … …  
    11471147         * @var bool
    11481148         */
    1149         var $is_search = false;
     1149        public $is_search = false;
    11501150
    11511151        /**
    … …  
    11561156         * @var bool
    11571157         */
    1158         var $is_feed = false;
     1158        public $is_feed = false;
    11591159
    11601160        /**
    … …  
    11651165         * @var bool
    11661166         */
    1167         var $is_comment_feed = false;
     1167        public $is_comment_feed = false;
    11681168
    11691169        /**
    … …  
    11741174         * @var bool
    11751175         */
    1176         var $is_trackback = false;
     1176        public $is_trackback = false;
    11771177
    11781178        /**
    … …  
    11831183         * @var bool
    11841184         */
    1185         var $is_home = false;
     1185        public $is_home = false;
    11861186
    11871187        /**
    … …  
    11921192         * @var bool
    11931193         */
    1194         var $is_404 = false;
     1194        public $is_404 = false;
    11951195
    11961196        /**
    … …  
    12011201         * @var bool
    12021202         */
    1203         var $is_comments_popup = false;
     1203        public $is_comments_popup = false;
    12041204
    12051205        /**
    … …  
    12101210         * @var bool
    12111211         */
    1212         var $is_paged = false;
     1212        public $is_paged = false;
    12131213
    12141214        /**
    … …  
    12191219         * @var bool
    12201220         */
    1221         var $is_admin = false;
     1221        public $is_admin = false;
    12221222
    12231223        /**
    … …  
    12281228         * @var bool
    12291229         */
    1230         var $is_attachment = false;
     1230        public $is_attachment = false;
    12311231
    12321232        /**
    … …  
    12371237         * @var bool
    12381238         */
    1239         var $is_singular = false;
     1239        public $is_singular = false;
    12401240
    12411241        /**
    … …  
    12461246         * @var bool
    12471247         */
    1248         var $is_robots = false;
     1248        public $is_robots = false;
    12491249
    12501250        /**
    … …  
    12571257         * @var bool
    12581258         */
    1259         var $is_posts_page = false;
     1259        public $is_posts_page = false;
    12601260
    12611261        /**
    … …  
    12661266         * @var bool
    12671267         */
    1268         var $is_post_type_archive = false;
     1268        public $is_post_type_archive = false;
    12691269
    12701270        /**
    … …  
    12751275         * @access private
    12761276         */
    1277         var $query_vars_hash = false;
     1277        private $query_vars_hash = false;
    12781278
    12791279        /**
    … …  
    12841284         * @access private
    12851285         */
    1286         var $query_vars_changed = true;
     1286        private $query_vars_changed = true;
    12871287
    12881288        /**
    … …  
    12931293         * @var bool
    12941294         */
    1295          var $thumbnails_cached = false;
     1295         public $thumbnails_cached = false;
    12961296
    12971297        /**
    … …  
    13111311         * @access private
    13121312         */
    1313         function init_query_flags() {
     1313        private function init_query_flags() {
    13141314                $this->is_single = false;
    13151315                $this->is_preview = false;
    … …  
    13471347         * @access public
    13481348         */
    1349         function init() {
     1349        public function init() {
    13501350                unset($this->posts);
    13511351                unset($this->query);
    … …  
    13751375         * @access public
    13761376         */
    1377         function parse_query_vars() {
     1377        public function parse_query_vars() {
    13781378                $this->parse_query();
    13791379        }
    … …  
    13881388         * @return array Complete query variables with undefined ones filled in empty.
    13891389         */
    1390         function fill_query_vars($array) {
     1390        public function fill_query_vars($array) {
    13911391                $keys = array(
    13921392                        'error'
    … …  
    14521452         * @param string|array $query Optional query.
    14531453         */
    1454         function parse_query( $query =  '' ) {
     1454        public function parse_query( $query =  '' ) {
    14551455                if ( ! empty( $query ) ) {
    14561456                        $this->init();
    … …  
    17331733         * @param array &$q The query variables
    17341734         */
    1735         function parse_tax_query( &$q ) {
     1735        protected function parse_tax_query( &$q ) {
    17361736                if ( ! empty( $q['tax_query'] ) && is_array( $q['tax_query'] ) ) {
    17371737                        $tax_query = $q['tax_query'];
    … …  
    21142114         * @access public
    21152115         */
    2116         function set_404() {
     2116        public function set_404() {
    21172117                $is_feed = $this->is_feed;
    21182118
    … …  
    21332133         * @return mixed
    21342134         */
    2135         function get( $query_var, $default = '' ) {
     2135        public function get( $query_var, $default = '' ) {
    21362136                if ( isset( $this->query_vars[ $query_var ] ) ) {
    21372137                        return $this->query_vars[ $query_var ];
    … …  
    21502150         * @param mixed $value Query variable value.
    21512151         */
    2152         function set($query_var, $value) {
     2152        public function set($query_var, $value) {
    21532153                $this->query_vars[$query_var] = $value;
    21542154        }
    … …  
    21662166         * @return array List of posts.
    21672167         */
    2168         function get_posts() {
     2168        public function get_posts() {
    21692169                global $wpdb;
    21702170
    … …  
    34673467         * @return WP_Post Next post.
    34683468         */
    3469         function next_post() {
     3469        public function next_post() {
    34703470
    34713471                $this->current_post++;
    … …  
    34863486         * @uses do_action_ref_array() Calls 'loop_start' if loop has just started
    34873487         */
    3488         function the_post() {
     3488        public function the_post() {
    34893489                global $post;
    34903490                $this->in_the_loop = true;
    … …  
    35153515         * @return bool True if posts are available, false if end of loop.
    35163516         */
    3517         function have_posts() {
     3517        public function have_posts() {
    35183518                if ( $this->current_post + 1 < $this->post_count ) {
    35193519                        return true;
    … …  
    35413541         * @access public
    35423542         */
    3543         function rewind_posts() {
     3543        public function rewind_posts() {
    35443544                $this->current_post = -1;
    35453545                if ( $this->post_count > 0 ) {
    … …  
    35563556         * @return object Comment object.
    35573557         */
    3558         function next_comment() {
     3558        public function next_comment() {
    35593559                $this->current_comment++;
    35603560
    … …  
    35713571         * @uses do_action() Calls 'comment_loop_start' hook when first comment is processed.
    35723572         */
    3573         function the_comment() {
     3573        public function the_comment() {
    35743574                global $comment;
    35753575
    … …  
    35963596         * @return bool True, if more comments. False, if no more posts.
    35973597         */
    3598         function have_comments() {
     3598        public function have_comments() {
    35993599                if ( $this->current_comment + 1 < $this->comment_count ) {
    36003600                        return true;
    … …  
    36123612         * @access public
    36133613         */
    3614         function rewind_comments() {
     3614        public function rewind_comments() {
    36153615                $this->current_comment = -1;
    36163616                if ( $this->comment_count > 0 ) {
    … …  
    36283628         * @return array List of posts.
    36293629         */
    3630         function query( $query ) {
     3630        public function query( $query ) {
    36313631                $this->init();
    36323632                $this->query = $this->query_vars = wp_parse_args( $query );
    … …  
    36463646         * @return object
    36473647         */
    3648         function get_queried_object() {
     3648        public function get_queried_object() {
    36493649                if ( isset($this->queried_object) )
    36503650                        return $this->queried_object;
    … …  
    37143714         * @return int
    37153715         */
    3716         function get_queried_object_id() {
     3716        public function get_queried_object_id() {
    37173717                $this->get_queried_object();
    37183718
    … …  
    37353735         * @return WP_Query
    37363736         */
    3737         function __construct($query = '') {
     3737        public function __construct($query = '') {
    37383738                if ( ! empty($query) ) {
    37393739                        $this->query($query);
    37403740                }
     3741        }
     3742
     3743        /**
     3744         * Make private properties readable for backwards compatibility
     3745         *
     3746         * @since 4.0.0
     3747         * @param string $name
     3748         * @return mixed
     3749         */
     3750        public function __get( $name ) {
     3751                return $this->$name;
     3752        }
     3753
     3754        /**
     3755         * Make private properties setable for backwards compatibility
     3756         *
     3757         * @since 4.0.0
     3758         * @param string $name
     3759         * @return mixed
     3760         */
     3761        public function __isset( $name ) {
     3762                return isset( $this->$name );
     3763        }
     3764
     3765        /**
     3766         * Make private properties setable for backwards compatibility
     3767         *
     3768         * @since 4.0.0
     3769         * @param string $name
     3770         * @return mixed
     3771         */
     3772        public function __unset( $name ) {
     3773                unset( $this->$name );
     3774        }
     3775
     3776        /**
     3777         * Make private/protected methods readable for backwards compatibility
     3778         *
     3779         * @since 4.0.0
     3780         * @param string $name
     3781         * @param array $arguments
     3782         * @return mixed
     3783         */
     3784        public function __call( $name, $arguments ) {
     3785                return call_user_func_array( array( $this, $name ), $arguments );
    37413786        }
    37423787
    … …  
    37503795         * @return bool
    37513796         */
    3752         function is_archive() {
     3797        public function is_archive() {
    37533798                return (bool) $this->is_archive;
    37543799        }
    … …  
    37623807         * @return bool
    37633808         */
    3764         function is_post_type_archive( $post_types = '' ) {
     3809        public function is_post_type_archive( $post_types = '' ) {
    37653810                if ( empty( $post_types ) || ! $this->is_post_type_archive )
    37663811                        return (bool) $this->is_post_type_archive;
    … …  
    37823827         * @return bool
    37833828         */
    3784         function is_attachment( $attachment = '' ) {
     3829        public function is_attachment( $attachment = '' ) {
    37853830                if ( ! $this->is_attachment ) {
    37863831                        return false;
    … …  
    38163861         * @return bool
    38173862         */
    3818         function is_author( $author = '' ) {
     3863        public function is_author( $author = '' ) {
    38193864                if ( !$this->is_author )
    38203865                        return false;
    … …  
    38483893         * @return bool
    38493894         */
    3850         function is_category( $category = '' ) {
     3895        public function is_category( $category = '' ) {
    38513896                if ( !$this->is_category )
    38523897                        return false;
    … …  
    38803925         * @return bool
    38813926         */
    3882         function is_tag( $tag = '' ) {
     3927        public function is_tag( $tag = '' ) {
    38833928                if ( ! $this->is_tag )
    38843929                        return false;
    … …  
    39173962         * @return bool
    39183963         */
    3919         function is_tax( $taxonomy = '', $term = '' ) {
     3964        public function is_tax( $taxonomy = '', $term = '' ) {
    39203965                global $wp_taxonomies;
    39213966
    … …  
    39523997         * @return bool
    39533998         */
    3954         function is_comments_popup() {
     3999        public function is_comments_popup() {
    39554000                return (bool) $this->is_comments_popup;
    39564001        }
    … …  
    39634008         * @return bool
    39644009         */
    3965         function is_date() {
     4010        public function is_date() {
    39664011                return (bool) $this->is_date;
    39674012        }
    … …  
    39744019         * @return bool
    39754020         */
    3976         function is_day() {
     4021        public function is_day() {
    39774022                return (bool) $this->is_day;
    39784023        }
    … …  
    39864031         * @return bool
    39874032         */
    3988         function is_feed( $feeds = '' ) {
     4033        public function is_feed( $feeds = '' ) {
    39894034                if ( empty( $feeds ) || ! $this->is_feed )
    39904035                        return (bool) $this->is_feed;
    … …  
    40024047         * @return bool
    40034048         */
    4004         function is_comment_feed() {
     4049        public function is_comment_feed() {
    40054050                return (bool) $this->is_comment_feed;
    40064051        }
    … …  
    40244069         * @return bool True, if front of site.
    40254070         */
    4026         function is_front_page() {
     4071        public function is_front_page() {
    40274072                // most likely case
    40284073                if ( 'posts' == get_option( 'show_on_front') && $this->is_home() )
    … …  
    40504095         * @return bool True if blog view homepage.
    40514096         */
    4052         function is_home() {
     4097        public function is_home() {
    40534098                return (bool) $this->is_home;
    40544099        }
    … …  
    40614106         * @return bool
    40624107         */
    4063         function is_month() {
     4108        public function is_month() {
    40644109                return (bool) $this->is_month;
    40654110        }
    … …  
    40794124         * @return bool
    40804125         */
    4081         function is_page( $page = '' ) {
     4126        public function is_page( $page = '' ) {
    40824127                if ( !$this->is_page )
    40834128                        return false;
    … …  
    41074152         * @return bool
    41084153         */
    4109         function is_paged() {
     4154        public function is_paged() {
    41104155                return (bool) $this->is_paged;
    41114156        }
    … …  
    41184163         * @return bool
    41194164         */
    4120         function is_preview() {
     4165        public function is_preview() {
    41214166                return (bool) $this->is_preview;
    41224167        }
    … …  
    41294174         * @return bool
    41304175         */
    4131         function is_robots() {
     4176        public function is_robots() {
    41324177                return (bool) $this->is_robots;
    41334178        }
    … …  
    41404185         * @return bool
    41414186         */
    4142         function is_search() {
     4187        public function is_search() {
    41434188                return (bool) $this->is_search;
    41444189        }
    … …  
    41604205         * @return bool
    41614206         */
    4162         function is_single( $post = '' ) {
     4207        public function is_single( $post = '' ) {
    41634208                if ( !$this->is_single )
    41644209                        return false;
    … …  
    41954240         * @return bool
    41964241         */
    4197         function is_singular( $post_types = '' ) {
     4242        public function is_singular( $post_types = '' ) {
    41984243                if ( empty( $post_types ) || !$this->is_singular )
    41994244                        return (bool) $this->is_singular;
    … …  
    42114256         * @return bool
    42124257         */
    4213         function is_time() {
     4258        public function is_time() {
    42144259                return (bool) $this->is_time;
    42154260        }
    … …  
    42224267         * @return bool
    42234268         */
    4224         function is_trackback() {
     4269        public function is_trackback() {
    42254270                return (bool) $this->is_trackback;
    42264271        }
    … …  
    42334278         * @return bool
    42344279         */
    4235         function is_year() {
     4280        public function is_year() {
    42364281                return (bool) $this->is_year;
    42374282        }
    … …  
    42444289         * @return bool
    42454290         */
    4246         function is_404() {
     4291        public function is_404() {
    42474292                return (bool) $this->is_404;
    42484293        }
    … …  
    42554300         * @return bool
    42564301         */
    4257         function is_main_query() {
     4302        public function is_main_query() {
    42584303                global $wp_the_query;
    42594304                return $wp_the_query === $this;
    … …  
    42684313         * @return bool
    42694314         */
    4270         function reset_postdata() {
     4315        public function reset_postdata() {
    42714316                if ( ! empty( $this->post ) ) {
    42724317                        $GLOBALS['post'] = $this->post;
  • trunk/tests/phpunit/includes/functions.php

    r28493 r28523  
    5050        }
    5151
     52        public function __set( $name, $value ) {
     53                return $this->$name = $value;
     54        }
     55
     56        public function __isset( $name ) {
     57                return isset( $this->$name );
     58        }
     59
     60        public function __unset( $name ) {
     61                unset( $this->$name );
     62        }
     63
    5264        public function __call( $name, $arguments ) {
    5365                return call_user_func_array( array( $this, $name ), $arguments );
  • trunk/tests/phpunit/tests/basic.php

    r28493 r28523  
    146146                $this->assertEquals( 'maybe', $basic->callMe() );
    147147        }
     148
     149        function test_subclass_isset() {
     150                $basic = new Basic_Subclass();
     151
     152                $this->assertTrue( isset( $basic->foo ) );
     153        }
     154
     155        function test_subclass_unset() {
     156                $basic = new Basic_Subclass();
     157
     158                unset( $basic->foo );
     159
     160                $this->assertFalse( isset( $basic->foo ) );
     161        }
    148162}
Note: See TracChangeset for help on using the changeset viewer.