wppaste
WordPress

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

Since
Twenty Fourteen 1.0
Source
wp-content/themes/twentyfourteen/inc/widgets.php:75
Outputs the HTML for this widget.

Compatibility

WordPress
since Twenty Fourteen 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.
$instancearray
An array of settings for this widget instance.

Performance profile

How much work a call to Twenty_Fourteen_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_posts().

Scaling
Scales with input

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

Instructions
61–122

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

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

  • hookthird-party callbacksapply_filters()called directly
  • optionoption read or writeget_option()called directly
  • querycontent queryget_posts()called directly
  • cacheobject cachewp_cache_get()one call below Twenty_Fourteen_Ephemera_Widget::widget()
  • serializeserialisationmaybe_unserialize()one call below Twenty_Fourteen_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 · 4 distinct outcomes

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

WhenInstructionsCalls it makes
!isset($instance) && empty($instance) && !->have_posts()61–62__(), __(), apply_filters(), get_option(), ->have_posts()
!isset($instance) && !empty($instance) && !->have_posts()67–68__(), __(), absint(), apply_filters(), get_option(), ->have_posts()
!isset($instance) && empty($instance)115–116__(), __(), apply_filters(), get_option(), ->have_posts(), esc_attr(), get_post_format_link(), esc_url(), esc_html(), ->have_posts(), get_post_format_link(), esc_url(), __(), printf(), wp_reset_postdata()
!isset($instance) && !empty($instance)121–122__(), __(), absint(), apply_filters(), get_option(), ->have_posts(), esc_attr(), get_post_format_link(), esc_url(), esc_html(), ->have_posts(), get_post_format_link(), esc_url(), __(), printf(), wp_reset_postdata()

This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev40561–121251 fewer instruction than PHP 8.5
8.540661–12225
8.440661–122253 fewer instructions than PHP 8.3
8.340961–12225
8.240961–12225
8.140961–122258 fewer instructions than PHP 7.4
7.441761–12725

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_Fourteen_Ephemera_Widget::widget() runs, in this order:

  1. apply_filters( widget_title )filterline 117 (+42 into the body)

    Filters the widget title.

Uses · 33

Show all 33

Source code

	public function widget( $args, $instance ) {		$format = isset( $instance['format'] ) ? $instance['format'] : ''; 		if ( ! $format || ! in_array( $format, $this->formats, true ) ) {			$format = 'aside';		} 		switch ( $format ) {			case 'image':				$format_string      = __( 'Images', 'twentyfourteen' );				$format_string_more = __( 'More images', 'twentyfourteen' );				break;			case 'video':				$format_string      = __( 'Videos', 'twentyfourteen' );				$format_string_more = __( 'More videos', 'twentyfourteen' );				break;			case 'audio':				$format_string      = __( 'Audio', 'twentyfourteen' );				$format_string_more = __( 'More audio', 'twentyfourteen' );				break;			case 'quote':				$format_string      = __( 'Quotes', 'twentyfourteen' );				$format_string_more = __( 'More quotes', 'twentyfourteen' );				break;			case 'link':				$format_string      = __( 'Links', 'twentyfourteen' );				$format_string_more = __( 'More links', 'twentyfourteen' );				break;			case 'gallery':				$format_string      = __( 'Galleries', 'twentyfourteen' );				$format_string_more = __( 'More galleries', 'twentyfourteen' );				break;			case 'aside':			default:				$format_string      = __( 'Asides', 'twentyfourteen' );				$format_string_more = __( 'More asides', 'twentyfourteen' );				break;		} 		$number = ! empty( $instance['number'] ) ? absint( $instance['number'] ) : 2;		$title  = ! empty( $instance['title'] ) ? $instance['title'] : $format_string;		/** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */		$title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); 		$ephemera = new WP_Query(			array(				'order'          => 'DESC',				'posts_per_page' => $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-$format" ),						'field'    => 'slug',						'operator' => 'IN',					),				),			)		); 		if ( $ephemera->have_posts() ) :			$tmp_content_width        = $GLOBALS['content_width'];			$GLOBALS['content_width'] = 306; 			echo $args['before_widget'];			?>			<h1 class="widget-title <?php echo esc_attr( $format ); ?>">				<a class="entry-format" href="<?php echo esc_url( get_post_format_link( $format ) ); ?>"><?php echo esc_html( $title ); ?></a>			</h1>			<ol> 				<?php				while ( $ephemera->have_posts() ) :					$ephemera->the_post();					$tmp_more        = $GLOBALS['more'];					$GLOBALS['more'] = 0;					?>				<li>

Changelog

Introduced in Twenty Fourteen 1.0. Unchanged from 6.7.7 through 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.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-content/themes/twentyfourteen/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.