登录后重定向- Wordpress PHP



我有一个自定义登录页面,一旦用户登录,将他带回到同一页面,我希望在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-user.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>

* *下* *

<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: https://url/');"在stm-lms-user-redirect.php中不工作

我有一个自定义登录页面,一旦用户登录,将他带回同一页面,我希望在php的主页上有一个重定向,我发现了这个重定向php文件,我如何修改它让用户回家?

我包括所有可能感兴趣的文件

感谢

这可以使用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();
}
}

你必须在头部发送到浏览器之前重定向。因此,在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();
}
}

相关内容

  • 没有找到相关文章

最新更新