0

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:

  1. I copied the Page Template and renamed it Protected Page Template
  2. 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?

1
  • FYI - KnowledgeBase has a "Template" selection - it currently uses page.php even though I have selected page-protected.php so this feature is broken, hence why I'm looking for an alternative Commented Apr 28, 2017 at 1:23

1 Answer 1

0

The template name is stored in the postmeta table, you can identify the page template by different ways but i would do with like:

1. $template = get_post_meta( $post->ID, '_wp_page_template', true );
    echo "Template: " . $template;
2. echo basename( get_page_template() ) 

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.