Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kimcoleman/1b480f16506163d4dbf23f3d64ab0468 to your computer and use it in GitHub Desktop.
Save kimcoleman/1b480f16506163d4dbf23f3d64ab0468 to your computer and use it in GitHub Desktop.
Trigger a Popup Maker to display on the redirected page once the post views limit is reached.
<?php
/**
* Trigger a Popup Maker to display on the redirected page once the post views limit is reached.
* Requires: https://www.paidmembershipspro.com/add-ons/pmpro-limit-post-views/ and https://wordpress.org/plugins/popup-maker/
*/
function trigger_popup_maker_with_limit_post_views() {
// Check cookie for views value and compare to limit based on visitor/user.
if ( ! empty( $_COOKIE['pmpro_lpv_count'] ) ) {
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 );
if ( $limit >= $limitparts[1] ) {
?>
<script type="text/javascript">
jQuery(document).ready(function($) {
$('#popmake-1').popmake('open');
});
</script>
<?php
}
}
}
}
add_action( 'wp_footer', 'trigger_popup_maker_with_limit_post_views' );
@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