将订阅者重定向到登录后最后查看的页面

时间:2020-03-29 作者:Xtonys

我希望用户“订阅者”被重定向到他们上次查看的页面。目前,用户被重定向到他们的“myaccount”配置文件页面(my account.php)。我正试图弄清楚如何调整我已经拥有的内容,或者在这里插入另一篇文章中的脚本。

我很确定这里没有数据库工作要做,这只是对脚本的一个更改,对吗?

任何人都可以检查此wp登录。php脚本,并让我知道要更改什么?我还有两个功能。public\\u html结构中的php文件。

提前谢谢你。。。

$requested_redirect_to = isset( $_REQUEST[\'redirect_to\'] ) ? $_REQUEST[\'redirect_to\'] : \'\';
        /**
         * Filters the login redirect URL.
         *
         * @since 3.0.0
         *
         * @param string           $redirect_to           The redirect destination URL.
         * @param string           $requested_redirect_to The requested redirect destination URL passed as a parameter.
         * @param WP_User|WP_Error $user                  WP_User object if login was successful, WP_Error object otherwise.
         */
        $redirect_to = apply_filters( \'login_redirect\', $redirect_to, $requested_redirect_to, $user );

        if ( ! is_wp_error( $user ) && ! $reauth ) {
            if ( $interim_login ) {
                $message       = \'<p class="message">\' . __( \'You have logged in successfully.\' ) . \'</p>\';
                $interim_login = \'success\';
                login_header( \'\', $message );

                ?>
                </div>
                <?php

                /** This action is documented in wp-login.php */
                do_action( \'login_footer\' );

                if ( $customize_login ) {
                    ?>
                    <script type="text/javascript">setTimeout( function(){ new wp.customize.Messenger({ url: \'<?php echo wp_customize_url(); ?>\', channel: \'login\' }).send(\'login\') }, 1000 );</script>
                    <?php
                }

                ?>
                </body></html>
                <?php

                exit;
            }

1 个回复
SO网友:Gui

第一条建议,不要修改Wordpress核心文件!这是一种错误的做法,您的所有更改都将在下一次Wordpress更新时删除。仅对wp内容文件夹进行更改。

我相信您可以使用javascript和Cookie保存用户登录前访问的最后一个页面。

最近,我在一家商店遇到了类似的问题,我希望用户即使在浏览单个产品和相关产品等之后,也可以通过单击“后退”按钮返回到所访问的最新产品档案。。。

下面是我使用的js。这将转到您的登录页面

// Get the previous page visited URL
var prevURL = document.referrer;

// Function to set the cookie
function setCookie(cname, cvalue, exdays) {
    var d = new Date();
    d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
    var expires = "expires="+d.toUTCString();
    document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}

// Now set the cookie with this URL
setCookie("url", prevURL, 1);


// Function to read cookies
function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(\';\');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==\' \') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

// Read the cookie and redirect to the URL on click
var url = readCookie(\'url\');

jQuery(\'a#backToShop\').on(\'click\', function(e){
    e.preventDefault();
    window.open(url , "_self");
});
您可能希望更改最后一个jQuery“click”函数,使其适合所需的行为,可能是函数中的一个操作。wp\\u登录后要重定向的子主题的php

希望这有帮助!

相关推荐

301 Redirection After Comment

下面的代码将访问者重定向到您想要的任何页面。// Redirect to thank you post after comment add_action(\'comment_post_redirect\', \'redirect_to_thank_page\'); function redirect_to_thank_page() { return \'https://example.com/thank-you\'; } 但是,我使用WP Multisite