Skip to content

Instantly share code, notes, and snippets.

@filipvanreeth
Last active December 5, 2016 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save filipvanreeth/3c7ae5f27f5610ec8f58eb219f432580 to your computer and use it in GitHub Desktop.
Save filipvanreeth/3c7ae5f27f5610ec8f58eb219f432580 to your computer and use it in GitHub Desktop.
Whity Page - Show a different front page if the user is not logged in
<?php
/*
Template Name: Whity Page
Show a different front page if the user is not logged in. In this case we use a white page without any content.
*/
$frontpage_id = get_option( 'page_on_front' );
$get_page_template = get_post_meta( $frontpage_id, '_wp_page_template', true );
// Set template name (ex.page-whity.php);
$template_name = 'page-whity.php';
if( $get_page_template == $template_name ) {
$user = wp_get_current_user();
$allowed_roles = array('editor', 'administrator', 'author');
if( array_intersect($allowed_roles, $user->roles ) ) {
// Set the page ID to redirect to
$post_id = 71;
$wp_redirect_url = get_permalink( $post_id );
wp_redirect( $wp_redirect_url );
exit;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment