Skip to content

Instantly share code, notes, and snippets.

@tannerm
Last active April 12, 2017 01:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tannerm/ac441e33cb87e78912df52f9ba0ad56e to your computer and use it in GitHub Desktop.
Save tannerm/ac441e33cb87e78912df52f9ba0ad56e to your computer and use it in GitHub Desktop.
<?php
/**
* Filter the subscriptions that can be used in the upgrade path
* original filter: https://docs.google.com/document/d/19-H7iF-6M_xuKQIF_V6VdeuwXyXaGgWAU9zrJnxavOw/edit
*/
function trm_filter_subscriptions( $subscriptions, $user_id ) {
// make sure the user is active and get the subscription ID
$user_subscription = ( rcp_is_recurring( $user_id ) && rcp_is_active( $user_id ) && 'cancelled' !== rcp_get_status() ) ? rcp_get_subscription_id( $user_id ) : '';
$subscriptions = rcp_get_subscription_levels( 'active' );
foreach ( $subscriptions as $key => $subscription ) {
// remove the user's current subscription from the list
if ( $user_subscription == $subscription->id ) {
unset( $subscriptions[ $key ] );
}
// remove any other subscriptions that should not show on the upgrade/downgrade path
if ( in_array( $subscription->id, array() ) ) {
unset( $subscription[ $key ] );
}
}
}
add_filter( 'rcp_get_upgrade_paths', 'trm_filter_subscriptions', 10, 2 );
function trm_remove_level_fee( $level ) {
if ( ! is_active() ) {
return $level;
}
$level->fee = 0;
return $level;
}
apply_filter( 'rcp_get_level', 'trm_remove_level_fee' );
/**
* Remove fees from levels if user is active
* https://github.com/restrictcontentpro/restrict-content-pro/blob/master/includes/class-rcp-levels.php
*/
function trm_remove_levels_fee( $levels ) {
if ( ! is_active() ) {
return $level;
}
foreach ( $levels as $key => $level ) {
$levels[ $key ] = trm_remove_level_fee( $level );
}
return $feeless_levels;
}
apply_filter( 'rcp_get_levels', 'trm_remove_levels_fee' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment