1

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.

  • I would not use this plugin at all as this screams SQL Injection to me. – Brian Fegter Feb 13 '17 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. – Hejhejhej123 Feb 14 '17 at 16:40
  • You can answer your own question and accept it if you've solved it. – Brian Fegter Feb 14 '17 at 18:07
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.

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

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.