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();
    }
}
2
  • Hello! Could you detail how are those functions being called?
    – Tom J Nowell
    Oct 26, 2018 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'). Oct 26, 2018 at 18:40

1 Answer 1

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();
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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