wppaste
WordPress

wp_login_form( array $args = array() ): void|string

Since
3.0.0, 6.6.0
Source
wp-includes/general-template.php:726
Provides a simple login form for use anywhere within WordPress.

Description

The login form HTML is echoed by default. Pass a false value for $echo to return it instead.

Compatibility

WordPress
since 6.6.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

$argsarrayoptional
Array of options to control the form output. Default empty array.Default: array()
  • $echobooldefault: true (echo)

    Whether to display the login form or return the form HTML code.
  • $redirectstringdefault: is to redirect back to the request URI

    URL to redirect to. Must be absolute, as in "https://example.com/mypage/".
  • $form_idstringdefault: 'loginform'

    ID attribute value for the form.
  • $label_usernamestringdefault: 'Username or Email Address'

    Label for the username or email address field.
  • $label_passwordstringdefault: 'Password'

    Label for the password field.
  • $label_rememberstringdefault: 'Remember Me'

    Label for the remember field.
  • $label_log_instringdefault: 'Log In'

    Label for the submit button.
  • $id_usernamestringdefault: 'user_login'

    ID attribute value for the username field.
  • $id_passwordstringdefault: 'user_pass'

    ID attribute value for the password field.
  • $id_rememberstringdefault: 'rememberme'

    ID attribute value for the remember field.
  • $id_submitstringdefault: 'wp-submit'

    ID attribute value for the submit button.
  • $rememberbool

    Whether to display the "rememberme" checkbox in the form.
  • $value_usernamestringdefault: value for the username field. Default empty

  • $value_rememberbooldefault: false (unchecked)

    Whether the "Remember Me" checkbox should be checked by default.
  • $required_usernamebooldefault: false

    Whether the username field has the 'required' attribute.
  • $required_passwordbooldefault: false

    Whether the password field has the 'required' attribute.

Return value

void|string
Void if 'echo' argument is true, login form HTML if 'echo' is false.

Performance profile

How much work a call to wp_login_form() 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

Touches nothing outside its own arguments.

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
170–196

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 203.

Plugin surface
4 hooks

Third-party callbacks on 'login_form_defaults', 'login_form_top', 'login_form_middle' run inside this call, and their cost is not bounded by anything here.

Called by
1

1 place in core call this, so the cost is paid more often than your own code shows.

What it touches

  • hookthird-party callbacksapply_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 · 2 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_login_form() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
!$args170–175is_ssl(), __(), __(), __(), __(), apply_filters(), wp_parse_args(), apply_filters(), apply_filters(), apply_filters(), is_rtl(), esc_attr(), site_url(), esc_url(), sprintf(), esc_attr(), esc_html(), esc_attr(), sprintf(), esc_attr(), esc_html(), sprintf(), esc_attr(), esc_attr(), esc_url(), sprintf()
$args190–196is_ssl(), __(), __(), __(), __(), apply_filters(), wp_parse_args(), apply_filters(), apply_filters(), apply_filters(), is_rtl(), esc_attr(), site_url(), esc_url(), sprintf(), esc_attr(), esc_html(), esc_attr(), sprintf(), esc_attr(), esc_html(), sprintf(), esc_attr(), esc_html(), sprintf(), esc_attr(), esc_attr(), esc_url(), sprintf()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev202170–19571 fewer instruction than PHP 8.5
8.5203170–1967
8.4203170–1967
8.3203170–1967
8.2203170–1967
8.1203170–1967
7.4203170–1967

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 · 4

4 hooks fire while wp_login_form() runs, in this order:

  1. apply_filters( login_form_defaults )filterline 759 (+33 into the body)

    Filters the default login form output arguments.

  2. apply_filters( login_form_top )filterline 771 (+45 into the body)

    Filters content to display at the top of the login form.

  3. apply_filters( login_form_middle )filterline 784 (+58 into the body)

    Filters content to display in the middle of the login form.

  4. apply_filters( login_form_bottom )filterline 796 (+70 into the body)

    Filters content to display at the bottom of the login form.

Uses · 9

  • is_ssl()Determines if SSL is used.
  • __()Retrieves the translation of $text.
  • wp_parse_args()Merges user defined arguments into defaults array.
  • apply_filters()Calls the callback functions that have been added to a filter hook.
  • is_rtl()Determines whether the current locale is right-to-left (RTL).
  • esc_attr()Escaping for HTML attributes.
  • esc_url()Checks and cleans a URL.
  • 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.
  • esc_html()Escaping for HTML blocks.

Used by · 1

Source code

function wp_login_form( $args = array() ) {	$defaults = array(		'echo'              => true,		// Default 'redirect' value takes the user back to the request URI.		'redirect'          => ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'],		'form_id'           => 'loginform',		'label_username'    => __( 'Username or Email Address' ),		'label_password'    => __( 'Password' ),		'label_remember'    => __( 'Remember Me' ),		'label_log_in'      => __( 'Log In' ),		'id_username'       => 'user_login',		'id_password'       => 'user_pass',		'id_remember'       => 'rememberme',		'id_submit'         => 'wp-submit',		'remember'          => true,		'value_username'    => '',		// Set 'value_remember' to true to default the "Remember me" checkbox to checked.		'value_remember'    => false,		// Set 'required_username' to true to add the required attribute to username field.		'required_username' => false,		// Set 'required_password' to true to add the required attribute to password field.		'required_password' => false,	); 	/**	 * Filters the default login form output arguments.	 *	 * @since 3.0.0	 *	 * @see wp_login_form()	 *	 * @param array $defaults An array of default login form arguments.	 */	$args = wp_parse_args( $args, apply_filters( 'login_form_defaults', $defaults ) ); 	/**	 * Filters content to display at the top of the login form.	 *	 * The filter evaluates just following the opening form tag element.	 *	 * @since 3.0.0	 *	 * @param string $content Content to display. Default empty.	 * @param array  $args    Array of login form arguments.	 */	$login_form_top = apply_filters( 'login_form_top', '', $args ); 	/**	 * Filters content to display in the middle of the login form.	 *	 * The filter evaluates just following the location where the 'login-password'	 * field is displayed.	 *	 * @since 3.0.0	 *	 * @param string $content Content to display. Default empty.	 * @param array  $args    Array of login form arguments.	 */	$login_form_middle = apply_filters( 'login_form_middle', '', $args ); 	/**	 * Filters content to display at the bottom of the login form.	 *	 * The filter evaluates just preceding the closing form tag element.	 *	 * @since 3.0.0	 *	 * @param string $content Content to display. Default empty.	 * @param array  $args    Array of login form arguments.	 */	$login_form_bottom = apply_filters( 'login_form_bottom', '', $args ); 	$direction_style = is_rtl() ? ' style="direction: ltr;"' : ''; 	$form =		sprintf(			'<form name="%1$s" id="%1$s" action="%2$s" method="post">',			esc_attr( $args['form_id'] ),			esc_url( site_url( 'wp-login.php', 'login_post' ) )		) .

Changelog

Introduced in 3.0.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

6.6.0
Added required_username and required_password arguments.from the docblock
3.0.0
Introduced.from the docblock

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.