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.

git-svn-id: http://svn.automattic.com/wordpress/trunk@17738 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
nacin 2011-04-28 09:47:30 +00:00
parent 4964598cea
commit 2b71bba9c2
2 changed files with 10 additions and 9 deletions

View File

@ -366,9 +366,14 @@ function twentyeleven_page_menu_args( $args ) {
add_filter( 'wp_page_menu_args', 'twentyeleven_page_menu_args' );
/**
* Register widgetized area and update sidebar with default widgets
* Register our sidebars and widgetized areas. Also register the default Epherma widget.
*
* @since Twenty Eleven 1.0
*/
function twentyeleven_widgets_init() {
register_widget( 'Twenty_Eleven_Ephemera_Widget' );
register_sidebar( array(
'name' => __( 'Main Sidebar', 'twentyeleven' ),
'id' => 'sidebar-1',
@ -418,7 +423,7 @@ function twentyeleven_widgets_init() {
'after_title' => '</h1>',
) );
}
add_action( 'init', 'twentyeleven_widgets_init' );
add_action( 'widgets_init', 'twentyeleven_widgets_init' );
/**
* Display navigation to next/previous pages when applicable

View File

@ -78,13 +78,11 @@ class Twenty_Eleven_Ephemera_Widget extends WP_Widget {
echo $title; // Can set this with a widget option, or omit altogether
echo $after_title;
global $post;
?>
<ol>
<?php while ( $ephemera->have_posts() ) : $ephemera->the_post(); ?>
<?php if ( 'link' != get_post_format( $post->ID ) ) : ?>
<?php if ( 'link' != get_post_format() ) : ?>
<li class="entry-title">
<a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyeleven' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a>
@ -116,7 +114,7 @@ class Twenty_Eleven_Ephemera_Widget extends WP_Widget {
echo $after_widget;
// Reset the global $the_post as this query will have stomped on it
// Reset the post globals as this query will have stomped on it
wp_reset_postdata();
// end check for ephemeral posts
@ -161,6 +159,4 @@ class Twenty_Eleven_Ephemera_Widget extends WP_Widget {
<input id="<?php echo esc_attr( $this->get_field_id( 'number' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'number' ) ); ?>" type="text" value="<?php echo esc_attr( $number ); ?>" size="3" /></p>
<?php
}
}
add_action( 'widgets_init', create_function( '', "register_widget( 'Twenty_Eleven_Ephemera_Widget' );" ) );
}