Skip to content

Instantly share code, notes, and snippets.

@aaroneaton
Last active August 29, 2015 14:03
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 aaroneaton/afc887d53ffbc65b308f to your computer and use it in GitHub Desktop.
Save aaroneaton/afc887d53ffbc65b308f to your computer and use it in GitHub Desktop.
Limits the number of times an optin can be viewed
<?php
add_filter( 'optinmonster_output', 'limit_views' );
function limit_views ( $optins ) {
// Replace this with your optin slug
$optin_slug = 'yf3rluqqcj-lightbox';
// Replace this with the number of views
$view_limit = 100;
// Set the specified optin to false if limit has been reached
if ( isset( $optins[$optin_slug] ) ) {
$args = array(
'name' => $optin_slug,
'post_type' => 'optin',
'post_status' => 'publish',
'numberposts' => 1,
);
$posts = get_posts( $args );
$target = $posts[0];
// If you want to limit by conversions, change 'om_counter' to 'om_conversions'
$count = get_post_meta( $target->ID, 'om_counter', true );
if ( (int) $count > (int) $view_limit ) {
$optins[$optin_slug] = false;
}
}
return $optins;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment