wp_login_url( string $redirect = '', bool $force_reauth = false ): string
- Since
- 2.7.0
- Source
wp-includes/general-template.php:648
Compatibility
- WordPress
- since 2.7.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
$redirectstringoptional- Path to redirect to on log in.Default:
'' $force_reauthbooloptional- Whether to force reauthorization, even if a cookie is present.
Default false.Default:false
Return value
string- The login URL. Not HTML-encoded.
Performance profile
How much work a call to wp_login_url() 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
- 17–32
- Plugin surface
- 1 hook
- Called by
- 21
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 32.
Third-party callbacks on 'login_url' run inside this call, and their cost is not bounded by anything here.
21 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
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 · 4 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_login_url() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
empty($redirect) | 17 | site_url(), apply_filters() |
empty($redirect) | 23 | site_url(), add_query_arg(), apply_filters() |
!empty($redirect) | 26 | site_url(), urlencode(), add_query_arg(), apply_filters() |
!empty($redirect) | 32 | site_url(), urlencode(), add_query_arg(), add_query_arg(), apply_filters() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 32 instructions, 17–32 executed per call, 2 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_login_url() runs, in this order:
Uses · 3
- site_url()Retrieves the URL for the current site where WordPress application files (e.g. wp-blog-header.php or the wp-admin/ folder) are accessible.
- add_query_arg()Retrieves a modified URL query string.
- apply_filters()Calls the callback functions that have been added to a filter hook.
Used by · 21
- WP_Customize_Manager::customize_pane_settings()Prints JavaScript settings for parent window.
- WP_Recovery_Mode_Link_Service::get_recovery_mode_begin_url()Gets a URL to begin recovery mode.
- WP_Recovery_Mode_Link_Service::handle_begin_link()Enters recovery mode when the user hits wp-login.php with a valid recovery mode link.
- auth_redirect()Checks if a user is logged in, if not it redirects them to the login page.
- comment_form()Outputs a complete commenting form for use within a template.
- confirm_another_blog_signup()Shows a message confirming that the new site has been created.
- get_comment_reply_link()Retrieves HTML content for reply to comment link.
- get_post_reply_link()Retrieves HTML content for reply to post link.
- is_login()Determines whether the current request is for the login screen.
- network_step2()Prints step 2 for Network installation process.
- register_new_user()Handles registering a new user.
- wp_admin_bar_recovery_mode_menu()Adds a link to exit recovery mode when Recovery Mode is active.
Show all 21
- wp_auth_check_html()Outputs the HTML that shows the wp-login dialog when the user is no longer logged in.
- wp_loginout()Displays the Log In/Out link.
- wp_new_blog_notification()Notifies the site admin that the installation of WordPress is complete.
- wp_recovery_mode_nag()Displays a notice when the user is in recovery mode.
- wp_redirect_admin_locations()Redirects a variety of shorthand URLs to the admin.
- wp_send_user_request()Send a confirmation request email to confirm an action.
- wp_xmlrpc_server::initialise_blog_option_info()Sets up blog options property.
- wpmu_validate_user_signup()Sanitizes and validates data required for a user sign-up.
- wpmu_welcome_user_notification()Notifies a user that their account activation has been successful.
Source code
function wp_login_url( $redirect = '', $force_reauth = false ) { $login_url = site_url( 'wp-login.php', 'login' ); if ( ! empty( $redirect ) ) { $login_url = add_query_arg( 'redirect_to', urlencode( $redirect ), $login_url ); } if ( $force_reauth ) { $login_url = add_query_arg( 'reauth', '1', $login_url ); } /** * Filters the login URL. * * @since 2.8.0 * @since 4.2.0 The `$force_reauth` parameter was added. * * @param string $login_url The login URL. Not HTML-encoded. * @param string $redirect The path to redirect to on login, if supplied. * @param bool $force_reauth Whether to force reauthorization, even if a cookie is present. */ return apply_filters( 'login_url', $login_url, $redirect, $force_reauth );}Changelog
Introduced in 2.7.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/general-template.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.