Why are cookies unrecognized when a link is clicked from an external source (i.e. Excel, Word, etc…)

后端 未结 17 2633
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-28 04:39

I noticed that when a link is clicked externally from the web browser, such as from Excel or Word, that my session cookie is initially unrecognized, even if the link opens u

17条回答
  •  半阙折子戏
    2020-11-28 04:49

    Here is my solution for this in WordPress. Add this to functions.php in your theme or another plugin file.

    This may be helpful if your system, like WP, sends logged out users to a login page with a redirect to the page they were trying to access. Word was sending users to this page, but then WP wasn't properly handling the case where a user was already logged in. This code checks if there is a current user and a redirect_to param passed. If so, it redirects to the redirect_to location.

    function my_logged_in_redirect_to()
    {
    global $current_user;
    
    if($current_user->ID && $_REQUEST['redirect_to'])
    {           
        wp_redirect($_REQUEST['redirect_to']);
        exit;
    }
    }
    add_action('wp', 'my_logged_in_redirect_to');
    

提交回复
热议问题