From b8ffd73debd51df7c799c2886a5719e0c50aadcb Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Wed, 4 Nov 2026 14:14:34 +0530 Subject: [PATCH 1/4] Docs: Document the deprecated integer `$args` in `wp_get_recent_posts()`. `wp_get_recent_posts()` still accepts an integer number of posts, which has been deprecated since 3.1.0. The `@param` tag documented `$args` as `array` only, so PHPStan concluded that `is_numeric( $args )` can never be true. It then reported that the `absint()` call in that branch receives an unresolvable type. This change documents `$args` as `array|int`, states the deprecation in its description, deletes the now empty `argument.unresolvableType` baseline, and removes its `includes` line from `phpstan.neon.dist`. There is no runtime change. See #65817. Co-Authored-By: Claude Opus 5.5 --- phpstan.neon.dist | 1 - src/wp-includes/post.php | 9 ++++--- .../baselines/argument.unresolvableType.neon | 25 ------------------- 3 files changed, 5 insertions(+), 30 deletions(-) delete mode 100644 tests/phpstan/baselines/argument.unresolvableType.neon diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 655bb9bbc807c..0af28d696b2af 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -23,7 +23,6 @@ includes: # and the list between the markers. Do not edit that list by hand. # phpstan:baselines start - tests/phpstan/baselines/argument.type.neon - - tests/phpstan/baselines/argument.unresolvableType.neon - tests/phpstan/baselines/assign.propertyType.neon - tests/phpstan/baselines/binaryOp.invalid.neon - tests/phpstan/baselines/booleanAnd.alwaysFalse.neon diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index 5806d879f1c5e..e186de3c5ce1c 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -4707,10 +4707,11 @@ function wp_get_post_terms( $post_id = 0, $taxonomy = 'post_tag', $args = array( * * @see get_posts() * - * @param array $args Optional. Arguments to retrieve posts. Default empty array. - * @param string $output Optional. The required return type. One of OBJECT or ARRAY_A, which - * correspond to a WP_Post object or an associative array, respectively. - * Default ARRAY_A. + * @param array|int $args Optional. Arguments to retrieve posts. Passing an integer number + * of posts is deprecated since 3.1.0. Default empty array. + * @param string $output Optional. The required return type. One of OBJECT or ARRAY_A, which + * correspond to a WP_Post object or an associative array, respectively. + * Default ARRAY_A. * @return array|false Array of recent posts, where the type of each element is determined * by the `$output` parameter. Empty array on failure. * diff --git a/tests/phpstan/baselines/argument.unresolvableType.neon b/tests/phpstan/baselines/argument.unresolvableType.neon deleted file mode 100644 index 3e8cdcb76c85d..0000000000000 --- a/tests/phpstan/baselines/argument.unresolvableType.neon +++ /dev/null @@ -1,25 +0,0 @@ -# PHPStan baseline for the `argument.unresolvableType` errors in WordPress core. -# -# https://phpstan.org/error-identifiers/argument.unresolvableType -# -# Each entry is scoped to a single file and carries an exact occurrence count, -# so that a new instance is reported as a new error rather than being absorbed -# silently. Fixing an occurrence therefore means decrementing or removing its -# entry here as part of the same change. -# -# The goal is to empty this file and delete it, along with the `includes` entry -# for it in phpstan.neon.dist. -# -# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with -# -# composer phpstan:baselines -- --identifier=argument.unresolvableType -# -# which reruns the analysis with this file suppressed so the errors surface again. - -parameters: - ignoreErrors: - - - message: '#^Parameter \#1 \$maybeint of function absint contains unresolvable type\.$#' - identifier: argument.unresolvableType - count: 1 - path: ../../../src/wp-includes/post.php From 38433cff3e90f3e066cebbf1a6ba346b37951560 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 25 Nov 2026 00:24:39 -0800 Subject: [PATCH 2/4] Docs: Document the arguments of `wp_get_recent_posts()`. Add a hash for `$args` listing the keys whose defaults differ from those of `get_posts()`, and a `@phpstan-param` that narrows the deprecated integer form to `positive-int`. The function passes an integer through `absint()`, so a caller passing a negative number silently gets that many posts as a positive count, and one passing `0` gets the number from the `posts_per_page` option. PHPStan now flags those calls. The shape is written by hand rather than derived from the hash, since the hash cannot express `positive-int`, as in `wp_delete_term()`. It is left open with `...`, because any `WP_Query` argument is accepted. Co-Authored-By: Claude Opus 5.5 (medium effort) Claude-Code-Session-Id: afd4d078-9c23-4da0-9ee0-7b1e32f41dd6 --- src/wp-includes/post.php | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index 1741fb187f8be..ea29c94631211 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -4708,14 +4708,32 @@ function wp_get_post_terms( $post_id = 0, $taxonomy = 'post_tag', $args = array( * * @see get_posts() * - * @param array|int $args Optional. Arguments to retrieve posts. Passing an integer number - * of posts is deprecated since 3.1.0. Default empty array. + * @param array|int $args { + * Optional. Arguments to retrieve posts. See {@see get_posts()} and + * {@see WP_Query::parse_query()} for all available arguments. Those listed here + * have defaults that differ. Passing an integer number of posts is deprecated + * since 3.1.0. Default empty array. + * + * @type int $numberposts Total number of posts to retrieve. Accepts -1 for all. + * Default 10. + * @type int $offset The number of posts to offset before retrieval. Default 0. + * @type string|array $orderby Sort retrieved posts by parameter. Default 'post_date'. + * @type string|string[] $post_status A post status (string) or array of post statuses. + * Default 'draft, publish, future, pending, private'. + * } * @param string $output Optional. The required return type. One of OBJECT or ARRAY_A, which * correspond to a WP_Post object or an associative array, respectively. * Default ARRAY_A. * @return array|false Array of recent posts, where the type of each element is determined * by the `$output` parameter. Empty array on failure. * + * @phpstan-param positive-int|array{ + * numberposts?: int, + * offset?: int, + * orderby?: string|array, + * post_status?: string|string[], + * ... + * } $args * @phpstan-param 'OBJECT'|'ARRAY_A' $output * @phpstan-return ( * $output is 'ARRAY_A' ? array> : WP_Post[]|false From ff55202fadb74f194a7d644bbf976e5f02e2e60d Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 25 Nov 2026 00:31:11 -0800 Subject: [PATCH 3/4] Code Quality: Type the arguments `wp_get_recent_posts()` passes to `get_posts()`. The inline `@var` on the parsed arguments only typed `fields`, so every other key was `mixed`, and at level 10 PHPStan reported that the array could not be passed to `get_posts()`, whose hash types `numberposts`, `category`, `include`, `exclude`, and `suppress_filters`. The `@var` now types those keys too. The `$args` shape gains the same keys, so callers are checked against the same contract as callers of `get_posts()`. The `include` and `exclude` defaults change from `''` to `array()`, matching `get_posts()` and the documented `int[]`. There is no runtime change, since `get_posts()` only reads either one when it is not empty. Co-Authored-By: Claude Opus 5.5 (medium effort) Claude-Code-Session-Id: afd4d078-9c23-4da0-9ee0-7b1e32f41dd6 --- src/wp-includes/post.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index ea29c94631211..d1075035d7363 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -4732,6 +4732,10 @@ function wp_get_post_terms( $post_id = 0, $taxonomy = 'post_tag', $args = array( * offset?: int, * orderby?: string|array, * post_status?: string|string[], + * category?: int|string, + * include?: int[], + * exclude?: int[], + * suppress_filters?: bool, * ... * } $args * @phpstan-param 'OBJECT'|'ARRAY_A' $output @@ -4753,8 +4757,8 @@ function wp_get_recent_posts( $args = array(), $output = ARRAY_A ) { 'category' => 0, 'orderby' => 'post_date', 'order' => 'DESC', - 'include' => '', - 'exclude' => '', + 'include' => array(), + 'exclude' => array(), 'meta_key' => '', 'meta_value' => '', 'post_type' => 'post', @@ -4762,7 +4766,7 @@ function wp_get_recent_posts( $args = array(), $output = ARRAY_A ) { 'suppress_filters' => true, ); - /** @var array{ fields: null, ... } $parsed_args */ + /** @var array{ numberposts: int, category: int|string, include: int[], exclude: int[], suppress_filters: bool, fields: null, ... } $parsed_args */ $parsed_args = wp_parse_args( $args, $defaults ); $results = get_posts( $parsed_args ); From 24c323ee32925bbc80af85579e2626538acc25ae Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 25 Nov 2026 00:35:27 -0800 Subject: [PATCH 4/4] Code Quality: Limit `fields` in `wp_get_recent_posts()` to full post objects. The inline `@var` on the parsed arguments pinned `fields` to `null` so that the conditional return type of `get_posts()` resolves to `WP_Post[]`. Nothing checked that claim, so a caller could pass `'fields' => 'ids'` unflagged, and with the default `ARRAY_A` output `get_object_vars()` then receives an integer and throws a `TypeError`. The `$args` shape now limits `fields` to `''` or `'all'`, so PHPStan flags callers that ask for IDs, and the `@var` repeats that type in place of `null`. There is no runtime change. Co-Authored-By: Claude Opus 5.5 (medium effort) Claude-Code-Session-Id: afd4d078-9c23-4da0-9ee0-7b1e32f41dd6 --- src/wp-includes/post.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index d1075035d7363..6d42c97836dea 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -4736,6 +4736,7 @@ function wp_get_post_terms( $post_id = 0, $taxonomy = 'post_tag', $args = array( * include?: int[], * exclude?: int[], * suppress_filters?: bool, + * fields?: ''|'all', * ... * } $args * @phpstan-param 'OBJECT'|'ARRAY_A' $output @@ -4766,7 +4767,7 @@ function wp_get_recent_posts( $args = array(), $output = ARRAY_A ) { 'suppress_filters' => true, ); - /** @var array{ numberposts: int, category: int|string, include: int[], exclude: int[], suppress_filters: bool, fields: null, ... } $parsed_args */ + /** @var array{ numberposts: int, category: int|string, include: int[], exclude: int[], suppress_filters: bool, fields?: ''|'all', ... } $parsed_args */ $parsed_args = wp_parse_args( $args, $defaults ); $results = get_posts( $parsed_args );