Make WordPress Core

Changeset 32110


Ignore:
Timestamp:
04/11/2015 09:33:14 PM (9 years ago)
Author:
markjaquith
Message:

Tell developers how to correctly silence register_sidebar() notices.

  • If we just tell them they they should set an id parameter, they might set an arbitrary one on an existing (i.e. not in-development) theme, causing widgets to be lost.
  • This way, we tell them to set it to the auto-generated id that the sidebar already has.
  • Widget content is not lost, and now their sidebar has a concrete handle.

fixes #31675

File:
1 edited

Legend:

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

    r31905 r32110  
    804804    $i = count($wp_registered_sidebars) + 1;
    805805
    806     if ( empty( $args['id'] ) ) {
    807         /* translators: %s: the id argument */
    808         _doing_it_wrong( __FUNCTION__, sprintf( __( 'You should set %s in the arguments array.' ), '<code>id</code>' ), '4.2.0' );
    809     }
     806    $id_is_empty = empty( $args['id'] );
    810807
    811808    $defaults = array(
     
    821818
    822819    $sidebar = wp_parse_args( $args, $defaults );
     820
     821    if ( $id_is_empty ) {
     822        /* translators: %1$s: the id argument */
     823        _doing_it_wrong( __FUNCTION__, sprintf( __( 'No %1$s was set in the arguments array for the "%2$s" sidebar. Defaulting to "%3$s". Manually set the %1$s to  "%3$s" to silence this notice and keep existing sidebar content.' ), '<code>id</code>', $sidebar['name'], $sidebar['id'] ), '4.2.0' );
     824    }
    823825
    824826    $wp_registered_sidebars[$sidebar['id']] = $sidebar;
Note: See TracChangeset for help on using the changeset viewer.