Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Limit the number of total sign ups for a given membership level
function pmproml_pmpro_save_membership_level($level_id)
{
if( $level_id <= 0 )
{
return;
}
$limit = $_REQUEST['pmpro_member_limit'];
update_option('pmpro_limit_'.$level_id, $limit);
}
add_action('pmpro_save_membership_level','pmproml_pmpro_save_membership_level');
function pmproml_pmpro_membership_level_after_other_settings(){
?>
<h3 class="topborder"><?php _e('Membership Limits', 'pmpro');?></h3>
<table class="form-table">
<tbody>
<tr>
<th scope="row" valign="top"><label for="pmpro_member_limit"><?php _e('Maximum', 'pmpro');?>:</label></th>
<td>
<?php
if(isset($_REQUEST['edit'])){
$edit = intval($_REQUEST['edit']);
$limit = get_option('pmpro_limit_'.$edit);
}
else{
$limit = "";
}
?>
<input type="text" name="pmpro_member_limit" id="pmpro_member_limit" value= '<?php echo $limit; ?>' >
<p class="description">Set the maximum number of members for this level</p>
</td>
</tr>
</tbody>
</table>
<?php
}
add_action('pmpro_membership_level_after_other_settings','pmproml_pmpro_membership_level_after_other_settings');
function pmproml_pmpro_registration_checks($value)
{
global $wpdb;
$level_id = intval($_REQUEST['level']);
$limit = get_option('pmpro_limit_'.$level_id);
$sql = "SELECT COUNT(*)
FROM {$wpdb->pmpro_memberships_users}
WHERE `status` LIKE 'active' AND `membership_id` = ". $level_id;
$member_count = $wpdb->get_var($sql);
if($member_count >= $limit)
{
global $pmpro_msg, $pmpro_msgt;
$pmpro_msg = "Membership Limit has been reached for this level";
$pmpro_msgt = "pmpro_error";
$value = false;
}
return $value;
}
add_filter('pmpro_registration_checks', 'pmproml_pmpro_registration_checks');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.