Changeset 4138
- Timestamp:
- 09/27/2016 05:56:20 PM (8 years ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-bbp-user-badges
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-bbp-user-badges/inc/class-plugin.php
r3980 r4138 55 55 56 56 // Add badge before reply author info. 57 add_action( 'bbp_theme_before_reply_author_details', array( $this, ' wporg_support_add_author_badges' ) );57 add_action( 'bbp_theme_before_reply_author_details', array( $this, 'add_user_badges' ) ); 58 58 } 59 59 … … 103 103 104 104 public function bbp_get_reply_class( $classes, $reply_id ) { 105 // Class related to moderators. 106 if ( $this->is_user_moderator() ) { 107 $classes[] = 'by-moderator'; 108 } 109 105 110 // Class related to plugin and theme authors/contributors. 106 111 if ( $info = $this->get_author_badge_info() ) { … … 125 130 * the plugin/theme they contribute to. 126 131 */ 127 public function wporg_support_add_author_badges() { 132 public function add_user_badges() { 133 $output = $this->get_author_badge(); 134 135 // Don't assign moderator badge if already assigning author badge. 136 if ( ! $output ) { 137 $output = $this->get_moderator_badge(); 138 } 139 140 if ( $output ) { 141 echo $this->format_badge( $output['type'], $output['label'], $output['help'] ); 142 } 143 } 144 145 protected function format_badge( $type, $label, $help = '' ) { 146 $output = ''; 147 148 if ( $label ) { 149 $output .= sprintf( 150 '<span class="author-badge author-badge-%s" title="%s">%s</span>', 151 esc_attr( $type ), 152 esc_attr( $help ), 153 $label 154 ); 155 } 156 157 // Return the markup. 158 return $output; 159 } 160 161 protected function get_author_badge() { 128 162 if ( ! $info = $this->get_author_badge_info() ) { 129 163 return; … … 152 186 } 153 187 154 // Build the markup. 155 $output = ''; 156 if ( $label ) { 157 $output .= sprintf( 158 '<span class="author-badge %s-author-badge" title="%s">%s</span>', 159 esc_attr( $info['type'] ), 160 esc_attr( $help ), 161 $label 162 ); 163 } 164 165 // Output the markup. 166 echo $output; 188 return $label ? array( 'type' => $info['type'], 'label' => $label, 'help' => $help ) : false; 189 } 190 191 protected function get_moderator_badge() { 192 $label = $help = null; 193 194 if ( $this->is_user_moderator() ) { 195 $label = __( 'Moderator', 'wporg-forums' ); 196 $help = __( 'This person is a moderator on this forum', 'wporg-forums' ); 197 } 198 199 return $label ? array( 'type' => 'moderator', 'label' => $label, 'help' => $help ) : false; 167 200 } 168 201 … … 251 284 } 252 285 286 /** 287 * Checks if the specified user is a forum moderator or keymaster. 288 * 289 * By default, this considers a keymaster as being a moderator for the purpose 290 * of badging them. Use the $strict argument to check that the user is a 291 * moderator without considering if they are a keymaster. 292 * 293 * @param string $user_id Optional. User ID. Assumes current reply author ID 294 * if not provided. 295 * @param bool $strict Optional. True if user should strictly be checked 296 * for being a moderator, false will also check if they 297 * are a keymaster. Default false. 298 * @return bool True if user is a moderator, false otherwise. 299 */ 300 public function is_user_moderator( $user_id = '', $strict = false ) { 301 if ( ! $user_id ) { 302 $user_id = bbp_get_reply_author_id(); 303 } 304 305 return ( user_can( $user_id, 'moderate' ) || ( ! $strict && bbp_is_user_keymaster( $user_id ) ) ); 306 } 253 307 } -
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-bbp-user-badges/wporg-bbp-user-badges.php
r3978 r4138 1 1 <?php 2 2 /** 3 * Plugin Name: bbPress: ShowUser Badges4 * Description: Display a badge for plugin and theme authors and contributors for replies in their own support forums.3 * Plugin Name: bbPress: User Badges 4 * Description: Display a badge in user replies as appropriate (such as for a plugin/theme author/contributor, moderator). 5 5 * Version: 1.0 6 6 * Author: WordPress.org
Note: See TracChangeset
for help on using the changeset viewer.