Skip to content

Instantly share code, notes, and snippets.

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 gabrielmerovingi/ebf588c2c0e860c5f7898dfa8e3655d5 to your computer and use it in GitHub Desktop.
Save gabrielmerovingi/ebf588c2c0e860c5f7898dfa8e3655d5 to your computer and use it in GitHub Desktop.
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