WordPress函数:wp_loginout

一、函数简介

该函数显示一个登录链接。若用户已登录,该函数将显示登出链接。该函数可利用一个选择性重定向参数为登录/登出后的用户进行重定向。

<?php wp_loginout(); ?>

二、函数参数

  • $redirect (字符串)(可选)登录/登出后进行重定向的URL。默认值:None

三、函数案例

<?php wp_loginout($redirect="https://www.szsthilarys.com/?p=817"); ?>

四、调试效果

五、源代码

/**
 * Displays the Log In/Out link.
 *
 * Displays a link, which allows users to navigate to the Log In page to log in
 * or log out depending on whether they are currently logged in.
 *
 * @since 1.5.0
 *
 * @param string $redirect Optional path to redirect to on login/logout.
 * @param bool   $display  Default to echo and not return the link.
 * @return void|string Void if `$display` argument is true, log in/out link if `$display` is false.
 */
function wp_loginout( $redirect = '', $display = true ) {
	if ( ! is_user_logged_in() ) {
		$link = '<a href="' . esc_url( wp_login_url( $redirect ) ) . '">' . __( 'Log in' ) . '</a>';
	} else {
		$link = '<a href="' . esc_url( wp_logout_url( $redirect ) ) . '">' . __( 'Log out' ) . '</a>';
	}

	if ( $display ) {
		/**
		 * Filters the HTML output for the Log In/Log Out link.
		 *
		 * @since 1.5.0
		 *
		 * @param string $link The HTML link content.
		 */
		echo apply_filters( 'loginout', $link );
	} else {
		/** This filter is documented in wp-includes/general-template.php */
		return apply_filters( 'loginout', $link );
	}
}

THE END