From faccc617fbfe7981b7b0e6215a3dd44b36f28067 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Thu, 25 Aug 2016 19:42:43 +0000 Subject: [PATCH] Query: collapse several of the `is_*` methods using `__call()`. Add `@method` annotations. Fixes #37830. Built from https://develop.svn.wordpress.org/trunk@38356 git-svn-id: http://core.svn.wordpress.org/trunk@38297 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-query.php | 176 ++++----------------------------- wp-includes/version.php | 2 +- 2 files changed, 21 insertions(+), 157 deletions(-) diff --git a/wp-includes/class-wp-query.php b/wp-includes/class-wp-query.php index 0ca0572b9d..de7c7b9da1 100644 --- a/wp-includes/class-wp-query.php +++ b/wp-includes/class-wp-query.php @@ -14,6 +14,21 @@ * * @since 1.5.0 * @since 4.5.0 Removed the `$comments_popup` property. + * + * @method bool is_archive() Is the query for an existing archive page? Month, Year, Category, Author, Post Type archive... + * @method bool is_date() Is the query for an existing date archive? + * @method bool is_day() Is the query for an existing day archive? + * @method bool is_comment_feed() Is the query for a comments feed? + * @method bool is_month() Is the query for an existing month archive? + * @method bool is_paged() Is the query for paged result and not for the first page? + * @method bool is_preview() Is the query for a post or page preview? + * @method bool is_robots() Is the query for the robots file? + * @method bool is_search() Is the query for a search? + * @method bool is_time() Is the query for a specific time? + * @method bool is_trackback() Is the query for a trackback endpoint call? + * @method bool is_year() Is the query for an existing year archive? + * @method bool is_404() Is the query a 404 (returns no results)? + * @method bool is_embed() Is the query for an embedded post? */ class WP_Query { @@ -3381,20 +3396,12 @@ class WP_Query { if ( in_array( $name, $this->compat_methods ) ) { return call_user_func_array( array( $this, $name ), $arguments ); } - return false; - } - /** - * Is the query for an existing archive page? - * - * Month, Year, Category, Author, Post Type archive... - * - * @since 3.1.0 - * - * @return bool - */ - public function is_archive() { - return (bool) $this->is_archive; + if ( 'is_' === substr( $name, 0, 3 ) && property_exists( $this, $name ) ) { + return (bool) $this->{$name}; + } + + return false; } /** @@ -3604,28 +3611,6 @@ class WP_Query { return false; } - /** - * Is the query for an existing date archive? - * - * @since 3.1.0 - * - * @return bool - */ - public function is_date() { - return (bool) $this->is_date; - } - - /** - * Is the query for an existing day archive? - * - * @since 3.1.0 - * - * @return bool - */ - public function is_day() { - return (bool) $this->is_day; - } - /** * Is the query for a feed? * @@ -3643,17 +3628,6 @@ class WP_Query { return in_array( $qv, (array) $feeds ); } - /** - * Is the query for a comments feed? - * - * @since 3.1.0 - * - * @return bool - */ - public function is_comment_feed() { - return (bool) $this->is_comment_feed; - } - /** * Is the query for the front page of the site? * @@ -3700,17 +3674,6 @@ class WP_Query { return (bool) $this->is_home; } - /** - * Is the query for an existing month archive? - * - * @since 3.1.0 - * - * @return bool - */ - public function is_month() { - return (bool) $this->is_month; - } - /** * Is the query for an existing single page? * @@ -3758,50 +3721,6 @@ class WP_Query { return false; } - /** - * Is the query for paged result and not for the first page? - * - * @since 3.1.0 - * - * @return bool - */ - public function is_paged() { - return (bool) $this->is_paged; - } - - /** - * Is the query for a post or page preview? - * - * @since 3.1.0 - * - * @return bool - */ - public function is_preview() { - return (bool) $this->is_preview; - } - - /** - * Is the query for the robots file? - * - * @since 3.1.0 - * - * @return bool - */ - public function is_robots() { - return (bool) $this->is_robots; - } - - /** - * Is the query for a search? - * - * @since 3.1.0 - * - * @return bool - */ - public function is_search() { - return (bool) $this->is_search; - } - /** * Is the query for an existing single post? * @@ -3873,61 +3792,6 @@ class WP_Query { return in_array( $post_obj->post_type, (array) $post_types ); } - /** - * Is the query for a specific time? - * - * @since 3.1.0 - * - * @return bool - */ - public function is_time() { - return (bool) $this->is_time; - } - - /** - * Is the query for a trackback endpoint call? - * - * @since 3.1.0 - * - * @return bool - */ - public function is_trackback() { - return (bool) $this->is_trackback; - } - - /** - * Is the query for an existing year archive? - * - * @since 3.1.0 - * - * @return bool - */ - public function is_year() { - return (bool) $this->is_year; - } - - /** - * Is the query a 404 (returns no results)? - * - * @since 3.1.0 - * - * @return bool - */ - public function is_404() { - return (bool) $this->is_404; - } - - /** - * Is the query for an embedded post? - * - * @since 4.4.0 - * - * @return bool - */ - public function is_embed() { - return (bool) $this->is_embed; - } - /** * Is the query the main query? * diff --git a/wp-includes/version.php b/wp-includes/version.php index 26174d679d..cdf097bf7c 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.7-alpha-38355'; +$wp_version = '4.7-alpha-38356'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.