Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kimcoleman/165901b6a15e47207a1ed0f7b0ede19b to your computer and use it in GitHub Desktop.
Save kimcoleman/165901b6a15e47207a1ed0f7b0ede19b to your computer and use it in GitHub Desktop.
Redirect away from checkout if the secret URL parameter is missing.
<?php
/**
* Redirect away from checkout if the secret URL parameter is missing.
*/
function my_pmpro_template_url_parameter_at_checkout() {
global $pmpro_pages;
// Return early if we are not on a PMPro page.
if ( empty( $pmpro_pages ) ) {
return;
}
// Return early if this is not the checkout page.
if ( ! is_page( $pmpro_pages['checkout'] ) ) {
return;
}
// Get the level.
$pmpro_level = pmpro_getLevelAtCheckout();
// Return early if this is not level ID 2.
if ( empty( $pmpro_level->id ) || $pmpro_level->id !== '2' ) {
return;
}
// Get the URL parameter.
$my_url_parameter = sanitize_text_field( $_GET['my_url_parameter'] );
// Redirect away from checkout if the URL parameter is missing.
if ( empty( $my_url_parameter ) ) {
wp_redirect( pmpro_url( 'levels' ) );
exit;
}
}
add_action( 'template_redirect', 'my_pmpro_template_url_parameter_at_checkout' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment