Created
July 12, 2012 20:18
-
-
Save strangerstudios/3100680 to your computer and use it in GitHub Desktop.
Hidden Levels for Paid Memberships Pro
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 | |
/* | |
Plugin Name: PMPro Hidden Levels | |
Plugin URI: http://www.paidmembershipspro.com/pmpro-hidden-levels/ | |
Description: With this plugin, select levels are removed from the levels page but still available for checkout if you visit the checkout URL directly. | |
Version: .1 | |
Author: Stranger Studios | |
Author URI: http://www.strangerstudios.com | |
*/ | |
/* | |
The Paid Memberships Pro plugin must be installed and active for this plugin to work. | |
(!) Edit the variable below to set which levels should removed from the levels page. | |
*/ | |
global $phl_hidden_levels; | |
$phl_hidden_levels = array(2,3); | |
/* | |
Remove the levels from the levels page. | |
*/ | |
function phl_pmpro_levels_array($levels) | |
{ | |
global $phl_hidden_levels; | |
$newarray = array(); | |
foreach($levels as $level) | |
{ | |
if(!in_array($level->id, $phl_hidden_levels)) | |
$newarray[] = $level; | |
} | |
return $newarray; | |
} | |
add_filter("pmpro_levels_array", "phl_pmpro_levels_array"); | |
/* | |
Require a certain discount code to checkout. | |
*/ | |
global $phl_required_codes; | |
$phl_required_codes = array(2 => "level2", 3 => "level3"); | |
function phl_pmpro_registration_checks($okay) | |
{ | |
//only check if we're okay so far | |
if($okay) | |
{ | |
//is this a level that requires a discount code? | |
global $pmpro_level, $phl_required_codes; | |
foreach($phl_required_codes as $level_id => $code) | |
{ | |
if($pmpro_level->id == $level_id) | |
{ | |
//level matched. do they have the code? | |
if(empty($_REQUEST['discount_code']) || strtolower($_REQUEST['discount_code']) != strtolower($code)) | |
{ | |
global $pmpro_msg, $pmpro_msgt; | |
$pmpro_msg = "A certain discount code is required to check out for this level. Please try again."; | |
$pmpro_msgt = "pmpro_error"; | |
$okay = false; | |
break; | |
} | |
} | |
} | |
} | |
return $okay; | |
} | |
add_filter("pmpro_registration_checks", "phl_pmpro_registration_checks"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment