WordPress.org

Make WordPress Core

Changeset 17738


Ignore:
Timestamp:
04/28/2011 09:47:30 AM (7 years ago)
Author:
nacin
Message:

In Twenty Eleven: Register the widget from functions.php. Kill create_function. Attach twentyeleven_widgets_init() to widgets_init, rather than init. Eliminate use of the $post global in the widget. see #17198.

Location:
trunk/wp-content/themes/twentyeleven
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-content/themes/twentyeleven/functions.php

    r17735 r17738  
    367367
    368368/**
    369  * Register widgetized area and update sidebar with default widgets
     369 * Register our sidebars and widgetized areas. Also register the default Epherma widget.
     370 *
     371 * @since Twenty Eleven 1.0
    370372 */
    371373function twentyeleven_widgets_init() {
     374
     375    register_widget( 'Twenty_Eleven_Ephemera_Widget' );
     376
    372377    register_sidebar( array(
    373378        'name' => __( 'Main Sidebar', 'twentyeleven' ),
     
    419424    ) );
    420425}
    421 add_action( 'init', 'twentyeleven_widgets_init' );
     426add_action( 'widgets_init', 'twentyeleven_widgets_init' );
    422427
    423428/**
  • trunk/wp-content/themes/twentyeleven/inc/widgets.php

    r17723 r17738  
    7979        echo $after_title;
    8080
    81         global $post;
    82 
    8381        ?>
    8482        <ol>
    8583        <?php while ( $ephemera->have_posts() ) : $ephemera->the_post(); ?>
    8684
    87             <?php if ( 'link' != get_post_format( $post->ID ) ) : ?>
     85            <?php if ( 'link' != get_post_format() ) : ?>
    8886
    8987            <li class="entry-title">
     
    117115        echo $after_widget;
    118116
    119         // Reset the global $the_post as this query will have stomped on it
     117        // Reset the post globals as this query will have stomped on it
    120118        wp_reset_postdata();
    121119
     
    163161    }
    164162}
    165 
    166 add_action( 'widgets_init', create_function( '', "register_widget( 'Twenty_Eleven_Ephemera_Widget' );" ) );
Note: See TracChangeset for help on using the changeset viewer.