[wp-trac] [WordPress Trac] #40009: register_sidebar() mixes up widgets

WordPress Trac noreply at wordpress.org
Wed Mar 1 19:56:19 UTC 2017


#40009: register_sidebar() mixes up widgets
--------------------------+-----------------------------
 Reporter:  edge22        |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Widgets       |    Version:  4.7.2
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 Kind of an interesting issue.

 Let's say you have a set of widgets created:


 {{{
 add_action( 'widgets_init', 'samples_widgets_init' );
 function sample_widgets_init()
 {
         // Set up our array of widgets
         $widgets = array(
                 'sidebar-1' => __( 'Right Sidebar' ),
                 'sidebar-2' => __( 'Left Sidebar' ),
                 'header' => __( 'Header' ),
                 'footer-1' => __( 'Footer Widget 1' ),
                 'footer-2' => __( 'Footer Widget 2' ),
                 'footer-3' => __( 'Footer Widget 3' ),
                 'footer-4' => __( 'Footer Widget 4' ),
                 'footer-5' => __( 'Footer Widget 5' ),
                 'footer-bar' => __( 'Footer Bar' )
         );

         // Loop through them to create our widget areas
         foreach ( $widgets as $id => $name ) {
                 register_sidebar( array(
                         'name'          => $name,
                         'id'            => $id,
                         'before_widget' => '<aside id="%1$s" class="widget
 %2$s">',
                         'after_widget'  => '</aside>',
                         'before_title'  => '<h4 class="widget-title">',
                         'after_title'   => '</h4>',
                 ) );
         }
 }
 }}}

 Works perfectly.

 Ok, now let's insert a new widget area into the mix (not at the end).

 {{{
 add_action( 'widgets_init', 'samples_widgets_init' );
 function sample_widgets_init()
 {
         // Set up our array of widgets
         $widgets = array(
                 'sidebar-1' => __( 'Right Sidebar' ),
                 'sidebar-2' => __( 'Left Sidebar' ),
                 'top-bar' => __( 'Top Bar' ),
                 'header' => __( 'Header' ),
                 'footer-1' => __( 'Footer Widget 1' ),
                 'footer-2' => __( 'Footer Widget 2' ),
                 'footer-3' => __( 'Footer Widget 3' ),
                 'footer-4' => __( 'Footer Widget 4' ),
                 'footer-5' => __( 'Footer Widget 5' ),
                 'footer-bar' => __( 'Footer Bar' )
         );

         // Loop through them to create our widget areas
         foreach ( $widgets as $id => $name ) {
                 register_sidebar( array(
                         'name'          => $name,
                         'id'            => $id,
                         'before_widget' => '<aside id="%1$s" class="widget
 %2$s">',
                         'after_widget'  => '</aside>',
                         'before_title'  => '<h4 class="widget-title">',
                         'after_title'   => '</h4>',
                 ) );
         }
 }
 }}}

 So we've added a top bar widget area above the header.

 '''This works fine, UNLESS the theme folder name changes.'''

 So let's say someone downloads this new version from GitHub and keeps the
 -master part of the folder name and they activate it.

 All of a sudden, the widget that was in the Footer 1 area is moved into
 the Header widget area.

 My assumption would be that since we have an ID set, the order shouldn't
 change regardless of new widget areas being inserted into the mix.

 The same things happens without the foreach as well.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/40009>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list