Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example on how to redirect a user to a specific page on your WordPress website when they run out of myCRED points.
/**
* Redirect When Out of Points
* @since 1.0
* @version 1.0
*/
function mycred_pro_redirect_when_no_more_points() {
// The Page ID where we want users to be redirected to
// when they have run out of points
$redirect_to = 1;
if ( is_user_logged_in() && function_exists( 'mycred' ) && ! is_page( $redirect_to ) ) {
$mycred = mycred();
$user_id = get_current_user_id();
$balance = $mycred->get_users_balance( $user_id );
// If we are out of points
if ( $balance <= $mycred->zero() ) {
wp_redirect( esc_url( get_permalink( $redirect_to ) ) );
exit;
}
}
}
add_action( 'template_redirect', 'mycred_pro_redirect_when_no_more_points' );
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.