From 40b738335bf4d891af104865c6a4d22833369179 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Thu, 26 Nov 2020 17:04:06 +0000 Subject: [PATCH] Docs: Corrections and improvements to docs for properties of the `WP_Query` class. This also adds additional type hinting inside some methods to help IDEs. See #51800 Built from https://develop.svn.wordpress.org/trunk@49700 git-svn-id: http://core.svn.wordpress.org/trunk@49423 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-query.php | 32 ++++++++++++++++++++++---------- wp-includes/version.php | 2 +- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/wp-includes/class-wp-query.php b/wp-includes/class-wp-query.php index 02d3be96c1..076e3749a0 100644 --- a/wp-includes/class-wp-query.php +++ b/wp-includes/class-wp-query.php @@ -76,7 +76,7 @@ class WP_Query { public $queried_object_id; /** - * Get post database query. + * SQL for the database query. * * @since 2.0.1 * @var string @@ -84,10 +84,10 @@ class WP_Query { public $request; /** - * List of posts. + * Array of post objects or post IDs. * * @since 1.5.0 - * @var array + * @var WP_Post[]|int[] */ public $posts; @@ -118,8 +118,11 @@ class WP_Query { /** * The current post. * + * This property does not get populated when the `fields` argument is set to + * `ids` or `id=>parent`. + * * @since 1.5.0 - * @var WP_Post + * @var WP_Post|null */ public $post; @@ -127,7 +130,7 @@ class WP_Query { * The list of comments for current post. * * @since 2.2.0 - * @var array + * @var WP_Comment[] */ public $comments; @@ -148,10 +151,10 @@ class WP_Query { public $current_comment = -1; /** - * Current comment ID. + * Current comment object. * * @since 2.2.0 - * @var int + * @var WP_Comment */ public $comment; @@ -2660,6 +2663,7 @@ class WP_Query { $comments = (array) $wpdb->get_results( "SELECT $distinct {$wpdb->comments}.* FROM {$wpdb->comments} $cjoin $cwhere $cgroupby $corderby $climits" ); // Convert to WP_Comment. + /** @var WP_Comment[] */ $this->comments = array_map( 'get_comment', $comments ); $this->comment_count = count( $this->comments ); @@ -2944,9 +2948,9 @@ class WP_Query { * * @since 4.6.0 * - * @param array|null $posts Return an array of post data to short-circuit WP's query, - * or null to allow WP to run its normal queries. - * @param WP_Query $this The WP_Query instance (passed by reference). + * @param WP_Post[]|int[]|null $posts Return an array of post data to short-circuit WP's query, + * or null to allow WP to run its normal queries. + * @param WP_Query $this The WP_Query instance (passed by reference). */ $this->posts = apply_filters_ref_array( 'posts_pre_query', array( null, &$this ) ); @@ -2955,6 +2959,7 @@ class WP_Query { $this->posts = $wpdb->get_col( $this->request ); } + /** @var int[] */ $this->posts = array_map( 'intval', $this->posts ); $this->post_count = count( $this->posts ); $this->set_found_posts( $q, $limits ); @@ -2970,6 +2975,7 @@ class WP_Query { $this->post_count = count( $this->posts ); $this->set_found_posts( $q, $limits ); + /** @var int[] */ $r = array(); foreach ( $this->posts as $key => $post ) { $this->posts[ $key ]->ID = (int) $post->ID; @@ -3030,6 +3036,7 @@ class WP_Query { // Convert to WP_Post objects. if ( $this->posts ) { + /** @var WP_Post[] */ $this->posts = array_map( 'get_post', $this->posts ); } @@ -3066,6 +3073,7 @@ class WP_Query { $comments_request = "SELECT {$wpdb->comments}.* FROM {$wpdb->comments} $cjoin $cwhere $cgroupby $corderby $climits"; $comments = $wpdb->get_results( $comments_request ); // Convert to WP_Comment. + /** @var WP_Comment[] */ $this->comments = array_map( 'get_comment', $comments ); $this->comment_count = count( $this->comments ); } @@ -3195,12 +3203,14 @@ class WP_Query { if ( $this->posts ) { $this->post_count = count( $this->posts ); + /** @var WP_Post[] */ $this->posts = array_map( 'get_post', $this->posts ); if ( $q['cache_results'] ) { update_post_caches( $this->posts, $post_type, $q['update_post_term_cache'], $q['update_post_meta_cache'] ); } + /** @var WP_Post */ $this->post = reset( $this->posts ); } else { $this->post_count = 0; @@ -3281,6 +3291,7 @@ class WP_Query { $this->current_post++; + /** @var WP_Post */ $this->post = $this->posts[ $this->current_post ]; return $this->post; } @@ -3374,6 +3385,7 @@ class WP_Query { public function next_comment() { $this->current_comment++; + /** @var WP_Comment */ $this->comment = $this->comments[ $this->current_comment ]; return $this->comment; } diff --git a/wp-includes/version.php b/wp-includes/version.php index 0d4ececc97..d3e3f18177 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.7-alpha-49699'; +$wp_version = '5.7-alpha-49700'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.