Last active
March 9, 2023 07:08
-
-
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.
This file contains hidden or 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 | |
/** | |
* 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' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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/