Skip to content

Instantly share code, notes, and snippets.

@eighty20results
Created April 14, 2018 03:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eighty20results/0d0a2f40e7cccd2fc618fdac02c4cc6a to your computer and use it in GitHub Desktop.
Save eighty20results/0d0a2f40e7cccd2fc618fdac02c4cc6a to your computer and use it in GitHub Desktop.
Load custom cancellation page for certain membership levels
<?php
/**
* Filter handler for `pmpro_pages_shortcode_cancel` (load custom cancellation page for certain membeship levels)
*
* @param string $content
*
* @return string
*/
function gc_custom_cancel_page( $content ) {
$standard_cancellation_ids = array( 5, ); // Petrolhead level ID
$custom_cancellation_page = 1027; // Using the 'Collectors Cancellation' page ID as the custom page
if ( isset( $_REQUEST['levelstocancel'] ) && $_REQUEST['levelstocancel'] !== 'all' ) {
//convert spaces back to +
$_REQUEST['levelstocancel'] = str_replace( array( ' ', '%20' ), '+', $_REQUEST['levelstocancel'] );
//get the ids
$old_level_ids = array_map( 'intval',
explode( "+",
preg_replace( "/[^0-9al\+]/", "", $_REQUEST['levelstocancel'] )
)
);
} else if ( isset( $_REQUEST['levelstocancel'] ) && $_REQUEST['levelstocancel'] == 'all' ) {
$all_levels = pmpro_getAllLevels( true, true );
$old_level_ids = array_keys( $all_levels );
} else {
$old_level_ids = false;
}
if ( false === $old_level_ids ) {
return $content;
}
// Iterate through the levels to cancel and load the custom page if applicable
foreach( $old_level_ids as $old_level_id ) {
// Do we load the custom cancellation page template?
if ( ! in_array( $old_level_id, $standard_cancellation_ids ) ) {
// Load the 'Collectors Cancellation' custom page (Page/Post ID: 1027)
$cancellation_page = get_post( $custom_cancellation_page );
$content = apply_filters( 'the_content', $cancellation_page->post_content );
break; // Exit the loop
}
}
return $content;
}
add_filter( 'pmpro_pages_shortcode_cancel', 'gc_custom_cancel_page', 20, 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment