返回介绍

wp_logout_url()

发布于 2017-09-11 12:23:44 字数 3920 浏览 1030 评论 0 收藏 0

wp_logout_url( string $redirect = '' )

Retrieves the logout URL.


description

Returns the URL that allows the user to log out of the site.


参数

$redirect

(string) (Optional) Path to redirect to on logout.

Default value: ''


返回值

(string) The logout URL. Note: HTML-encoded via esc_html() in wp_nonce_url().


源代码

File: wp-includes/general-template.php

function wp_logout_url($redirect = '') {
	$args = array( 'action' => 'logout' );
	if ( !empty($redirect) ) {
		$args['redirect_to'] = urlencode( $redirect );
	}

	$logout_url = add_query_arg($args, site_url('wp-login.php', 'login'));
	$logout_url = wp_nonce_url( $logout_url, 'log-out' );

	/**
	 * Filters the logout URL.
	 *
	 * @since 2.8.0
	 *
	 * @param string $logout_url The HTML-encoded logout URL.
	 * @param string $redirect   Path to redirect to on logout.
	 */
	return apply_filters( 'logout_url', $logout_url, $redirect );
}

更新日志

Versiondescription
2.7.0Introduced.

相关函数

Uses

  • wp-includes/general-template.php: logout_url
  • wp-includes/functions.php: wp_nonce_url()
  • wp-includes/functions.php: add_query_arg()
  • wp-includes/link-template.php: site_url()
  • wp-includes/plugin.php: apply_filters()

Used By

  • wp-includes/general-template.php: wp_loginout()
  • wp-includes/functions.php: wp_nonce_ays()
  • wp-includes/class-wp-admin-bar.php: WP_Admin_Bar::_render()
  • wp-includes/admin-bar.php: wp_admin_bar_my_account_menu()
  • wp-includes/comment-template.php: comment_form()

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: 1You must log in to vote on the helpfulness of this note Contributed by Codex

    This example shows how to logout and redirect to another site. If you are using wp_logout_url to redirect to another site on logout (e.g. another subsite in a MultiSite network) you’ll need to make use of the allowed_redirect_hosts filter.

    
    add_filter( 'allowed_redirect_hosts', 'wpdocs_allow_ms_parent_redirect' );
    
    /**
     * Add host to redirection whitelist.
     * @param  array $allowed Redirection allowed hosts.
     * @return array          Extended redirection allowed hosts.
     */
    function wpdocs_allow_ms_parent_redirect( $allowed ) {
    	$allowed[] = 'multisiteparent.com';
    	return $allowed;
    }
    
    <a href="<?php echo wp_logout_url( 'http://multisiteparent.com' ); ?>">Logout</a>
    
  2. Default Usage.

    
    <a href="<?php echo wp_logout_url(); ?>">Logout</a>
    

    This example shows how to logout and redirect to current page inside the loop.

    
    <a href="<?php echo wp_logout_url( get_permalink() ); ?>">Logout</a>
    

    This example shows how to logout and redirect to homepage.

    
    <a href="<?php echo wp_logout_url( home_url() ); ?>">Logout</a>
    

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文