Created
June 20, 2017 14:28
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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