Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Adjust Eligeble Users
- * Removes users that have 100 points or higher as balance from gaining a recurring payout.
- * @requires myCRED 1.6 or higher
- * @version 1.0
- */
- add_filter( 'mycred_get_eligeble_users', 'mycred_pro_adjust_bank_eligeble_users', 10, 2 );
- function mycred_pro_adjust_bank_eligeble_users( $users, $banking ) {
- // Only applicable for "Recurring Payouts"
- if ( $banking->id != 'payouts' ) return $users;
- // No use to do anything if there are no eligeble users
- if ( empty( $users ) ) return $users;
- // First we need to get the correct balance key
- $balance_key = $banking->mycred_type;
- if ( is_multisite() && $GLOBALS['blog_id'] > 1 && ! $banking->core->use_central_logging )
- $balance_key .= '_' . $GLOBALS['blog_id'];
- // For our SQL query we need to take into account if we are using decimals
- $balance_format = '%d';
- if ( isset( $banking->core->format['decimals'] ) && $banking->core->format['decimals'] > 0 )
- $balance_format = 'CAST( %f AS DECIMAL( 10, ' . $banking->core->format['decimals'] . ' ) )';
- global $wpdb;
- // Remove all users that have 100 points or more
- $max = 100;
- // Next we get all ineligible users
- $ineligible_user_ids = $wpdb->get_col( $wpdb->prepare( "
- SELECT DISTINCT user_id
- FROM {$wpdb->usermeta}
- WHERE meta_key = %s
- AND meta_value >= {$balance_format};", $balance_key, $max ) );
- // If we have results, remove them from $users
- if ( ! empty( $ineligible_user_ids ) ) {
- $new_user_list = array();
- foreach ( $users as $user_id ) {
- if ( ! in_array( $user_id, $ineligible_user_ids ) )
- $new_user_list[] = $user_id;
- }
- $users = $new_user_list;
- }
- // Return for processing
- return $users;
- }
Add Comment
Please, Sign In to add comment