Commit 025d935281 for wordpress.org

commit 025d935281909e3eb3bc5e6c45b00622c83650f3
Author: westonruter <westonruter@git.wordpress.org>
Date:   Fri Oct 30 18:17:51 2026 +0000

    Docs: Document hooks that may pass a null post object.

    Several hooks document their post parameter as `WP_Post` even though `get_post()` can return null before the hook fires, so callbacks that type-hint `WP_Post` fatal with a `TypeError`. This was reported for the Image Placeholders plugin, where a plugin filtered `post_thumbnail_id` to an ID with no post, leading `wp_get_attachment_image()` to pass a null `$attachment` to `wp_get_attachment_image_attributes`. The same applies to `post_password_required` and `the_password_form` when no post is found, and to `media_view_settings` and `media_view_strings` whenever `wp_enqueue_media()` is not called for a specific post. Core and bundled theme callbacks of these hooks are updated to match.

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

    See #65860.

    Built from https://develop.svn.wordpress.org/trunk@65075


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

diff --git a/wp-content/themes/twentyseventeen/functions.php b/wp-content/themes/twentyseventeen/functions.php
index e693c0fe16..356ab022a0 100644
--- a/wp-content/themes/twentyseventeen/functions.php
+++ b/wp-content/themes/twentyseventeen/functions.php
@@ -609,7 +609,7 @@ add_filter( 'get_header_image_tag', 'twentyseventeen_header_image_tag', 10, 3 );
  *
  * @param string[]     $attr       Array of attribute values for the image markup, keyed by attribute name.
  *                                 See wp_get_attachment_image().
- * @param WP_Post      $attachment Image attachment post.
+ * @param WP_Post|null $attachment Image attachment post, or null if no post is found.
  * @param string|int[] $size       Requested image size. Can be any registered image size name, or
  *                                 an array of width and height values in pixels (in that order).
  * @return string[] The filtered attributes for the image markup.
