Make WordPress Core

Changeset 13698


Ignore:
Timestamp:
03/14/2010 10:55:17 AM (15 years ago)
Author:
dd32
Message:

Ensure that for multiple sidebar additions, the ID is unique (even if specified). Append -2.. for > 1 sidebars. Props minusfive. Fixes #12606

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/widgets.php

    r13098 r13698  
    462462 * number the sidebar is currently when greater than one. If first sidebar, the
    463463 * name will be just "Sidebar". The default for id is "sidebar-" followed by the
    464  * number the sidebar creation is currently at.
     464 * number the sidebar creation is currently at. If the id is provided, and mutliple
     465 * sidebars are being defined, the id will have "-2" appended, and so on.
    465466 *
    466467 * @since 2.2.0
     
    481482        parse_str($args, $args);
    482483
    483     for ( $i=1; $i <= $number; $i++ ) {
     484    for ( $i = 1; $i <= $number; $i++ ) {
    484485        $_args = $args;
    485486
    486         if ( $number > 1 ) {
     487        if ( $number > 1 )
    487488            $_args['name'] = isset($args['name']) ? sprintf($args['name'], $i) : sprintf(__('Sidebar %d'), $i);
    488         } else {
     489        else
    489490            $_args['name'] = isset($args['name']) ? $args['name'] : __('Sidebar');
    490         }
    491 
    492         if (isset($args['id'])) {
     491
     492        if ( isset($args['id']) ) {
    493493            $_args['id'] = $args['id'];
     494            if ( $number > 1 ) // Ensure that for multiple additions, the ID is unique (even if specified). Append -xx for > 1 sidebars.
     495                $_args['id'] .= '-' . $i;
    494496        } else {
    495497            $n = count($wp_registered_sidebars);
     
    497499                $n++;
    498500                $_args['id'] = "sidebar-$n";
    499             } while (isset($wp_registered_sidebars[$_args['id']]));
     501            } while ( isset($wp_registered_sidebars[$_args['id']]) );
    500502        }
    501503
Note: See TracChangeset for help on using the changeset viewer.