Advertisement
designbymerovingi

Redirect From Page based on Balance

Mar 13th, 2015
646
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. /**
  2. * Redirect Users from Page Based on Balance
  3. * @version 1.0
  4. */
  5. add_action( 'template_redirect', 'mycred_pro_restrict_page_access' );
  6. function mycred_pro_restrict_page_access() {
  7.  
  8. // Only applicable to the page with the ID 40
  9. if ( ! is_page( 40 ) ) return;
  10.  
  11. $redirect = false;
  12.  
  13. // Redirect visitors
  14. if ( ! is_user_logged_in() )
  15. $redirect = true;
  16.  
  17. // Logged in users need a balance check
  18. if ( ! $redirect && function_exists( 'mycred' ) ) {
  19.  
  20. $point_type = 'mycred_default';
  21. $min_balance = 100;
  22.  
  23. $mycred = mycred( $point_type );
  24. $balance = $mycred->get_users_balance( get_current_user_id(), $point_type );
  25.  
  26. // Check balance against minimum requirement
  27. if ( $balance < $min_balance )
  28. $redirect = true;
  29.  
  30. }
  31.  
  32. // Do the redirect
  33. if ( $redirect ) {
  34.  
  35. wp_redirect( get_permalink( 22 ) );
  36. exit;
  37.  
  38. }
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement