[wp-trac] [WordPress Trac] #42998: Custom HTML Widget uses widget_text twice in markup
WordPress Trac
noreply at wordpress.org
Fri Mar 23 20:56:39 UTC 2018
#42998: Custom HTML Widget uses widget_text twice in markup
--------------------------+--------------------
Reporter: dreamwhisper | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: 5.0
Component: Widgets | Version: 4.8.1
Severity: normal | Resolution:
Keywords: needs-patch | Focuses:
--------------------------+--------------------
Changes (by westonruter):
* milestone: Awaiting Review => 5.0
Comment:
Replying to [comment:7 alexvorn2]:
> I found we can add the 4th parameter "1" in the preg_replace function,
that will replace only once, so it will look like this:
>
> {{{
> $args['before_widget'] = preg_replace( '/(?<=\sclass=["\'])/',
'widget_text ', $args['before_widget'], 1 );
> }}}
>
> But what if we have wrapper div elements? ... that will appear before
not only after.
I think you have the right approach here. The wrapper element ''should''
have a class added to it, or else things won't work as expected in the
Customizer preview: https://github.com/WordPress/wordpress-
develop/blob/7c2f975/src/wp-includes/js/customize-preview-
widgets.js#L609-L619
The only hardening that may be warranted is to check if the
`before_widget` actually starts with an element that has a `class`
attribute in it. For example:
{{{#!php
<?php
if ( preg_match( '#^<[^>]+class=[^>]+>#', $args['before_widget'] ) ) {
$args['before_widget'] = preg_replace( '/(?<=\sclass=["\'])/',
'widget_text ', $args['before_widget'], 1 );
}
}}}
But that's probably somewhat overkill.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/42998#comment:10>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list