5ally

[WordPress] my_force_login()

Mar 23rd, 2018
136
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Info about this Paste: https://wordpress.stackexchange.com/q/298596/137402
  2.  
  3. function my_force_login() {
  4.     $post = get_post(); // The current post.
  5.  
  6.     if (empty($post) || is_user_logged_in() || !is_singular()) return;
  7.  
  8.     $ids = array(1753, 109); // array of post/Page IDs or post/Page parent IDs that force login to read
  9.  
  10.     if (in_array((int)$post->ID, $ids) || in_array((int)$post->post_parent, $ids)) {
  11.         auth_redirect();
  12.     }
  13. }
RAW Paste Data