diff --git a/wp-content/themes/twentysixteen/functions.php b/wp-content/themes/twentysixteen/functions.php
index 72bfab48f0..f6939eaa22 100644
--- a/wp-content/themes/twentysixteen/functions.php
+++ b/wp-content/themes/twentysixteen/functions.php
@@ -593,7 +593,7 @@ add_filter( 'wp_calculate_image_sizes', 'twentysixteen_content_image_sizes_attr'
  *
  * @param string[]     $attr       Array of attribute values for the image markup, keyed by attribute name.
  *                                 See wp_get_attachment_image().
- * @param WP_Post      $attachment Image attachment post.
+ * @param WP_Post|null $attachment Image attachment post, or null if no post is found.
  * @param string|int[] $size       Requested image size. Can be any registered image size name, or
  *                                 an array of width and height values in pixels (in that order).
  * @return string[] The filtered attributes for the image markup.
diff --git a/wp-content/themes/twentytwentyone/inc/template-functions.php b/wp-content/themes/twentytwentyone/inc/template-functions.php
index f141b99a8c..b7cbb1c6b1 100644
--- a/wp-content/themes/twentytwentyone/inc/template-functions.php
+++ b/wp-content/themes/twentytwentyone/inc/template-functions.php
@@ -424,8 +424,9 @@ function twenty_twenty_one_print_first_instance_of_block( $block_name, $content
  * @since Twenty Twenty-One 1.4 Corrected parameter name for `$output`,
  *                              added the `$post` parameter.
  *
- * @param string      $output The password form HTML output.
- * @param int|WP_Post $post   Optional. Post ID or WP_Post object. Default is global $post.
+ * @param string           $output The password form HTML output.
+ * @param int|WP_Post|null $post   Optional. Post ID or WP_Post object, or null if no post is found.
+ *                                 Default is global $post.
  * @return string HTML content for password form for password protected post.
  */
 function twenty_twenty_one_password_form( $output, $post = 0 ) {
@@ -446,7 +447,7 @@ add_filter( 'the_password_form', 'twenty_twenty_one_password_form', 10, 2 );
  *
  * @param string[]     $attr       Array of attribute values for the image markup, keyed by attribute name.
  *                                 See wp_get_attachment_image().
- * @param WP_Post      $attachment Image attachment post.
+ * @param WP_Post|null $attachment Image attachment post, or null if no post is found.
  * @param string|int[] $size       Requested image size. Can be any registered image size name, or
  *                                 an array of width and height values in pixels (in that order).
  * @return string[] The filtered attributes for the image markup.
diff --git a/wp-includes/abilities/class-wp-abilities-content.php b/wp-includes/abilities/class-wp-abilities-content.php
index 6be7e065e0..17e1a81ac3 100644
--- a/wp-includes/abilities/class-wp-abilities-content.php
+++ b/wp-includes/abilities/class-wp-abilities-content.php
@@ -1549,8 +1549,8 @@ final class WP_Abilities_Content {
 	 *
 	 * @since 7.2.0
 	 *
-	 * @param mixed $required Whether the post currently requires a password.
-	 * @param mixed $post     The post being checked; a WP_Post when invoked by the core filter.
+	 * @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.
 	 * @return bool Whether the post still requires a password.
 	 */
 	private function allow_password_content( $required, $post ): bool {
diff --git a/wp-includes/media.php b/wp-includes/media.php
index 54638b4ed7..4cd69ade6c 100644
--- a/wp-includes/media.php
+++ b/wp-includes/media.php
@@ -1275,7 +1275,7 @@ function wp_get_attachment_image( $attachment_id, $size = 'thumbnail', $icon = f
 		 *
 		 * @param string[]     $attr       Array of attribute values for the image markup, keyed by attribute name.
 		 *                                 See wp_get_attachment_image().
-		 * @param WP_Post      $attachment Image attachment post.
+		 * @param WP_Post|null $attachment Image attachment post, or null if no post is found.
 		 * @param string|int[] $size       Requested image size. Can be any registered image size name, or
 		 *                                 an array of width and height values in pixels (in that order).
 		 */
@@ -5281,8 +5281,8 @@ function wp_enqueue_media( $args = array() ) {
 	 *
 	 * @since 3.5.0
 	 *
-	 * @param array   $settings List of media view settings.
-	 * @param WP_Post $post     Post object.
+	 * @param array        $settings List of media view settings.
+	 * @param WP_Post|null $post     Post object, or null if the media modal is not for a specific post.
 	 */
 	$settings = apply_filters( 'media_view_settings', $settings, $post );

@@ -5291,8 +5291,8 @@ function wp_enqueue_media( $args = array() ) {
 	 *
 	 * @since 3.5.0
 	 *
-	 * @param string[] $strings Array of media view strings keyed by the name they'll be referenced by in JavaScript.
-	 * @param WP_Post  $post    Post object.
+	 * @param string[]     $strings Array of media view strings keyed by the name they'll be referenced by in JavaScript.
+	 * @param WP_Post|null $post    Post object, or null if the media modal is not for a specific post.
 	 */
 	$strings = apply_filters( 'media_view_strings', $strings, $post );

diff --git a/wp-includes/post-template.php b/wp-includes/post-template.php
index 8a571495e9..0c2e25112f 100644
--- a/wp-includes/post-template.php
+++ b/wp-includes/post-template.php
@@ -914,9 +914,9 @@ function post_password_required( $post = null ) {
 	 *
 	 * @since 4.7.0
 	 *
-	 * @param bool    $required Whether the user needs to supply a password. True if password has not been
-	 *                          provided or is incorrect, false if password has been supplied or is not required.
-	 * @param WP_Post $post     Post object.
+	 * @param bool         $required Whether the user needs to supply a password. True if password has not been
+	 *                               provided or is incorrect, false if password has been supplied or is not required.
+	 * @param WP_Post|null $post     Post object, or null if no post is found.
 	 */
 	return apply_filters( 'post_password_required', $required, $post );
 }
@@ -1862,9 +1862,9 @@ function get_the_password_form( $post = 0 ) {
 	 * @since 5.8.0 Added the `$post` parameter.
 	 * @since 6.8.0 Added the `$invalid_password` parameter.
 	 *
-	 * @param string  $output           The password form HTML output.
-	 * @param WP_Post $post             Post object.
-	 * @param string  $invalid_password The invalid password message.
+	 * @param string       $output           The password form HTML output.
+	 * @param WP_Post|null $post             Post object, or null if no post is found.
+	 * @param string       $invalid_password The invalid password message.
 	 */
 	return apply_filters( 'the_password_form', $output, $post, $invalid_password );
 }
diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
index 0a74771450..0c24925ff9 100644
--- a/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
+++ b/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
@@ -181,8 +181,8 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
 	 *
 	 * @since 5.7.1
 	 *
-	 * @param bool    $required Whether the post requires a password check.
-	 * @param WP_Post $post     The post been password checked.
+	 * @param bool         $required Whether the post requires a password check.
+	 * @param WP_Post|null $post     The post being password checked, or null if no post is found.
 	 * @return bool Result of password check taking into account REST API considerations.
 	 */
 	public function check_password_required( $required, $post ) {
diff --git a/wp-includes/version.php b/wp-includes/version.php
index 8b0c24bc70..3196452919 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
  *
  * @global string $wp_version
  */
-$wp_version = '7.2-beta3-65074';
+$wp_version = '7.2-beta3-65075';

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