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.

git-svn-id: https://develop.svn.wordpress.org/trunk@50961 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov
2021-05-24 09:50:30 +00:00
parent 987acb5954
commit 2c7c677f25
4 changed files with 18 additions and 14 deletions

View File

@@ -753,8 +753,13 @@ function dynamic_sidebar( $index = 1 ) {
$classname_ .= '_' . get_class( $cn );
}
}
$classname_ = ltrim( $classname_, '_' );
$params[0]['before_widget'] = sprintf( $params[0]['before_widget'], $id, $classname_ );
$classname_ = ltrim( $classname_, '_' );
$params[0]['before_widget'] = sprintf(
$params[0]['before_widget'],
str_replace( '\\', '_', $id ),
$classname_
);
/**
* Filters the parameters passed to a widget's display callback.