diff -r 3d4e9c994f10 -r a86126ab1dd4 wp/wp-includes/class-wp-query.php --- a/wp/wp-includes/class-wp-query.php Tue Oct 22 16:11:46 2019 +0200 +++ b/wp/wp-includes/class-wp-query.php Tue Dec 15 13:49:49 2020 +0100 @@ -10,7 +10,7 @@ /** * The WordPress Query class. * - * @link https://codex.wordpress.org/Function_Reference/WP_Query Codex page. + * @link https://developer.wordpress.org/reference/classes/wp_query/ * * @since 1.5.0 * @since 4.5.0 Removed the `$comments_popup` property. @@ -37,7 +37,7 @@ * Taxonomy query, as passed to get_tax_sql() * * @since 3.1.0 - * @var object WP_Tax_Query + * @var WP_Tax_Query A taxonomy query instance. */ public $tax_query; @@ -45,7 +45,7 @@ * Metadata query container * * @since 3.2.0 - * @var object WP_Meta_Query + * @var WP_Meta_Query A meta query instance. */ public $meta_query = false; @@ -53,7 +53,7 @@ * Date query container * * @since 3.7.0 - * @var object WP_Date_Query + * @var WP_Date_Query A date query instance. */ public $date_query = false; @@ -391,6 +391,14 @@ public $is_robots = false; /** + * Signifies whether the current query is for the favicon.ico file. + * + * @since 5.4.0 + * @var bool + */ + public $is_favicon = false; + + /** * Signifies whether the current query is for the page_for_posts page. * * Basically, the homepage if the option isn't set for the static homepage. @@ -478,6 +486,7 @@ $this->is_attachment = false; $this->is_singular = false; $this->is_robots = false; + $this->is_favicon = false; $this->is_posts_page = false; $this->is_post_type_archive = false; } @@ -522,7 +531,7 @@ * Fills in the query variables, which do not exist within the parameter. * * @since 2.1.0 - * @since 4.4.0 Removed the `comments_popup` public query variable. + * @since 4.5.0 Removed the `comments_popup` public query variable. * * @param array $array Defined query variables. * @return array Complete query variables with undefined ones filled in empty. @@ -613,6 +622,7 @@ * @since 4.6.0 Added 'post_name__in' support for `$orderby`. Introduced the `$lazy_load_term_meta` argument. * @since 4.9.0 Introduced the `$comment_count` parameter. * @since 5.1.0 Introduced the `$meta_compare_key` parameter. + * @since 5.3.0 Introduced the `$meta_type_key` parameter. * * @param string|array $query { * Optional. Array or string of Query parameters. @@ -639,13 +649,16 @@ * See WP_Date_Query::__construct(). * @type int $day Day of the month. Default empty. Accepts numbers 1-31. * @type bool $exact Whether to search by exact keyword. Default false. - * @type string|array $fields Which fields to return. Single field or all fields (string), - * or array of fields. 'id=>parent' uses 'id' and 'post_parent'. - * Default all fields. Accepts 'ids', 'id=>parent'. + * @type string $fields Post fields to query for. Accepts: + * - '' Returns an array of complete post objects (`WP_Post[]`). + * - 'ids' Returns an array of post IDs (`int[]`). + * - 'id=>parent' Returns an associative array of parent post IDs, + * keyed by post ID (`int[]`). + * Default ''. * @type int $hour Hour of the day. Default empty. Accepts numbers 0-23. * @type int|bool $ignore_sticky_posts Whether to ignore sticky posts or not. Setting this to false * excludes stickies from 'post__in'. Accepts 1|true, 0|false. - * Default 0|false. + * Default false. * @type int $m Combination YearMonth. Accepts any four-digit year and month * numbers 1-12. Default empty. * @type string $meta_compare Comparison operator to test the 'meta_value'. @@ -654,6 +667,7 @@ * @type array $meta_query An associative array of WP_Meta_Query arguments. See WP_Meta_Query. * @type string $meta_value Custom field value. * @type int $meta_value_num Custom field value number. + * @type string $meta_type_key Cast for 'meta_key'. See WP_Meta_Query::construct(). * @type int $menu_order The menu order of the posts. * @type int $monthnum The two-digit month. Default empty. Accepts numbers 1-12. * @type string $name Post slug. @@ -674,7 +688,6 @@ * 'post_name__in', 'post_parent__in', and the array keys * of `$meta_query`. Default is 'date', except when a search * is being performed, when the default is 'relevance'. - * * @type int $p Post ID. * @type int $page Show the number of posts that would show up on page X of a * static front page. @@ -683,10 +696,11 @@ * @type string $pagename Page slug. * @type string $perm Show posts if user has the appropriate capability. * @type string $ping_status Ping status. - * @type array $post__in An array of post IDs to retrieve, sticky posts will be included - * @type string $post_mime_type The mime type of the post. Used for 'attachment' post_type. + * @type array $post__in An array of post IDs to retrieve, sticky posts will be included. * @type array $post__not_in An array of post IDs not to retrieve. Note: a string of comma- * separated IDs will NOT work. + * @type string $post_mime_type The mime type of the post. Used for 'attachment' post_type. + * @type array $post_name__in An array of post slugs that results must match. * @type int $post_parent Page ID to retrieve child pages for. Use 0 to only retrieve * top-level pages. * @type array $post_parent__in An array containing parent page IDs to query child pages from. @@ -697,7 +711,6 @@ * @type int $posts_per_page The number of posts to query for. Use -1 to request all posts. * @type int $posts_per_archive_page The number of posts to query for by archive page. Overrides * 'posts_per_page' when is_archive(), or is_search() are true. - * @type array $post_name__in An array of post slugs that results must match. * @type string $s Search keyword(s). Prepending a term with a hyphen will * exclude posts matching that term. Eg, 'pillow -sofa' will * return posts containing 'pillow' but not 'sofa'. The @@ -707,9 +720,9 @@ * @type bool $sentence Whether to search by phrase. Default false. * @type bool $suppress_filters Whether to suppress filters. Default false. * @type string $tag Tag slug. Comma-separated (either), Plus-separated (all). - * @type array $tag__and An array of tag ids (AND in). - * @type array $tag__in An array of tag ids (OR in). - * @type array $tag__not_in An array of tag ids (NOT in). + * @type array $tag__and An array of tag IDs (AND in). + * @type array $tag__in An array of tag IDs (OR in). + * @type array $tag__not_in An array of tag IDs (NOT in). * @type int $tag_id Tag id or comma-separated list of IDs. * @type array $tag_slug__and An array of tag slugs (AND in). * @type array $tag_slug__in An array of tag slugs (OR in). unless 'ignore_sticky_posts' is @@ -730,7 +743,8 @@ public function parse_query( $query = '' ) { if ( ! empty( $query ) ) { $this->init(); - $this->query = $this->query_vars = wp_parse_args( $query ); + $this->query = wp_parse_args( $query ); + $this->query_vars = $this->query; } elseif ( ! isset( $this->query ) ) { $this->query = $this->query_vars; } @@ -741,6 +755,8 @@ if ( ! empty( $qv['robots'] ) ) { $this->is_robots = true; + } elseif ( ! empty( $qv['favicon'] ) ) { + $this->is_favicon = true; } if ( ! is_scalar( $qv['p'] ) || $qv['p'] < 0 ) { @@ -757,8 +773,8 @@ $qv['w'] = absint( $qv['w'] ); $qv['m'] = is_scalar( $qv['m'] ) ? preg_replace( '|[^0-9]|', '', $qv['m'] ) : ''; $qv['paged'] = absint( $qv['paged'] ); - $qv['cat'] = preg_replace( '|[^0-9,-]|', '', $qv['cat'] ); // comma separated list of positive or negative integers - $qv['author'] = preg_replace( '|[^0-9,-]|', '', $qv['author'] ); // comma separated list of positive or negative integers + $qv['cat'] = preg_replace( '|[^0-9,-]|', '', $qv['cat'] ); // Comma-separated list of positive or negative integers. + $qv['author'] = preg_replace( '|[^0-9,-]|', '', $qv['author'] ); // Comma-separated list of positive or negative integers. $qv['pagename'] = trim( $qv['pagename'] ); $qv['name'] = trim( $qv['name'] ); $qv['title'] = trim( $qv['title'] ); @@ -790,18 +806,14 @@ $qv['attachment_id'] = absint( $qv['attachment_id'] ); - if ( ( '' != $qv['attachment'] ) || ! empty( $qv['attachment_id'] ) ) { + if ( ( '' !== $qv['attachment'] ) || ! empty( $qv['attachment_id'] ) ) { $this->is_single = true; $this->is_attachment = true; - } elseif ( '' != $qv['name'] ) { + } elseif ( '' !== $qv['name'] ) { $this->is_single = true; } elseif ( $qv['p'] ) { $this->is_single = true; - } elseif ( ( '' !== $qv['hour'] ) && ( '' !== $qv['minute'] ) && ( '' !== $qv['second'] ) && ( '' != $qv['year'] ) && ( '' != $qv['monthnum'] ) && ( '' != $qv['day'] ) ) { - // If year, month, day, hour, minute, and second are set, a single - // post is being queried. - $this->is_single = true; - } elseif ( '' != $qv['pagename'] || ! empty( $qv['page_id'] ) ) { + } elseif ( '' !== $qv['pagename'] || ! empty( $qv['page_id'] ) ) { $this->is_page = true; $this->is_single = false; } else { @@ -869,7 +881,7 @@ } } - if ( '' != $qv['w'] ) { + if ( $qv['w'] ) { $this->is_date = true; } @@ -881,7 +893,7 @@ continue; } - if ( isset( $tax_query['operator'] ) && 'NOT IN' != $tax_query['operator'] ) { + if ( isset( $tax_query['operator'] ) && 'NOT IN' !== $tax_query['operator'] ) { switch ( $tax_query['taxonomy'] ) { case 'category': $this->is_category = true; @@ -896,13 +908,13 @@ } unset( $tax_query ); - if ( empty( $qv['author'] ) || ( $qv['author'] == '0' ) ) { + if ( empty( $qv['author'] ) || ( '0' == $qv['author'] ) ) { $this->is_author = false; } else { $this->is_author = true; } - if ( '' != $qv['author_name'] ) { + if ( '' !== $qv['author_name'] ) { $this->is_author = true; } @@ -934,7 +946,7 @@ $this->is_paged = true; } - // if we're previewing inside the write screen + // If we're previewing inside the write screen. if ( '' != $qv['preview'] ) { $this->is_preview = true; } @@ -954,15 +966,17 @@ $this->is_comment_feed = true; } - if ( ! ( $this->is_singular || $this->is_archive || $this->is_search || $this->is_feed || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) || $this->is_trackback || $this->is_404 || $this->is_admin || $this->is_robots ) ) { + if ( ! ( $this->is_singular || $this->is_archive || $this->is_search || $this->is_feed + || ( defined( 'REST_REQUEST' ) && REST_REQUEST && $this->is_main_query() ) + || $this->is_trackback || $this->is_404 || $this->is_admin || $this->is_robots || $this->is_favicon ) ) { $this->is_home = true; } - // Correct is_* for page_on_front and page_for_posts - if ( $this->is_home && 'page' == get_option( 'show_on_front' ) && get_option( 'page_on_front' ) ) { + // Correct `is_*` for 'page_on_front' and 'page_for_posts'. + if ( $this->is_home && 'page' === get_option( 'show_on_front' ) && get_option( 'page_on_front' ) ) { $_query = wp_parse_args( $this->query ); - // pagename can be set and empty depending on matched rewrite rules. Ignore an empty pagename. - if ( isset( $_query['pagename'] ) && '' == $_query['pagename'] ) { + // 'pagename' can be set and empty depending on matched rewrite rules. Ignore an empty 'pagename'. + if ( isset( $_query['pagename'] ) && '' === $_query['pagename'] ) { unset( $_query['pagename'] ); } @@ -972,7 +986,7 @@ $this->is_page = true; $this->is_home = false; $qv['page_id'] = get_option( 'page_on_front' ); - // Correct for page_on_front + // Correct for 'page_on_front'. if ( ! empty( $qv['paged'] ) ) { $qv['page'] = $qv['paged']; unset( $qv['paged'] ); @@ -980,12 +994,12 @@ } } - if ( '' != $qv['pagename'] ) { + if ( '' !== $qv['pagename'] ) { $this->queried_object = get_page_by_path( $qv['pagename'] ); - if ( $this->queried_object && 'attachment' == $this->queried_object->post_type ) { + if ( $this->queried_object && 'attachment' === $this->queried_object->post_type ) { if ( preg_match( '/^[^%]*%(?:postname)%/', get_option( 'permalink_structure' ) ) ) { - // See if we also have a post with the same slug + // See if we also have a post with the same slug. $post = get_page_by_path( $qv['pagename'], OBJECT, 'post' ); if ( $post ) { $this->queried_object = $post; @@ -1001,25 +1015,25 @@ unset( $this->queried_object ); } - if ( 'page' == get_option( 'show_on_front' ) && isset( $this->queried_object_id ) && $this->queried_object_id == get_option( 'page_for_posts' ) ) { + if ( 'page' === get_option( 'show_on_front' ) && isset( $this->queried_object_id ) && get_option( 'page_for_posts' ) == $this->queried_object_id ) { $this->is_page = false; $this->is_home = true; $this->is_posts_page = true; } - if ( isset( $this->queried_object_id ) && $this->queried_object_id == get_option( 'wp_page_for_privacy_policy' ) ) { + if ( isset( $this->queried_object_id ) && get_option( 'wp_page_for_privacy_policy' ) == $this->queried_object_id ) { $this->is_privacy_policy = true; } } if ( $qv['page_id'] ) { - if ( 'page' == get_option( 'show_on_front' ) && $qv['page_id'] == get_option( 'page_for_posts' ) ) { + if ( 'page' === get_option( 'show_on_front' ) && get_option( 'page_for_posts' ) == $qv['page_id'] ) { $this->is_page = false; $this->is_home = true; $this->is_posts_page = true; } - if ( $qv['page_id'] == get_option( 'wp_page_for_privacy_policy' ) ) { + if ( get_option( 'wp_page_for_privacy_policy' ) == $qv['page_id'] ) { $this->is_privacy_policy = true; } } @@ -1045,7 +1059,7 @@ } $this->is_singular = $this->is_single || $this->is_page || $this->is_attachment; - // Done correcting is_* for page_on_front and page_for_posts + // Done correcting `is_*` for 'page_on_front' and 'page_for_posts'. if ( '404' == $qv['error'] ) { $this->set_404(); @@ -1091,8 +1105,8 @@ } foreach ( get_taxonomies( array(), 'objects' ) as $taxonomy => $t ) { - if ( 'post_tag' == $taxonomy ) { - continue; // Handled further down in the $q['tag'] block + if ( 'post_tag' === $taxonomy ) { + continue; // Handled further down in the $q['tag'] block. } if ( $t->query_var && ! empty( $q[ $t->query_var ] ) ) { @@ -1132,14 +1146,16 @@ } } - // If querystring 'cat' is an array, implode it. + // If query string 'cat' is an array, implode it. if ( is_array( $q['cat'] ) ) { $q['cat'] = implode( ',', $q['cat'] ); } - // Category stuff + // Category stuff. + if ( ! empty( $q['cat'] ) && ! $this->is_singular ) { - $cat_in = $cat_not_in = array(); + $cat_in = array(); + $cat_not_in = array(); $cat_array = preg_split( '/[,\s]+/', urldecode( $q['cat'] ) ); $cat_array = array_map( 'intval', $cat_array ); @@ -1214,13 +1230,14 @@ ); } - // If querystring 'tag' is array, implode it. + // If query string 'tag' is array, implode it. if ( is_array( $q['tag'] ) ) { $q['tag'] = implode( ',', $q['tag'] ); } - // Tag stuff - if ( '' != $q['tag'] && ! $this->is_singular && $this->query_vars_changed ) { + // Tag stuff. + + if ( '' !== $q['tag'] && ! $this->is_singular && $this->query_vars_changed ) { if ( strpos( $q['tag'], ',' ) !== false ) { $tags = preg_split( '/[,\r\n\t ]+/', $q['tag'] ); foreach ( (array) $tags as $tag ) { @@ -1319,12 +1336,12 @@ $search = ''; - // added slashes screw with quote grouping when done early, so done later + // Added slashes screw with quote grouping when done early, so done later. $q['s'] = stripslashes( $q['s'] ); if ( empty( $_GET['s'] ) && $this->is_main_query() ) { $q['s'] = urldecode( $q['s'] ); } - // there are no line breaks in fields + // There are no line breaks in fields. $q['s'] = str_replace( array( "\r", "\n" ), '', $q['s'] ); $q['search_terms_count'] = 1; if ( ! empty( $q['sentence'] ) ) { @@ -1333,7 +1350,7 @@ if ( preg_match_all( '/".*?("|$)|((?<=[\t ",+])|^)[^\t ",+]+/', $q['s'], $matches ) ) { $q['search_terms_count'] = count( $matches[0] ); $q['search_terms'] = $this->parse_search_terms( $matches[0] ); - // if the search string has only short terms or stopwords, or is 10+ terms long, match it as sentence + // If the search string has only short terms or stopwords, or is 10+ terms long, match it as sentence. if ( empty( $q['search_terms'] ) || count( $q['search_terms'] ) > 9 ) { $q['search_terms'] = array( $q['s'] ); } @@ -1358,7 +1375,7 @@ foreach ( $q['search_terms'] as $term ) { // If there is an $exclusion_prefix, terms prefixed with it should be excluded. - $exclude = $exclusion_prefix && ( $exclusion_prefix === substr( $term, 0, 1 ) ); + $exclude = $exclusion_prefix && ( substr( $term, 0, 1 ) === $exclusion_prefix ); if ( $exclude ) { $like_op = 'NOT LIKE'; $andor_op = 'AND'; @@ -1398,7 +1415,7 @@ * @since 3.7.0 * * @param string[] $terms Array of terms to check. - * @return array Terms that are not stopwords. + * @return string[] Terms that are not stopwords. */ protected function parse_search_terms( $terms ) { $strtolower = function_exists( 'mb_strtolower' ) ? 'mb_strtolower' : 'strtolower'; @@ -1407,7 +1424,7 @@ $stopwords = $this->get_search_stopwords(); foreach ( $terms as $term ) { - // keep before/after spaces when term is for exact match + // Keep before/after spaces when term is for exact match. if ( preg_match( '/^".+"$/', $term ) ) { $term = trim( $term, "\"'" ); } else { @@ -1434,14 +1451,15 @@ * * @since 3.7.0 * - * @return array Stopwords. + * @return string[] Stopwords. */ protected function get_search_stopwords() { if ( isset( $this->stopwords ) ) { return $this->stopwords; } - /* translators: This is a comma-separated list of very common words that should be excluded from a search, + /* + * translators: This is a comma-separated list of very common words that should be excluded from a search, * like a, an, and the. These are usually called "stopwords". You should not simply translate these individual * words into your language. Instead, look for and provide commonly accepted stopwords in your language. */ @@ -1496,17 +1514,17 @@ $search_orderby = ''; - // sentence match in 'post_title' + // Sentence match in 'post_title'. if ( $like ) { $search_orderby .= $wpdb->prepare( "WHEN {$wpdb->posts}.post_title LIKE %s THEN 1 ", $like ); } - // sanity limit, sort as sentence when more than 6 terms - // (few searches are longer than 6 terms and most titles are not) + // Sanity limit, sort as sentence when more than 6 terms + // (few searches are longer than 6 terms and most titles are not). if ( $num_terms < 7 ) { - // all words in title + // All words in title. $search_orderby .= 'WHEN ' . implode( ' AND ', $q['search_orderby_title'] ) . ' THEN 2 '; - // any word in title, not needed when $num_terms == 1 + // Any word in title, not needed when $num_terms == 1. if ( $num_terms > 1 ) { $search_orderby .= 'WHEN ' . implode( ' OR ', $q['search_orderby_title'] ) . ' THEN 3 '; } @@ -1522,7 +1540,7 @@ $search_orderby = '(CASE ' . $search_orderby . 'ELSE 6 END)'; } } else { - // single word or sentence search + // Single word or sentence search. $search_orderby = reset( $q['search_orderby_title'] ) . ' DESC'; } @@ -1691,6 +1709,15 @@ $this->is_404 = true; $this->is_feed = $is_feed; + + /** + * Fires after a 404 is triggered. + * + * @since 5.5.0 + * + * @param WP_Query $this The WP_Query instance (passed by reference). + */ + do_action_ref_array( 'set_404', array( $this ) ); } /** @@ -1754,14 +1781,14 @@ // Shorthand. $q = &$this->query_vars; - // Fill again in case pre_get_posts unset some vars. + // Fill again in case 'pre_get_posts' unset some vars. $q = $this->fill_query_vars( $q ); - // Parse meta query + // Parse meta query. $this->meta_query = new WP_Meta_Query(); $this->meta_query->parse_query_vars( $q ); - // Set a flag if a pre_get_posts hook changed the query vars. + // Set a flag if a 'pre_get_posts' hook changed the query vars. $hash = md5( serialize( $this->query_vars ) ); if ( $hash != $this->query_vars_hash ) { $this->query_vars_changed = true; @@ -1769,7 +1796,7 @@ } unset( $hash ); - // First let's clear some variables + // First let's clear some variables. $distinct = ''; $whichauthor = ''; $whichmimetype = ''; @@ -1785,8 +1812,8 @@ _deprecated_argument( 'WP_Query', '3.1.0', - /* translators: 1: caller_get_posts, 2: ignore_sticky_posts */ sprintf( + /* translators: 1: caller_get_posts, 2: ignore_sticky_posts */ __( '%1$s is deprecated. Use %2$s instead.' ), 'caller_get_posts', 'ignore_sticky_posts' @@ -1841,11 +1868,11 @@ $q['showposts'] = (int) $q['showposts']; $q['posts_per_page'] = $q['showposts']; } - if ( ( isset( $q['posts_per_archive_page'] ) && $q['posts_per_archive_page'] != 0 ) && ( $this->is_archive || $this->is_search ) ) { + if ( ( isset( $q['posts_per_archive_page'] ) && 0 != $q['posts_per_archive_page'] ) && ( $this->is_archive || $this->is_search ) ) { $q['posts_per_page'] = $q['posts_per_archive_page']; } if ( ! isset( $q['nopaging'] ) ) { - if ( $q['posts_per_page'] == -1 ) { + if ( -1 == $q['posts_per_page'] ) { $q['nopaging'] = true; } else { $q['nopaging'] = false; @@ -1853,7 +1880,7 @@ } if ( $this->is_feed ) { - // This overrides posts_per_page. + // This overrides 'posts_per_page'. if ( ! empty( $q['posts_per_rss'] ) ) { $q['posts_per_page'] = $q['posts_per_rss']; } else { @@ -1864,15 +1891,15 @@ $q['posts_per_page'] = (int) $q['posts_per_page']; if ( $q['posts_per_page'] < -1 ) { $q['posts_per_page'] = abs( $q['posts_per_page'] ); - } elseif ( $q['posts_per_page'] == 0 ) { + } elseif ( 0 == $q['posts_per_page'] ) { $q['posts_per_page'] = 1; } - if ( ! isset( $q['comments_per_page'] ) || $q['comments_per_page'] == 0 ) { + if ( ! isset( $q['comments_per_page'] ) || 0 == $q['comments_per_page'] ) { $q['comments_per_page'] = get_option( 'comments_per_page' ); } - if ( $this->is_home && ( empty( $this->query ) || $q['preview'] == 'true' ) && ( 'page' == get_option( 'show_on_front' ) ) && get_option( 'page_on_front' ) ) { + if ( $this->is_home && ( empty( $this->query ) || 'true' === $q['preview'] ) && ( 'page' === get_option( 'show_on_front' ) ) && get_option( 'page_on_front' ) ) { $this->is_page = true; $this->is_home = false; $q['page_id'] = get_option( 'page_on_front' ); @@ -1904,7 +1931,7 @@ if ( '' !== $q['menu_order'] ) { $where .= " AND {$wpdb->posts}.menu_order = " . $q['menu_order']; } - // The "m" parameter is meant for months but accepts datetimes of varying specificity + // The "m" parameter is meant for months but accepts datetimes of varying specificity. if ( $q['m'] ) { $where .= " AND YEAR({$wpdb->posts}.post_date)=" . substr( $q['m'], 0, 4 ); if ( strlen( $q['m'] ) > 5 ) { @@ -1924,7 +1951,7 @@ } } - // Handle the other individual date parameters + // Handle the other individual date parameters. $date_parameters = array(); if ( '' !== $q['hour'] ) { @@ -1961,14 +1988,14 @@ } unset( $date_parameters, $date_query ); - // Handle complex date queries + // Handle complex date queries. if ( ! empty( $q['date_query'] ) ) { $this->date_query = new WP_Date_Query( $q['date_query'] ); $where .= $this->date_query->get_sql(); } // If we've got a post_type AND it's not "any" post_type. - if ( ! empty( $q['post_type'] ) && 'any' != $q['post_type'] ) { + if ( ! empty( $q['post_type'] ) && 'any' !== $q['post_type'] ) { foreach ( (array) $q['post_type'] as $_post_type ) { $ptype_obj = get_post_type_object( $_post_type ); if ( ! $ptype_obj || ! $ptype_obj->query_var || empty( $q[ $ptype_obj->query_var ] ) ) { @@ -1986,7 +2013,7 @@ // Only one request for a slug is possible, this is why name & pagename are overwritten above. break; - } //end foreach + } // End foreach. unset( $ptype_obj ); } @@ -1995,14 +2022,14 @@ } // Parameters related to 'post_name'. - if ( '' != $q['name'] ) { + if ( '' !== $q['name'] ) { $q['name'] = sanitize_title_for_query( $q['name'] ); $where .= " AND {$wpdb->posts}.post_name = '" . $q['name'] . "'"; - } elseif ( '' != $q['pagename'] ) { + } elseif ( '' !== $q['pagename'] ) { if ( isset( $this->queried_object_id ) ) { $reqpage = $this->queried_object_id; } else { - if ( 'page' != $q['post_type'] ) { + if ( 'page' !== $q['post_type'] ) { foreach ( (array) $q['post_type'] as $_post_type ) { $ptype_obj = get_post_type_object( $_post_type ); if ( ! $ptype_obj || ! $ptype_obj->hierarchical ) { @@ -2026,19 +2053,20 @@ } $page_for_posts = get_option( 'page_for_posts' ); - if ( ( 'page' != get_option( 'show_on_front' ) ) || empty( $page_for_posts ) || ( $reqpage != $page_for_posts ) ) { + if ( ( 'page' !== get_option( 'show_on_front' ) ) || empty( $page_for_posts ) || ( $reqpage != $page_for_posts ) ) { $q['pagename'] = sanitize_title_for_query( wp_basename( $q['pagename'] ) ); $q['name'] = $q['pagename']; $where .= " AND ({$wpdb->posts}.ID = '$reqpage')"; $reqpage_obj = get_post( $reqpage ); - if ( is_object( $reqpage_obj ) && 'attachment' == $reqpage_obj->post_type ) { + if ( is_object( $reqpage_obj ) && 'attachment' === $reqpage_obj->post_type ) { $this->is_attachment = true; - $post_type = $q['post_type'] = 'attachment'; + $post_type = 'attachment'; + $q['post_type'] = 'attachment'; $this->is_page = true; $q['attachment_id'] = $reqpage; } } - } elseif ( '' != $q['attachment'] ) { + } elseif ( '' !== $q['attachment'] ) { $q['attachment'] = sanitize_title_for_query( wp_basename( $q['attachment'] ) ); $q['name'] = $q['attachment']; $where .= " AND {$wpdb->posts}.post_name = '" . $q['attachment'] . "'"; @@ -2053,7 +2081,7 @@ $q['p'] = absint( $q['attachment_id'] ); } - // If a post number is specified, load that post + // If a post number is specified, load that post. if ( $q['p'] ) { $where .= " AND {$wpdb->posts}.ID = " . $q['p']; } elseif ( $q['post__in'] ) { @@ -2075,7 +2103,7 @@ } if ( $q['page_id'] ) { - if ( ( 'page' != get_option( 'show_on_front' ) ) || ( $q['page_id'] != get_option( 'page_for_posts' ) ) ) { + if ( ( 'page' !== get_option( 'show_on_front' ) ) || ( get_option( 'page_for_posts' ) != $q['page_id'] ) ) { $q['p'] = $q['page_id']; $where = " AND {$wpdb->posts}.ID = " . $q['page_id']; } @@ -2098,7 +2126,7 @@ $search = apply_filters_ref_array( 'posts_search', array( $search, &$this ) ); } - // Taxonomies + // Taxonomies. if ( ! $this->is_singular ) { $this->parse_tax_query( $q ); @@ -2110,11 +2138,11 @@ if ( $this->is_tax ) { if ( empty( $post_type ) ) { - // Do a fully inclusive search for currently registered post types of queried taxonomies + // Do a fully inclusive search for currently registered post types of queried taxonomies. $post_type = array(); $taxonomies = array_keys( $this->tax_query->queried_terms ); foreach ( get_post_types( array( 'exclude_from_search' => false ) ) as $pt ) { - $object_taxonomies = $pt === 'attachment' ? get_taxonomies_for_attachments() : get_object_taxonomies( $pt ); + $object_taxonomies = 'attachment' === $pt ? get_taxonomies_for_attachments() : get_object_taxonomies( $pt ); if ( array_intersect( $taxonomies, $object_taxonomies ) ) { $post_type[] = $pt; } @@ -2126,7 +2154,7 @@ } $post_status_join = true; - } elseif ( in_array( 'attachment', (array) $post_type ) ) { + } elseif ( in_array( 'attachment', (array) $post_type, true ) ) { $post_status_join = true; } } @@ -2147,7 +2175,7 @@ continue; } - if ( ! in_array( $queried_taxonomy, array( 'category', 'post_tag' ) ) ) { + if ( ! in_array( $queried_taxonomy, array( 'category', 'post_tag' ), true ) ) { $q['taxonomy'] = $queried_taxonomy; if ( 'slug' === $queried_items['field'] ) { @@ -2162,7 +2190,7 @@ } } - // 'cat', 'category_name', 'tag_id' + // 'cat', 'category_name', 'tag_id'. foreach ( $this->tax_query->queried_terms as $queried_taxonomy => $queried_items ) { if ( empty( $queried_items['terms'][0] ) ) { continue; @@ -2191,9 +2219,9 @@ $groupby = "{$wpdb->posts}.ID"; } - // Author/user stuff - - if ( ! empty( $q['author'] ) && $q['author'] != '0' ) { + // Author/user stuff. + + if ( ! empty( $q['author'] ) && '0' != $q['author'] ) { $q['author'] = addslashes_gpc( '' . urldecode( $q['author'] ) ); $authors = array_unique( array_map( 'intval', preg_split( '/[,\s]+/', $q['author'] ) ) ); foreach ( $authors as $author ) { @@ -2211,15 +2239,15 @@ $where .= " AND {$wpdb->posts}.post_author IN ($author__in) "; } - // Author stuff for nice URLs - - if ( '' != $q['author_name'] ) { + // Author stuff for nice URLs. + + if ( '' !== $q['author_name'] ) { if ( strpos( $q['author_name'], '/' ) !== false ) { $q['author_name'] = explode( '/', $q['author_name'] ); if ( $q['author_name'][ count( $q['author_name'] ) - 1 ] ) { - $q['author_name'] = $q['author_name'][ count( $q['author_name'] ) - 1 ]; // no trailing slash + $q['author_name'] = $q['author_name'][ count( $q['author_name'] ) - 1 ]; // No trailing slash. } else { - $q['author_name'] = $q['author_name'][ count( $q['author_name'] ) - 2 ]; // there was a trailing slash + $q['author_name'] = $q['author_name'][ count( $q['author_name'] ) - 2 ]; // There was a trailing slash. } } $q['author_name'] = sanitize_title_for_query( $q['author_name'] ); @@ -2257,9 +2285,9 @@ } } - // MIME-Type stuff for attachment browsing - - if ( isset( $q['post_mime_type'] ) && '' != $q['post_mime_type'] ) { + // MIME-Type stuff for attachment browsing. + + if ( isset( $q['post_mime_type'] ) && '' !== $q['post_mime_type'] ) { $whichmimetype = wp_post_mime_type_where( $q['post_mime_type'], $wpdb->posts ); } $where .= $search . $whichauthor . $whichmimetype; @@ -2294,7 +2322,7 @@ } else { $orderby = "{$wpdb->posts}.post_date " . $q['order']; } - } elseif ( 'none' == $q['orderby'] ) { + } elseif ( 'none' === $q['orderby'] ) { $orderby = ''; } else { $orderby_array = array(); @@ -2387,7 +2415,7 @@ $where .= $wpdb->prepare( " AND {$wpdb->posts}.ping_status = %s ", $q['ping_status'] ); } - if ( 'any' == $post_type ) { + if ( 'any' === $post_type ) { $in_search_post_types = get_post_types( array( 'exclude_from_search' => false ) ); if ( empty( $in_search_post_types ) ) { $where .= ' AND 1=0 '; @@ -2433,16 +2461,16 @@ $r_status = array(); $p_status = array(); $e_status = array(); - if ( in_array( 'any', $q_status ) ) { + if ( in_array( 'any', $q_status, true ) ) { foreach ( get_post_stati( array( 'exclude_from_search' => true ) ) as $status ) { - if ( ! in_array( $status, $q_status ) ) { + if ( ! in_array( $status, $q_status, true ) ) { $e_status[] = "{$wpdb->posts}.post_status <> '$status'"; } } } else { foreach ( get_post_stati() as $status ) { - if ( in_array( $status, $q_status ) ) { - if ( 'private' == $status ) { + if ( in_array( $status, $q_status, true ) ) { + if ( 'private' === $status ) { $p_status[] = "{$wpdb->posts}.post_status = '$status'"; } else { $r_status[] = "{$wpdb->posts}.post_status = '$status'"; @@ -2451,7 +2479,7 @@ } } - if ( empty( $q['perm'] ) || 'readable' != $q['perm'] ) { + if ( empty( $q['perm'] ) || 'readable' !== $q['perm'] ) { $r_status = array_merge( $r_status, $p_status ); unset( $p_status ); } @@ -2460,14 +2488,14 @@ $statuswheres[] = '(' . join( ' AND ', $e_status ) . ')'; } if ( ! empty( $r_status ) ) { - if ( ! empty( $q['perm'] ) && 'editable' == $q['perm'] && ! current_user_can( $edit_others_cap ) ) { + if ( ! empty( $q['perm'] ) && 'editable' === $q['perm'] && ! current_user_can( $edit_others_cap ) ) { $statuswheres[] = "({$wpdb->posts}.post_author = $user_id " . 'AND (' . join( ' OR ', $r_status ) . '))'; } else { $statuswheres[] = '(' . join( ' OR ', $r_status ) . ')'; } } if ( ! empty( $p_status ) ) { - if ( ! empty( $q['perm'] ) && 'readable' == $q['perm'] && ! current_user_can( $read_private_cap ) ) { + if ( ! empty( $q['perm'] ) && 'readable' === $q['perm'] && ! current_user_can( $read_private_cap ) ) { $statuswheres[] = "({$wpdb->posts}.post_author = $user_id " . 'AND (' . join( ' OR ', $p_status ) . '))'; } else { $statuswheres[] = '(' . join( ' OR ', $p_status ) . ')'; @@ -2489,7 +2517,7 @@ // Add public states. $public_states = get_post_stati( array( 'public' => true ) ); foreach ( (array) $public_states as $state ) { - if ( 'publish' == $state ) { // Publish is hard-coded above. + if ( 'publish' === $state ) { // Publish is hard-coded above. continue; } $where .= " OR {$wpdb->posts}.post_status = '$state'"; @@ -2545,7 +2573,7 @@ $join = apply_filters_ref_array( 'posts_join', array( $join, &$this ) ); } - // Paging + // Paging. if ( empty( $q['nopaging'] ) && ! $this->is_singular ) { $page = absint( $q['paged'] ); if ( ! $page ) { @@ -2562,13 +2590,13 @@ $limits = 'LIMIT ' . $pgstrt . $q['posts_per_page']; } - // Comments feeds + // Comments feeds. if ( $this->is_comment_feed && ! $this->is_singular ) { if ( $this->is_archive || $this->is_search ) { $cjoin = "JOIN {$wpdb->posts} ON ({$wpdb->comments}.comment_post_ID = {$wpdb->posts}.ID) $join "; $cwhere = "WHERE comment_approved = '1' $where"; $cgroupby = "{$wpdb->comments}.comment_id"; - } else { // Other non singular e.g. front + } else { // Other non-singular, e.g. front. $cjoin = "JOIN {$wpdb->posts} ON ( {$wpdb->comments}.comment_post_ID = {$wpdb->posts}.ID )"; $cwhere = "WHERE ( post_status = 'publish' OR ( post_status = 'inherit' AND post_type = 'attachment' ) ) AND comment_approved = '1'"; $cgroupby = ''; @@ -2625,11 +2653,13 @@ */ $climits = apply_filters_ref_array( 'comment_feed_limits', array( 'LIMIT ' . get_option( 'posts_per_rss' ), &$this ) ); } + $cgroupby = ( ! empty( $cgroupby ) ) ? 'GROUP BY ' . $cgroupby : ''; $corderby = ( ! empty( $corderby ) ) ? 'ORDER BY ' . $corderby : ''; + $climits = ( ! empty( $climits ) ) ? $climits : ''; $comments = (array) $wpdb->get_results( "SELECT $distinct {$wpdb->comments}.* FROM {$wpdb->comments} $cjoin $cwhere $cgroupby $corderby $climits" ); - // Convert to WP_Comment + // Convert to WP_Comment. $this->comments = array_map( 'get_comment', $comments ); $this->comment_count = count( $this->comments ); @@ -2887,7 +2917,8 @@ $found_rows = 'SQL_CALC_FOUND_ROWS'; } - $this->request = $old_request = "SELECT $found_rows $distinct $fields FROM {$wpdb->posts} $join WHERE 1=1 $where $groupby $orderby $limits"; + $old_request = "SELECT $found_rows $distinct $fields FROM {$wpdb->posts} $join WHERE 1=1 $where $groupby $orderby $limits"; + $this->request = $old_request; if ( ! $q['suppress_filters'] ) { /** @@ -2919,7 +2950,7 @@ */ $this->posts = apply_filters_ref_array( 'posts_pre_query', array( null, &$this ) ); - if ( 'ids' == $q['fields'] ) { + if ( 'ids' === $q['fields'] ) { if ( null === $this->posts ) { $this->posts = $wpdb->get_col( $this->request ); } @@ -2931,7 +2962,7 @@ return $this->posts; } - if ( 'id=>parent' == $q['fields'] ) { + if ( 'id=>parent' === $q['fields'] ) { if ( null === $this->posts ) { $this->posts = $wpdb->get_results( $this->request ); } @@ -2951,7 +2982,7 @@ } if ( null === $this->posts ) { - $split_the_query = ( $old_request == $this->request && "{$wpdb->posts}.*" == $fields && ! empty( $limits ) && $q['posts_per_page'] < 500 ); + $split_the_query = ( $old_request == $this->request && "{$wpdb->posts}.*" === $fields && ! empty( $limits ) && $q['posts_per_page'] < 500 ); /** * Filters whether to split the query. @@ -2968,7 +2999,7 @@ $split_the_query = apply_filters( 'split_the_query', $split_the_query, $this ); if ( $split_the_query ) { - // First get the IDs and then fill in the objects + // First get the IDs and then fill in the objects. $this->request = "SELECT $found_rows $distinct {$wpdb->posts}.ID FROM {$wpdb->posts} $join WHERE 1=1 $where $groupby $orderby $limits"; @@ -3034,7 +3065,7 @@ $comments_request = "SELECT {$wpdb->comments}.* FROM {$wpdb->comments} $cjoin $cwhere $cgroupby $corderby $climits"; $comments = $wpdb->get_results( $comments_request ); - // Convert to WP_Comment + // Convert to WP_Comment. $this->comments = array_map( 'get_comment', $comments ); $this->comment_count = count( $this->comments ); } @@ -3042,35 +3073,43 @@ // Check post status to determine if post should be displayed. if ( ! empty( $this->posts ) && ( $this->is_single || $this->is_page ) ) { $status = get_post_status( $this->posts[0] ); + if ( 'attachment' === $this->posts[0]->post_type && 0 === (int) $this->posts[0]->post_parent ) { $this->is_page = false; $this->is_single = true; $this->is_attachment = true; } - $post_status_obj = get_post_status_object( $status ); // If the post_status was specifically requested, let it pass through. - if ( ! $post_status_obj->public && ! in_array( $status, $q_status ) ) { - - if ( ! is_user_logged_in() ) { - // User must be logged in to view unpublished posts. - $this->posts = array(); - } else { - if ( $post_status_obj->protected ) { - // User must have edit permissions on the draft to preview. - if ( ! current_user_can( $edit_cap, $this->posts[0]->ID ) ) { - $this->posts = array(); + if ( ! in_array( $status, $q_status, true ) ) { + $post_status_obj = get_post_status_object( $status ); + + if ( $post_status_obj && ! $post_status_obj->public ) { + if ( ! is_user_logged_in() ) { + // User must be logged in to view unpublished posts. + $this->posts = array(); + } else { + if ( $post_status_obj->protected ) { + // User must have edit permissions on the draft to preview. + if ( ! current_user_can( $edit_cap, $this->posts[0]->ID ) ) { + $this->posts = array(); + } else { + $this->is_preview = true; + if ( 'future' !== $status ) { + $this->posts[0]->post_date = current_time( 'mysql' ); + } + } + } elseif ( $post_status_obj->private ) { + if ( ! current_user_can( $read_cap, $this->posts[0]->ID ) ) { + $this->posts = array(); + } } else { - $this->is_preview = true; - if ( 'future' != $status ) { - $this->posts[0]->post_date = current_time( 'mysql' ); - } - } - } elseif ( $post_status_obj->private ) { - if ( ! current_user_can( $read_cap, $this->posts[0]->ID ) ) { $this->posts = array(); } - } else { + } + } elseif ( ! $post_status_obj ) { + // Post status is not registered, assume it's not public. + if ( ! current_user_can( $edit_cap, $this->posts[0]->ID ) ) { $this->posts = array(); } } @@ -3089,23 +3128,23 @@ } } - // Put sticky posts at the top of the posts array + // Put sticky posts at the top of the posts array. $sticky_posts = get_option( 'sticky_posts' ); if ( $this->is_home && $page <= 1 && is_array( $sticky_posts ) && ! empty( $sticky_posts ) && ! $q['ignore_sticky_posts'] ) { $num_posts = count( $this->posts ); $sticky_offset = 0; // Loop over posts and relocate stickies to the front. for ( $i = 0; $i < $num_posts; $i++ ) { - if ( in_array( $this->posts[ $i ]->ID, $sticky_posts ) ) { + if ( in_array( $this->posts[ $i ]->ID, $sticky_posts, true ) ) { $sticky_post = $this->posts[ $i ]; - // Remove sticky from current position + // Remove sticky from current position. array_splice( $this->posts, $i, 1 ); - // Move to front, after other stickies + // Move to front, after other stickies. array_splice( $this->posts, $sticky_offset, 0, array( $sticky_post ) ); // Increment the sticky offset. The next sticky will be placed at this offset. $sticky_offset++; - // Remove post from sticky posts array - $offset = array_search( $sticky_post->ID, $sticky_posts ); + // Remove post from sticky posts array. + $offset = array_search( $sticky_post->ID, $sticky_posts, true ); unset( $sticky_posts[ $offset ] ); } } @@ -3115,7 +3154,7 @@ $sticky_posts = array_diff( $sticky_posts, $q['post__not_in'] ); } - // Fetch sticky posts that weren't in the query results + // Fetch sticky posts that weren't in the query results. if ( ! empty( $sticky_posts ) ) { $stickies = get_posts( array( @@ -3198,10 +3237,12 @@ * * @since 2.1.0 * - * @param string $found_posts The query to run to find the found posts. - * @param WP_Query $this The WP_Query instance (passed by reference). + * @param string $found_posts_query The query to run to find the found posts. + * @param WP_Query $this The WP_Query instance (passed by reference). */ - $this->found_posts = $wpdb->get_var( apply_filters_ref_array( 'found_posts_query', array( 'SELECT FOUND_ROWS()', &$this ) ) ); + $found_posts_query = apply_filters_ref_array( 'found_posts_query', array( 'SELECT FOUND_ROWS()', &$this ) ); + + $this->found_posts = (int) $wpdb->get_var( $found_posts_query ); } else { if ( is_array( $this->posts ) ) { $this->found_posts = count( $this->posts ); @@ -3222,7 +3263,7 @@ * @param int $found_posts The number of posts found. * @param WP_Query $this The WP_Query instance (passed by reference). */ - $this->found_posts = apply_filters_ref_array( 'found_posts', array( $this->found_posts, &$this ) ); + $this->found_posts = (int) apply_filters_ref_array( 'found_posts', array( $this->found_posts, &$this ) ); if ( ! empty( $limits ) ) { $this->max_num_pages = ceil( $this->found_posts / $q['posts_per_page'] ); @@ -3252,13 +3293,13 @@ * * @since 1.5.0 * - * @global WP_Post $post + * @global WP_Post $post Global post object. */ public function the_post() { global $post; $this->in_the_loop = true; - if ( $this->current_post == -1 ) { // loop has just started + if ( -1 == $this->current_post ) { // Loop has just started. /** * Fires once the loop is started. * @@ -3280,7 +3321,7 @@ * * @since 1.5.0 * - * @return bool True if posts are available, false if end of loop. + * @return bool True if posts are available, false if end of the loop. */ public function have_posts() { if ( $this->current_post + 1 < $this->post_count ) { @@ -3294,7 +3335,7 @@ * @param WP_Query $this The WP_Query instance (passed by reference). */ do_action_ref_array( 'loop_end', array( &$this ) ); - // Do some cleaning up after the loop + // Do some cleaning up after the loop. $this->rewind_posts(); } elseif ( 0 === $this->post_count ) { /** @@ -3341,14 +3382,15 @@ * Sets up the current comment. * * @since 2.2.0 - * @global WP_Comment $comment Current comment. + * + * @global WP_Comment $comment Global comment object. */ public function the_comment() { global $comment; $comment = $this->next_comment(); - if ( $this->current_comment == 0 ) { + if ( 0 == $this->current_comment ) { /** * Fires once the comment loop is started. * @@ -3365,7 +3407,7 @@ * * @since 2.2.0 * - * @return bool True, if more comments. False, if no more posts. + * @return bool True if comments are available, false if no more comments. */ public function have_comments() { if ( $this->current_comment + 1 < $this->comment_count ) { @@ -3394,12 +3436,15 @@ * * @since 1.5.0 * + * @see WP_Query::parse_query() for all available arguments. + * * @param string|array $query URL query string or array of query arguments. * @return WP_Post[]|int[] Array of post objects or post IDs. */ public function query( $query ) { $this->init(); - $this->query = $this->query_vars = wp_parse_args( $query ); + $this->query = wp_parse_args( $query ); + $this->query_vars = $this->query; return $this->get_posts(); } @@ -3443,7 +3488,7 @@ $query = $this->tax_query->queried_terms[ $matched_taxonomy ]; if ( ! empty( $query['terms'] ) ) { - if ( 'term_id' == $query['field'] ) { + if ( 'term_id' === $query['field'] ) { $term = get_term( reset( $query['terms'] ), $matched_taxonomy ); } else { $term = get_term_by( $query['field'], reset( $query['terms'] ), $matched_taxonomy ); @@ -3505,6 +3550,8 @@ * * @since 1.5.0 * + * @see WP_Query::parse_query() for all available arguments. + * * @param string|array $query URL query string or array of vars. */ public function __construct( $query = '' ) { @@ -3522,7 +3569,7 @@ * @return mixed Property. */ public function __get( $name ) { - if ( in_array( $name, $this->compat_fields ) ) { + if ( in_array( $name, $this->compat_fields, true ) ) { return $this->$name; } } @@ -3536,7 +3583,7 @@ * @return bool Whether the property is set. */ public function __isset( $name ) { - if ( in_array( $name, $this->compat_fields ) ) { + if ( in_array( $name, $this->compat_fields, true ) ) { return isset( $this->$name ); } } @@ -3546,13 +3593,13 @@ * * @since 4.0.0 * - * @param string $name Method to call. - * @param array $arguments Arguments to pass when calling. + * @param string $name Method to call. + * @param array $arguments Arguments to pass when calling. * @return mixed|false Return value of the callback, false otherwise. */ public function __call( $name, $arguments ) { - if ( in_array( $name, $this->compat_methods ) ) { - return call_user_func_array( array( $this, $name ), $arguments ); + if ( in_array( $name, $this->compat_methods, true ) ) { + return $this->$name( ...$arguments ); } return false; } @@ -3564,7 +3611,7 @@ * * @since 3.1.0 * - * @return bool + * @return bool Whether the query is for an existing archive page. */ public function is_archive() { return (bool) $this->is_archive; @@ -3575,8 +3622,9 @@ * * @since 3.1.0 * - * @param mixed $post_types Optional. Post type or array of posts types to check against. - * @return bool + * @param string|string[] $post_types Optional. Post type or array of posts types + * to check against. Default empty. + * @return bool Whether the query is for an existing post type archive page. */ public function is_post_type_archive( $post_types = '' ) { if ( empty( $post_types ) || ! $this->is_post_type_archive ) { @@ -3589,7 +3637,7 @@ } $post_type_object = get_post_type_object( $post_type ); - return in_array( $post_type_object->name, (array) $post_types ); + return in_array( $post_type_object->name, (array) $post_types, true ); } /** @@ -3597,8 +3645,9 @@ * * @since 3.1.0 * - * @param mixed $attachment Attachment ID, title, slug, or array of such. - * @return bool + * @param int|string|int[]|string[] $attachment Optional. Attachment ID, title, slug, or array of such + * to check against. Default empty. + * @return bool Whether the query is for an existing attachment page. */ public function is_attachment( $attachment = '' ) { if ( ! $this->is_attachment ) { @@ -3613,11 +3662,11 @@ $post_obj = $this->get_queried_object(); - if ( in_array( (string) $post_obj->ID, $attachment ) ) { + if ( in_array( (string) $post_obj->ID, $attachment, true ) ) { return true; - } elseif ( in_array( $post_obj->post_title, $attachment ) ) { + } elseif ( in_array( $post_obj->post_title, $attachment, true ) ) { return true; - } elseif ( in_array( $post_obj->post_name, $attachment ) ) { + } elseif ( in_array( $post_obj->post_name, $attachment, true ) ) { return true; } return false; @@ -3631,8 +3680,9 @@ * * @since 3.1.0 * - * @param mixed $author Optional. User ID, nickname, nicename, or array of User IDs, nicknames, and nicenames - * @return bool + * @param int|string|int[]|string[] $author Optional. User ID, nickname, nicename, or array of such + * to check against. Default empty. + * @return bool Whether the query is for an existing author archive page. */ public function is_author( $author = '' ) { if ( ! $this->is_author ) { @@ -3647,11 +3697,11 @@ $author = array_map( 'strval', (array) $author ); - if ( in_array( (string) $author_obj->ID, $author ) ) { + if ( in_array( (string) $author_obj->ID, $author, true ) ) { return true; - } elseif ( in_array( $author_obj->nickname, $author ) ) { + } elseif ( in_array( $author_obj->nickname, $author, true ) ) { return true; - } elseif ( in_array( $author_obj->user_nicename, $author ) ) { + } elseif ( in_array( $author_obj->user_nicename, $author, true ) ) { return true; } @@ -3666,8 +3716,9 @@ * * @since 3.1.0 * - * @param mixed $category Optional. Category ID, name, slug, or array of Category IDs, names, and slugs. - * @return bool + * @param int|string|int[]|string[] $category Optional. Category ID, name, slug, or array of such + * to check against. Default empty. + * @return bool Whether the query is for an existing category archive page. */ public function is_category( $category = '' ) { if ( ! $this->is_category ) { @@ -3682,11 +3733,11 @@ $category = array_map( 'strval', (array) $category ); - if ( in_array( (string) $cat_obj->term_id, $category ) ) { + if ( in_array( (string) $cat_obj->term_id, $category, true ) ) { return true; - } elseif ( in_array( $cat_obj->name, $category ) ) { + } elseif ( in_array( $cat_obj->name, $category, true ) ) { return true; - } elseif ( in_array( $cat_obj->slug, $category ) ) { + } elseif ( in_array( $cat_obj->slug, $category, true ) ) { return true; } @@ -3701,8 +3752,9 @@ * * @since 3.1.0 * - * @param mixed $tag Optional. Tag ID, name, slug, or array of Tag IDs, names, and slugs. - * @return bool + * @param int|string|int[]|string[] $tag Optional. Tag ID, name, slug, or array of such + * to check against. Default empty. + * @return bool Whether the query is for an existing tag archive page. */ public function is_tag( $tag = '' ) { if ( ! $this->is_tag ) { @@ -3717,11 +3769,11 @@ $tag = array_map( 'strval', (array) $tag ); - if ( in_array( (string) $tag_obj->term_id, $tag ) ) { + if ( in_array( (string) $tag_obj->term_id, $tag, true ) ) { return true; - } elseif ( in_array( $tag_obj->name, $tag ) ) { + } elseif ( in_array( $tag_obj->name, $tag, true ) ) { return true; - } elseif ( in_array( $tag_obj->slug, $tag ) ) { + } elseif ( in_array( $tag_obj->slug, $tag, true ) ) { return true; } @@ -3742,9 +3794,13 @@ * * @global array $wp_taxonomies * - * @param mixed $taxonomy Optional. Taxonomy slug or slugs. - * @param mixed $term Optional. Term ID, name, slug or array of Term IDs, names, and slugs. - * @return bool True for custom taxonomy archive pages, false for built-in taxonomies (category and tag archives). + * @param string|string[] $taxonomy Optional. Taxonomy slug or slugs to check against. + * Default empty. + * @param int|string|int[]|string[] $term Optional. Term ID, name, slug, or array of such + * to check against. Default empty. + * @return bool Whether the query is for an existing custom taxonomy archive page. + * True for custom taxonomy archive pages, false for built-in taxonomies + * (category and tag archives). */ public function is_tax( $taxonomy = '', $term = '' ) { global $wp_taxonomies; @@ -3762,11 +3818,11 @@ $term_array = (array) $term; // Check that the taxonomy matches. - if ( ! ( isset( $queried_object->taxonomy ) && count( $tax_array ) && in_array( $queried_object->taxonomy, $tax_array ) ) ) { + if ( ! ( isset( $queried_object->taxonomy ) && count( $tax_array ) && in_array( $queried_object->taxonomy, $tax_array, true ) ) ) { return false; } - // Only a Taxonomy provided. + // Only a taxonomy provided. if ( empty( $term ) ) { return true; } @@ -3786,7 +3842,7 @@ * @since 3.1.0 * @deprecated 4.5.0 * - * @return bool + * @return false Always returns false. */ public function is_comments_popup() { _deprecated_function( __FUNCTION__, '4.5.0' ); @@ -3799,7 +3855,7 @@ * * @since 3.1.0 * - * @return bool + * @return bool Whether the query is for an existing date archive. */ public function is_date() { return (bool) $this->is_date; @@ -3810,7 +3866,7 @@ * * @since 3.1.0 * - * @return bool + * @return bool Whether the query is for an existing day archive. */ public function is_day() { return (bool) $this->is_day; @@ -3821,18 +3877,21 @@ * * @since 3.1.0 * - * @param string|array $feeds Optional feed types to check. - * @return bool + * @param string|string[] $feeds Optional. Feed type or array of feed types + * to check against. Default empty. + * @return bool Whether the query is for a feed. */ public function is_feed( $feeds = '' ) { if ( empty( $feeds ) || ! $this->is_feed ) { return (bool) $this->is_feed; } + $qv = $this->get( 'feed' ); - if ( 'feed' == $qv ) { + if ( 'feed' === $qv ) { $qv = get_default_feed(); } - return in_array( $qv, (array) $feeds ); + + return in_array( $qv, (array) $feeds, true ); } /** @@ -3840,7 +3899,7 @@ * * @since 3.1.0 * - * @return bool + * @return bool Whether the query is for a comments feed. */ public function is_comment_feed() { return (bool) $this->is_comment_feed; @@ -3860,13 +3919,15 @@ * * @since 3.1.0 * - * @return bool True, if front of site. + * @return bool Whether the query is for the front page of the site. */ public function is_front_page() { - // most likely case - if ( 'posts' == get_option( 'show_on_front' ) && $this->is_home() ) { + // Most likely case. + if ( 'posts' === get_option( 'show_on_front' ) && $this->is_home() ) { return true; - } elseif ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_on_front' ) && $this->is_page( get_option( 'page_on_front' ) ) ) { + } elseif ( 'page' === get_option( 'show_on_front' ) && get_option( 'page_on_front' ) + && $this->is_page( get_option( 'page_on_front' ) ) + ) { return true; } else { return false; @@ -3887,7 +3948,7 @@ * * @since 3.1.0 * - * @return bool True if blog view homepage. + * @return bool Whether the query is for the blog homepage. */ public function is_home() { return (bool) $this->is_home; @@ -3904,10 +3965,12 @@ * * @since 5.2.0 * - * @return bool True, if Privacy Policy page. + * @return bool Whether the query is for the Privacy Policy page. */ public function is_privacy_policy() { - if ( get_option( 'wp_page_for_privacy_policy' ) && $this->is_page( get_option( 'wp_page_for_privacy_policy' ) ) ) { + if ( get_option( 'wp_page_for_privacy_policy' ) + && $this->is_page( get_option( 'wp_page_for_privacy_policy' ) ) + ) { return true; } else { return false; @@ -3919,7 +3982,7 @@ * * @since 3.1.0 * - * @return bool + * @return bool Whether the query is for an existing month archive. */ public function is_month() { return (bool) $this->is_month; @@ -3936,7 +3999,8 @@ * * @since 3.1.0 * - * @param int|string|array $page Optional. Page ID, title, slug, path, or array of such. Default empty. + * @param int|string|int[]|string[] $page Optional. Page ID, title, slug, path, or array of such + * to check against. Default empty. * @return bool Whether the query is for an existing single page. */ public function is_page( $page = '' ) { @@ -3952,11 +4016,11 @@ $page = array_map( 'strval', (array) $page ); - if ( in_array( (string) $page_obj->ID, $page ) ) { + if ( in_array( (string) $page_obj->ID, $page, true ) ) { return true; - } elseif ( in_array( $page_obj->post_title, $page ) ) { + } elseif ( in_array( $page_obj->post_title, $page, true ) ) { return true; - } elseif ( in_array( $page_obj->post_name, $page ) ) { + } elseif ( in_array( $page_obj->post_name, $page, true ) ) { return true; } else { foreach ( $page as $pagepath ) { @@ -3975,11 +4039,11 @@ } /** - * Is the query for paged result and not for the first page? + * Is the query for a paged result and not for the first page? * * @since 3.1.0 * - * @return bool + * @return bool Whether the query is for a paged result. */ public function is_paged() { return (bool) $this->is_paged; @@ -3990,29 +4054,40 @@ * * @since 3.1.0 * - * @return bool + * @return bool Whether the query is for a post or page preview. */ public function is_preview() { return (bool) $this->is_preview; } /** - * Is the query for the robots file? + * Is the query for the robots.txt file? * * @since 3.1.0 * - * @return bool + * @return bool Whether the query is for the robots.txt file. */ public function is_robots() { return (bool) $this->is_robots; } /** + * Is the query for the favicon.ico file? + * + * @since 5.4.0 + * + * @return bool Whether the query is for the favicon.ico file. + */ + public function is_favicon() { + return (bool) $this->is_favicon; + } + + /** * Is the query for a search? * * @since 3.1.0 * - * @return bool + * @return bool Whether the query is for a search. */ public function is_search() { return (bool) $this->is_search; @@ -4031,7 +4106,8 @@ * * @since 3.1.0 * - * @param int|string|array $post Optional. Post ID, title, slug, path, or array of such. Default empty. + * @param int|string|int[]|string[] $post Optional. Post ID, title, slug, path, or array of such + * to check against. Default empty. * @return bool Whether the query is for an existing single post. */ public function is_single( $post = '' ) { @@ -4047,11 +4123,11 @@ $post = array_map( 'strval', (array) $post ); - if ( in_array( (string) $post_obj->ID, $post ) ) { + if ( in_array( (string) $post_obj->ID, $post, true ) ) { return true; - } elseif ( in_array( $post_obj->post_title, $post ) ) { + } elseif ( in_array( $post_obj->post_title, $post, true ) ) { return true; - } elseif ( in_array( $post_obj->post_name, $post ) ) { + } elseif ( in_array( $post_obj->post_name, $post, true ) ) { return true; } else { foreach ( $post as $postpath ) { @@ -4080,8 +4156,10 @@ * * @since 3.1.0 * - * @param string|array $post_types Optional. Post type or array of post types. Default empty. - * @return bool Whether the query is for an existing single post of any of the given post types. + * @param string|string[] $post_types Optional. Post type or array of post types + * to check against. Default empty. + * @return bool Whether the query is for an existing single post + * or any of the given post types. */ public function is_singular( $post_types = '' ) { if ( empty( $post_types ) || ! $this->is_singular ) { @@ -4090,7 +4168,7 @@ $post_obj = $this->get_queried_object(); - return in_array( $post_obj->post_type, (array) $post_types ); + return in_array( $post_obj->post_type, (array) $post_types, true ); } /** @@ -4098,7 +4176,7 @@ * * @since 3.1.0 * - * @return bool + * @return bool Whether the query is for a specific time. */ public function is_time() { return (bool) $this->is_time; @@ -4109,7 +4187,7 @@ * * @since 3.1.0 * - * @return bool + * @return bool Whether the query is for a trackback endpoint call. */ public function is_trackback() { return (bool) $this->is_trackback; @@ -4120,7 +4198,7 @@ * * @since 3.1.0 * - * @return bool + * @return bool Whether the query is for an existing year archive. */ public function is_year() { return (bool) $this->is_year; @@ -4131,7 +4209,7 @@ * * @since 3.1.0 * - * @return bool + * @return bool Whether the query is a 404 error. */ public function is_404() { return (bool) $this->is_404; @@ -4142,7 +4220,7 @@ * * @since 4.4.0 * - * @return bool + * @return bool Whether the query is for an embedded post. */ public function is_embed() { return (bool) $this->is_embed; @@ -4153,9 +4231,9 @@ * * @since 3.3.0 * - * @global WP_Query $wp_query Global WP_Query instance. - * - * @return bool + * @global WP_Query $wp_query WordPress Query object. + * + * @return bool Whether the query is the main query. */ public function is_main_query() { global $wp_the_query; @@ -4168,15 +4246,15 @@ * @since 4.1.0 * @since 4.4.0 Added the ability to pass a post ID to `$post`. * - * @global int $id - * @global WP_User $authordata - * @global string|int|bool $currentday - * @global string|int|bool $currentmonth - * @global int $page - * @global array $pages - * @global int $multipage - * @global int $more - * @global int $numpages + * @global int $id + * @global WP_User $authordata + * @global string $currentday + * @global string $currentmonth + * @global int $page + * @global array $pages + * @global int $multipage + * @global int $more + * @global int $numpages * * @param WP_Post|object|int $post WP_Post instance or Post ID/object. * @return true True when finished. @@ -4208,7 +4286,7 @@ $numpages = $elements['numpages']; /** - * Fires once the post data has been setup. + * Fires once the post data has been set up. * * @since 2.8.0 * @since 4.1.0 Introduced `$this` parameter. @@ -4227,7 +4305,7 @@ * @since 5.2.0 * * @param WP_Post|object|int $post WP_Post instance or Post ID/object. - * @return array|bool $elements Elements of post or false on failure. + * @return array|bool Elements of post or false on failure. */ public function generate_postdata( $post ) { @@ -4256,7 +4334,7 @@ * Force full post content when viewing the permalink for the $post, * or when on an RSS feed. Otherwise respect the 'more' tag. */ - if ( $post->ID === get_queried_object_id() && ( $this->is_page() || $this->is_single() ) ) { + if ( get_queried_object_id() === $post->ID && ( $this->is_page() || $this->is_single() ) ) { $more = 1; } elseif ( $this->is_feed() ) { $more = 1; @@ -4318,7 +4396,7 @@ * * @since 3.7.0 * - * @global WP_Post $post + * @global WP_Post $post Global post object. */ public function reset_postdata() { if ( ! empty( $this->post ) ) {