Skip to content

Instantly share code, notes, and snippets.

@hivepress
Created April 26, 2022 17:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hivepress/301255c7912349e05d81f6ffd42227eb to your computer and use it in GitHub Desktop.
Save hivepress/301255c7912349e05d81f6ffd42227eb to your computer and use it in GitHub Desktop.
Hide the listing pages from non-registered users (redirect to login form) #hivepress #listings
<?php
add_action(
'template_redirect',
function() {
if ( ! is_user_logged_in() && in_array( hivepress()->router->get_current_route_name(), [ 'listing_view_page', 'listings_view_page' ] ) ) {
wp_safe_redirect( hivepress()->router->get_return_url( 'user_login_page' ) );
exit;
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment