Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dwanjuki/49db8eccf37cf940213ac45875265f6f to your computer and use it in GitHub Desktop.
Save dwanjuki/49db8eccf37cf940213ac45875265f6f 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' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment