WordPress.org

Making WordPress.org

Changeset 5869


Ignore:
Timestamp:
09/03/2017 09:47:54 PM (4 years ago)
Author:
SergeyBiryukov
Message:

Support Forums, User Badges: Add "Plugin Support" badge for users assigned as the plugin support reps.

See #2699.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-bbp-user-badges/inc/class-plugin.php

    r5523 r5869  
    199199            } elseif ( $this->is_user_contributor( $info['user_nicename'], $info['type'], $info['slug'] ) ) {
    200200                $contrib_type = 'contributor';
     201            } elseif ( $this->is_user_support_rep( $info['user_nicename'], $info['type'], $info['slug'] ) ) {
     202                $contrib_type = 'support-rep';
    201203            } else {
    202204                $contrib_type = '';
     
    313315            }
    314316        }
     317        elseif ( $this->is_user_support_rep( $info['user_nicename'], $info['type'], $info['slug'] ) ) {
     318            if ( 'plugin' == $info['type'] ) {
     319                $label = __( 'Plugin Support', 'wporg-forums' );
     320                $help  = __( 'This person is a support representative for this plugin', 'wporg-forums' );
     321            } else {
     322                $label = __( 'Theme Support', 'wporg-forums' );
     323                $help  = __( 'This person is a support representative for this theme', 'wporg-forums' );
     324            }
     325        }
    315326
    316327        return $label ? array( 'type' => $info['type'], 'label' => $label, 'help' => $help ) : false;
     
    388399
    389400        return $contributors && in_array( $user_nicename, $contributors );
     401    }
     402
     403    /**
     404     * Checks if the specified user is a support rep for the specified plugin/theme.
     405     *
     406     * A support representative is someone assigned as such by the plugin or theme author.
     407     *
     408     * @param string $user_nicename User slug.
     409     * @param string $type          Either 'plugin' or 'theme'.
     410     * @param string $slug          Slug for the plugin or theme.
     411     * @return bool                 True if user is a support rep, false otherwise.
     412     */
     413    public function is_user_support_rep( $user_nicename, $type, $slug ) {
     414        if ( class_exists( '\WordPressdotorg\Forums\Plugin' ) ) {
     415            if ( 'plugin' === $type ) {
     416                $compat = \WordPressdotorg\Forums\Plugin::get_instance()->plugins;
     417            } else {
     418                $compat = \WordPressdotorg\Forums\Plugin::get_instance()->themes;
     419            }
     420        } else {
     421            $compat = null;
     422        }
     423
     424        $support_reps = $compat ? $compat->get_support_reps( $slug ) : array();
     425
     426        return $support_reps && in_array( $user_nicename, $support_reps );
    390427    }
    391428
Note: See TracChangeset for help on using the changeset viewer.