Your first function is just on the wrong hook. init
is too soon for knowing which page template/page you are on because the query is not set up yet. The best hook for redirecting is usually template_direct
. The following works for me:
function template_login_permit() {
if (
is_page_template('templates/tpl-aa.php') ||
is_page_template('templates/tpl-bb.php') ||
is_page_template('templates/tpl-cc.php') ||
is_page_template('templates/tpl-dd.php') ||
is_page_template('templates/tpl-ee.php') ||
is_page('shop')
) {
if ( !is_user_logged_in() ) {
auth_redirect();
}
}
}
add_action( 'template_redirect', 'template_login_permit' );