Every article and help document I find on this topic is focused on the WordPress built-in feature using the page->Visibility setting which is extremely limited and useless for true page protection.
I want staff to be registered with their own individual logins in Users which I have done using Profile Press and on login, I can redirect them to a specific page - easy.
The problem first came when people try to access a protected page directly so to resolve this:
- I copied the
Page Template
and renamed itProtected Page Template
- I added some code to
functions.php
:
function check_is_logged_in( ) {
global $post;
if ( !is_user_logged_in () && get_page_template_slug($post->ID)=='page-protected.php' ) :
wp_redirect( home_url().'/log-in/', 302 );
exit;
endif;
}
add_action( 'get_header', 'check_is_logged_in' );
This partially resolved my issue so that if anyone tried to access the page directly, they were redirected and now, all I need to do is set the Page Template to Protected Page Template
- Fixed.
But...
Now I have installed the PressApps Knowledge Base plugin and I want this to also be password protected BUT, get_page_template_slug() returns empty
and is not included.
Is there another value I can use and test to identify the page template or page type?