[wp-trac] [WordPress Trac] #47863: Fix odd, unexpected output from shortcode_parse_attts
WordPress Trac
noreply at wordpress.org
Fri Oct 11 12:49:58 UTC 2019
#47863: Fix odd, unexpected output from shortcode_parse_attts
---------------------------------------------+-----------------------------
Reporter: mauteri | Owner: SergeyBiryukov
Type: defect (bug) | Status: reopened
Priority: normal | Milestone: 5.3
Component: Shortcodes | Version:
Severity: normal | Resolution:
Keywords: has-patch has-unit-tests commit | Focuses:
---------------------------------------------+-----------------------------
Changes (by david.binda):
* status: closed => reopened
* resolution: fixed =>
Comment:
I have run into an issue with the new implementation, where the code was
either relying on the 0 key containing the shortcode's tag, or where the
code was adjusted to the original behaviour and was blindly removing the 0
key.
In both cases, the implementation is broken with this change being in
place. While I like this change, there might be more issues with
shortcodes once 5.3 is relased, similar to what I've been seeing during my
tests.
In case we are okay with such a breaking change, perhaps it might be worth
writing a blog post on the breaking change, with some guidance on how to
properly adjust the broken code.
Here are some of the example codes I've run into:
Example 1:
{{{#!php
$shortcode = '[unittest attr1 attr2]';
$atts = shortcode_parse_atts( $shortcode );
// Drop '[unittest ' part.
array_shift( $atts ); // With r46369 being applied, this removes the attr1
instead of [unittest
}}}
Example 2:
{{{#!php
$shortcode = '[unittest attr1 attr2]';
$atts = shortcode_parse_atts( $shortcode );
$tag = trim( $attrs[0], '[' ); // With r46369 being applied, the $tag
holds attr1 instead of unittest
}}}
IMHO, the correct usage for for the both examples above would be following
logic:
{{{#!php
$shortcode = '[unittest attr1 attr2]';
if ( preg_match( '/'. get_shortcode_regex( [ 'unittest' ] ) .'/s',
$shortcode, $matches ) ) {
$tag = $matches[2];
$atts = shortcode_parse_atts( $matches[3] );
}
}}}
But that's perhaps for a blog post.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/47863#comment:23>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list