Skip to content

Commit 160e1fe

Browse files
authored
Merge branch 'WordPress:trunk' into trunk
2 parents 6899814 + 99fc144 commit 160e1fe

3 files changed

Lines changed: 42 additions & 17 deletions

File tree

src/wp-includes/class-wp-post.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,9 +388,11 @@ public function filter( $filter ) {
388388
* @since 3.5.0
389389
*
390390
* @return array<string, mixed> Object as array.
391+
*
392+
* @phpstan-return non-empty-array<string, mixed>
391393
*/
392394
public function to_array() {
393-
/** @var array<string, mixed> $post */
395+
/** @var non-empty-array<string, mixed> $post */
394396
$post = get_object_vars( $this );
395397

396398
foreach ( array( 'ancestors', 'page_template', 'post_category', 'tags_input' ) as $key ) {

src/wp-includes/post.php

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -990,8 +990,8 @@ function _wp_relative_upload_path( $path ) {
990990
* @phpstan-param 'OBJECT'|'ARRAY_A'|'ARRAY_N' $output
991991
* @phpstan-return (
992992
* $args is array{ fields: 'ids', ... } ? int[] : (
993-
* $output is 'ARRAY_A' ? array<int, array<string, mixed>> : (
994-
* $output is 'ARRAY_N' ? array<int, array<int, mixed>> : WP_Post[]
993+
* $output is 'ARRAY_A' ? array<int, non-empty-array<string, mixed>> : (
994+
* $output is 'ARRAY_N' ? array<int, non-empty-array<int, mixed>> : WP_Post[]
995995
* )
996996
* )
997997
* )
@@ -1040,13 +1040,17 @@ function get_children( $args = '', $output = OBJECT ) {
10401040
} elseif ( ARRAY_A === $output ) {
10411041
$weeuns = array();
10421042
foreach ( (array) $kids as $kid ) {
1043-
$weeuns[ $kid->ID ] = get_object_vars( $kids[ $kid->ID ] );
1043+
/** @var non-empty-array<string, mixed> $vars */
1044+
$vars = get_object_vars( $kids[ $kid->ID ] );
1045+
$weeuns[ $kid->ID ] = $vars;
10441046
}
10451047
return $weeuns;
10461048
} elseif ( ARRAY_N === $output ) {
10471049
$babes = array();
10481050
foreach ( (array) $kids as $kid ) {
1049-
$babes[ $kid->ID ] = array_values( get_object_vars( $kids[ $kid->ID ] ) );
1051+
/** @var non-empty-array<string, mixed> $vars */
1052+
$vars = get_object_vars( $kids[ $kid->ID ] );
1053+
$babes[ $kid->ID ] = array_values( $vars );
10501054
}
10511055
return $babes;
10521056
} else {
@@ -1124,8 +1128,8 @@ function get_extended( $post ) {
11241128
* @phpstan-param 'OBJECT'|'ARRAY_A'|'ARRAY_N' $output
11251129
* @phpstan-param 'raw'|'edit'|'db'|'display' $filter
11261130
* @phpstan-return (
1127-
* $output is 'ARRAY_A' ? array<string, mixed>|null : (
1128-
* $output is 'ARRAY_N' ? array<int, mixed>|null : (
1131+
* $output is 'ARRAY_A' ? non-empty-array<string, mixed>|null : (
1132+
* $output is 'ARRAY_N' ? non-empty-array<int, mixed>|null : (
11291133
* WP_Post|null
11301134
* )
11311135
* )
@@ -4452,7 +4456,7 @@ function wp_get_post_terms( $post_id = 0, $taxonomy = 'post_tag', $args = array(
44524456
*
44534457
* @phpstan-param 'OBJECT'|'ARRAY_A' $output
44544458
* @phpstan-return (
4455-
* $output is 'ARRAY_A' ? array<int, array<string, mixed>> : WP_Post[]|false
4459+
* $output is 'ARRAY_A' ? array<int, non-empty-array<string, mixed>> : WP_Post[]|false
44564460
* )
44574461
*/
44584462
function wp_get_recent_posts( $args = array(), $output = ARRAY_A ) {
@@ -4485,12 +4489,13 @@ function wp_get_recent_posts( $args = array(), $output = ARRAY_A ) {
44854489

44864490
// Backward compatibility. Prior to 3.1 expected posts to be returned in array.
44874491
if ( ARRAY_A === $output ) {
4492+
$posts = array();
44884493
foreach ( $results as $key => $result ) {
4489-
/** @var array<string, mixed> $object_vars */
4490-
$object_vars = get_object_vars( $result );
4491-
$results[ $key ] = $object_vars;
4494+
/** @var non-empty-array<string, mixed> $object_vars */
4495+
$object_vars = get_object_vars( $result );
4496+
$posts[ $key ] = $object_vars;
44924497
}
4493-
return $results ? $results : array();
4498+
return $posts;
44944499
}
44954500

44964501
return $results ? $results : false;
@@ -6146,6 +6151,10 @@ function trackback_url_list( $tb_list, $post_id ) {
61466151
// Get post data.
61476152
$postdata = get_post( $post_id, ARRAY_A );
61486153

6154+
if ( ! $postdata ) {
6155+
return;
6156+
}
6157+
61496158
// Form an excerpt.
61506159
$excerpt = strip_tags( $postdata['post_excerpt'] ? $postdata['post_excerpt'] : $postdata['post_content'] );
61516160

@@ -6206,8 +6215,8 @@ function get_all_page_ids() {
62066215
* @phpstan-param 'OBJECT'|'ARRAY_A'|'ARRAY_N' $output
62076216
* @phpstan-param 'raw'|'edit'|'db'|'display' $filter
62086217
* @phpstan-return (
6209-
* $output is 'ARRAY_A' ? array<string, mixed>|null : (
6210-
* $output is 'ARRAY_N' ? array<int, mixed>|null : (
6218+
* $output is 'ARRAY_A' ? non-empty-array<string, mixed>|null : (
6219+
* $output is 'ARRAY_N' ? non-empty-array<int, mixed>|null : (
62116220
* WP_Post|null
62126221
* )
62136222
* )
@@ -6234,8 +6243,8 @@ function get_page( $page, $output = OBJECT, $filter = 'raw' ) {
62346243
* @phpstan-param 'OBJECT'|'ARRAY_A'|'ARRAY_N' $output
62356244
* @phpstan-param string|string[] $post_type
62366245
* @phpstan-return (
6237-
* $output is 'ARRAY_A' ? array<string, mixed>|null : (
6238-
* $output is 'ARRAY_N' ? array<int, mixed>|null : (
6246+
* $output is 'ARRAY_A' ? non-empty-array<string, mixed>|null : (
6247+
* $output is 'ARRAY_N' ? non-empty-array<int, mixed>|null : (
62396248
* WP_Post|null
62406249
* )
62416250
* )

src/wp-includes/revision.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,17 @@ function wp_save_revisioned_meta_fields( $revision_id, $post_id ) {
423423
* respectively. Default OBJECT.
424424
* @param string $filter Optional sanitization filter. See sanitize_post(). Default 'raw'.
425425
* @return WP_Post|array|null WP_Post (or array) on success, or null on failure.
426+
*
427+
* @phpstan-param int|WP_Post $post
428+
* @phpstan-param 'OBJECT'|'ARRAY_A'|'ARRAY_N' $output
429+
* @phpstan-param 'raw'|'edit'|'db'|'display' $filter
430+
* @phpstan-return (
431+
* $output is 'ARRAY_A' ? non-empty-array<string, mixed>|null : (
432+
* $output is 'ARRAY_N' ? non-empty-array<int, mixed>|null : (
433+
* WP_Post|null
434+
* )
435+
* )
436+
* )
426437
*/
427438
function wp_get_post_revision( &$post, $output = OBJECT, $filter = 'raw' ) {
428439
$revision = get_post( $post, OBJECT, $filter );
@@ -438,10 +449,13 @@ function wp_get_post_revision( &$post, $output = OBJECT, $filter = 'raw' ) {
438449
if ( OBJECT === $output ) {
439450
return $revision;
440451
} elseif ( ARRAY_A === $output ) {
452+
/** @var non-empty-array<string, mixed> $_revision */
441453
$_revision = get_object_vars( $revision );
442454
return $_revision;
443455
} elseif ( ARRAY_N === $output ) {
444-
$_revision = array_values( get_object_vars( $revision ) );
456+
/** @var non-empty-array<string, mixed> $vars */
457+
$vars = get_object_vars( $revision );
458+
$_revision = array_values( $vars );
445459
return $_revision;
446460
}
447461

0 commit comments

Comments
 (0)