WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/01/2019 03:41:58 AM (6 weeks ago)
Author:
whyisjake
Message:

Shortcodes: Improve handling from shortcode_parse_attts().

Ensure consistency between shortcode_parse_attts() when being used directly.

Props mauteri, birgire, SergeyBiryukov, kadamwhite, whyisjake.
Fixes #47863.

File:
1 edited

Legend:

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

    r46232 r46369  
    489489 *
    490490 * @since 2.5.0
    491  *
    492  * @param string $text
     491 * @since 5.3.0 Support of a full shortcode input.
     492 *
     493 * @param string $text  Any single shortcode of any format or key/value pair string.
    493494 * @return array|string List of attribute values.
    494495 *                      Returns empty array if trim( $text ) == '""'.
     
    499500    $atts    = array();
    500501    $pattern = get_shortcode_atts_regex();
    501     $text    = preg_replace( "/[\x{00a0}\x{200b}]+/u", ' ', $text );
     502    $text    = trim( preg_replace( "/[\x{00a0}\x{200b}]+/u", ' ', $text ) );
     503
     504    // Remove everything but attributes from shortcode.
     505    if ( preg_match( '#^\[[\w-]+([^\]]*?)\/?\]#', $text, $matches ) ) {
     506        $text = $matches[1];
     507    }
     508
    502509    if ( preg_match_all( $pattern, $text, $match, PREG_SET_ORDER ) ) {
    503510        foreach ( $match as $m ) {
     
    517524        }
    518525
    519         // Reject any unclosed HTML elements
     526        // Reject any unclosed HTML elements.
    520527        foreach ( $atts as &$value ) {
    521528            if ( false !== strpos( $value, '<' ) ) {
     
    528535        $atts = ltrim( $text );
    529536    }
     537
    530538    return $atts;
    531539}
Note: See TracChangeset for help on using the changeset viewer.