WordPress.org

Making WordPress.org

Changeset 4205


Ignore:
Timestamp:
10/10/2016 06:36:21 PM (3 years ago)
Author:
coffee2code
Message:

Support Forums, User Badges: Display plugin/theme author/contributor badge in user profile replies loop (and other out-of-forum-context views).

Fixes #2094.

File:
1 edited

Legend:

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

    r4150 r4205  
    6969        );
    7070
    71         if ( ! in_array( bbp_get_forum_id(), $badgeable_forums ) ) {
    72             return;
    73         }
    74 
    75         $slug = $type = null;
     71        $forum_id = bbp_get_reply_forum_id();
     72        $topic_id = bbp_get_reply_topic_id();
     73
     74        if ( ! in_array( $forum_id, $badgeable_forums ) ) {
     75            return;
     76        }
     77
     78        $slugs = $types = array();
    7679
    7780        $user_id = bbp_get_reply_author_id();
     
    8285        $user_login = get_user_by( 'id', $user_id )->user_login;
    8386
    84         $support_forum = \WordPressdotorg\Forums\Plugin::get_instance();
    85 
    8687        // Check if the thread is associated with a plugin.
    87         if ( $slug = $support_forum->plugins->slug ) {
    88             $type = 'plugin';
     88        if ( $forum_id === \WordPressdotorg\Forums\Plugin::PLUGINS_FORUM_ID ) {
     89            $types = array( 'plugin' );
    8990        }
    9091        // Else check if the thread is associated with a theme.
    91         elseif ( $slug = $support_forum->themes->slug ) {
    92             $type = 'theme';
     92        elseif ( $forum_id === \WordPressdotorg\Forums\Plugin::THEMES_FORUM_ID ) {
     93            $types = array( 'theme' );
     94        }
     95        // Else check if the thread is a review.
     96        elseif ( $forum_id === \WordPressdotorg\Forums\Plugin::REVIEWS_FORUM_ID ) {
     97            // Need to check for plugin AND theme association to know which the review is for.
     98            $types = array( 'plugin', 'theme' );
    9399        }
    94100        // Else not a type of concern.
     
    97103        }
    98104
     105        foreach ( $types as $type ) {
     106            $slugs = wp_get_post_terms( $topic_id, 'topic-' . $type, array( 'fields' => 'slugs' ) );
     107            if ( $slugs ) {
     108                break;
     109            }
     110        }
     111
     112        if ( ! $slugs ) {
     113            return;
     114        }
     115
    99116        return array(
    100117            'type'       => $type,
    101             'slug'       => $slug,
     118            'slug'       => $slugs[0],
    102119            'user_login' => $user_login,
    103120        );
Note: See TracChangeset for help on using the changeset viewer.