0

I have custom account page for user, i want the users who are not logged in site when enter http://example.com/account redirected to a custom login page.

Here My code

function setup_user_panel_url()
{
   add_rewrite_rule('account', 'index.php?account=1', 'top');
   flush_rewrite_rules();
}

function check_request($query)
{
    if (isset($query->query_vars['account'])) {
      include USER_PANEL_VIEWS . 'panel.php';
      exit();
    }
}
  • Hello! Could you detail how are those functions being called? – Tom J Nowell Oct 26 '18 at 18:07
  • You can check the user login status via is_user_logged_in() function and then redirect to the non-logged-on users to the custom login page via wp_redirect('http://example.com/account'). – Kashif Rafique Oct 26 '18 at 18:40
0

I should add is_user_logged_in() wordpress function. and check if user is not logged in site redirect user to home page with wp_redirect(home_url()) function.

 if (isset($query->query_vars['account'])) {

    if (!is_user_logged_in()) {
        wp_redirect(home_url());
        exit();
    }

    include NABRO_USER_PANEL_VIEWS . 'panel.php';
    exit();
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.