WP_Widget_Tag_Cloud::widget( array $args, array $instance )
- Since
- 2.8.0
- Source
wp-includes/widgets/class-wp-widget-tag-cloud.php:42
Compatibility
- WordPress
- since 2.8.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- Display arguments including 'before_title', 'after_title', 'before_widget', and 'after_widget'.
$instancearray- Settings for the current Tag Cloud widget instance.
Performance profile
How much work a call to WP_Widget_Tag_Cloud::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
- Constant
- Instructions
- 28–89
- Plugin surface
- 3 hooks
- Called by
- 0
Reaches the database via get_terms().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 99.
Third-party callbacks on 'widget_tag_cloud_args', 'widget_title', 'navigation_widgets_format' 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
- hookthird-party callbacks
apply_filters()called directly - querycontent query
get_terms()one call below WP_Widget_Tag_Cloud::widget()
Further down the call graph this can also reach option, cache, serialize and transient. Those are 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 WP_Widget_Tag_Cloud::widget() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!empty($instance) && empty($tag_cloud) | 28 | ->_get_current_taxonomy(), taxonomy(), apply_filters() |
empty($instance) && $current_taxonomy === "post_tag" && empty($tag_cloud) | 33 | ->_get_current_taxonomy(), __(), taxonomy(), apply_filters() |
empty($instance) && $current_taxonomy !== "post_tag" && empty($tag_cloud) | 34 | ->_get_current_taxonomy(), get_taxonomy(), taxonomy(), apply_filters() |
!empty($instance) && !empty($tag_cloud) && $format !== "html5" | 61–68 | ->_get_current_taxonomy(), taxonomy(), apply_filters(), apply_filters(), current_theme_supports(), apply_filters() |
empty($instance) && $current_taxonomy === "post_tag" && !empty($tag_cloud) && $format !== "html5" | 66–73 | ->_get_current_taxonomy(), __(), taxonomy(), apply_filters(), apply_filters(), current_theme_supports(), apply_filters() |
empty($instance) && $current_taxonomy !== "post_tag" && !empty($tag_cloud) && $format !== "html5" | 67–74 | ->_get_current_taxonomy(), get_taxonomy(), taxonomy(), apply_filters(), apply_filters(), current_theme_supports(), apply_filters() |
!empty($instance) && !empty($tag_cloud) && $format === "html5" | 75–83 | ->_get_current_taxonomy(), taxonomy(), apply_filters(), apply_filters(), current_theme_supports(), apply_filters(), strip_tags(), esc_attr() |
empty($instance) && $current_taxonomy === "post_tag" && !empty($tag_cloud) && $format === "html5" | 80–88 | ->_get_current_taxonomy(), __(), taxonomy(), apply_filters(), apply_filters(), current_theme_supports(), apply_filters(), strip_tags(), esc_attr() |
empty($instance) && $current_taxonomy !== "post_tag" && !empty($tag_cloud) && $format === "html5" | 81–89 | ->_get_current_taxonomy(), get_taxonomy(), taxonomy(), apply_filters(), apply_filters(), current_theme_supports(), apply_filters(), strip_tags(), esc_attr() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 99 | 28–89 | 8 | |
| 8.5 | 99 | 28–89 | 8 | |
| 8.4 | 99 | 28–89 | 8 | 2 fewer instructions than PHP 8.3 |
| 8.3 | 101 | 28–91 | 8 | |
| 8.2 | 101 | 28–91 | 8 | |
| 8.1 | 101 | 28–91 | 8 | |
| 7.4 | 101 | 28–91 | 8 |
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 · 3
3 hooks fire while WP_Widget_Tag_Cloud::widget() runs, in this order:
- apply_filters( widget_tag_cloud_args )filterline 73 (+31 into the body)
Filters the taxonomy used in the Tag Cloud widget.
- apply_filters( navigation_widgets_format )filterline 99 (+57 into the body)
Filters the HTML format of widgets with navigation links.
Uses · 7
- __()Retrieves the translation of $text.
- get_taxonomy()Retrieves the taxonomy object of $taxonomy.
- wp_tag_cloud()Displays a tag cloud.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- current_theme_supports()Checks a theme's support for a given feature.
- esc_attr()Escaping for HTML attributes.
- WP_Widget_Tag_Cloud::_get_current_taxonomy()Retrieves the taxonomy for the current Tag cloud widget instance.
Source code
public function widget( $args, $instance ) { $current_taxonomy = $this->_get_current_taxonomy( $instance ); if ( ! empty( $instance['title'] ) ) { $title = $instance['title']; } else { if ( 'post_tag' === $current_taxonomy ) { $title = __( 'Tags' ); } else { $tax = get_taxonomy( $current_taxonomy ); $title = $tax->labels->name; } } $default_title = $title; $show_count = ! empty( $instance['count'] ); $tag_cloud = wp_tag_cloud( /** * Filters the taxonomy used in the Tag Cloud widget. * * @since 2.8.0 * @since 3.0.0 Added taxonomy drop-down. * @since 4.9.0 Added the `$instance` parameter. * * @see wp_tag_cloud() * * @param array $args Args used for the tag cloud widget. * @param array $instance Array of settings for the current widget. */ apply_filters( 'widget_tag_cloud_args', array( 'taxonomy' => $current_taxonomy, 'echo' => false, 'show_count' => $show_count, ), $instance ) ); if ( empty( $tag_cloud ) ) { return; } /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); echo $args['before_widget']; if ( $title ) { echo $args['before_title'] . $title . $args['after_title']; } $format = current_theme_supports( 'html5', 'navigation-widgets' ) ? 'html5' : 'xhtml'; /** This filter is documented in wp-includes/widgets/class-wp-nav-menu-widget.php */ $format = apply_filters( 'navigation_widgets_format', $format ); if ( 'html5' === $format ) { // The title may be filtered: Strip out HTML and make sure the aria-label is never empty. $title = trim( strip_tags( $title ) ); $aria_label = $title ? $title : $default_title; echo '<nav aria-label="' . esc_attr( $aria_label ) . '">'; } echo '<div class="tagcloud">'; echo $tag_cloud; echo "</div>\n"; if ( 'html5' === $format ) { echo '</nav>'; } echo $args['after_widget']; }Changelog
Introduced in 2.8.0. Unchanged from 6.7.7 through 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-includes/widgets/class-wp-widget-tag-cloud.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.