Media: Prevent warning if [caption] shortcode is used without attributes.

Props maltfield, aslamdoctor.
Fixes #59206.

git-svn-id: https://develop.svn.wordpress.org/trunk@56488 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Pascal Birchler
2023-08-29 15:33:43 +00:00
parent 61cd1a5210
commit ec94944ae4

View File

@@ -2361,6 +2361,10 @@ add_shortcode( 'caption', 'img_caption_shortcode' );
* @return string HTML content to display the caption.
*/
function img_caption_shortcode( $attr, $content = '' ) {
if ( ! $attr ) {
$attr = array();
}
// New-style shortcode with the caption inside the shortcode with the link and image tags.
if ( ! isset( $attr['caption'] ) ) {
if ( preg_match( '#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches ) ) {