最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

customization - Auto redirect after session expire, but only for one user

programmeradmin0浏览0评论

Does anyone have an insight as to how I could auto redirect only one user instead of for everyone when a session times out?

IE user - paul when his session times out, takes him to XYZ/page instead of the basic re-log in page? Everyone else would still use the default log out redirect.

I am using this in my functions now:

add_action('wp_logout','auto_redirect_after_logout');

function auto_redirect_after_logout(){
  wp_safe_redirect( home_url() );
  exit;
}

Does anyone have an insight as to how I could auto redirect only one user instead of for everyone when a session times out?

IE user - paul when his session times out, takes him to XYZ/page instead of the basic re-log in page? Everyone else would still use the default log out redirect.

I am using this in my functions now:

add_action('wp_logout','auto_redirect_after_logout');

function auto_redirect_after_logout(){
  wp_safe_redirect( home_url() );
  exit;
}
Share Improve this question edited Dec 17, 2020 at 18:44 Theodore asked Dec 17, 2020 at 18:37 Theodore Theodore 112 bronze badges 2
  • Basically, all you have to do is to tie the username / id to a simple condition. Get the users ID, then redirect only if it's that ID / user. Some more research on that should take you there – user3135691 Commented Dec 17, 2020 at 18:50
  • Is the above code what I seek for doing this and tying this to or is there a better function? And does this apply from the admin area too? I cant get the above to work even in a basic way. – Theodore Commented Dec 17, 2020 at 19:01
Add a comment  | 

1 Answer 1

Reset to default 1

In functions.php add:

<?php

function ps_redirect_after_logout(){
     // get the current user's id
     $current_user_id = get_current_user_id();
     // Get Paul
     $paul = get_user_by('login', 'Paul');
     $paulsid = $paul->ID;
     // check if current user is Paul
     if($current_user_id == $paulsid) {

         wp_redirect('https://www.example.club/logout-page/');
         exit();
         
     }
}
add_action('wp_logout','ps_redirect_after_logout');

I haven't tested this code, but something like this should be the way to go.

发布评论

评论列表(0)

  1. 暂无评论