Certain pages on a client site are confidential and I need to restrict access to logged in users. I have looked at various membership plugins but they are overkill for my very basic and specific needs.
I found this snippet which I tested in functions.php
function my_force_login() {
global $post;
if (!is_single()) return;
$ids = array(188); // array of post IDs that force login to read
if (in_array((int)$post->ID, $ids) && !is_user_logged_in()) {
auth_redirect();
}
}
When I tested it this code, it restricted a particular blog post EXACTLY how I want it. (the key here is that if the user clicks on a link to a restricted page but is not logged in, they are redirected to a login page, but after they complete login, they should be redirected back to the EXACT original page)
Now I need to modify that code so it will do the following:
Restrict all the pages with a particular parent.
Is that possible? How should the code be modified to achieve this outcome?
Thanks