2014-02-19 15:26
浏览 75


When any page is viewed, I need to make sure that the user ID is in a custom database table, and if the id is not present there, I want to log the user out and not allow him to see any content. I also want to display a custom message on the login page saying "You are not authorised to see this blog."

I tried doing this with some of the wp logout/redirect functions, but I want this to be automatic on all pages across the wp site. Also I don't know how to sent the custom message to the login page. I guess I could just set a POST value or something like that and modify the login page to check if that value is present.

Any help or tips on how to do this properly would be appreciated.

图片转代码服务由CSDN问答提供 功能建议

当查看任何页面时,我需要确保用户ID在自定义数据库表中,如果 id不在那里,我想将用户注销,不允许他看到任何内容。 我还想在登录页面上显示一条自定义消息,说“您无权查看此博客。”

我尝试使用某些wp注销/重定向功能执行此操作,但是 我希望这在wp网站的所有页面上都是自动的。 此外,我不知道如何将自定义消息发送到登录页面。 我想我可以设置一个POST值或类似的东西,并修改登录页面以检查该值是否存在。


  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • drtpbx3606 2014-02-19 15:48

    Try following

    Put the code below in your theme templates.

        //Logic for checking whether the ID exists or not

    Put following in your function.php

        //When the user is logged out redirect him/her to the login page with a custom parameter
        function go_home(){
          wp_redirect( '/wp-login.php?action=logout&custom-logout=yes' );
        //If the custom parameter is set display the message on the login screen
        if(!empty($_GET['custom-logout']) && strtolower($_GET['custom-logout']) == "yes"){
         function custom_login_message() {
             $message = '<p class="message">Add your message here...</p><br />';
             return $message;
         add_filter('login_message', 'custom_login_message');
    解决 无用
    打赏 举报

相关推荐 更多相似问题