Twenty_Eleven_Ephemera_Widget::widget( array $args, $instance )
- Since
- Twenty Eleven 1.0
- Source
wp-content/themes/twentyeleven/inc/widgets.php:55
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
- Scaling
- Scales with input
- Instructions
- 21–105
- Plugin surface
- 1 hook
- Called by
- 0
Reaches the database via get_post().
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 177.
Third-party callbacks on 'widget_title' run inside this call, and their cost is not bounded by anything here.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- cacheobject cache
wp_cache_get()called directly - hookthird-party callbacks
apply_filters()called directly - optionoption read or write
get_option()called directly - serializeserialisation
maybe_unserialize()one call below Twenty_Eleven_Ephemera_Widget::widget() - querycontent query
get_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.
| When | Instructions | Calls it makes |
|---|---|---|
!is_customize_preview() && isset($cache) | 21–24 | wp_cache_get(), is_customize_preview() |
is_customize_preview() && !empty($instance) && !->have_posts() | 67–77 | wp_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–82 | wp_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–82 | wp_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–87 | wp_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–95 | wp_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–100 | wp_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–100 | wp_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–105 | wp_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
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 176 | 21–104 | 11 | 1 fewer instruction than PHP 8.5 |
| 8.5 | 177 | 21–105 | 11 | |
| 8.4 | 177 | 21–105 | 11 | |
| 8.3 | 177 | 21–105 | 11 | |
| 8.2 | 177 | 21–105 | 11 | |
| 8.1 | 177 | 21–105 | 11 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 178 | 21–105 | 11 |
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:
Uses · 15
- wp_cache_get()Retrieves the cache contents from the cache by key and group.
- is_customize_preview()Whether the site is being previewed in the Customizer.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- __()Retrieves the translation of $text.
- absint()Converts a value to non-negative integer.
- get_option()Retrieves an option value based on an option name.
- get_post_format()Retrieve the format slug for a post
- esc_url()Checks and cleans a URL.
- get_permalink()Retrieves the full permalink for the current post or post ID.
- the_title()Displays or retrieves the current post title with optional markup.
- comments_popup_link()Displays the link to the comments for the current post ID.
- twentyeleven_get_first_url()Returns the first link from the post content. If none found, the post permalink is used as a fallback.
Show all 15
- wp_reset_postdata()After looping through a separate query, this function restores the $post global to the current post in the main query.
- wp_cache_set()Saves the data to the cache.
- WP_Query::__construct()Constructor.
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 →</span>', 'twentyeleven' ), __( '1 <span class="reply">comment →</span>', 'twentyeleven' ), __( '% <span class="reply">comments →</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(); ?> <span>→</span></a> <span class="comments-link"> <?php comments_popup_link( __( '0 <span class="reply">comments →</span>', 'twentyeleven' ), __( '1 <span class="reply">comment →</span>', 'twentyeleven' ), __( '% <span class="reply">comments →</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.
Signature, return type and hooks compared across 5 parsed releases.
$instance retyped from array to untyped.verified against sourceAbout 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.