[wp-trac] [WordPress Trac] #42998: Custom HTML Widget uses widget_text twice in markup
WordPress Trac
noreply at wordpress.org
Tue Jan 9 04:57:17 UTC 2018
#42998: Custom HTML Widget uses widget_text twice in markup
-------------------------------------------+------------------------------
Reporter: dreamwhisper | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Widgets | Version: 4.8.1
Severity: normal | Resolution:
Keywords: reporter-feedback needs-patch | Focuses:
-------------------------------------------+------------------------------
Comment (by alexvorn2):
So is my code good? Or we need only to use REGEX algorithm?
`$widget_id` is the string name of the widget
So the code is this:
{{{
$args['before_widget'] = str_replace( 'id="' . $widget_id . '" class="',
'id="' . $widget_id . '" class="widget_text ', $args['before_widget'] );
}}}
It will replace only once because it will search for widget ID too, and
the first div will be changed... Or If someone is good at REGEX '''to make
this code replace only once''':
{{{
$args['before_widget'] = preg_replace( '/(?<=\sclass=["\'])/',
'widget_text ', $args['before_widget'] );
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/42998#comment:6>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list