Commit 59838e6bb2 for wordpress.org

commit 59838e6bb200526b71683f5fb01752e20ead15bb
Author: swissspidy <swissspidy@git.wordpress.org>
Date:   Wed Nov 25 11:13:00 2026 +0000

    Code Quality: Add PHPStan array shapes.

    Document the known keys of arrays that functions accept or return as array shapes, such as the HTTP API response, which is defined once on `WP_Http` and reused by the remote request functions, and the widget, robots, and admin helper arrays. This lets static analysis check how the values are used.

    Developed in: https://github.com/WordPress/wordpress-develop/pull/13894

    Props swissspidy, westonruter, marian1, johnbillion.
    See #66739.
    Built from https://develop.svn.wordpress.org/trunk@65777


    git-svn-id: http://core.svn.wordpress.org/trunk@64806 1a063a9b-81f0-0310-95a4-ce76da25c4cd

diff --git a/wp-admin/includes/media.php b/wp-admin/includes/media.php
index 9f5b87ce85..543d2c7f89 100644
--- a/wp-admin/includes/media.php
+++ b/wp-admin/includes/media.php
@@ -1237,6 +1237,8 @@ function image_align_input_fields( $post, $checked = '' ) {
  * @param WP_Post     $post
  * @param bool|string $check
  * @return array<string, string> An array of data for the image size input fields.
+ *
+ * @phpstan-return array{label: string, input: 'html', html: string}
  */
 function image_size_input_fields( $post, $check = '' ) {
 	/**
@@ -1937,6 +1939,8 @@ function get_media_item( $attachment_id, $args = null ) {
  * @param int   $attachment_id
  * @param array $args
  * @return array<string, string> An array containing the media item and its metadata.
+ *
+ * @phpstan-return array{item: string, meta: string}
  */
 function get_compat_media_markup( $attachment_id, $args = null ) {
 	$post = get_post( $attachment_id );
diff --git a/wp-admin/includes/ms.php b/wp-admin/includes/ms.php
index 8e3c141af2..ff9fb830c4 100644
--- a/wp-admin/includes/ms.php
+++ b/wp-admin/includes/ms.php
@@ -1187,6 +1187,8 @@ function network_edit_site_nav( $args = array() ) {
  * @since 4.9.0
  *
  * @return array Help tab arguments.
+ *
+ * @phpstan-return array{id: non-falsy-string, title: string, content: non-falsy-string}
  */
 function get_site_screen_help_tab_args() {
 	return array(
diff --git a/wp-admin/includes/nav-menu.php b/wp-admin/includes/nav-menu.php
index dc90feb3b3..68726f4062 100644
--- a/wp-admin/includes/nav-menu.php
+++ b/wp-admin/includes/nav-menu.php
@@ -1348,6 +1348,16 @@ function wp_get_nav_menu_to_edit( $menu_id = 0 ) {
  * @since 3.0.0
  *
  * @return string[] Array of column titles keyed by their column name.
+ *
+ * @phpstan-return array{
+ *     _title: string,
+ *     cb: non-falsy-string,
+ *     link-target: string,
+ *     title-attribute: string,
+ *     css-classes: string,
+ *     xfn: string,
+ *     description: string,
+ * }
  */
 function wp_nav_menu_manage_columns() {
 	return array(
diff --git a/wp-admin/includes/post.php b/wp-admin/includes/post.php
index f08f81766d..7d900970fd 100644
--- a/wp-admin/includes/post.php
+++ b/wp-admin/includes/post.php
@@ -1220,6 +1220,8 @@ function _fix_attachment_links( $post ) {
  *
  * @param string $type The post_type you want the statuses for. Default 'post'.
  * @return string[] An array of all the statuses for the supplied post type.
+ *
+ * @phpstan-return list<string>
  */
 function get_available_post_statuses( $type = 'post' ) {
 	$statuses = wp_count_posts( $type );
diff --git a/wp-includes/class-wp-dependencies.php b/wp-includes/class-wp-dependencies.php
index f9aa688cca..204ade1d6f 100644
--- a/wp-includes/class-wp-dependencies.php
+++ b/wp-includes/class-wp-dependencies.php
@@ -73,7 +73,9 @@ class WP_Dependencies {
 	 *
 	 * @since 2.8.0
 	 *
-	 * @var (int|false)[]
+	 * @var array<string, int|false>
+	 *
+	 * @phpstan-var array<non-empty-string, int|false>
 	 */
 	public $groups = array();

diff --git a/wp-includes/class-wp-http.php b/wp-includes/class-wp-http.php
index 66cf907d0e..de53011d11 100644
--- a/wp-includes/class-wp-http.php
+++ b/wp-includes/class-wp-http.php
@@ -29,6 +29,15 @@ if ( ! class_exists( 'WpOrg\Requests\Autoload' ) ) {
  * Debugging includes several actions, which pass different variables for debugging the HTTP API.
  *
  * @since 2.7.0
+ *
+ * @phpstan-type HTTP_Response array{
+ *     headers: \WpOrg\Requests\Utility\CaseInsensitiveDictionary|array<string, string>,
+ *     body: string,
+ *     response: array{code: int|false, message: string|false},
+ *     cookies: WP_Http_Cookie[],
+ *     filename?: string|null,
+ *     http_response?: WP_HTTP_Requests_Response|null,
+ * }
  */
 #[AllowDynamicProperties]
 class WP_Http {
@@ -166,6 +175,8 @@ class WP_Http {
 	 *     @type string|null                                            $filename      Optional. Filename of the response.
 	 *     @type WP_HTTP_Requests_Response|null                         $http_response Response object.
 	 * }
+	 *
+	 * @phpstan-return HTTP_Response|WP_Error
 	 */
 	public function request( $url, $args = array() ) {
 		$defaults = array(
@@ -647,6 +658,8 @@ class WP_Http {
 	 * @param string|array $args Optional. Override the defaults.
 	 * @return array|WP_Error Array containing 'headers', 'body', 'response', 'cookies', 'filename'.
 	 *                        A WP_Error instance upon error. See WP_Http::response() for details.
+	 *
+	 * @phpstan-return HTTP_Response|WP_Error
 	 */
 	public function post( $url, $args = array() ) {
 		$defaults    = array( 'method' => 'POST' );
@@ -665,6 +678,8 @@ class WP_Http {
 	 * @param string|array $args Optional. Override the defaults.
 	 * @return array|WP_Error Array containing 'headers', 'body', 'response', 'cookies', 'filename'.
 	 *                        A WP_Error instance upon error. See WP_Http::response() for details.
+	 *
+	 * @phpstan-return HTTP_Response|WP_Error
 	 */
 	public function get( $url, $args = array() ) {
 		$defaults    = array( 'method' => 'GET' );
@@ -683,6 +698,8 @@ class WP_Http {
 	 * @param string|array $args Optional. Override the defaults.
 	 * @return array|WP_Error Array containing 'headers', 'body', 'response', 'cookies', 'filename'.
 	 *                        A WP_Error instance upon error. See WP_Http::response() for details.
+	 *
+	 * @phpstan-return HTTP_Response|WP_Error
 	 */
 	public function head( $url, $args = array() ) {
 		$defaults    = array( 'method' => 'HEAD' );
diff --git a/wp-includes/class-wp-widget.php b/wp-includes/class-wp-widget.php
index f1d432c0d3..9cc2d79a7a 100644
--- a/wp-includes/class-wp-widget.php
+++ b/wp-includes/class-wp-widget.php
@@ -109,6 +109,22 @@ class WP_Widget {
 	 * @param array $args     Display arguments including 'before_title', 'after_title',
 	 *                        'before_widget', and 'after_widget'.
 	 * @param array $instance The settings for the particular instance of the widget.
+	 *
+	 * @phpstan-param array{
+	 *     name?: string,
+	 *     id?: string,
+	 *     description?: string,
+	 *     class?: string,
+	 *     before_widget: string,
+	 *     after_widget: string,
+	 *     before_title: string,
+	 *     after_title: string,
+	 *     before_sidebar?: string,
+	 *     after_sidebar?: string,
+	 *     show_in_rest?: bool,
+	 *     widget_id?: string,
+	 *     widget_name?: string,
+	 * } $args
 	 */
 	public function widget( $args, $instance ) {
 		die( 'function WP_Widget::widget() must be overridden in a subclass.' );
diff --git a/wp-includes/feed.php b/wp-includes/feed.php
index 952194c1bc..016d6a86b3 100644
--- a/wp-includes/feed.php
+++ b/wp-includes/feed.php
@@ -599,6 +599,8 @@ function atom_enclosure() {
  *
  * @param string $data Input string.
  * @return array array(type, value)
+ *
+ * @phpstan-return array{'html'|'text'|'xhtml', string}
  */
 function prep_atom_text_construct( $data ) {
 	if ( ! str_contains( $data, '<' ) && ! str_contains( $data, '&' ) ) {
diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php
index 14836be11d..6bfba5a873 100644
--- a/wp-includes/formatting.php
+++ b/wp-includes/formatting.php
@@ -611,6 +611,8 @@ function wpautop( $text, $br = true ) {
  *
  * @param string $input The text which has to be formatted.
  * @return string[] Array of the formatted text.
+ *
+ * @phpstan-return non-empty-list<string>
  */
 function wp_html_split( $input ) {
 	return preg_split( get_html_split_regex(), $input, -1, PREG_SPLIT_DELIM_CAPTURE );
diff --git a/wp-includes/functions.php b/wp-includes/functions.php
index 693ba8c388..9f05a8c592 100644
--- a/wp-includes/functions.php
+++ b/wp-includes/functions.php
@@ -8394,6 +8394,7 @@ function wp_unique_prefixed_id( $prefix = '' ) {
  * @param string $prefix Optional. A prefix to prepend to the generated ID. Default empty string.
  * @return string The generated unique ID for the array.
  *
+ * @phpstan-param non-empty-array $data
  * @phpstan-return ( $prefix is lowercase-string ? lowercase-string&non-falsy-string : non-falsy-string )
  */
 function wp_unique_id_from_values( array $data, string $prefix = '' ): string {
diff --git a/wp-includes/http.php b/wp-includes/http.php
index 34e1f452a7..ac589db1e9 100644
--- a/wp-includes/http.php
+++ b/wp-includes/http.php
@@ -48,6 +48,15 @@ function _wp_http_get_object() {
  *                     See WP_Http::request() for information on accepted arguments.
  * @return array|WP_Error The response or WP_Error on failure.
  *                        See WP_Http::request() for information on return value.
+ *
+ * @phpstan-return array{
+ *     headers: \WpOrg\Requests\Utility\CaseInsensitiveDictionary|array<string, string>,
+ *     body: string,
+ *     response: array{code: int|false, message: string|false},
+ *     cookies: WP_Http_Cookie[],
+ *     filename?: string|null,
+ *     http_response?: WP_HTTP_Requests_Response|null,
+ * }|WP_Error
  */
 function wp_safe_remote_request( $url, $args = array() ) {
 	$args['reject_unsafe_urls'] = true;
@@ -77,6 +86,15 @@ function wp_safe_remote_request( $url, $args = array() ) {
  *                     See WP_Http::request() for information on accepted arguments.
  * @return array|WP_Error The response or WP_Error on failure.
  *                        See WP_Http::request() for information on return value.
+ *
+ * @phpstan-return array{
+ *     headers: \WpOrg\Requests\Utility\CaseInsensitiveDictionary|array<string, string>,
+ *     body: string,
+ *     response: array{code: int|false, message: string|false},
+ *     cookies: WP_Http_Cookie[],
+ *     filename?: string|null,
+ *     http_response?: WP_HTTP_Requests_Response|null,
+ * }|WP_Error
  */
 function wp_safe_remote_get( $url, $args = array() ) {
 	$args['reject_unsafe_urls'] = true;
@@ -106,6 +124,15 @@ function wp_safe_remote_get( $url, $args = array() ) {
  *                     See WP_Http::request() for information on accepted arguments.
  * @return array|WP_Error The response or WP_Error on failure.
  *                        See WP_Http::request() for information on return value.
+ *
+ * @phpstan-return array{
+ *     headers: \WpOrg\Requests\Utility\CaseInsensitiveDictionary|array<string, string>,
+ *     body: string,
+ *     response: array{code: int|false, message: string|false},
+ *     cookies: WP_Http_Cookie[],
+ *     filename?: string|null,
+ *     http_response?: WP_HTTP_Requests_Response|null,
+ * }|WP_Error
  */
 function wp_safe_remote_post( $url, $args = array() ) {
 	$args['reject_unsafe_urls'] = true;
@@ -135,6 +162,15 @@ function wp_safe_remote_post( $url, $args = array() ) {
  *                     See WP_Http::request() for information on accepted arguments.
  * @return array|WP_Error The response or WP_Error on failure.
  *                        See WP_Http::request() for information on return value.
+ *
+ * @phpstan-return array{
+ *     headers: \WpOrg\Requests\Utility\CaseInsensitiveDictionary|array<string, string>,
+ *     body: string,
+ *     response: array{code: int|false, message: string|false},
+ *     cookies: WP_Http_Cookie[],
+ *     filename?: string|null,
+ *     http_response?: WP_HTTP_Requests_Response|null,
+ * }|WP_Error
  */
 function wp_safe_remote_head( $url, $args = array() ) {
 	$args['reject_unsafe_urls'] = true;
@@ -162,6 +198,15 @@ function wp_safe_remote_head( $url, $args = array() ) {
  *                     See WP_Http::request() for information on accepted arguments.
  * @return array|WP_Error The response array or a WP_Error on failure.
  *                        See WP_Http::request() for information on return value.
+ *
+ * @phpstan-return array{
+ *     headers: \WpOrg\Requests\Utility\CaseInsensitiveDictionary|array<string, string>,
+ *     body: string,
+ *     response: array{code: int|false, message: string|false},
+ *     cookies: WP_Http_Cookie[],
+ *     filename?: string|null,
+ *     http_response?: WP_HTTP_Requests_Response|null,
+ * }|WP_Error
  */
 function wp_remote_request( $url, $args = array() ) {
 	$http = _wp_http_get_object();
@@ -183,6 +228,15 @@ function wp_remote_request( $url, $args = array() ) {
  *                     See WP_Http::request() for information on accepted arguments.
  * @return array|WP_Error The response or WP_Error on failure.
  *                        See WP_Http::request() for information on return value.
+ *
+ * @phpstan-return array{
+ *     headers: \WpOrg\Requests\Utility\CaseInsensitiveDictionary|array<string, string>,
+ *     body: string,
+ *     response: array{code: int|false, message: string|false},
+ *     cookies: WP_Http_Cookie[],
+ *     filename?: string|null,
+ *     http_response?: WP_HTTP_Requests_Response|null,
+ * }|WP_Error
  */
 function wp_remote_get( $url, $args = array() ) {
 	$http = _wp_http_get_object();
@@ -204,6 +258,15 @@ function wp_remote_get( $url, $args = array() ) {
  *                     See WP_Http::request() for information on accepted arguments.
  * @return array|WP_Error The response or WP_Error on failure.
  *                        See WP_Http::request() for information on return value.
+ *
+ * @phpstan-return array{
+ *     headers: \WpOrg\Requests\Utility\CaseInsensitiveDictionary|array<string, string>,
+ *     body: string,
+ *     response: array{code: int|false, message: string|false},
+ *     cookies: WP_Http_Cookie[],
+ *     filename?: string|null,
+ *     http_response?: WP_HTTP_Requests_Response|null,
+ * }|WP_Error
  */
 function wp_remote_post( $url, $args = array() ) {
 	$http = _wp_http_get_object();
@@ -225,6 +288,15 @@ function wp_remote_post( $url, $args = array() ) {
  *                     See WP_Http::request() for information on accepted arguments.
  * @return array|WP_Error The response or WP_Error on failure.
  *                        See WP_Http::request() for information on return value.
+ *
+ * @phpstan-return array{
+ *     headers: \WpOrg\Requests\Utility\CaseInsensitiveDictionary|array<string, string>,
+ *     body: string,
+ *     response: array{code: int|false, message: string|false},
+ *     cookies: WP_Http_Cookie[],
+ *     filename?: string|null,
+ *     http_response?: WP_HTTP_Requests_Response|null,
+ * }|WP_Error
  */
 function wp_remote_head( $url, $args = array() ) {
 	$http = _wp_http_get_object();
diff --git a/wp-includes/nav-menu.php b/wp-includes/nav-menu.php
index 191c8d0648..2420a2583c 100644
--- a/wp-includes/nav-menu.php
+++ b/wp-includes/nav-menu.php
@@ -85,7 +85,7 @@ function is_nav_menu( $menu ) {
  *
  * @global array $_wp_registered_nav_menus
  *
- * @param string[] $locations Associative array of menu location identifiers (like a slug) and descriptive text.
+ * @param array<string, string> $locations Associative array of menu location identifiers (like a slug) and descriptive text.
  */
 function register_nav_menus( $locations = array() ) {
 	global $_wp_registered_nav_menus;
diff --git a/wp-includes/robots-template.php b/wp-includes/robots-template.php
index e719e745d6..49216bfa74 100644
--- a/wp-includes/robots-template.php
+++ b/wp-includes/robots-template.php
@@ -64,8 +64,8 @@ function wp_robots() {
  *
  * @see wp_robots_no_robots()
  *
- * @param array $robots Associative array of robots directives.
- * @return array Filtered robots directives.
+ * @param array<string, bool|string> $robots Associative array of robots directives.
+ * @return array<string, bool|string> Filtered robots directives.
  */
 function wp_robots_noindex( array $robots ) {
 	if ( ! get_option( 'blog_public' ) ) {
@@ -86,8 +86,8 @@ function wp_robots_noindex( array $robots ) {
  *
  * @see wp_robots_no_robots()
  *
- * @param array $robots Associative array of robots directives.
- * @return array Filtered robots directives.
+ * @param array<string, bool|string> $robots Associative array of robots directives.
+ * @return array<string, bool|string> Filtered robots directives.
  */
 function wp_robots_noindex_embeds( array $robots ) {
 	if ( is_embed() ) {
@@ -112,8 +112,8 @@ function wp_robots_noindex_embeds( array $robots ) {
  *
  * @see wp_robots_no_robots()
  *
- * @param array $robots Associative array of robots directives.
- * @return array Filtered robots directives.
+ * @param array<string, bool|string> $robots Associative array of robots directives.
+ * @return array<string, bool|string> Filtered robots directives.
  */
 function wp_robots_noindex_search( array $robots ) {
 	if ( is_search() ) {
@@ -134,8 +134,10 @@ function wp_robots_noindex_search( array $robots ) {
  *
  * @since 5.7.0
  *
- * @param array $robots Associative array of robots directives.
- * @return array Filtered robots directives.
+ * @param array<string, bool|string> $robots Associative array of robots directives.
+ * @return array<string, bool|string> Filtered robots directives.
+ *
+ * @phpstan-return array{ noindex: true, ...<string, bool|string> }
  */
 function wp_robots_no_robots( array $robots ) {
 	$robots['noindex'] = true;
@@ -161,8 +163,10 @@ function wp_robots_no_robots( array $robots ) {
  *
  * @since 5.7.0
  *
- * @param array $robots Associative array of robots directives.
- * @return array Filtered robots directives.
+ * @param array<string, bool|string> $robots Associative array of robots directives.
+ * @return array<string, bool|string> Filtered robots directives.
+ *
+ * @phpstan-return array{ noindex: true, noarchive: true, ...<string, bool|string> }
  */
 function wp_robots_sensitive_page( array $robots ) {
 	$robots['noindex']   = true;
@@ -182,8 +186,8 @@ function wp_robots_sensitive_page( array $robots ) {
  *
  * @since 5.7.0
  *
- * @param array $robots Associative array of robots directives.
- * @return array Filtered robots directives.
+ * @param array<string, bool|string> $robots Associative array of robots directives.
+ * @return array<string, bool|string> Filtered robots directives.
  */
 function wp_robots_max_image_preview_large( array $robots ) {
 	if ( get_option( 'blog_public' ) ) {
diff --git a/wp-includes/shortcodes.php b/wp-includes/shortcodes.php
index bc946676bd..32429b871d 100644
--- a/wp-includes/shortcodes.php
+++ b/wp-includes/shortcodes.php
@@ -188,6 +188,8 @@ function has_shortcode( $content, $tag ) {
  *
  * @param string $content The content to check.
  * @return string[] An array of registered shortcode names found in the content.
+ *
+ * @phpstan-return list<string>
  */
 function get_shortcode_tags_in_content( $content ) {
 	if ( ! str_contains( $content, '[' ) ) {
diff --git a/wp-includes/version.php b/wp-includes/version.php
index a73939508a..e2e7b133ee 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
  *
  * @global string $wp_version
  */
-$wp_version = '7.3-alpha-65776';
+$wp_version = '7.3-alpha-65777';

 /**
  * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
diff --git a/wp-includes/widgets.php b/wp-includes/widgets.php
index 31fce41b65..b6d9c01885 100644
--- a/wp-includes/widgets.php
+++ b/wp-includes/widgets.php
@@ -1717,6 +1717,25 @@ function wp_widget_rss_output( $rss, $args = array() ) {
  *
  * @param array|string $args   Values for input fields.
  * @param array        $inputs Override default display options.
+ *
+ * @phpstan-param array{
+ *     number: int|string,
+ *     error?: string|false,
+ *     title?: string,
+ *     url?: string,
+ *     items?: int,
+ *     show_summary?: int,
+ *     show_author?: int,
+ *     show_date?: int,
+ * } $args
+ * @phpstan-param array{
+ *     title?: bool|'hidden',
+ *     url?: bool|'hidden',
+ *     items?: bool|'hidden',
+ *     show_summary?: bool|'hidden',
+ *     show_author?: bool|'hidden',
+ *     show_date?: bool|'hidden',
+ * } $inputs
  */
 function wp_widget_rss_form( $args, $inputs = null ) {
 	$default_inputs = array(
@@ -1802,6 +1821,17 @@ foreach ( array_keys( $default_inputs ) as $input ) :
  * @param array $widget_rss RSS widget feed data. Expects unescaped data.
  * @param bool  $check_feed Optional. Whether to check feed for errors. Default true.
  * @return array
+ *
+ * @phpstan-return array{
+ *     title: string,
+ *     url: string,
+ *     link: string,
+ *     items: int<1, 20>,
+ *     error: string|false,
+ *     show_summary: int,
+ *     show_author: int,
+ *     show_date: int,
+ * }
  */
 function wp_widget_rss_process( $widget_rss, $check_feed = true ) {
 	$items = (int) $widget_rss['items'];