wppaste
WordPress

Twenty_Eleven_Ephemera_Widget::widget( array $args, $instance )

Since
Twenty Eleven 1.0
Source
wp-content/themes/twentyeleven/inc/widgets.php:55
Outputs the HTML for this widget.

Compatibility

WordPress
since Twenty Eleven 1.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$argsarray
An array of standard parameters for widgets in this theme.
$instance

Performance profile

How much work a call to Twenty_Eleven_Ephemera_Widget::widget() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Heavy

Reaches the database via get_post().

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
21–105

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 177.

Plugin surface
1 hook

Third-party callbacks on 'widget_title' run inside this call, and their cost is not bounded by anything here.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • cacheobject cachewp_cache_get()called directly
  • hookthird-party callbacksapply_filters()called directly
  • optionoption read or writeget_option()called directly
  • serializeserialisationmaybe_unserialize()one call below Twenty_Eleven_Ephemera_Widget::widget()
  • querycontent queryget_post()one call below Twenty_Eleven_Ephemera_Widget::widget()

Further down the call graph this can also reach transient. That is the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 9 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost Twenty_Eleven_Ephemera_Widget::widget() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
!is_customize_preview() && isset($cache)21–24wp_cache_get(), is_customize_preview()
is_customize_preview() && !empty($instance) && !->have_posts()67–77wp_cache_get(), is_customize_preview(), ob_start(), apply_filters(), absint(), get_option(), DESC(), ->have_posts(), ob_get_flush(), is_customize_preview()
!empty($instance) && !->have_posts() && !is_customize_preview()72–82wp_cache_get(), is_customize_preview(), ob_start(), apply_filters(), absint(), get_option(), DESC(), ->have_posts(), ob_get_flush(), is_customize_preview(), wp_cache_set()
is_customize_preview() && empty($instance) && !->have_posts()72–82wp_cache_get(), is_customize_preview(), ob_start(), __(), apply_filters(), absint(), get_option(), DESC(), ->have_posts(), ob_get_flush(), is_customize_preview()
empty($instance) && !->have_posts() && !is_customize_preview()77–87wp_cache_get(), is_customize_preview(), ob_start(), __(), apply_filters(), absint(), get_option(), DESC(), ->have_posts(), ob_get_flush(), is_customize_preview(), wp_cache_set()
is_customize_preview() && !empty($instance)85–95wp_cache_get(), is_customize_preview(), ob_start(), apply_filters(), absint(), get_option(), DESC(), ->have_posts(), ->have_posts(), wp_reset_postdata(), ob_get_flush(), is_customize_preview()
!empty($instance) && !is_customize_preview()90–100wp_cache_get(), is_customize_preview(), ob_start(), apply_filters(), absint(), get_option(), DESC(), ->have_posts(), ->have_posts(), wp_reset_postdata(), ob_get_flush(), is_customize_preview(), wp_cache_set()
is_customize_preview() && empty($instance)90–100wp_cache_get(), is_customize_preview(), ob_start(), __(), apply_filters(), absint(), get_option(), DESC(), ->have_posts(), ->have_posts(), wp_reset_postdata(), ob_get_flush(), is_customize_preview()
empty($instance) && !is_customize_preview()95–105wp_cache_get(), is_customize_preview(), ob_start(), __(), apply_filters(), absint(), get_option(), DESC(), ->have_posts(), ->have_posts(), wp_reset_postdata(), ob_get_flush(), is_customize_preview(), wp_cache_set()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev17621–104111 fewer instruction than PHP 8.5
8.517721–10511
8.417721–10511
8.317721–10511
8.217721–10511
8.117721–105111 fewer instruction than PHP 7.4
7.417821–10511

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Hooks and filters fired · 1

One hook fires while Twenty_Eleven_Ephemera_Widget::widget() runs, in this order:

  1. apply_filters( widget_title )filterline 74 (+19 into the body)

    Filters the widget title.

Uses · 15

Show all 15

Source code

	public function widget( $args, $instance ) {		$cache = wp_cache_get( 'widget_twentyeleven_ephemera', 'widget' ); 		if ( ! is_array( $cache ) ) {			$cache = array();		} 		if ( ! isset( $args['widget_id'] ) ) {			$args['widget_id'] = null;		} 		if ( ! is_customize_preview() && isset( $cache[ $args['widget_id'] ] ) ) {			echo $cache[ $args['widget_id'] ];			return;		} 		ob_start(); 		/** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */		$args['title'] = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Ephemera', 'twentyeleven' ) : $instance['title'], $instance, $this->id_base ); 		if ( ! isset( $instance['number'] ) ) {			$instance['number'] = '10';		} 		$args['number'] = absint( $instance['number'] );		if ( ! $args['number'] ) {			$args['number'] = 10;		} 		$ephemera_args = array(			'order'          => 'DESC',			'posts_per_page' => $args['number'],			'no_found_rows'  => true,			'post_status'    => 'publish',			'post__not_in'   => get_option( 'sticky_posts' ),			'tax_query'      => array(				array(					'taxonomy' => 'post_format',					'terms'    => array( 'post-format-aside', 'post-format-link', 'post-format-status', 'post-format-quote' ),					'field'    => 'slug',					'operator' => 'IN',				),			),		);		$ephemera      = new WP_Query( $ephemera_args ); 		if ( $ephemera->have_posts() ) :			echo $args['before_widget'];			echo $args['before_title'];			echo $args['title'];			echo $args['after_title'];			?>			<ol>			<?php			while ( $ephemera->have_posts() ) :				$ephemera->the_post();				?> 				<?php if ( 'link' !== get_post_format() ) : ?> 				<li class="widget-entry-title">					<a href="<?php echo esc_url( get_permalink() ); ?>" rel="bookmark"><?php the_title(); ?></a>					<span class="comments-link">						<?php comments_popup_link( __( '0 <span class="reply">comments &rarr;</span>', 'twentyeleven' ), __( '1 <span class="reply">comment &rarr;</span>', 'twentyeleven' ), __( '% <span class="reply">comments &rarr;</span>', 'twentyeleven' ) ); ?>					</span>				</li> 				<?php else : ?> 				<li class="widget-entry-title">					<a href="<?php echo esc_url( twentyeleven_get_first_url() ); ?>" rel="bookmark"><?php the_title(); ?>&nbsp;<span>&rarr;</span></a>					<span class="comments-link">						<?php comments_popup_link( __( '0 <span class="reply">comments &rarr;</span>', 'twentyeleven' ), __( '1 <span class="reply">comment &rarr;</span>', 'twentyeleven' ), __( '% <span class="reply">comments &rarr;</span>', 'twentyeleven' ) ); ?>					</span>				</li> 				<?php endif; ?> 			<?php endwhile; ?>

Changelog

Introduced in Twenty Eleven 1.0. One change between 6.7.7 and 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

7.0.4
Parameter $instance retyped from array to untyped.verified against source
Twenty Eleven 1.0
Twenty Eleven 1.0from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-content/themes/twentyeleven/inc/widgets.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.