Skip to content

Instantly share code, notes, and snippets.

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 kimcoleman/69249876ef3e5dd15699d22c2789c87d to your computer and use it in GitHub Desktop.
Save kimcoleman/69249876ef3e5dd15699d22c2789c87d to your computer and use it in GitHub Desktop.
Notification bar when post views are being tracked and restricted by the Limit Post Views Add On
<?php
/**
* Notification bar when post views are being tracked and restricted by the Limit Post Views Add On
* Requires: https://www.paidmembershipspro.com/add-ons/pmpro-limit-post-views/
*/
function add_notification_bar_for_limit_post_view_alt() {
// check for past views and if we are on a single page. needs to check if the post is locked at all by default.
if ( ! empty( $_COOKIE['pmpro_lpv_count'] ) && is_single() ) {
global $current_user;
// Check cookie for views value.
$parts = explode( ';', sanitize_text_field( $_COOKIE['pmpro_lpv_count'] ) );
$limitparts = explode( ',', $parts[0] );
// Get the level limit for the current user.
if ( defined( 'PMPRO_LPV_LIMIT' ) && PMPRO_LPV_LIMIT > 0 ) {
$limit = intval( PMPRO_LPV_LIMIT );
?>
<div class="banner banner_action" style="position: fixed; bottom: 0; color: #FFF; font-size: 2.5rem; left: 0; width: 100%;">
<div style="display: inline-block; margin-right: 1em; padding: 1em; background: #FF0000;">
<?php echo esc_html( $limitparts[1] + 1 ); ?>/<?php echo esc_html( $limit ); ?>
</div>
<a style="color: #FFF;" href="<?php echo wp_login_url( get_permalink() ); ?>" title="Log in">Log in</a> or <a style="color: #FFF;" href="<?php echo pmpro_url( 'levels' ); ?>" title="Subscribe now">subscribe now</a> for unlimited online access.
</div>
<?php
}
}
}
add_action( 'wp_footer' , 'add_notification_bar_for_limit_post_view_alt', 15 );
@laurenhagan0306
Copy link

This recipe is included in the blog post on "Improve the user experience (and increase signups) when using the Limit Post Views Add On" at Paid Memberships Pro here: https://www.paidmembershipspro.com/improve-the-user-experience-and-increase-signups-when-using-the-limit-post-views-add-on/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment