WP_Widget_Text::widget( array $args, array $instance )
- Since
- 2.8.0
- Source
wp-includes/widgets/class-wp-widget-text.php:227
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 Text widget instance.
Performance profile
How much work a call to WP_Widget_Text::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
- Trivial
- Scaling
- Constant
- Instructions
- 93–135
- Plugin surface
- 3 hooks
- Called by
- 0
Touches nothing outside its own arguments.
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 149.
Third-party callbacks on 'widget_title', 'widget_text', 'widget_text_content' 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
Further down the call graph this can also reach option, cache, serialize, query 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 · 56 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Widget_Text::widget() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
empty($instance) && !is_singular() | 93–108 | apply_filters(), has_filter(), is_singular(), apply_filters(), has_filter() |
empty($instance) && !is_singular() | 95–109 | apply_filters(), has_filter(), is_singular(), apply_filters(), apply_filters() |
empty($instance) && is_singular() | 96–111 | apply_filters(), has_filter(), is_singular(), get_queried_object(), apply_filters(), has_filter() |
!is_singular() | 97–112 | apply_filters(), has_filter(), is_singular(), apply_filters(), wpautop(), has_filter() |
empty($instance) && !is_singular() | 98–113 | apply_filters(), has_filter(), is_singular(), apply_filters(), has_filter(), add_filter() |
empty($instance) && is_singular() | 98–112 | apply_filters(), has_filter(), is_singular(), get_queried_object(), apply_filters(), apply_filters() |
empty($instance) && !is_singular() | 98–113 | apply_filters(), has_filter(), remove_filter(), is_singular(), apply_filters(), has_filter() |
empty($instance) && !is_singular() && has_filter() | 100–114 | apply_filters(), has_filter(), is_singular(), apply_filters(), has_filter(), do_shortcode() |
empty($instance) && !is_singular() | 100–114 | apply_filters(), has_filter(), is_singular(), apply_filters(), apply_filters(), add_filter() |
empty($instance) && !is_singular() | 100–114 | apply_filters(), has_filter(), remove_filter(), is_singular(), apply_filters(), apply_filters() |
is_singular() | 100–115 | apply_filters(), has_filter(), is_singular(), get_queried_object(), apply_filters(), wpautop(), has_filter() |
empty($instance) && is_singular() | 101–116 | apply_filters(), has_filter(), is_singular(), get_queried_object(), apply_filters(), has_filter(), add_filter() |
44 further outcomes, up to 135 instructions
empty($instance) && is_singular() | 101–116 | apply_filters(), has_filter(), remove_filter(), is_singular(), get_queried_object(), apply_filters(), has_filter() |
!is_singular() | 102–117 | apply_filters(), has_filter(), is_singular(), apply_filters(), wpautop(), has_filter(), add_filter() |
!is_singular() | 102–117 | apply_filters(), has_filter(), remove_filter(), is_singular(), apply_filters(), wpautop(), has_filter() |
empty($instance) && is_singular() && has_filter() | 103–117 | apply_filters(), has_filter(), is_singular(), get_queried_object(), apply_filters(), has_filter(), do_shortcode() |
empty($instance) && is_singular() | 103–117 | apply_filters(), has_filter(), is_singular(), get_queried_object(), apply_filters(), apply_filters(), add_filter() |
empty($instance) && !is_singular() | 103–118 | apply_filters(), has_filter(), remove_filter(), is_singular(), apply_filters(), has_filter(), add_filter() |
empty($instance) && is_singular() | 103–117 | apply_filters(), has_filter(), remove_filter(), is_singular(), get_queried_object(), apply_filters(), apply_filters() |
!is_singular() && has_filter() | 104–118 | apply_filters(), has_filter(), is_singular(), apply_filters(), has_filter(), shortcode_unautop(), do_shortcode() |
!is_singular() && has_filter() | 104–118 | apply_filters(), has_filter(), is_singular(), apply_filters(), wpautop(), has_filter(), do_shortcode() |
empty($instance) && !is_singular() && has_filter() | 105–119 | apply_filters(), has_filter(), is_singular(), apply_filters(), has_filter(), do_shortcode(), add_filter() |
empty($instance) && !is_singular() && has_filter() | 105–119 | apply_filters(), has_filter(), remove_filter(), is_singular(), apply_filters(), has_filter(), do_shortcode() |
empty($instance) && !is_singular() | 105–119 | apply_filters(), has_filter(), remove_filter(), is_singular(), apply_filters(), apply_filters(), add_filter() |
is_singular() | 105–120 | apply_filters(), has_filter(), is_singular(), get_queried_object(), apply_filters(), wpautop(), has_filter(), add_filter() |
is_singular() | 105–120 | apply_filters(), has_filter(), remove_filter(), is_singular(), get_queried_object(), apply_filters(), wpautop(), has_filter() |
empty($instance) && is_singular() | 106–121 | apply_filters(), has_filter(), remove_filter(), is_singular(), get_queried_object(), apply_filters(), has_filter(), add_filter() |
is_singular() && has_filter() | 107–121 | apply_filters(), has_filter(), is_singular(), get_queried_object(), apply_filters(), has_filter(), shortcode_unautop(), do_shortcode() |
is_singular() && has_filter() | 107–121 | apply_filters(), has_filter(), is_singular(), get_queried_object(), apply_filters(), wpautop(), has_filter(), do_shortcode() |
!is_singular() | 107–122 | apply_filters(), has_filter(), remove_filter(), is_singular(), apply_filters(), wpautop(), has_filter(), add_filter() |
!is_singular() && has_filter() | 108–122 | apply_filters(), has_filter(), is_singular(), apply_filters(), wpautop(), has_filter(), shortcode_unautop(), do_shortcode() |
empty($instance) && is_singular() && has_filter() | 108–122 | apply_filters(), has_filter(), is_singular(), get_queried_object(), apply_filters(), has_filter(), do_shortcode(), add_filter() |
empty($instance) && is_singular() && has_filter() | 108–122 | apply_filters(), has_filter(), remove_filter(), is_singular(), get_queried_object(), apply_filters(), has_filter(), do_shortcode() |
empty($instance) && is_singular() | 108–122 | apply_filters(), has_filter(), remove_filter(), is_singular(), get_queried_object(), apply_filters(), apply_filters(), add_filter() |
!is_singular() && has_filter() | 109–123 | apply_filters(), has_filter(), is_singular(), apply_filters(), has_filter(), shortcode_unautop(), do_shortcode(), add_filter() |
!is_singular() && has_filter() | 109–123 | apply_filters(), has_filter(), is_singular(), apply_filters(), wpautop(), has_filter(), do_shortcode(), add_filter() |
!is_singular() && has_filter() | 109–123 | apply_filters(), has_filter(), remove_filter(), is_singular(), apply_filters(), has_filter(), shortcode_unautop(), do_shortcode() |
!is_singular() && has_filter() | 109–123 | apply_filters(), has_filter(), remove_filter(), is_singular(), apply_filters(), wpautop(), has_filter(), do_shortcode() |
empty($instance) && !is_singular() && has_filter() | 110–124 | apply_filters(), has_filter(), remove_filter(), is_singular(), apply_filters(), has_filter(), do_shortcode(), add_filter() |
is_singular() | 110–125 | apply_filters(), has_filter(), remove_filter(), is_singular(), get_queried_object(), apply_filters(), wpautop(), has_filter(), add_filter() |
is_singular() && has_filter() | 111–125 | apply_filters(), has_filter(), is_singular(), get_queried_object(), apply_filters(), wpautop(), has_filter(), shortcode_unautop(), do_shortcode() |
is_singular() && has_filter() | 112–126 | apply_filters(), has_filter(), is_singular(), get_queried_object(), apply_filters(), has_filter(), shortcode_unautop(), do_shortcode(), add_filter() |
is_singular() && has_filter() | 112–126 | apply_filters(), has_filter(), is_singular(), get_queried_object(), apply_filters(), wpautop(), has_filter(), do_shortcode(), add_filter() |
is_singular() && has_filter() | 112–126 | apply_filters(), has_filter(), remove_filter(), is_singular(), get_queried_object(), apply_filters(), has_filter(), shortcode_unautop(), do_shortcode() |
is_singular() && has_filter() | 112–126 | apply_filters(), has_filter(), remove_filter(), is_singular(), get_queried_object(), apply_filters(), wpautop(), has_filter(), do_shortcode() |
!is_singular() && has_filter() | 113–127 | apply_filters(), has_filter(), is_singular(), apply_filters(), wpautop(), has_filter(), shortcode_unautop(), do_shortcode(), add_filter() |
!is_singular() && has_filter() | 113–127 | apply_filters(), has_filter(), remove_filter(), is_singular(), apply_filters(), wpautop(), has_filter(), shortcode_unautop(), do_shortcode() |
empty($instance) && is_singular() && has_filter() | 113–127 | apply_filters(), has_filter(), remove_filter(), is_singular(), get_queried_object(), apply_filters(), has_filter(), do_shortcode(), add_filter() |
!is_singular() && has_filter() | 114–128 | apply_filters(), has_filter(), remove_filter(), is_singular(), apply_filters(), has_filter(), shortcode_unautop(), do_shortcode(), add_filter() |
!is_singular() && has_filter() | 114–128 | apply_filters(), has_filter(), remove_filter(), is_singular(), apply_filters(), wpautop(), has_filter(), do_shortcode(), add_filter() |
is_singular() && has_filter() | 116–130 | apply_filters(), has_filter(), is_singular(), get_queried_object(), apply_filters(), wpautop(), has_filter(), shortcode_unautop(), do_shortcode(), add_filter() |
is_singular() && has_filter() | 116–130 | apply_filters(), has_filter(), remove_filter(), is_singular(), get_queried_object(), apply_filters(), wpautop(), has_filter(), shortcode_unautop(), do_shortcode() |
is_singular() && has_filter() | 117–131 | apply_filters(), has_filter(), remove_filter(), is_singular(), get_queried_object(), apply_filters(), has_filter(), shortcode_unautop(), do_shortcode(), add_filter() |
is_singular() && has_filter() | 117–131 | apply_filters(), has_filter(), remove_filter(), is_singular(), get_queried_object(), apply_filters(), wpautop(), has_filter(), do_shortcode(), add_filter() |
!is_singular() && has_filter() | 118–132 | apply_filters(), has_filter(), remove_filter(), is_singular(), apply_filters(), wpautop(), has_filter(), shortcode_unautop(), do_shortcode(), add_filter() |
is_singular() && has_filter() | 121–135 | apply_filters(), has_filter(), remove_filter(), is_singular(), get_queried_object(), apply_filters(), wpautop(), has_filter(), shortcode_unautop(), do_shortcode(), add_filter() |
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
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 149 | 93–135 | 16 | |
| 8.5 | 149 | 93–135 | 16 | |
| 8.4 | 149 | 93–135 | 16 | |
| 8.3 | 149 | 93–135 | 16 | |
| 8.2 | 149 | 93–135 | 16 | |
| 8.1 | 149 | 93–135 | 16 | 2 fewer instructions than PHP 7.4 |
| 7.4 | 151 | 93–135 | 16 |
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_Text::widget() runs, in this order:
- apply_filters( widget_text )filterline 283 (+56 into the body)
Filters the content of the Text widget.
- apply_filters( widget_text_content )filterline 298 (+71 into the body)
Filters the content of the Text widget to apply changes expected from the visual (TinyMCE) editor.
Uses · 9
- apply_filters()Calls the callback functions that have been added to a filter hook.
- has_filter()Checks if any filter has been registered for a hook.
- remove_filter()Removes a callback function from a filter hook.
- is_singular()Determines whether the query is for an existing single post of any post type (post, attachment, page, custom post types).
- get_queried_object()Retrieves the currently queried object.
- add_filter()Adds a callback function to a filter hook.
- wpautop()Replaces double line breaks with paragraph elements.
- shortcode_unautop()Don't auto-p wrap shortcodes that stand alone.
- do_shortcode()Searches content for shortcodes and filter shortcodes through their hooks.
Source code
public function widget( $args, $instance ) { global $post; $title = ! empty( $instance['title'] ) ? $instance['title'] : ''; /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); $text = ! empty( $instance['text'] ) ? $instance['text'] : ''; $is_visual_text_widget = ( ! empty( $instance['visual'] ) && ! empty( $instance['filter'] ) ); // In 4.8.0 only, visual Text widgets get filter=content, without visual prop; upgrade instance props just-in-time. if ( ! $is_visual_text_widget ) { $is_visual_text_widget = ( isset( $instance['filter'] ) && 'content' === $instance['filter'] ); } if ( $is_visual_text_widget ) { $instance['filter'] = true; $instance['visual'] = true; } /* * Suspend legacy plugin-supplied do_shortcode() for 'widget_text' filter for the visual Text widget to prevent * shortcodes being processed twice. Now do_shortcode() is added to the 'widget_text_content' filter in core itself * and it applies after wpautop() to prevent corrupting HTML output added by the shortcode. When do_shortcode() is * added to 'widget_text_content' then do_shortcode() will be manually called when in legacy mode as well. */ $widget_text_do_shortcode_priority = has_filter( 'widget_text', 'do_shortcode' ); $should_suspend_legacy_shortcode_support = ( $is_visual_text_widget && false !== $widget_text_do_shortcode_priority ); if ( $should_suspend_legacy_shortcode_support ) { remove_filter( 'widget_text', 'do_shortcode', $widget_text_do_shortcode_priority ); } // Override global $post so filters (and shortcodes) apply in a consistent context. $original_post = $post; if ( is_singular() ) { // Make sure post is always the queried object on singular queries (not from another sub-query that failed to clean up the global $post). $post = get_queried_object(); } else { // Nullify the $post global during widget rendering to prevent shortcodes from running with the unexpected context on archive queries. $post = null; } // Prevent dumping out all attachments from the media library. add_filter( 'shortcode_atts_gallery', array( $this, '_filter_gallery_shortcode_attrs' ) ); /** * Filters the content of the Text widget. * * @since 2.3.0 * @since 4.4.0 Added the `$widget` parameter. * @since 4.8.1 The `$widget` param may now be a `WP_Widget_Custom_HTML` object in addition to a `WP_Widget_Text` object. * * @param string $text The widget content. * @param array $instance Array of settings for the current widget. * @param WP_Widget_Text|WP_Widget_Custom_HTML $widget Current text or HTML widget instance. */ $text = apply_filters( 'widget_text', $text, $instance, $this ); if ( $is_visual_text_widget ) { /** * Filters the content of the Text widget to apply changes expected from the visual (TinyMCE) editor. * * By default a subset of the_content filters are applied, including wpautop and wptexturize. * * @since 4.8.0 * * @param string $text The widget content. * @param array $instance Array of settings for the current widget. * @param WP_Widget_Text $widget Current Text widget instance. */ $text = apply_filters( 'widget_text_content', $text, $instance, $this ); } else { // Now in legacy mode, add paragraphs and line breaks when checkbox is checked. if ( ! empty( $instance['filter'] ) ) { $text = wpautop( $text ); } /* * Manually do shortcodes on the content when the core-added filter is present. It is added by defaultChangelog
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 6.8.8 tag, from
src/wp-includes/widgets/class-wp-widget-text.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.