WP_Widget_Links::widget( array $args, array $instance )
- Since
- 2.8.0
- Source
wp-includes/widgets/class-wp-widget-links.php:41
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 Links widget instance.
Performance profile
How much work a call to WP_Widget_Links::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
- 56–64
- Plugin surface
- 1 hook
- 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 65.
Third-party callbacks on 'widget_links_args' 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_Links::widget()
Further down the call graph this can also reach cache, option, 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 · 1 distinct outcome
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Widget_Links::widget() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 56–64 | apply_filters(), wp_list_bookmarks() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 65 | 56–64 | 8 | |
| 8.5 | 65 | 56–64 | 8 | |
| 8.4 | 65 | 56–64 | 8 | 4 fewer instructions than PHP 8.3 |
| 8.3 | 69 | 60–68 | 8 | |
| 8.2 | 69 | 60–68 | 8 | |
| 8.1 | 69 | 60–68 | 8 | |
| 7.4 | 69 | 60–68 | 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 · 1
One hook fires while WP_Widget_Links::widget() runs, in this order:
- apply_filters( widget_links_args )filterline 80 (+39 into the body)
Filters the arguments for the Links widget.
Uses · 2
- wp_list_bookmarks()Retrieves or echoes all of the bookmarks.
- apply_filters()Calls the callback functions that have been added to a filter hook.
Source code
public function widget( $args, $instance ) { $show_description = $instance['description'] ?? false; $show_name = $instance['name'] ?? false; $show_rating = $instance['rating'] ?? false; $show_images = $instance['images'] ?? true; $category = $instance['category'] ?? false; $orderby = $instance['orderby'] ?? 'name'; $order = 'rating' === $orderby ? 'DESC' : 'ASC'; $limit = $instance['limit'] ?? -1; $before_widget = preg_replace( '/ id="[^"]*"/', ' id="%id"', $args['before_widget'] ); $widget_links_args = array( 'title_before' => $args['before_title'], 'title_after' => $args['after_title'], 'category_before' => $before_widget, 'category_after' => $args['after_widget'], 'show_images' => $show_images, 'show_description' => $show_description, 'show_name' => $show_name, 'show_rating' => $show_rating, 'category' => $category, 'class' => 'linkcat widget', 'orderby' => $orderby, 'order' => $order, 'limit' => $limit, ); /** * Filters the arguments for the Links widget. * * @since 2.6.0 * @since 4.4.0 Added the `$instance` parameter. * * @see wp_list_bookmarks() * * @param array $widget_links_args An array of arguments to retrieve the links list. * @param array $instance The settings for the particular instance of the widget. */ wp_list_bookmarks( apply_filters( 'widget_links_args', $widget_links_args, $instance ) ); }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-links.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.