登录后重定向- WordPress PHP

92vpleto  于 2022-11-28  发布在  WordPress
关注(0)|答案(2)|浏览(317)

我有一个自定义的登录页面,一旦用户登录,带他回到相同的页面,我想有一个在主页上的php重定向,我发现这个重定向php文件,我如何修改它让用户回家?
我包括所有可能感兴趣的文件
谢谢
stm-lms-user-redirect.php

<?php

$redirect_url = get_site_url();

if(is_user_logged_in()) {
    $lms_settings = get_option('stm_lms_settings', array());
    $user_url = (!empty($lms_settings['user_url'])) ? $lms_settings['user_url'] : '/lms-user';
    $redirect_url .= $user_url . '/' .  get_current_user_id();
}

//wp_safe_redirect($redirect_url);

stm-lms-用户名.php

<?php
        do_action( 'stm_lms_before_user_header' );
        do_action( 'stm_lms_template_main' );
        
        $current_user = STM_LMS_User::get_current_user( '', true, true );
        $tpl          = 'account/private/main';
        
        stm_lms_register_style( 'user' );
        
        if ( function_exists( 'vc_asset_url' ) ) {
            wp_enqueue_style( 'stm_lms_wpb_front_css', vc_asset_url( 'css/js_composer.min.css' ), array(), time() );
        }
        ?>
        <?php STM_LMS_Templates::show_lms_template( 'modals/preloader' ); ?>
        <div class="stm-lms-wrapper stm-lms-wrapper-user user-account-page">
        
            <?php do_action( 'stm_lms_admin_after_wrapper_start', $current_user ); ?>
        
            <?php STM_LMS_Templates::show_lms_template( 'account/private/parts/become_instructor_info', compact( 'current_user' ) ); ?>
            <div class="container">
                <?php
                if ( ! empty( $tpl ) ) {
                    STM_LMS_Templates::show_lms_template( $tpl, compact( 'current_user' ) );}
                ?>
            </div>
        </div>

登录名.php

<div id="stm-lms-login<?php if (isset($form_position)) esc_attr_e($form_position); ?>" class="stm-lms-login active vue_is_disabled"
         v-init="site_key = '<?php echo stm_lms_filtered_output($site_key); ?>'"
         v-bind:class="{'is_vue_loaded' : vue_loaded}">

        <div class="stm-lms-login__top">
            <?php if (defined('WORDPRESS_SOCIAL_LOGIN_ABS_PATH') and apply_filters('stm_lms_show_social_login', true)) {
                do_action('wordpress_social_login');
            } ?>

            <h3><?php esc_html_e('Login', 'masterstudy-lms-learning-management-system'); ?></h3>

            <?php do_action('stm_lms_login_end'); ?>
        </div>

        <div class="stm_lms_login_wrapper">

            <div class="form-group">
                <label class="heading_font">
                    <?php echo apply_filters('stm_lms_login_label', esc_html__('Username', 'masterstudy-lms-learning-management-system')); ?>
                </label>
                <input class="form-control"
                       type="text"
                       name="login"
                       v-model="login"
                       v-on:keyup.enter="logIn()"
                       placeholder="<?php esc_html_e('Enter username', 'masterstudy-lms-learning-management-system'); ?>"/>
            </div>

            <div class="form-group">
                <label class="heading_font">
                    <?php echo apply_filters('stm_lms_password_label', esc_html__('Password', 'masterstudy-lms-learning-management-system')); ?>
                </label>
                <input class="form-control"
                       type="password"
                       name="password"
                       v-model="password"
                       v-on:keyup.enter="logIn()"
                       placeholder="<?php esc_html_e('Enter password', 'masterstudy-lms-learning-management-system'); ?>"/>
            </div>

            <div class="stm_lms_login_wrapper__actions">

                <label class="stm_lms_styled_checkbox stm_lms_remember_me">
                <span class="stm_lms_styled_checkbox__inner">
                    <input
                            type="checkbox"
                            name="remember_me"
                            v-model="remember"
                            v-on:keyup.enter="logIn()"
                    />
                    <span><i class="fa fa-check"></i> </span>
                </span>
                    <span><?php esc_html_e('Remember me', 'masterstudy-lms-learning-management-system'); ?></span>
                </label>

                <span class="lostpassword"
                      @click.prevent="open_lost_password = !open_lost_password"
                      title="<?php esc_html_e('Lost Password', 'masterstudy-lms-learning-management-system'); ?>">
                <?php esc_html_e('Lost Password', 'masterstudy-lms-learning-management-system'); ?>
            </span>

                <a href="#"
                   class="btn btn-default"
                   v-bind:class="{'loading': loading}"
                   @click.prevent="logIn()">
                    <span><?php echo _x('Login', 'Login button', 'masterstudy-lms-learning-management-system'); ?></span>
                </a>

            </div>

            <div class="stm_lms_lost_password_form" v-if="open_lost_password">

                <div class="form-group">
                    <label class="heading_font">
                        <?php echo apply_filters('stm_lms_lost_password_label', esc_html__('Login/E-mail', 'masterstudy-lms-learning-management-system')); ?>
                    </label>
                    <input class="form-control"
                           type="text"
                           name="login"
                           v-model="lost_password"
                           placeholder="<?php esc_html_e('Enter login/e-mail', 'masterstudy-lms-learning-management-system'); ?>"/>
                </div>

                <a href="#"
                   class="btn btn-default"
                   v-bind:class="{'loading': lost_password_process}"
                   @click.prevent="lostPassword()">
                    <span><?php esc_html_e('Send', 'masterstudy-lms-learning-management-system'); ?></span>
                </a>

            </div>

        </div>

        <transition name="slide-fade">
            <div class="stm-lms-message" v-bind:class="status" v-if="message" v-html="message">
            </div>
        </transition>

    </div>

