wp_login_form()创建一个登录对话框

目录

描述

Provides a simple login form for use anywhere within WordPress. By default, it echoes the HTML immediately. Pass array('echo' => false) to return the string instead.

wp_login_form() 描述

用法

 <?php wp_login_form$args ); ?> 

Default Usage

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
 <?php $args = array(        'echo'           => true,        'redirect' => ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'],        'form_id'        => 'loginform',        'label_username' => __( 'Username' ),        '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' => '',        'value_remember' => false); ?> 

wp_login_form() 用法

参数

echo

(boolean) (可选) Display the results. Options are:

  • 1 (true)
  • 0 (false)

默认值: true

redirect

(string) (可选) URL to redirect to. Must be absolute (as in, http://example.com/mypage/). Recommended: site_url( '/mypage/ ' ).

默认值: the current page

form_id

(string) (可选) form_id.

默认值: loginform

remember

(boolean) (可选) Whether to remember the values.

  • 1 (true)
  • 0 (false)

默认值: true

value_username

(string) (可选) value_username.

默认值: NULL

value_remember

(string) (可选)

  • 1 (true)
  • 0 (false)

默认值: false

wp_login_form() 参数

示例

Default Usage

This simple function displays a login form:

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */

<?php wp_login_form(); ?>

wp_login_form() 示例

历史

  • 添加于 版本: 3.0.0

wp_login_form() 历史

源文件

wp_login_form() 函数的代码位于 wp-includes/general-template.php.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Provides a simple login form for use anywhere within WordPress. By default, it echoes
 * the HTML immediately. Pass array('echo'=>false) to return the string instead.
 *
 * @since 3.0.0
 *
 * @param array $args Configuration options to modify the form output.
 * @return string|void String when retrieving.
 */
function wp_login_form( $args = array() ) {
	$defaults = array(
		'echo' => true,
		'redirect' => ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], // Default redirect is back to the current page
		'form_id' => 'loginform',
		'label_username' => __( 'Username' ),
		'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' => '',
		'value_remember' => false, // Set this to true to default the "Remember me" checkbox to checked
	);

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

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

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

	/**
	 * Filter 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 = '
		
' . $login_form_top . ' ' . $login_form_middle . ' ' . ( $args['remember'] ? '' : '' ) . ' ' . $login_form_bottom . '
'; if ( $args['echo'] ) echo $form; else return $form; }

wp_login_form() 源文件

相关