doutan1875 2019-01-26 18:33
浏览 47

如何将特定用户重定向到特定页面? 登录后我不是在谈论

I use WordPress.

I know how to redirect a user to a specific page after logging in. But let's say they have already logged-in and they click specific URL, they should be redirected to another.

Sample: USER A The user has already logged-in. He clicks domainname.com/my-account He will be redirected to domainname.com/profile1

USER B The user has already logged-in. He clicks domainname.com/my-account He will be redirected to domainname.com/profile2

All of them click the domainname.com/my-account but they have to be redirected to a different page.

This redirection is per user. Is there a way to do this in function.php?

  • 写回答

2条回答 默认 最新

  • dougou8639 2019-01-26 18:42
    关注

    You could do this using the global $_SERVER-variable.

    But in order to provide you a full answer, then I would need to know, how you distinquish, if a user should see /profile1 or profile2. Is it all women that sees /profile1, or all administrators or all those names 'Jim'?

    This is a version, where the user with the username jim will see profile1, - and everybody else will see profile2.

    function custom20180126_redirect() {
    
      $user = wp_get_current_user();
      $target_uri = $_SERVER['REQUEST_URI'];
      if( $target_uri == '/my-account' ){
        if( $user->data->user_login == 'jim' ){
          wp_redirect( '/profile1' );
        } else {
          wp_redirect( '/profile2' );  
        } 
      }
    }
    add_action( 'template_redirect', 'custom20180126_redirect' );
    

    Pop that in your functions.php...

    评论

报告相同问题?

悬赏问题

  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教