| 1 | <?php
|
|---|
| 2 | /*
|
|---|
| 3 | Plugin Name: Orange Hats
|
|---|
| 4 | Plugin URI: http://www.example.org
|
|---|
| 5 | Description: Amends poster image to show if they've contributed bug reports. Allows moderators to mark certain users as a "bug squatter."
|
|---|
| 6 | Author: The dashing DJPaul, aided and abetted by that machiavellian rascal, burtadsit.
|
|---|
| 7 | Author URI: http://www.metabiscuits.com/
|
|---|
| 8 | Version: 0.5
|
|---|
| 9 | */
|
|---|
| 10 |
|
|---|
| 11 | function oh_get_avatar($avatar, $id_or_email, $size, $default) {
|
|---|
| 12 | if ('1' == bb_get_usermeta($id_or_email, 'orangehats_is_bugswatter')) {
|
|---|
| 13 |
|
|---|
| 14 | $watermark_start = '<div style="position: relative; width: '.$size.'px; height: '.$size.'px;"><img src="http://testbp.org/favicon.ico" alt="Buddypress bug swatter badge of honour" title="Buddypress bug swatter - badge of honour" style="position: absolute; bottom: -2px; right: -2px;" />';
|
|---|
| 15 | $watermark_end = '</div>';
|
|---|
| 16 | return $watermark_start . $avatar . $watermark_end;
|
|---|
| 17 | } else {
|
|---|
| 18 |
|
|---|
| 19 | return $avatar;
|
|---|
| 20 | }
|
|---|
| 21 | }
|
|---|
| 22 | add_filter('bb_get_avatar', 'oh_get_avatar', 1, 4);
|
|---|
| 23 |
|
|---|
| 24 | function oh_add_admin_page() {
|
|---|
| 25 | global $bb_submenu;
|
|---|
| 26 | $bb_submenu['users.php'][] = array(__('Bug Swatters', 'orangehats'), 'edit_users', 'oh_admin_page');
|
|---|
| 27 | }
|
|---|
| 28 | add_action( 'bb_admin_menu_generator', 'oh_add_admin_page' );
|
|---|
| 29 |
|
|---|
| 30 | // NOT bbdb::prepared
|
|---|
| 31 | function oh_get_bugswatters( $page = 1 ) {
|
|---|
| 32 | global $bbdb, $bb_last_countable_query;
|
|---|
| 33 | $page = (int) $page;
|
|---|
| 34 | $limit = (int) bb_get_option('page_topics');
|
|---|
| 35 | if ( 1 < $page )
|
|---|
| 36 | $limit = ($limit * ($page - 1)) . ", $limit";
|
|---|
| 37 | $bb_last_countable_query = "SELECT user_id FROM $bbdb->usermeta WHERE meta_key='orangehats_is_bugswatter' AND meta_value='1' ORDER BY umeta_id DESC LIMIT $limit";
|
|---|
| 38 | if ( $ids = (array) $bbdb->get_col( $bb_last_countable_query ) )
|
|---|
| 39 | bb_cache_users( $ids );
|
|---|
| 40 | return $ids;
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 | function oh_admin_page() {
|
|---|
| 44 | class oh_BugSwatter_Users extends BB_Users_By_Role {
|
|---|
| 45 | var $title = '';
|
|---|
| 46 |
|
|---|
| 47 | function oh_BugSwatter_Users( $page = '' ) { // constructor
|
|---|
| 48 | $this->raw_page = ( '' == $page ) ? false : (int) $page;
|
|---|
| 49 | $this->page = (int) ( '' == $page ) ? 1 : $page;
|
|---|
| 50 | $this->title = __('These users have been marked as Buddypress bug swatters');
|
|---|
| 51 |
|
|---|
| 52 | $this->prepare_query();
|
|---|
| 53 | $this->query();
|
|---|
| 54 | $this->do_paging();
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | function query() {
|
|---|
| 58 | $this->results = oh_get_bugswatters( $this->page );
|
|---|
| 59 |
|
|---|
| 60 | if ( $this->results )
|
|---|
| 61 | $this->total_users_for_query = bb_count_last_query();
|
|---|
| 62 | else
|
|---|
| 63 | $this->search_errors = new WP_Error('no_matching_users_found', __('No matching users were found!'));
|
|---|
| 64 |
|
|---|
| 65 | if ( is_wp_error( $this->search_errors ) )
|
|---|
| 66 | bb_admin_notice( $this->search_errors );
|
|---|
| 67 | }
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | $bugswatters = new oh_BugSwatter_Users( $_GET['userspage'] );
|
|---|
| 71 | $bugswatters->display( false, bb_current_user_can( 'edit_users' ) );
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | function oh_profile_admin_keys( $a ) {
|
|---|
| 75 | $a['orangehats_is_bugswatter'] = array(
|
|---|
| 76 | 0, // Required
|
|---|
| 77 | __('This user is a Buddypress bug swatters'), // Label
|
|---|
| 78 | 'checkbox', // Type
|
|---|
| 79 | '1', // Value
|
|---|
| 80 | '' // Default when not set
|
|---|
| 81 | );
|
|---|
| 82 | return $a;
|
|---|
| 83 | }
|
|---|
| 84 | add_filter( 'get_profile_admin_keys', 'oh_profile_admin_keys' );
|
|---|
| 85 |
|
|---|
| 86 | ?>
|
|---|