Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if ( ! function_exists( 'mycred_assign_ranks' ) ) :
- function mycred_assign_ranks( $point_type = MYCRED_DEFAULT_TYPE_KEY ) {
- global $wpdb;
- $mycred = mycred( $point_type );
- $end = '';
- if ( $point_type != MYCRED_DEFAULT_TYPE_KEY )
- $end = $point_type;
- do_action( 'mycred_assign_ranks_start' );
- $balance_format = '%d';
- if ( isset( $mycred->format['decimals'] ) && $mycred->format['decimals'] > 0 ) {
- $length = 65 - $mycred->format['decimals'];
- $balance_format = 'CAST( %f AS DECIMAL( ' . $length . ', ' . $mycred->format['decimals'] . ' ) )';
- }
- $ranks = mycred_get_ranks( 'publish', '-1', 'ASC', $point_type );
- $balance_key = mycred_get_meta_key( $point_type );
- if ( mycred_rank_based_on_total( $point_type ) )
- $balance_key = mycred_get_meta_key( $point_type, '_total' );
- $count = 0;
- if ( ! empty( $ranks ) ) {
- foreach ( $ranks as $rank ) {
- $count += $wpdb->query( $wpdb->prepare( "
- UPDATE {$wpdb->usermeta} ranks
- INNER JOIN {$wpdb->usermeta} balance ON ( ranks.user_id = balance.user_id AND balance.meta_key = %s )
- SET ranks.meta_value = %d
- WHERE ranks.meta_key = %s
- AND balance.meta_value BETWEEN {$balance_format} AND {$balance_format};", $balance_key, $rank->post_id, mycred_get_meta_key( 'mycred_rank', $end ), $rank->minimum, $rank->maximum ) );
- }
- }
- do_action( 'mycred_assign_ranks_end' );
- return $count;
- }
- endif;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement