4

I´m using a plugin called "private content login redirect".

The plugin is actually only containing this piece of code:

    add_action('template_redirect', 'private_content_redirect_to_login', 9);
function private_content_redirect_to_login() {
  global $wp_query,$wpdb;
  if (is_404()) {
    $private = $wpdb->get_row($wp_query->request);
    $location = wp_login_url($_SERVER["REQUEST_URI"]);
    if( 'private' == $private->post_status  ) {
      wp_safe_redirect($location);
      exit;
    }
  }
}

What it does is this: When a non-logged in user is viewing a private page, it redirects them to the log-in page. After they log in, they are taken back to the private page they just visited and can read it.

I would like it to redirect them to log-in page, but when they have logged in, they should be taken to a specific page (ex http://www.testsite.com/start) instead of the private page they visited.

3
  • I would not use this plugin at all as this screams SQL Injection to me. Feb 13, 2017 at 22:02
  • Why is this? I solved it using two different plugins instead. One for redirecting all 404 pages to login and one for redirecting after login. Feb 14, 2017 at 16:40
  • You can answer your own question and accept it if you've solved it. Feb 14, 2017 at 18:07

1 Answer 1

0

from your code you need to change one for redirect user to specific page after login.

Your code : $location = wp_login_url($_SERVER["REQUEST_URI"]);

Change it as $location = wp_login_url (i.e. http://www.testsite.com/start); // pass url of page where you want to redirect user after login

Hope this will help you.

1
  • didnt, work. took me to 404 page. But i solved it anyway (se answear to Brian). Thanks for the help anyway! Feb 14, 2017 at 16:42

Your Answer

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

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