From 72050b685038c561d4efadb1a35390b2685d5293 Mon Sep 17 00:00:00 2001 From: Md Abul Bashar Date: Thu, 3 Dec 2026 19:38:09 +0600 Subject: [PATCH 1/3] Code Quality: Document the boolean return of update_meta_cache(). The `update_{$meta_type}_metadata_cache` filter can short-circuit the function, which then returns a boolean. Update the `@return` of the function and of the post, term and site wrappers, and remove the matching `return.type` baseline entry. --- src/wp-includes/meta.php | 3 ++- src/wp-includes/ms-site.php | 3 ++- src/wp-includes/post.php | 3 ++- src/wp-includes/taxonomy.php | 3 ++- tests/phpstan/baselines/return.type.neon | 5 ----- 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/wp-includes/meta.php b/src/wp-includes/meta.php index 64e075017648d..3cdb7df584e65 100644 --- a/src/wp-includes/meta.php +++ b/src/wp-includes/meta.php @@ -1182,7 +1182,8 @@ function delete_metadata_by_mid( $meta_type, $meta_id ) { * @param string $meta_type Type of object metadata is for. Accepts 'blog', 'post', 'comment', 'term', * 'user', or any other object type with an associated meta table. * @param string|int[] $object_ids Array or comma delimited list of object IDs to update cache for. - * @return array|false Metadata cache for the specified objects, or false on failure. + * @return array|bool Metadata cache for the specified objects, false on failure, or a boolean + * if the update was short-circuited by the filter. */ function update_meta_cache( $meta_type, $object_ids ) { global $wpdb; diff --git a/src/wp-includes/ms-site.php b/src/wp-includes/ms-site.php index 71b9823728d7a..814dee933c4ac 100644 --- a/src/wp-includes/ms-site.php +++ b/src/wp-includes/ms-site.php @@ -419,7 +419,8 @@ function update_site_cache( $sites, $update_meta_cache = true ) { * @since 5.1.0 * * @param array $site_ids List of site IDs. - * @return array|false An array of metadata on success, false if there is nothing to update. + * @return array|bool An array of metadata on success, false if there is nothing to update, + * or a boolean if the update was short-circuited by the filter. */ function update_sitemeta_cache( $site_ids ) { // Ensure this filter is hooked in even if the function is called early. diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index 6d42c97836dea..e1ce57797dffa 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -8353,7 +8353,8 @@ function update_post_parent_caches( $posts ) { * @since 2.1.0 * * @param int[] $post_ids Array of post IDs. - * @return array|false An array of metadata on success, false if there is nothing to update. + * @return array|bool An array of metadata on success, false if there is nothing to update, + * or a boolean if the update was short-circuited by the filter. */ function update_postmeta_cache( $post_ids ) { return update_meta_cache( 'post', $post_ids ); diff --git a/src/wp-includes/taxonomy.php b/src/wp-includes/taxonomy.php index 06d1d3581dd00..46f8347dd7867 100644 --- a/src/wp-includes/taxonomy.php +++ b/src/wp-includes/taxonomy.php @@ -1556,7 +1556,8 @@ function update_term_meta( $term_id, $meta_key, $meta_value, $prev_value = '' ) * @since 4.4.0 * * @param array $term_ids List of term IDs. - * @return array|false An array of metadata on success, false if there is nothing to update. + * @return array|bool An array of metadata on success, false if there is nothing to update, + * or a boolean if the update was short-circuited by the filter. */ function update_termmeta_cache( $term_ids ) { return update_meta_cache( 'term', $term_ids ); diff --git a/tests/phpstan/baselines/return.type.neon b/tests/phpstan/baselines/return.type.neon index 9143cbd2bbad7..e2bcbc565e381 100644 --- a/tests/phpstan/baselines/return.type.neon +++ b/tests/phpstan/baselines/return.type.neon @@ -68,11 +68,6 @@ parameters: identifier: return.type count: 1 path: ../../../src/wp-includes/fonts.php - - - message: '#^Function update_meta_cache\(\) should return array\|false but returns bool\.$#' - identifier: return.type - count: 1 - path: ../../../src/wp-includes/meta.php - message: '#^Function wp_post_revision_title\(\) should return string\|false but returns null\.$#' identifier: return.type From db7c591d4c32b8cd46ef7bdc5af451fcdf95b247 Mon Sep 17 00:00:00 2001 From: Md Abul Bashar Date: Thu, 3 Dec 2026 23:17:17 +0600 Subject: [PATCH 2/3] Code Quality: Narrow the array type returned by update_meta_cache(). The returned cache is keyed by object ID and holds the values of each meta key as strings. --- src/wp-includes/meta.php | 4 ++-- src/wp-includes/ms-site.php | 4 ++-- src/wp-includes/post.php | 4 ++-- src/wp-includes/taxonomy.php | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/wp-includes/meta.php b/src/wp-includes/meta.php index 3cdb7df584e65..f16cb25842818 100644 --- a/src/wp-includes/meta.php +++ b/src/wp-includes/meta.php @@ -1182,8 +1182,8 @@ function delete_metadata_by_mid( $meta_type, $meta_id ) { * @param string $meta_type Type of object metadata is for. Accepts 'blog', 'post', 'comment', 'term', * 'user', or any other object type with an associated meta table. * @param string|int[] $object_ids Array or comma delimited list of object IDs to update cache for. - * @return array|bool Metadata cache for the specified objects, false on failure, or a boolean - * if the update was short-circuited by the filter. + * @return array>|bool Metadata cache for the specified objects, false on failure, + * or a boolean if the update was short-circuited by the filter. */ function update_meta_cache( $meta_type, $object_ids ) { global $wpdb; diff --git a/src/wp-includes/ms-site.php b/src/wp-includes/ms-site.php index 814dee933c4ac..f27fcd554f6f7 100644 --- a/src/wp-includes/ms-site.php +++ b/src/wp-includes/ms-site.php @@ -419,8 +419,8 @@ function update_site_cache( $sites, $update_meta_cache = true ) { * @since 5.1.0 * * @param array $site_ids List of site IDs. - * @return array|bool An array of metadata on success, false if there is nothing to update, - * or a boolean if the update was short-circuited by the filter. + * @return array>|bool An array of metadata on success, false if there is nothing to update, + * or a boolean if the update was short-circuited by the filter. */ function update_sitemeta_cache( $site_ids ) { // Ensure this filter is hooked in even if the function is called early. diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index e1ce57797dffa..4bc87e95548ff 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -8353,8 +8353,8 @@ function update_post_parent_caches( $posts ) { * @since 2.1.0 * * @param int[] $post_ids Array of post IDs. - * @return array|bool An array of metadata on success, false if there is nothing to update, - * or a boolean if the update was short-circuited by the filter. + * @return array>|bool An array of metadata on success, false if there is nothing to update, + * or a boolean if the update was short-circuited by the filter. */ function update_postmeta_cache( $post_ids ) { return update_meta_cache( 'post', $post_ids ); diff --git a/src/wp-includes/taxonomy.php b/src/wp-includes/taxonomy.php index 46f8347dd7867..aeff433daae2d 100644 --- a/src/wp-includes/taxonomy.php +++ b/src/wp-includes/taxonomy.php @@ -1556,8 +1556,8 @@ function update_term_meta( $term_id, $meta_key, $meta_value, $prev_value = '' ) * @since 4.4.0 * * @param array $term_ids List of term IDs. - * @return array|bool An array of metadata on success, false if there is nothing to update, - * or a boolean if the update was short-circuited by the filter. + * @return array>|bool An array of metadata on success, false if there is nothing to update, + * or a boolean if the update was short-circuited by the filter. */ function update_termmeta_cache( $term_ids ) { return update_meta_cache( 'term', $term_ids ); From ba9a0a437db0f53c8b0bacdee34f6b32c4f88699 Mon Sep 17 00:00:00 2001 From: Md Abul Bashar Date: Fri, 4 Dec 2026 01:06:45 +0600 Subject: [PATCH 3/3] Code Quality: Allow integer meta keys in the update_meta_cache() return type. A numeric meta key such as `123` is stored under an integer array key. --- src/wp-includes/meta.php | 4 ++-- src/wp-includes/ms-site.php | 4 ++-- src/wp-includes/post.php | 4 ++-- src/wp-includes/taxonomy.php | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/wp-includes/meta.php b/src/wp-includes/meta.php index f16cb25842818..f06dd2e57ccea 100644 --- a/src/wp-includes/meta.php +++ b/src/wp-includes/meta.php @@ -1182,8 +1182,8 @@ function delete_metadata_by_mid( $meta_type, $meta_id ) { * @param string $meta_type Type of object metadata is for. Accepts 'blog', 'post', 'comment', 'term', * 'user', or any other object type with an associated meta table. * @param string|int[] $object_ids Array or comma delimited list of object IDs to update cache for. - * @return array>|bool Metadata cache for the specified objects, false on failure, - * or a boolean if the update was short-circuited by the filter. + * @return array>|bool Metadata cache for the specified objects, false on failure, + * or a boolean if the update was short-circuited by the filter. */ function update_meta_cache( $meta_type, $object_ids ) { global $wpdb; diff --git a/src/wp-includes/ms-site.php b/src/wp-includes/ms-site.php index f27fcd554f6f7..9fdf0937b1717 100644 --- a/src/wp-includes/ms-site.php +++ b/src/wp-includes/ms-site.php @@ -419,8 +419,8 @@ function update_site_cache( $sites, $update_meta_cache = true ) { * @since 5.1.0 * * @param array $site_ids List of site IDs. - * @return array>|bool An array of metadata on success, false if there is nothing to update, - * or a boolean if the update was short-circuited by the filter. + * @return array>|bool An array of metadata on success, false if there is nothing to update, + * or a boolean if the update was short-circuited by the filter. */ function update_sitemeta_cache( $site_ids ) { // Ensure this filter is hooked in even if the function is called early. diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index 4bc87e95548ff..5cb2d3ce72da3 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -8353,8 +8353,8 @@ function update_post_parent_caches( $posts ) { * @since 2.1.0 * * @param int[] $post_ids Array of post IDs. - * @return array>|bool An array of metadata on success, false if there is nothing to update, - * or a boolean if the update was short-circuited by the filter. + * @return array>|bool An array of metadata on success, false if there is nothing to update, + * or a boolean if the update was short-circuited by the filter. */ function update_postmeta_cache( $post_ids ) { return update_meta_cache( 'post', $post_ids ); diff --git a/src/wp-includes/taxonomy.php b/src/wp-includes/taxonomy.php index aeff433daae2d..4a428ef3363d9 100644 --- a/src/wp-includes/taxonomy.php +++ b/src/wp-includes/taxonomy.php @@ -1556,8 +1556,8 @@ function update_term_meta( $term_id, $meta_key, $meta_value, $prev_value = '' ) * @since 4.4.0 * * @param array $term_ids List of term IDs. - * @return array>|bool An array of metadata on success, false if there is nothing to update, - * or a boolean if the update was short-circuited by the filter. + * @return array>|bool An array of metadata on success, false if there is nothing to update, + * or a boolean if the update was short-circuited by the filter. */ function update_termmeta_cache( $term_ids ) { return update_meta_cache( 'term', $term_ids );