WordPress.org

Make WordPress Core

Changeset 47371


Ignore:
Timestamp:
02/25/2020 07:27:22 PM (3 months ago)
Author:
SergeyBiryukov
Message:

Widgets: Create a unique HTML ID for the <ul> element of Recent Comments widget if more than one instance is displayed on the page.

Props peterwilsoncc, audrasjb, birgire, justinahinon, mbrailer, desrosj.
Fixes #46747.

Location:
trunk/src/wp-includes/widgets
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/widgets/class-wp-widget-categories.php

    r47287 r47371  
    3535     *
    3636     * @since 2.8.0
     37     * @since 4.2.0 Creates a unique HTML ID for the `<select>` element
     38     *              if more than one instance is displayed on the page.
    3739     *
    3840     * @staticvar bool $first_dropdown
  • trunk/src/wp-includes/widgets/class-wp-widget-recent-comments.php

    r47122 r47371  
    6767     *
    6868     * @since 2.8.0
     69     * @since 5.4.0 Creates a unique HTML ID for the `<ul>` element
     70     *              if more than one instance is displayed on the page.
     71     *
     72     * @staticvar bool $first_instance
    6973     *
    7074     * @param array $args     Display arguments including 'before_title', 'after_title',
     
    7377     */
    7478    public function widget( $args, $instance ) {
     79        static $first_instance = true;
     80
    7581        if ( ! isset( $args['widget_id'] ) ) {
    7682            $args['widget_id'] = $this->id;
     
    117123        }
    118124
    119         $output .= '<ul id="recentcomments">';
     125        $recent_comments_id = ( $first_instance ) ? 'recentcomments' : "recentcomments-{$this->number}";
     126        $first_instance     = false;
     127
     128        $output .= '<ul id="' . esc_attr( $recent_comments_id ) . '">';
    120129        if ( is_array( $comments ) && $comments ) {
    121130            // Prime cache for associated posts. (Prime post term cache if we need it for permalinks.)
Note: See TracChangeset for help on using the changeset viewer.