wp_login_form

函数


wp_login_form ( $args = array() )
参数
  • (array)
    $args
    { Optional. Array of options to control the form output. Default empty array. @type bool $echo Whether to display the login form or return the form HTML code. Default true (echo). @type string $redirect URL to redirect to. Must be absolute, as in “https://example.com/mypage/”. Default is to redirect back to the request URI. @type string $form_id ID attribute value for the form. Default ‘loginform’. @type string $label_username Label for the username or email address field. Default ‘Username or Email Address’. @type string $label_password Label for the password field. Default ‘Password’. @type string $label_remember Label for the remember field. Default ‘Remember Me’. @type string $label_log_in Label for the submit button. Default ‘Log In’. @type string $id_username ID attribute value for the username field. Default ‘user_login’. @type string $id_password ID attribute value for the password field. Default ‘user_pass’. @type string $id_remember ID attribute value for the remember field. Default ‘rememberme’. @type string $id_submit ID attribute value for the submit button. Default ‘wp-submit’. @type bool $remember Whether to display the “rememberme” checkbox in the form. @type string $value_username Default value for the username field. Default empty. @type bool $value_remember Whether the “Remember Me” checkbox should be checked by default. Default false (unchecked). }
    Required:
    Default: array()
返回值
  • (void|string) Void if ‘echo’ argument is true, login form HTML if ‘echo’ is false.
定义位置
  • wp-includes/general-template.php
    , line 511
引入
3.0.0
弃用

Provides a simple login form for use anywhere within WordPress.

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

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,
	);

	/**
	 * 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 );

	$form =
		sprintf(
			'

‘,
esc_attr( $args[‘form_id’] ),
esc_url( site_url( ‘wp-login.php’, ‘login_post’ ) )
) .
$login_form_top .
sprintf(

‘,
esc_attr( $args[‘id_username’] ),
esc_html( $args[‘label_username’] ),
esc_attr( $args[‘value_username’] )
) .
sprintf(

‘,
esc_attr( $args[‘id_password’] ),
esc_html( $args[‘label_password’] )
) .
$login_form_middle .
( $args[‘remember’] ?
sprintf(

‘,
esc_attr( $args[‘id_remember’] ),
( $args[‘value_remember’] ? ‘ checked=”checked”‘ : ” ),
esc_html( $args[‘label_remember’] )
) : ”
) .
sprintf(

‘,
esc_attr( $args[‘id_submit’] ),
esc_attr( $args[‘label_log_in’] ),
esc_url( $args[‘redirect’] )
) .
$login_form_bottom .
”;

if ( $args[‘echo’] ) {
echo $form;
} else {
return $form;
}
}