wp_loginout

函数
wp_loginout ( $redirect = '', $echo = true )
参数
  • (string) $redirect Optional path to redirect to on login/logout.
    Required:
    Default: (empty)
  • (bool) $echo Default to echo and not return the link.
    Required:
    Default: true
返回值
  • (void|string) Void if `$echo` argument is true, log in/out link if `$echo` is false.
定义位置
相关方法
wp_logoutwp_loginwp_login_urlwp_login_formwp_logout_url
引入
1.5.0
弃用
-

wp_loginout: 这个函数显示一个链接,根据当前用户的状态,将当前用户登录或退出网站。

显示登录/退出链接。

显示一个链接,允许用户导航到登录页面,根据他们当前是否已经登录,进行登录或退出。

function wp_loginout( $redirect = '', $echo = 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 ( $echo ) {
		/**
		 * 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 );
	}
}

常见问题

FAQs
查看更多 >