Make WordPress Core


Ignore:
Timestamp:
02/12/2024 04:06:47 PM (14 months ago)
Author:
swissspidy
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/shortcodes.php

    r57584 r57597  
    601601 *
    602602 * @since 2.5.0
     603 * @since 6.5.0 The function now always returns an empty array,
     604 *              even if the original arguments string cannot be parsed or is empty.
    603605 *
    604606 * @param string $text Shortcode arguments list.
    605  * @return array|string Array of attribute values keyed by attribute name.
    606  *                      Returns empty array if there are no attributes.
    607  *                      Returns the original arguments string if it cannot be parsed.
     607 * @return array Array of attribute values keyed by attribute name.
     608 *               Returns empty array if there are no attributes
     609 *               or if the original arguments string cannot be parsed.
    608610 */
    609611function shortcode_parse_atts( $text ) {
     
    636638            }
    637639        }
    638     } else {
    639         $atts = ltrim( $text );
    640640    }
    641641
Note: See TracChangeset for help on using the changeset viewer.