Making WordPress.org

Changeset 14547


Ignore:
Timestamp:
10/09/2025 03:19:46 AM (10 months ago)
Author:
dd32
Message:

Make: Add a tool to allow Make teams to assign / remove badges as needed.

This allows teams to grant badges from a central place (their Make site) without needing to have BuddyPress (profiles.wordpress.org) admin access.
See wp-admin => Tools -> Profile Badges.

By default this is limited to users with manage_options (Administrators) but can be lowered to those who can publish on the P2 or disabled.

A super-admin needs to set the badges which are able to be managed on each site.

See #8068.
Fixes #3043, #3026.

Location:
sites/trunk/wordpress.org/public_html/wp-content
Files:
4 added
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/mu-plugins/pub/profile-helpers.php

    r14115 r14547  
    5858                        FROM bpmain_wporg_groups_members m
    5959                        JOIN bpmain_wporg_groups g ON m.group_id = g.id
    60                         WHERE g.slug = %s AND m.is_confirmed = 1 AND m.is_banned = 0",
    61                 $badge
     60                        WHERE g.slug = %s AND m.is_confirmed = 1 AND m.is_banned = 0
     61                        ORDER BY date_modified DESC
     62                        LIMIT 10000", // Arbitrary high limit to avoid extra huge result sets.
     63                $badge,
    6264        ) );
    6365
     
    8688                $user_id
    8789        ), ARRAY_A );
     90
     91        return array_column( $badges, 'name', 'slug' );
     92}
     93
     94/**
     95 * Get a list of all available badges.
     96 *
     97 * WARNING: Uncached.
     98 *
     99 * @return array An array of badge names keyed by slug.
     100 */
     101function get_badges() {
     102        global $wpdb;
     103
     104        $badges = $wpdb->get_results(
     105                "SELECT slug, name
     106                        FROM bpmain_wporg_groups
     107                        ORDER BY name",
     108                ARRAY_A
     109        );
    88110
    89111        return array_column( $badges, 'name', 'slug' );
     
    229251        }
    230252
     253        $_user = false;
     254
     255        // If it looks like a profile url, extract the slug.
     256        if ( is_string( $user ) && str_starts_with( $user, 'https://profiles.wordpress.org/' ) ) {
     257
     258                $user = trim( str_replace( 'https://profiles.wordpress.org/', '', $user ), '/' );
     259                $user = explode( '/', $user )[0];
     260
     261                return get_user_by( 'slug', $user )->ID ?? false;
     262        }
     263
    231264        // Support user login / email / slug.
    232265        $_user = get_user_by( 'login', $user );
Note: See TracChangeset for help on using the changeset viewer.