Make WordPress Core


Ignore:
Timestamp:
05/24/2021 09:50:30 AM (4 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-includes/widgets.php

    r50372 r50961  
    754754            }
    755755        }
    756         $classname_                 = ltrim( $classname_, '_' );
    757         $params[0]['before_widget'] = sprintf( $params[0]['before_widget'], $id, $classname_ );
     756        $classname_ = ltrim( $classname_, '_' );
     757
     758        $params[0]['before_widget'] = sprintf(
     759            $params[0]['before_widget'],
     760            str_replace( '\\', '_', $id ),
     761            $classname_
     762        );
    758763
    759764        /**
Note: See TracChangeset for help on using the changeset viewer.