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
This commit is contained in:
parent
dcca93232b
commit
4b9a809bd7
|
@ -2085,6 +2085,7 @@ add_shortcode( 'caption', 'img_caption_shortcode' );
|
||||||
* @since 2.6.0
|
* @since 2.6.0
|
||||||
* @since 3.9.0 The `class` attribute was added.
|
* @since 3.9.0 The `class` attribute was added.
|
||||||
* @since 5.1.0 The `caption_id` 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 {
|
* @param array $attr {
|
||||||
* Attributes of the caption shortcode.
|
* Attributes of the caption shortcode.
|
||||||
|
@ -2097,10 +2098,10 @@ add_shortcode( 'caption', 'img_caption_shortcode' );
|
||||||
* @type string $caption The caption text.
|
* @type string $caption The caption text.
|
||||||
* @type string $class Additional class name(s) added to the caption container.
|
* @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.
|
* @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.
|
// New-style shortcode with the caption inside the shortcode with the link and image tags.
|
||||||
if ( ! isset( $attr['caption'] ) ) {
|
if ( ! isset( $attr['caption'] ) ) {
|
||||||
if ( preg_match( '#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches ) ) {
|
if ( preg_match( '#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches ) ) {
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @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.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue