Created
October 25, 2014 19:40
-
-
Save thomasgriffin/2448165e856ff79db829 to your computer and use it in GitHub Desktop.
Protected content for OptinMonster. This is an example template (taken from twenty fourteen) that checks to see if the lead passed is stored in the local lead storage before showing content.
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: Protected Content | |
* | |
* @package WordPress | |
* @subpackage Twenty_Fourteen | |
* @since Twenty Fourteen 1.0 | |
*/ | |
get_header(); ?> | |
<div id="main-content" class="main-content"> | |
<?php | |
if ( is_front_page() && twentyfourteen_has_featured_posts() ) { | |
// Include the featured content template. | |
get_template_part( 'featured-content' ); | |
} | |
?> | |
<div id="primary" class="content-area"> | |
<div id="content" class="site-content" role="main"> | |
<?php | |
// Start the Loop. | |
while ( have_posts() ) : the_post(); | |
// Check to ensure that the lead data has been passed to the page. | |
if ( empty( $_GET['om_email'] ) ) { | |
// Include the page content template for no content. | |
get_template_part( 'content', 'none' ); | |
} else { | |
// Get the email and name passed. | |
$email = urldecode( $_GET['om_email'] ); | |
global $wpdb; | |
// Verify that those match what is in our local lead storage. | |
if ( ! class_exists( 'Optin_Monster_Lead_Datastore' ) ) { | |
require plugin_dir_path( Optin_Monster::get_instance()->file ) . 'includes/global/lead-datastore.php'; | |
} | |
$leads = new Optin_Monster_Lead_Datastore( $wpdb ); | |
$found = $leads->find_where( 'lead_email', $email ); | |
// If no lead is found, don't show anything. | |
if ( ! $found ) { | |
// Include the page content template for no content. | |
get_template_part( 'content', 'none' ); | |
} else { | |
// Include the page content template. | |
get_template_part( 'content', 'page' ); | |
// If comments are open or we have at least one comment, load up the comment template. | |
if ( comments_open() || get_comments_number() ) { | |
comments_template(); | |
} | |
} | |
} | |
endwhile; | |
?> | |
</div><!-- #content --> | |
</div><!-- #primary --> | |
</div><!-- #main-content --> | |
<?php | |
get_sidebar(); | |
get_footer(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment