Make WordPress Core


Ignore:
Timestamp:
02/25/2020 07:27:22 PM (5 years 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.