WP_Widget::_register()
- Since
- 2.8.0
- Source
wp-includes/class-wp-widget.php:253
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.
Performance profile
How much work a call to WP_Widget::_register() 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
- Light
- Scaling
- Scales with input
- Instructions
- 12–26
- Plugin surface
- None
- Called by
- 0
Touches nothing outside its own arguments.
The body loops, so the work grows with how much data it finds.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 36.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What one call costs · 8 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Widget::_register() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!($settings instanceof) && !is_array($settings) | 12 | ->get_settings() |
$settings instanceof && !is_array($settings) | 13–15 | ->get_settings(), ->getArrayCopy() |
!($settings instanceof) && is_array($settings) | 17–18 | ->get_settings(), array_keys() |
!($settings instanceof) && !is_array($settings) | 17 | ->get_settings(), ->_set(), ->_register_one() |
$settings instanceof && is_array($settings) | 18–21 | ->get_settings(), ->getArrayCopy(), array_keys() |
$settings instanceof && !is_array($settings) | 18–20 | ->get_settings(), ->getArrayCopy(), ->_set(), ->_register_one() |
!($settings instanceof) && is_array($settings) | 22–23 | ->get_settings(), array_keys(), ->_set(), ->_register_one() |
$settings instanceof && is_array($settings) | 23–26 | ->get_settings(), ->getArrayCopy(), array_keys(), ->_set(), ->_register_one() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 36 | 12–26 | 7 | |
| 8.5 | 36 | 12–26 | 7 | |
| 8.4 | 36 | 12–26 | 7 | 2 fewer instructions than PHP 8.3 |
| 8.3 | 38 | 12–26 | 7 | |
| 8.2 | 38 | 12–26 | 7 | |
| 8.1 | 38 | 12–26 | 7 | |
| 7.4 | 38 | 12–26 | 7 |
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.
Uses · 3
- WP_Widget::get_settings()Retrieves the settings for all instances of the widget class.
- WP_Widget::_set()Sets the internal order number for the widget instance.
- WP_Widget::_register_one()Registers an instance of the widget class.
Source code
public function _register() { $settings = $this->get_settings(); $empty = true; // When $settings is an array-like object, get an intrinsic array for use with array_keys(). if ( $settings instanceof ArrayObject || $settings instanceof ArrayIterator ) { $settings = $settings->getArrayCopy(); } if ( is_array( $settings ) ) { foreach ( array_keys( $settings ) as $number ) { if ( is_numeric( $number ) ) { $this->_set( $number ); $this->_register_one( $number ); $empty = false; } } } if ( $empty ) { // If there are none, we register the widget's existence with a generic template. $this->_set( 1 ); $this->_register_one(); } }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/class-wp-widget.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.