Commit ac2a77f2ec for wordpress.org

commit ac2a77f2ec15cdb6db4e6e71a030fce40a47b4a4
Author: jorgefilipecosta <jorgefilipecosta@1a063a9b-81f0-0310-95a4-ce76da25c4cd>
Date:   Wed Dec 2 18:55:02 2026 +0000

    Abilities API: Resolve the PHPStan strict baseline errors in the core abilities.

    Narrows the types in the content, settings and users abilities so `src/wp-includes/abilities` passes the strict PHPStan configuration without baseline entries. Removes the 20 entries and the `cast.double`, `cast.string` and `foreach.nonIterable` baselines they emptied.
    Documents the types that `rest_is_boolean()` and `rest_is_integer()` accept and assert, and checks post type capabilities through a helper that requires them to be strings. The content query also checks that the page size is an integer, and it primes caches for and formats only the `WP_Post` results. Settings exposure names are cast to a string only when they are scalar.

    Props jorgefilipecosta.
    Fixes #66912.
    Built from https://develop.svn.wordpress.org/trunk@65864


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

diff --git a/wp-includes/abilities/class-wp-abilities-content.php b/wp-includes/abilities/class-wp-abilities-content.php
index f5a7e881b1..3dd9f9929d 100644
--- a/wp-includes/abilities/class-wp-abilities-content.php
+++ b/wp-includes/abilities/class-wp-abilities-content.php
@@ -303,7 +303,22 @@ final class WP_Abilities_Content {
 	 * @return bool True if the status may be queried.
 	 */
 	private function can_query_status( string $status, WP_Post_Type $post_type_object ): bool {
-		return in_array( $status, array( 'publish', 'private' ), true ) || is_post_status_viewable( $status ) || current_user_can( $post_type_object->cap->edit_posts );
+		return in_array( $status, array( 'publish', 'private' ), true ) || is_post_status_viewable( $status ) || $this->current_user_can_for_post_type( $post_type_object, 'edit_posts' );
+	}
+
+	/**
+	 * Checks whether the current user has a capability of a post type, such as `edit_posts`.
+	 *
+	 * @since 7.3.0
+	 *
+	 * @param WP_Post_Type $post_type_object The post type.
+	 * @param string       $capability       The name of the capability in the post type's `cap` object.
+	 * @return bool Whether the current user has the capability.
+	 */
+	private function current_user_can_for_post_type( WP_Post_Type $post_type_object, string $capability ): bool {
+		$cap = $post_type_object->cap->$capability ?? null;
+
+		return is_string( $cap ) && current_user_can( $cap );
 	}

 	/**
@@ -606,7 +621,7 @@ final class WP_Abilities_Content {
 			'post_status'            => $this->normalize_statuses( $statuses, $post_type_object, $lists_posts ),
 			'posts_per_page'         => $per_page,
 			'paged'                  => $page,
-			'perm'                   => current_user_can( $post_type_object->cap->read_private_posts ) ? '' : 'readable',
+			'perm'                   => $this->current_user_can_for_post_type( $post_type_object, 'read_private_posts' ) ? '' : 'readable',
 			'ignore_sticky_posts'    => true,
 			'update_post_meta_cache' => $prime_post_caches,
 			'update_post_term_cache' => $prime_post_caches,
@@ -646,8 +661,8 @@ final class WP_Abilities_Content {
 		 * does, since query filters such as `pre_get_posts` callbacks can change it. Without
 		 * paging, the query returns every post on one page.
 		 */
-		$query_per_page = (int) $query->get( 'posts_per_page' );
-		if ( $query->get( 'nopaging' ) || $query_per_page < 1 ) {
+		$query_per_page = $query->get( 'posts_per_page' );
+		if ( $query->get( 'nopaging' ) || ! is_int( $query_per_page ) || $query_per_page < 1 ) {
 			$total_pages = $total > 0 ? 1 : 0;
 		} else {
 			$total_pages = (int) ceil( $total / $query_per_page );
@@ -668,17 +683,18 @@ final class WP_Abilities_Content {
 		 * inherited read permissions read the parent, and format_post() sets up every post
 		 * with setup_postdata(), which reads the author.
 		 */
-		update_post_parent_caches( $query->posts );
-		update_post_author_caches( $query->posts );
+		$query_posts = array_filter( $query->posts ?? array(), static fn( $post ): bool => $post instanceof WP_Post );
+		update_post_parent_caches( $query_posts );
+		update_post_author_caches( $query_posts );

 		$posts = array();
-		foreach ( $query->posts as $post ) {
+		foreach ( $query_posts as $post ) {
 			/*
 			 * Skip posts of other post types, which query filters can add, such as a
 			 * `pre_get_posts` callback that adds post types to the blog home without an
 			 * is_main_query() check.
 			 */
-			if ( ! $post instanceof WP_Post || $post_type !== $post->post_type ) {
+			if ( $post_type !== $post->post_type ) {
 				continue;
 			}
 			if ( ! $this->check_read_permission( $post ) ) {
@@ -968,7 +984,7 @@ final class WP_Abilities_Content {
 	 *
 	 * @since 7.2.0
 	 *
-	 * @return array<string, mixed> Post field definitions.
+	 * @return array<string, array<string, mixed>> Post field definitions.
 	 */
 	private function get_post_properties(): array {
 		return array(
@@ -1123,7 +1139,7 @@ final class WP_Abilities_Content {
 		foreach ( $this->get_post_properties() as $name => $schema ) {
 			$paths[] = $name;

-			foreach ( array_keys( $schema['properties'] ?? array() ) as $sub_field ) {
+			foreach ( array_keys( (array) ( $schema['properties'] ?? array() ) ) as $sub_field ) {
 				$paths[] = "{$name}.{$sub_field}";
 			}
 		}
@@ -1550,8 +1566,8 @@ final class WP_Abilities_Content {
 	 *
 	 * @since 7.2.0
 	 *
-	 * @param bool         $required Whether the post currently requires a password.
-	 * @param WP_Post|null $post     The post being checked, or null if no post is found.
+	 * @param mixed $required Whether the post currently requires a password.
+	 * @param mixed $post     The post being checked, or null if no post is found.
 	 * @return bool Whether the post still requires a password.
 	 */
 	private function allow_password_content( $required, $post ): bool {
@@ -1692,10 +1708,14 @@ final class WP_Abilities_Content {
 	 *
 	 * @since 7.2.0
 	 *
+	 * @global array<string, positive-int> $wp_actions Stores the number of times each action was triggered.
+	 *
 	 * @param array<string, mixed> $previous_context The loop globals that get_post_context() returned.
 	 * @param bool                 $the_post_fired   Whether the `the_post` action had fired before the ability set up the post.
 	 */
 	private function restore_post_context( array $previous_context, bool $the_post_fired ): void {
+		global $wp_actions;
+
 		$previous_post = $previous_context['post'] ?? null;

 		/*
@@ -1735,7 +1755,7 @@ final class WP_Abilities_Content {
 			 * or a post was set, the count is left alone.
 			 */
 			if ( ! $previous_post instanceof WP_Post && ! $the_post_fired ) {
-				unset( $GLOBALS['wp_actions']['the_post'] );
+				unset( $wp_actions['the_post'] );
 			}
 		}
 	}
diff --git a/wp-includes/abilities/class-wp-abilities-settings.php b/wp-includes/abilities/class-wp-abilities-settings.php
index c0f3df7ce5..e2a734885d 100644
--- a/wp-includes/abilities/class-wp-abilities-settings.php
+++ b/wp-includes/abilities/class-wp-abilities-settings.php
@@ -707,7 +707,7 @@ final class WP_Abilities_Settings {
 			}

 			$option_name  = (string) $option_name;
-			$exposed_name = empty( $show['name'] ) ? $option_name : (string) $show['name'];
+			$exposed_name = ( empty( $show['name'] ) || ! is_scalar( $show['name'] ) ) ? $option_name : (string) $show['name'];

 			if ( isset( $settings[ $exposed_name ] ) ) {
 				_doing_it_wrong(
@@ -752,7 +752,7 @@ final class WP_Abilities_Settings {
 	 * @since 7.2.0
 	 *
 	 * @param array<string, mixed> $args The setting registration arguments.
-	 * @return array<string, mixed> The exposure arguments, with optional `name` and `schema` keys.
+	 * @return array<mixed> The exposure arguments, with optional `name` and `schema` keys.
 	 */
 	private function get_exposure_args( array $args ): array {
 		if ( is_array( $args['show_in_abilities'] ) ) {
@@ -771,10 +771,10 @@ final class WP_Abilities_Settings {
 	 * @since 7.2.0
 	 *
 	 * @param array<string, mixed> $args The setting registration arguments.
-	 * @param array<string, mixed> $show The exposure arguments, see get_exposure_args().
+	 * @param array<mixed>         $show The exposure arguments, see get_exposure_args().
 	 * @return array<string, mixed> The value JSON Schema.
 	 */
-	private function get_value_schema( array $args, $show ): array {
+	private function get_value_schema( array $args, array $show ): array {
 		$schema = array(
 			'type' => $args['type'],
 		);
diff --git a/wp-includes/abilities/class-wp-abilities-users.php b/wp-includes/abilities/class-wp-abilities-users.php
index 51df002dfe..16bd2ee807 100644
--- a/wp-includes/abilities/class-wp-abilities-users.php
+++ b/wp-includes/abilities/class-wp-abilities-users.php
@@ -438,7 +438,7 @@ final class WP_Abilities_Users {
 	 *
 	 * @since 7.2.0
 	 *
-	 * @return array<string, mixed> User field definitions.
+	 * @return array<string, array<string, mixed>> User field definitions.
 	 */
 	private function get_user_properties(): array {
 		return array(
@@ -557,7 +557,7 @@ final class WP_Abilities_Users {
 		foreach ( $this->get_user_properties() as $name => $schema ) {
 			$paths[] = $name;

-			foreach ( array_keys( $schema['properties'] ?? array() ) as $sub_field ) {
+			foreach ( array_keys( (array) ( $schema['properties'] ?? array() ) ) as $sub_field ) {
 				$paths[] = "{$name}.{$sub_field}";
 			}
 		}
diff --git a/wp-includes/rest-api.php b/wp-includes/rest-api.php
index 7b90f5fdc0..a29bf6639c 100644
--- a/wp-includes/rest-api.php
+++ b/wp-includes/rest-api.php
@@ -1675,8 +1675,10 @@ function rest_sanitize_boolean( $value ) {
  *
  * @since 4.7.0
  *
- * @param bool|string $maybe_bool The value being evaluated.
+ * @param mixed $maybe_bool The value being evaluated.
  * @return bool True if a boolean, otherwise false.
+ *
+ * @phpstan-assert-if-true bool|int|string $maybe_bool
  */
 function rest_is_boolean( $maybe_bool ) {
 	if ( is_bool( $maybe_bool ) ) {
@@ -1719,6 +1721,8 @@ function rest_is_boolean( $maybe_bool ) {
  *
  * @param mixed $maybe_integer The value being evaluated.
  * @return bool True if an integer, otherwise false.
+ *
+ * @phpstan-assert-if-true int|float|string $maybe_integer
  */
 function rest_is_integer( $maybe_integer ): bool {
 	if ( is_int( $maybe_integer ) ) {
@@ -3311,8 +3315,8 @@ function rest_filter_response_by_context( $response_data, $schema, $context ) {
  * @since 5.5.0
  * @since 5.6.0 Support the "patternProperties" keyword.
  *
- * @param array $schema The schema to modify.
- * @return array The modified schema.
+ * @param array<string, mixed> $schema The schema to modify.
+ * @return array<string, mixed> The modified schema.
  */
 function rest_default_additional_properties_to_false( $schema ) {
 	$type = (array) $schema['type'];
diff --git a/wp-includes/version.php b/wp-includes/version.php
index 8ac7c4a3c2..434cf35499 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
  *
  * @global string $wp_version
  */
-$wp_version = '7.3-alpha-65863';
+$wp_version = '7.3-alpha-65864';

 /**
  * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.