Shortcodes: Always return an array in shortcode_parse_atts().

Previously, `shortcode_parse_atts()` would return the input (an empty string) if a shortcode had no attributes, even though the documentation said otherwise.

Always returning an (empty) array reduces confusion and improves developer experience as the return value does not have to be manually checked in the shortcode itself.

Props: nicolefurlan, swissspidy, johnbillion, bedas.
Fixes #59249.

git-svn-id: https://develop.svn.wordpress.org/trunk@57597 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Pascal Birchler
2024-02-12 16:06:47 +00:00
parent edfdeaa105
commit 3a962003e9
3 changed files with 29 additions and 12 deletions
-4
View File
@@ -2354,10 +2354,6 @@ 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 ) ) {