Make WordPress Core

Changeset 38356


Ignore:
Timestamp:
08/25/2016 07:41:42 PM (8 years ago)
Author:
wonderboymusic
Message:

Query: collapse several of the is_* methods using __call(). Add @method annotations.

Fixes #37830.

File:
1 edited

Legend:

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

    r38351 r38356  
    1515 * @since 1.5.0
    1616 * @since 4.5.0 Removed the `$comments_popup` property.
     17 *
     18 * @method bool is_archive()      Is the query for an existing archive page? Month, Year, Category, Author, Post Type archive...
     19 * @method bool is_date()         Is the query for an existing date archive?
     20 * @method bool is_day()          Is the query for an existing day archive?
     21 * @method bool is_comment_feed() Is the query for a comments feed?
     22 * @method bool is_month()        Is the query for an existing month archive?
     23 * @method bool is_paged()        Is the query for paged result and not for the first page?
     24 * @method bool is_preview()      Is the query for a post or page preview?
     25 * @method bool is_robots()       Is the query for the robots file?
     26 * @method bool is_search()       Is the query for a search?
     27 * @method bool is_time()         Is the query for a specific time?
     28 * @method bool is_trackback()    Is the query for a trackback endpoint call?
     29 * @method bool is_year()         Is the query for an existing year archive?
     30 * @method bool is_404()          Is the query a 404 (returns no results)?
     31 * @method bool is_embed()        Is the query for an embedded post?
    1732 */
    1833class WP_Query {
     
    33823397            return call_user_func_array( array( $this, $name ), $arguments );
    33833398        }
     3399
     3400        if ( 'is_' === substr( $name, 0, 3 ) && property_exists( $this, $name ) ) {
     3401            return (bool) $this->{$name};
     3402        }
     3403
    33843404        return false;
    3385     }
    3386 
    3387     /**
    3388      * Is the query for an existing archive page?
    3389      *
    3390      * Month, Year, Category, Author, Post Type archive...
    3391      *
    3392      * @since 3.1.0
    3393      *
    3394      * @return bool
    3395      */
    3396     public function is_archive() {
    3397         return (bool) $this->is_archive;
    33983405    }
    33993406
     
    36033610
    36043611        return false;
    3605     }
    3606 
    3607     /**
    3608      * Is the query for an existing date archive?
    3609      *
    3610      * @since 3.1.0
    3611      *
    3612      * @return bool
    3613      */
    3614     public function is_date() {
    3615         return (bool) $this->is_date;
    3616     }
    3617 
    3618     /**
    3619      * Is the query for an existing day archive?
    3620      *
    3621      * @since 3.1.0
    3622      *
    3623      * @return bool
    3624      */
    3625     public function is_day() {
    3626         return (bool) $this->is_day;
    36273612    }
    36283613
     
    36423627            $qv = get_default_feed();
    36433628        return in_array( $qv, (array) $feeds );
    3644     }
    3645 
    3646     /**
    3647      * Is the query for a comments feed?
    3648      *
    3649      * @since 3.1.0
    3650      *
    3651      * @return bool
    3652      */
    3653     public function is_comment_feed() {
    3654         return (bool) $this->is_comment_feed;
    36553629    }
    36563630
     
    36993673    public function is_home() {
    37003674        return (bool) $this->is_home;
    3701     }
    3702 
    3703     /**
    3704      * Is the query for an existing month archive?
    3705      *
    3706      * @since 3.1.0
    3707      *
    3708      * @return bool
    3709      */
    3710     public function is_month() {
    3711         return (bool) $this->is_month;
    37123675    }
    37133676
     
    37603723
    37613724    /**
    3762      * Is the query for paged result and not for the first page?
    3763      *
    3764      * @since 3.1.0
    3765      *
    3766      * @return bool
    3767      */
    3768     public function is_paged() {
    3769         return (bool) $this->is_paged;
    3770     }
    3771 
    3772     /**
    3773      * Is the query for a post or page preview?
    3774      *
    3775      * @since 3.1.0
    3776      *
    3777      * @return bool
    3778      */
    3779     public function is_preview() {
    3780         return (bool) $this->is_preview;
    3781     }
    3782 
    3783     /**
    3784      * Is the query for the robots file?
    3785      *
    3786      * @since 3.1.0
    3787      *
    3788      * @return bool
    3789      */
    3790     public function is_robots() {
    3791         return (bool) $this->is_robots;
    3792     }
    3793 
    3794     /**
    3795      * Is the query for a search?
    3796      *
    3797      * @since 3.1.0
    3798      *
    3799      * @return bool
    3800      */
    3801     public function is_search() {
    3802         return (bool) $this->is_search;
    3803     }
    3804 
    3805     /**
    38063725     * Is the query for an existing single post?
    38073726     *
     
    38723791
    38733792        return in_array( $post_obj->post_type, (array) $post_types );
    3874     }
    3875 
    3876     /**
    3877      * Is the query for a specific time?
    3878      *
    3879      * @since 3.1.0
    3880      *
    3881      * @return bool
    3882      */
    3883     public function is_time() {
    3884         return (bool) $this->is_time;
    3885     }
    3886 
    3887     /**
    3888      * Is the query for a trackback endpoint call?
    3889      *
    3890      * @since 3.1.0
    3891      *
    3892      * @return bool
    3893      */
    3894     public function is_trackback() {
    3895         return (bool) $this->is_trackback;
    3896     }
    3897 
    3898     /**
    3899      * Is the query for an existing year archive?
    3900      *
    3901      * @since 3.1.0
    3902      *
    3903      * @return bool
    3904      */
    3905     public function is_year() {
    3906         return (bool) $this->is_year;
    3907     }
    3908 
    3909     /**
    3910      * Is the query a 404 (returns no results)?
    3911      *
    3912      * @since 3.1.0
    3913      *
    3914      * @return bool
    3915      */
    3916     public function is_404() {
    3917         return (bool) $this->is_404;
    3918     }
    3919 
    3920     /**
    3921      * Is the query for an embedded post?
    3922      *
    3923      * @since 4.4.0
    3924      *
    3925      * @return bool
    3926      */
    3927     public function is_embed() {
    3928         return (bool) $this->is_embed;
    39293793    }
    39303794
Note: See TracChangeset for help on using the changeset viewer.