Last active
December 5, 2016 14:17
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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