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

@@ -164,7 +164,6 @@ class WP_Widget {
$id_base = strtolower( $id_base );
} else {
$id_base = preg_replace( '/(wp_)?widget_/', '', strtolower( get_class( $this ) ) );
$id_base = str_replace( '\\', '-', $id_base );
}
$this->id_base = $id_base;
@@ -173,7 +172,7 @@ class WP_Widget {
$this->widget_options = wp_parse_args(
$widget_options,
array(
'classname' => $this->option_name,
'classname' => str_replace( '\\', '_', $this->option_name ),
'customize_selective_refresh' => false,
)
);