Forked from kimcoleman/trigger_popup_maker_with_limit_post_views.php
Created
March 9, 2023 07:08
-
-
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.
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