render_block_core_loginout( array $attributes ): string
- Since
- 5.8.0
- Source
wp-includes/blocks/loginout.php:17
core/loginout block on server.Compatibility
- WordPress
- since 5.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
$attributesarray- The block attributes.
Return value
string- Returns the login-out link or form.
Performance profile
How much work a call to render_block_core_loginout() 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
- 36–83
- Plugin surface
- None
- Called by
- 0
Touches nothing outside its own arguments.
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 86.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
apply_filters()one call below render_block_core_loginout()
Further down the call graph this can also reach option, cache, serialize, transient and query. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 4 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost render_block_core_loginout() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 36–43 | is_ssl(), is_user_logged_in(), wp_loginout(), class() |
!empty($attributes) && !wp_is_block_theme() | 46–51 | is_ssl(), is_user_logged_in(), wp_loginout(), wp_login_form(), wp_is_block_theme(), class() |
!empty($attributes) && wp_is_block_theme() && !->next_tag() | 55–60 | is_ssl(), is_user_logged_in(), wp_loginout(), wp_login_form(), wp_is_block_theme(), ->next_tag(), class() |
!empty($attributes) && wp_is_block_theme() && ->next_tag() | 78–83 | is_ssl(), is_user_logged_in(), wp_loginout(), wp_login_form(), wp_is_block_theme(), ->next_tag(), ->get_attribute(), ->get_attribute(), ->add_class(), wp_theme_get_element_class_name(), ->add_class(), ->get_updated_html(), class() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 86 instructions, 36–83 executed per call, 10 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.
Uses · 8
- is_ssl()Determines if SSL is used.
- is_user_logged_in()Determines whether the current visitor is a logged in user.
- wp_loginout()Displays the Log In/Out link.
- wp_login_form()Provides a simple login form for use anywhere within WordPress.
- wp_is_block_theme()Returns whether the active theme is a block-based theme or not.
- wp_theme_get_element_class_name()Given an element name, returns a class name.
- get_block_wrapper_attributes()Generates a string of attributes by applying to the current block being rendered all of the features that the block supports.
- WP_HTML_Tag_Processor::__construct()Constructor.
Source code
function render_block_core_loginout( $attributes ) { /* * Build the redirect URL. This current url fetching logic matches with the core. * * @see https://github.com/WordPress/wordpress-develop/blob/6bf62e58d21739938f3bb3f9e16ba702baf9c2cc/src/wp-includes/general-template.php#L528. */ $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $user_logged_in = is_user_logged_in(); $classes = $user_logged_in ? 'logged-in' : 'logged-out'; $contents = wp_loginout( isset( $attributes['redirectToCurrent'] ) && $attributes['redirectToCurrent'] ? $current_url : '', false ); // If logged-out and displayLoginAsForm is true, show the login form. if ( ! $user_logged_in && ! empty( $attributes['displayLoginAsForm'] ) ) { // Add a class. $classes .= ' has-login-form'; // Get the form. $contents = wp_login_form( array( 'echo' => false ) ); if ( wp_is_block_theme() ) { $processor = new WP_HTML_Tag_Processor( $contents ); while ( $processor->next_tag( 'input' ) ) { if ( 'submit' === $processor->get_attribute( 'type' ) && 'wp-submit' === $processor->get_attribute( 'name' ) ) { $processor->add_class( 'wp-block-button__link' ); $processor->add_class( wp_theme_get_element_class_name( 'button' ) ); $contents = $processor->get_updated_html(); break; } } } } $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) ); return '<div ' . $wrapper_attributes . '>' . $contents . '</div>';}Changelog
Introduced in 5.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/blocks/loginout.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.