<?php if (defined('APSL_VERSION') and apply_filters('stm_lms_show_social_login', true)) {
    echo do_shortcode("[apsl-login-lite login_text='']");
} ?>

<?php if (defined('NSL_PATH_FILE') and apply_filters('stm_lms_show_social_login', true)) {
    echo do_shortcode('[nextend_social_login]');
} ?>

<?php do_action('stm_lms_login_section_end'); ?>

我已经尝试修改代码但没有成功...我添加“header('Location:);“但无法正常工作。
我有一个自定义的登录页面,一旦用户登录,带他回到相同的页面,我想有一个在主页上的php重定向,我发现这个重定向php文件,我如何修改它让用户回到家?
我包括所有可能感兴趣的文件
谢谢

6kkfgxo0

6kkfgxo01#

这可以通过template_redirect钩子来实现,当用户登录并且只访问login.php页面时,钩子就会被触发。
把下面的代码放到你的functions.php文件中,让我知道它是否适合你。

add_action('template_redirect', 'kb_logged_in_redirect');
function kb_logged_in_redirect()
{
    if (is_page_template('login.php') && is_user_logged_in()) {
        $redirect_to = home_url();
        wp_safe_redirect($redirect_to);
        exit();
    }
}
xqnpmsa8

xqnpmsa82#

你必须在头文件发送到浏览器之前进行重定向。所以在'template_redirect'钩子下写你的条件代码。所以在你的stm-lms-user-redirect.php文件中写如下内容

add_filter('template_redirect', 'your_redirection_function', 10);
function your_redirection_function()
{
    $redirect_url = get_site_url();
    if (is_user_logged_in() && isset($_GET['send_some_get_perameter_from_form'])) {
        $lms_settings = get_option('stm_lms_settings', array());
        $user_url = (!empty($lms_settings['user_url'])) ?
            $lms_settings['user_url'] : '/lms-user';
        $redirect_url .= $user_url . '/' . get_current_user_id();
    }
}

关于$_ GET ['send_some_get_perameter_from_form']发送是很重要的。否则,整个网站将总是被重定向到$redirect_url页面。您可以将您的login.php包含在页面模板中,并且可以像这样编写代码

add_filter('template_redirect', 'your_redirection_function', 10);
function your_redirection_function()
{
    $redirect_url = get_site_url();
    if (is_user_logged_in() && is_page_template( 'your-page-template.php' );) {
        $lms_settings = get_option('stm_lms_settings', array());
        $user_url = (!empty($lms_settings['user_url'])) ?
            $lms_settings['user_url'] : '/lms-user';
        $redirect_url .= $user_url . '/'. get_current_user_id();
    }
}

相关问题