Changeset 62648
- Timestamp:
- 07/06/2026 08:53:46 PM (28 hours ago)
- Location:
- trunk/src/wp-includes
- Files:
-
- 3 edited
-
class-wp-post.php (modified) (8 diffs)
-
class-wp-query.php (modified) (1 diff)
-
post.php (modified) (24 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-post.php
r62437 r62648 219 219 * @since 3.5.0 220 220 * @var string 221 * @phpstan-var 'raw'|'edit'|'db'|'display'|'attribute'|'js' 221 222 */ 222 223 public $filter; … … 231 232 * @param int $post_id Post ID. 232 233 * @return WP_Post|false Post object, false otherwise. 234 * 235 * @phpstan-param int|numeric-string $post_id 233 236 */ 234 237 public static function get_instance( $post_id ) { … … 242 245 $_post = wp_cache_get( $post_id, 'posts' ); 243 246 244 if ( ! $_post) {247 if ( ! ( $_post instanceof stdClass ) && ! ( $_post instanceof WP_Post ) ) { 245 248 $_post = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE ID = %d LIMIT 1", $post_id ) ); 246 249 … … 250 253 251 254 $_post = sanitize_post( $_post, 'raw' ); 252 wp_cache_add( $_post->ID, $_post, 'posts' );255 wp_cache_add( (int) $_post->ID, $_post, 'posts' ); 253 256 } elseif ( empty( $_post->filter ) || 'raw' !== $_post->filter ) { 254 257 $_post = sanitize_post( $_post, 'raw' ); … … 317 320 } 318 321 319 if ( empty( $terms ) ) {322 if ( empty( $terms ) || $terms instanceof WP_Error ) { 320 323 return array(); 321 324 } … … 329 332 } 330 333 331 if ( empty( $terms ) ) {334 if ( empty( $terms ) || $terms instanceof WP_Error ) { 332 335 return array(); 333 336 } … … 351 354 352 355 /** 353 * {@Missing Summary} 356 * Applies the provided context filter for the current post. 357 * 358 * If the requested filter was already applied, then it returns without any changes. 359 * 360 * If the 'raw' filter is supplied, then a new instance of the post is obtained and this method _may_ return false 361 * in case the underlying post was deleted. 354 362 * 355 363 * @since 3.5.0 356 364 * 357 365 * @param string $filter Filter. 358 * @return WP_Post 366 * @return WP_Post|false 367 * 368 * @phpstan-param 'raw'|'edit'|'db'|'display'|'attribute'|'js' $filter 369 * @phpstan-return ( 370 * $filter is 'raw' ? WP_Post|false : WP_Post 371 * ) 359 372 */ 360 373 public function filter( $filter ) { … … 375 388 * @since 3.5.0 376 389 * 377 * @return array Object as array.390 * @return array<string, mixed> Object as array. 378 391 */ 379 392 public function to_array() { 393 /** @var array<string, mixed> $post */ 380 394 $post = get_object_vars( $this ); 381 395 -
trunk/src/wp-includes/class-wp-query.php
r62476 r62648 3947 3947 * @param string|array $query URL query string or array of query arguments. 3948 3948 * @return WP_Post[]|int[] Array of post objects or post IDs. 3949 * 3950 * @phpstan-return ( 3951 * $query is array{ fields: 'ids', ... } ? int[] : WP_Post[] 3952 * ) 3949 3953 */ 3950 3954 public function query( $query ) { -
trunk/src/wp-includes/post.php
r62623 r62648 987 987 * respectively. Default OBJECT. 988 988 * @return WP_Post[]|array[]|int[] Array of post objects, arrays, or IDs, depending on `$output`. 989 * 990 * @phpstan-param 'OBJECT'|'ARRAY_A'|'ARRAY_N' $output 991 * @phpstan-return ( 992 * $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[] 995 * ) 996 * ) 997 * ) 989 998 */ 990 999 function get_children( $args = '', $output = OBJECT ) { … … 1111 1120 * @return WP_Post|array|null Type corresponding to $output on success or null on failure. 1112 1121 * When $output is OBJECT, a `WP_Post` instance is returned. 1122 * 1123 * @phpstan-param int|numeric-string|WP_Post|null $post 1124 * @phpstan-param 'OBJECT'|'ARRAY_A'|'ARRAY_N' $output 1125 * @phpstan-param 'raw'|'edit'|'db'|'display' $filter 1126 * @phpstan-return ( 1127 * $output is 'ARRAY_A' ? array<string, mixed>|null : ( 1128 * $output is 'ARRAY_N' ? array<int, mixed>|null : ( 1129 * WP_Post|null 1130 * ) 1131 * ) 1132 * ) 1113 1133 */ 1114 1134 function get_post( $post = null, $output = OBJECT, $filter = 'raw' ) { … … 1120 1140 $_post = $post; 1121 1141 } elseif ( is_object( $post ) ) { 1142 /** @var stdClass $post */ 1122 1143 if ( empty( $post->filter ) ) { 1123 1144 $_post = sanitize_post( $post, 'raw' ); … … 1126 1147 $_post = new WP_Post( $post ); 1127 1148 } elseif ( isset( $post->ID ) ) { 1128 $_post = WP_Post::get_instance( $post->ID );1149 $_post = WP_Post::get_instance( (int) $post->ID ); 1129 1150 } else { 1130 1151 $_post = null; 1131 1152 } 1153 } elseif ( is_numeric( $post ) ) { 1154 $_post = WP_Post::get_instance( (int) $post ); 1132 1155 } else { 1133 $_post = WP_Post::get_instance( $post );1156 $_post = null; 1134 1157 } 1135 1158 … … 1139 1162 1140 1163 $_post = $_post->filter( $filter ); 1164 if ( ! $_post ) { 1165 return null; 1166 } 1141 1167 1142 1168 if ( ARRAY_A === $output ) { … … 1203 1229 * or 'display'. Default 'display'. 1204 1230 * @return int|string|int[] The value of the post field on success, empty string on failure. 1231 * 1232 * @phpstan-param 'raw'|'edit'|'db'|'display' $context 1233 * @phpstan-return ( 1234 * $field is 'ID'|'post_parent'|'menu_order' ? int|'' : ( 1235 * $field is 'ancestors' ? non-negative-int[]|'' : string 1236 * ) 1237 * ) 1205 1238 */ 1206 1239 function get_post_field( $field, $post = null, $context = 'display' ) { … … 1643 1676 * must match; 'not' means no elements may match. Default 'and'. 1644 1677 * @return string[]|WP_Post_Type[] An array of post type names or objects. 1678 * @phpstan-return ( $output is 'names' ? string[] : WP_Post_Type[] ) 1645 1679 */ 1646 1680 function get_post_types( $args = array(), $output = 'names', $operator = 'and' ) { … … 2579 2613 * } 2580 2614 * @return WP_Post[]|int[] Array of post objects or post IDs. 2615 * 2616 * @phpstan-return ( 2617 * $args is array{ fields: 'ids', ... } ? int[] : WP_Post[] 2618 * ) 2581 2619 */ 2582 2620 function get_posts( $args = null ) { … … 2917 2955 * @return object|WP_Post|array The now sanitized post object or array (will be the 2918 2956 * same type as `$post`). 2957 * 2958 * @phpstan-param stdClass|WP_Post|array<string, mixed> $post 2959 * @phpstan-param 'raw'|'edit'|'db'|'display'|'attribute'|'js' $context 2960 * @phpstan-return ( 2961 * $post is WP_Post ? WP_Post : ( 2962 * $post is stdClass ? stdClass : array<string, mixed> 2963 * ) 2964 * ) 2919 2965 */ 2920 2966 function sanitize_post( $post, $context = 'display' ) { … … 2928 2974 } 2929 2975 foreach ( array_keys( get_object_vars( $post ) ) as $field ) { 2930 $post->$field = sanitize_post_field( $field, $post->$field, $post->ID, $context );2976 $post->$field = sanitize_post_field( $field, $post->$field, (int) $post->ID, $context ); 2931 2977 } 2932 2978 $post->filter = $context; … … 2940 2986 } 2941 2987 foreach ( array_keys( $post ) as $field ) { 2942 $post[ $field ] = sanitize_post_field( $field, $post[ $field ], $post['ID'], $context );2988 $post[ $field ] = sanitize_post_field( $field, $post[ $field ], (int) $post['ID'], $context ); 2943 2989 } 2944 2990 $post['filter'] = $context; … … 2963 3009 * 'db', 'display', 'attribute' and 'js'. Default 'display'. 2964 3010 * @return mixed Sanitized value. 3011 * 3012 * @phpstan-param 'raw'|'edit'|'db'|'display'|'attribute'|'js' $context 3013 * @phpstan-return ( 3014 * $field is 'ID'|'post_parent'|'menu_order' ? int : ( 3015 * $field is 'ancestors' ? non-negative-int[] : string 3016 * ) 3017 * ) 2965 3018 */ 2966 3019 function sanitize_post_field( $field, $value, $post_id, $context = 'display' ) { … … 2973 3026 $array_int_fields = array( 'ancestors' ); 2974 3027 if ( in_array( $field, $array_int_fields, true ) ) { 2975 $value = array_map( 'absint', $value );3028 $value = array_map( 'absint', (array) $value ); 2976 3029 return $value; 2977 3030 } … … 4397 4450 * @return array|false Array of recent posts, where the type of each element is determined 4398 4451 * by the `$output` parameter. Empty array on failure. 4452 * 4453 * @phpstan-param 'OBJECT'|'ARRAY_A' $output 4454 * @phpstan-return ( 4455 * $output is 'ARRAY_A' ? array<int, array<string, mixed>> : WP_Post[]|false 4456 * ) 4399 4457 */ 4400 4458 function wp_get_recent_posts( $args = array(), $output = ARRAY_A ) { … … 4421 4479 ); 4422 4480 4481 /** @var array{ fields: null, ... } $parsed_args */ 4423 4482 $parsed_args = wp_parse_args( $args, $defaults ); 4424 4483 … … 4428 4487 if ( ARRAY_A === $output ) { 4429 4488 foreach ( $results as $key => $result ) { 4430 $results[ $key ] = get_object_vars( $result ); 4489 /** @var array<string, mixed> $object_vars */ 4490 $object_vars = get_object_vars( $result ); 4491 $results[ $key ] = $object_vars; 4431 4492 } 4432 4493 return $results ? $results : array(); … … 4505 4566 * @param bool $fire_after_hooks Optional. Whether to fire the after insert hooks. Default true. 4506 4567 * @return int|WP_Error The post ID on success. The value 0 or WP_Error on failure. 4568 * 4569 * @phpstan-return ( 4570 * $wp_error is false ? int : int|WP_Error 4571 * ) 4507 4572 */ 4508 4573 function wp_insert_post( $postarr, $wp_error = false, $fire_after_hooks = true ) { … … 5230 5295 * @param bool $fire_after_hooks Optional. Whether to fire the after insert hooks. Default true. 5231 5296 * @return int|WP_Error The post ID on success. The value 0 or WP_Error on failure. 5297 * 5298 * @phpstan-return ( 5299 * $wp_error is false ? int : int|WP_Error 5300 * ) 5232 5301 */ 5233 5302 function wp_update_post( $postarr = array(), $wp_error = false, $fire_after_hooks = true ) { … … 6133 6202 * 'edit', 'db', 'display'. Default 'raw'. 6134 6203 * @return WP_Post|array|null WP_Post or array on success, null on failure. 6204 * 6205 * @phpstan-param int|numeric-string|WP_Post|null $page 6206 * @phpstan-param 'OBJECT'|'ARRAY_A'|'ARRAY_N' $output 6207 * @phpstan-param 'raw'|'edit'|'db'|'display' $filter 6208 * @phpstan-return ( 6209 * $output is 'ARRAY_A' ? array<string, mixed>|null : ( 6210 * $output is 'ARRAY_N' ? array<int, mixed>|null : ( 6211 * WP_Post|null 6212 * ) 6213 * ) 6214 * ) 6135 6215 */ 6136 6216 function get_page( $page, $output = OBJECT, $filter = 'raw' ) { … … 6151 6231 * @param string|array $post_type Optional. Post type or array of post types. Default 'page'. 6152 6232 * @return WP_Post|array|null WP_Post (or array) on success, or null on failure. 6233 * 6234 * @phpstan-param 'OBJECT'|'ARRAY_A'|'ARRAY_N' $output 6235 * @phpstan-param string|string[] $post_type 6236 * @phpstan-return ( 6237 * $output is 'ARRAY_A' ? array<string, mixed>|null : ( 6238 * $output is 'ARRAY_N' ? array<int, mixed>|null : ( 6239 * WP_Post|null 6240 * ) 6241 * ) 6242 * ) 6153 6243 */ 6154 6244 function get_page_by_path( $page_path, $output = OBJECT, $post_type = 'page' ) { … … 6165 6255 return null; 6166 6256 } else { 6167 return get_post( $cached, $output );6257 return get_post( (int) $cached, $output ); 6168 6258 } 6169 6259 } … … 6193 6283 "; 6194 6284 6195 $pages = $wpdb->get_results( $sql, OBJECT_K ); 6285 /** @var array<object{ ID: string, post_name: string, post_parent: string, post_type: string }> $pages */ 6286 $pages = $wpdb->get_results( $sql, OBJECT_K ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- The escaping has been applied above via esc_sql(). 6196 6287 6197 6288 $revparts = array_reverse( $parts ); … … 6232 6323 6233 6324 if ( $found_id ) { 6234 return get_post( $found_id, $output );6325 return get_post( (int) $found_id, $output ); 6235 6326 } 6236 6327 … … 6651 6742 * @param bool $fire_after_hooks Optional. Whether to fire the after insert hooks. Default true. 6652 6743 * @return int|WP_Error The attachment ID on success. The value 0 or WP_Error on failure. 6744 * 6745 * @phpstan-return ( 6746 * $wp_error is false ? int : int|WP_Error 6747 * ) 6653 6748 */ 6654 6749 function wp_insert_attachment( $args, $file = false, $parent_post_id = 0, $wp_error = false, $fire_after_hooks = true ) {
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)