WordPress.org

Making WordPress.org

Changeset 4138


Ignore:
Timestamp:
09/27/2016 05:56:20 PM (3 years ago)
Author:
coffee2code
Message:

Support Forums: Add moderator badge to moderator forum replies.

  • Keymasters get the same "Moderator" badge as there is no need to publicly differentiate the roles.
  • The badge color matches the color used for the support team's profiles.wordpress.org badges.
  • In contexts where the user would otherwise get a plugin or theme author/contributor badge, the moderator badge is not shown.

See #2073.

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  
    5555
    5656        // 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' ) );
    5858    }
    5959
     
    103103
    104104    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
    105110        // Class related to plugin and theme authors/contributors.
    106111        if ( $info = $this->get_author_badge_info() ) {
     
    125130     * the plugin/theme they contribute to.
    126131     */
    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() {
    128162        if ( ! $info = $this->get_author_badge_info() ) {
    129163            return;
     
    152186        }
    153187
    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;
    167200    }
    168201
     
    251284    }
    252285
     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    }
    253307}
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-bbp-user-badges/wporg-bbp-user-badges.php

    r3978 r4138  
    11<?php
    22/**
    3  * Plugin Name: bbPress: Show User Badges
    4  * 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).
    55 * Version:     1.0
    66 * Author:      WordPress.org
Note: See TracChangeset for help on using the changeset viewer.