Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Limits the visibility of a level on the Levels page. Unlike setting "Allow Signups" members can access the checkout page to renew if needed.
<?php
function djn_pmpro_save_membership_level($level_id)
{
if( $level_id <= 0 )
{
return;
}
$limit = $_REQUEST['pmpro_show_level'];
update_option('pmpro_show_level_'.$level_id, $limit);
}
add_action('pmpro_save_membership_level','djn_pmpro_save_membership_level');
function djn_pmpro_membership_level_after_other_settings(){
?>
<h3 class="topborder"><?php _e('Membership Level Visibility', 'pmpro');?></h3>
<table class="form-table">
<tbody>
<tr>
<th scope="row" valign="top"><label for="pmpro_show_level"><?php _e('Show Level?', 'pmpro');?>:</label></th>
<td>
<?php
if(isset($_REQUEST['edit'])){
$edit = $_REQUEST['edit'];
$pmpro_show_level = get_option('pmpro_show_level_'.$edit);
if($pmpro_show_level === false)
$pmpro_show_level = 1;
}
else{
$limit = "";
}
?>
<select id="pmpro_show_level" name="pmpro_show_level">
<option value="1" <?php if($pmpro_show_level == 1) { ?>selected="selected"<?php } ?>><?php _e('Yes', 'pmpro');?></option>
<option value="0" <?php if(!$pmpro_show_level) { ?>selected="selected"<?php } ?>><?php _e('No', 'pmpro');?></option>
</select>
<p class="description">Show this level on the Levels page?</p>
</td>
</tr>
</tbody>
</table>
<?php
}
add_action('pmpro_membership_level_after_other_settings','djn_pmpro_membership_level_after_other_settings');
function djn_pmpro_levels_array($levels)
{
$new_levels = array();
foreach($levels as $key => $level)
{
$pmpro_show_level = get_option('pmpro_show_level_'.$level->id);
//means it was never saved
if($pmpro_show_level === false)
$pmpro_show_level = true;
if(!empty($pmpro_show_level))
$new_levels[$key] = $level;
}
return $new_levels;
}
add_filter("pmpro_levels_array", "djn_pmpro_levels_array");
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.