WP_Navigation_Fallback::get_fallback(): WP_Post|null
- Since
- 6.3.0
- Source
wp-includes/class-wp-navigation-fallback.php:70
Compatibility
- WordPress
- since 6.3.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.
Return value
WP_Post|null- the fallback Navigation Post or null.
Performance profile
How much work a call to WP_Navigation_Fallback::get_fallback() 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
- 10–31
- Plugin surface
- 1 hook
- Called by
- 2
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 40.
Third-party callbacks on 'wp_navigation_should_create_fallback' run inside this call, and their cost is not bounded by anything here.
2 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly
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_Navigation_Fallback::get_fallback() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 10–11 | apply_filters(), ::get_most_recently_published_navigation() |
| always | 19 | apply_filters(), ::get_most_recently_published_navigation(), ::create_classic_menu_fallback(), ::create_default_fallback() |
!is_wp_error() && $fallback instanceof | 21 | apply_filters(), ::get_most_recently_published_navigation(), ::create_classic_menu_fallback(), is_wp_error() |
| always | 23–25 | apply_filters(), ::get_most_recently_published_navigation(), ::create_classic_menu_fallback(), ::create_default_fallback(), is_wp_error() |
is_wp_error() | 23 | apply_filters(), ::get_most_recently_published_navigation(), ::create_classic_menu_fallback(), is_wp_error(), ::create_default_fallback() |
!is_wp_error() && !($fallback instanceof) | 23 | apply_filters(), ::get_most_recently_published_navigation(), ::create_classic_menu_fallback(), is_wp_error(), ::get_most_recently_published_navigation() |
!is_wp_error() && !($fallback instanceof) | 27 | apply_filters(), ::get_most_recently_published_navigation(), ::create_classic_menu_fallback(), ::create_default_fallback(), is_wp_error(), ::get_most_recently_published_navigation() |
is_wp_error() | 27–29 | apply_filters(), ::get_most_recently_published_navigation(), ::create_classic_menu_fallback(), is_wp_error(), ::create_default_fallback(), is_wp_error() |
!($fallback instanceof) | 31 | apply_filters(), ::get_most_recently_published_navigation(), ::create_classic_menu_fallback(), is_wp_error(), ::create_default_fallback(), is_wp_error(), ::get_most_recently_published_navigation() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 40 instructions, 10–31 executed per call, 8 branches. The work does not change between versions.
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_Navigation_Fallback::get_fallback() runs, in this order:
- apply_filters( wp_navigation_should_create_fallback )filterline 78 (+8 into the body)
Filters whether or not a fallback should be created.
Uses · 5
- apply_filters()Calls the callback functions that have been added to a filter hook.
- is_wp_error()Checks whether the given variable is a WordPress Error.
- static::get_most_recently_published_navigation()
- static::create_classic_menu_fallback()
- static::create_default_fallback()
Used by · 2
- WP_REST_Navigation_Fallback_Controller::get_item()Gets the most appropriate fallback Navigation Menu.
- block_core_navigation_get_fallback_blocks()Retrieves the appropriate fallback to be used on the front of the site when there is no menu assigned to the Nav block.
Source code
public static function get_fallback() { /** * Filters whether or not a fallback should be created. * * @since 6.3.0 * * @param bool $create Whether to create a fallback navigation menu. Default true. */ $should_create_fallback = apply_filters( 'wp_navigation_should_create_fallback', true ); $fallback = static::get_most_recently_published_navigation(); if ( $fallback || ! $should_create_fallback ) { return $fallback; } $fallback = static::create_classic_menu_fallback(); if ( $fallback && ! is_wp_error( $fallback ) ) { // Return the newly created fallback post object which will now be the most recently created navigation menu. return $fallback instanceof WP_Post ? $fallback : static::get_most_recently_published_navigation(); } $fallback = static::create_default_fallback(); if ( $fallback && ! is_wp_error( $fallback ) ) { // Return the newly created fallback post object which will now be the most recently created navigation menu. return $fallback instanceof WP_Post ? $fallback : static::get_most_recently_published_navigation(); } return null; }Changelog
Introduced in 6.3.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-navigation-fallback.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.