bb_bozo_recount_users

The BuddyPress bb bozo recount users function.

Description

bb_bozo_recount_users(); 

Usage

  1. if ( !function_exists( 'bb_bozo_recount_users' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bbpress/bb-plugins/bozo.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = bb_bozo_recount_users(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/bp-forums/bbpress/bb-plugins/bozo.php  
  1. function bb_bozo_recount_users() { 
  2. global $bbdb; 
  3. global $messages; 
  4. if ( isset($_POST['topics-replied-with-bozos']) && 1 == $_POST['topics-replied-with-bozos'] ) : 
  5. $messages[] = __('Counted each bozo user's total posts as well as the total topics to which they have replied'); 
  6. if ( $users = (array) $bbdb->get_col("SELECT ID FROM $bbdb->users") ) : 
  7. $no_bozos = array(); 
  8. $bozo_mkey = $bbdb->prefix . 'bozo_topics'; 
  9. foreach ( $users as $user ) : 
  10. $topics_replied = (int) $bbdb->get_var( $bbdb->prepare( 
  11. "SELECT COUNT(DISTINCT topic_id) FROM $bbdb->posts WHERE post_status = 0 AND poster_id = %d",  
  12. $user 
  13. ) ); 
  14. bb_update_usermeta( $user, $bbdb->prefix. 'topics_replied', $topics_replied ); 
  15. $bozo_keys = (array) $bbdb->get_col( $bbdb->prepare( 
  16. "SELECT topic_id, COUNT(post_id) FROM $bbdb->posts WHERE post_status > 1 AND poster_id = %d GROUP BY topic_id",  
  17. $user 
  18. ) ); 
  19. $bozo_values = (array) $bbdb->get_col('', 1); 
  20. if ( $c = count($bozo_keys) ) : 
  21. for ( $i=0; $i < $c; $i++ ) 
  22. $bozo_topics[(int) $bozo_keys[$i]] = (int) $bozo_values[$i]; 
  23. bb_update_usermeta( $user, $bozo_mkey, $bozo_topics ); 
  24. else : 
  25. $no_bozos[] = (int) $user; 
  26. endif; 
  27. endforeach; 
  28. if ( $no_bozos ) : 
  29. $no_bozos = join(', ', $no_bozos); 
  30. $bbdb->query( $bbdb->prepare( 
  31. "DELETE FROM $bbdb->usermeta WHERE user_id IN ($no_bozos) AND meta_key = %s",  
  32. $bozo_mkey 
  33. ) ); 
  34. endif; 
  35. unset($users, $user, $topics_replied, $bozo_keys, $bozo_values, $bozo_topics); 
  36. endif; 
  37. endif;