Created
April 23, 2020 13:10
-
-
Save arthurattwell/7841eeb619ab720d8392d707a23ff022 to your computer and use it in GitHub Desktop.
Sample template-part for Electric Book WP restricted pages
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 | |
/** | |
* The template for displaying single posts and pages, | |
* adapted as an Electric Book WP page for the Twenty Twenty theme | |
* | |
* @link https://developer.wordpress.org/themes/basics/template-hierarchy/ | |
* | |
* @package WordPress | |
* @subpackage Twenty_Twenty | |
* @since Twenty Twenty 1.0 | |
*/ | |
get_header(); | |
?> | |
<main id="site-content" role="main"> | |
<article <?php post_class(); ?> id="post-<?php the_ID(); ?>"> | |
<?php | |
get_template_part( 'template-parts/entry-header' ); | |
if ( ! is_search() ) { | |
get_template_part( 'template-parts/featured-image' ); | |
} | |
?> | |
<div class="post-inner thin"> | |
<div class="entry-content"> | |
<?php | |
// ------------------------------------------------------------------------- | |
// This is the part that does the work for Electric Book WP restricted pages | |
// ------------------------------------------------------------------------- | |
// check once-off token to prevent XSS and CSRF hacks | |
$redirect_token = isset($_GET['_wpnonce']) ? wp_verify_nonce($_GET['_wpnonce'], 'electric_book_wp_redirect') : false; | |
if ($redirect_token && isset($_GET['redirect_to'])) { | |
if (isset($_GET['reason']) && $_GET['reason'] === 'logged-out') { ?> | |
<p> | |
This is a restricted page. Please <a href="/wp-login.php?redirect_to=<?=urlencode($_GET['redirect_to'])?>">login to view it</a>. | |
</p> | |
<?php } elseif ($_GET['reason'] === 'role') { ?> | |
<p> | |
This is a restricted page. Although you are logged in, your profile lacks the necessary role required to view this page. | |
</p> | |
<?php } | |
} else { | |
echo 'I\'m just a normal WordPress page'; | |
} | |
// ------------------------------------------------------------------------- | |
?> | |
</div><!-- .entry-content --> | |
</div><!-- .post-inner --> | |
<div class="section-inner"> | |
<?php | |
wp_link_pages( | |
array( | |
'before' => '<nav class="post-nav-links bg-light-background" aria-label="' . esc_attr__( 'Page', 'twentytwenty' ) . '"><span class="label">' . __( 'Pages:', 'twentytwenty' ) . '</span>', | |
'after' => '</nav>', | |
'link_before' => '<span class="page-number">', | |
'link_after' => '</span>', | |
) | |
); | |
edit_post_link(); | |
// Single bottom post meta. | |
twentytwenty_the_post_meta( get_the_ID(), 'single-bottom' ); | |
if ( is_single() ) { | |
get_template_part( 'template-parts/entry-author-bio' ); | |
} | |
?> | |
</div><!-- .section-inner --> | |
<?php | |
if ( is_single() ) { | |
get_template_part( 'template-parts/navigation' ); | |
} | |
/** | |
* Output comments wrapper if it's a post, or if comments are open, | |
* or if there's a comment number – and check for password. | |
* */ | |
if ( ( is_single() || is_page() ) && ( comments_open() || get_comments_number() ) && ! post_password_required() ) { | |
?> | |
<div class="comments-wrapper section-inner"> | |
<?php comments_template(); ?> | |
</div><!-- .comments-wrapper --> | |
<?php | |
} | |
?> | |
</article><!-- .post --> | |
</main><!-- #site-content --> | |
<?php get_template_part( 'template-parts/footer-menus-widgets' ); ?> | |
<?php get_footer(); ?> |
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: Template for Electric Book WP restricted pages | |
* Template Post Type: post, page | |
* | |
* @package WordPress | |
* @subpackage Twenty_Twenty | |
* @since Twenty Twenty 1.0 | |
*/ | |
get_template_part( 'singular-restricted' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment