Hi,
I have used the GP Content block to style the archive page for one of my custom post types. I’d like to restrict that page to logged-in users only. But I can’t edit it like a regular page, so I can’t use the standard plugin I use to restrict specific pages to logged-in users.
Is there a nifty GP way to do this? If not, I’ve written this code snippet:
add_action( 'template_redirect', 'pa_redirect_from_selfjournal', 10, 0 );
function pa_redirect_from_selfjournal() {
$pl = get_permalink();
error_log( 'Permalink: ' . $pl );
if ( ! basename( get_permalink() === 'selfjournal' ) ) :
return;
endif;
if ( is_user_logged_in() ) :
return;
endif;
wp_safe_redirect( home_url() );
exit;
}
The issue is that the get_permalink() function returns the permalink of the first custom post within this archive (so something like /selfjournal/1 instead of /selfjournal/). How do I fix this?
Thanks!