Make WordPress Core


Ignore:
Timestamp:
05/24/2021 09:50:30 AM (3 years ago)
Author:
SergeyBiryukov
Message:

Widgets: Make sure WP_Widget constructor creates a correct classname value for a namespaced widget class.

This reverts the changes to id_base from [50953] due to backward compatibility concerns, and instead focuses on the id and class attributes specifically.

With this change, any backslashes in the id or class attributes for a namespaced widget class are converted to underscores, making it easier to style the output or target the widget with JavaScript.

Follow-up to [50953].

Fixes #44098.

File:
1 edited

Legend:

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

    r49113 r50961  
    163163
    164164    foreach ( $wp_registered_widgets as $widget_id => $widget ) {
    165         if ( preg_match( '/' . $id_base . '-([0-9]+)$/', $widget_id, $matches ) ) {
     165        if ( preg_match( '/' . preg_quote( $id_base, '/' ) . '-([0-9]+)$/', $widget_id, $matches ) ) {
    166166            $number = max( $number, $matches[1] );
    167167        }
Note: See TracChangeset for help on using the changeset viewer.