From 4b9a809bd7a73197764a97342bee7f3e57b8f6dc Mon Sep 17 00:00:00 2001 From: hellofromTonya Date: Wed, 15 Sep 2021 19:06:57 +0000 Subject: [PATCH] Media: Fix `$content` parameter default value in `img_caption_shortcode()`. The shortcode content is expected to be a string, not `null`. `do_shortcode()` expects a string for `$content`. The `img_caption_shortcode()` also expects a string for the `$content` parameter and is expected to return a string for the HTML content to display the caption. Prior to this commit: The default value for the `$content` parameter was set to `null`. If no `$content` was passed, the function: - could return `null` when the `$atts['width'] < 1` or there was no caption - else, it invoked `do_shortcode( $content )` passing `null` which on PHP 8.1+ triggers a deprecation notice: {{{ strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated }}} This commit: - Fixes the default `$content` value to align to the expected shortcode content of `string`, not `null`. - Fixes the PHP 8.1 deprecation notice when `null` was being passed to `do_shortcode()`. - Changes the assertion in a couple of tests to check for the empty string instead of `null. Follow-up to [8196], [8925], [8239], [26915], [31530], [42704]. Props jrf, hellofromTonya, azaozz, joedolson. See #53635. Built from https://develop.svn.wordpress.org/trunk@51816 git-svn-id: http://core.svn.wordpress.org/trunk@51423 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/media.php | 5 +++-- wp-includes/version.php | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/wp-includes/media.php b/wp-includes/media.php index 340ddc3bb4..43795c9084 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -2085,6 +2085,7 @@ add_shortcode( 'caption', 'img_caption_shortcode' ); * @since 2.6.0 * @since 3.9.0 The `class` attribute was added. * @since 5.1.0 The `caption_id` attribute was added. + * @since 5.9.0 The `$content` parameter default value changed from `null` to `''`. * * @param array $attr { * Attributes of the caption shortcode. @@ -2097,10 +2098,10 @@ add_shortcode( 'caption', 'img_caption_shortcode' ); * @type string $caption The caption text. * @type string $class Additional class name(s) added to the caption container. * } - * @param string $content Shortcode content. + * @param string $content Optional. Shortcode content. Default empty string. * @return string HTML content to display the caption. */ -function img_caption_shortcode( $attr, $content = null ) { +function img_caption_shortcode( $attr, $content = '' ) { // New-style shortcode with the caption inside the shortcode with the link and image tags. if ( ! isset( $attr['caption'] ) ) { if ( preg_match( '#((?:]+>\s*)?]+>(?:\s*)?)(.*)#is', $content, $matches ) ) { diff --git a/wp-includes/version.php b/wp-includes/version.php index 69b3b9af09..3bfe2fb7ab 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '5.9-alpha-51815'; +$wp_version = '5.9-alpha-51816'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.