Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
04/05/2017 12:00:40 AM (8 years ago)
Author:
dcavins
Message:

Add 'slug' parameter to BP_Groups_Group::get().

Add $slug parameter to groups_get_groups() and its underlying
function BP_Groups_Group::get(). Find a group or groups by passing a
single slug, a comma- or space-separated list of slugs, or any array of
slugs.

Fixes #7496.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-groups/classes/class-bp-groups-group.php

    r11447 r11523  
    861861     * @since 2.6.0 Added `$group_type`, `$group_type__in`, and `$group_type__not_in` parameters.
    862862     * @since 2.7.0 Added `$update_admin_cache` and `$parent_id` parameters.
     863     * @since 2.9.0 Added `$slug` parameter.
    863864     *
    864865     * @param array $args {
     
    877878     *     @type int          $user_id            Optional. If provided, results will be limited to groups
    878879     *                                            of which the specified user is a member. Default: null.
    879      *     @type string       $search_terms       Optional. If provided, only groups whose names or descriptions
     880     *     @type array|string $slug               Optional. Array or comma-separated list of group slugs to limit
     881     *                                            results to.
     882     *                                            Default: false.
     883     *     @type string       $search_terms       Optional. If provided, only groups whose names or descriptions
    880884     *                                            match the search terms will be returned. Allows specifying the
    881885     *                                            wildcard position using a '*' character before or after the
     
    939943            'page'               => null,
    940944            'user_id'            => 0,
     945            'slug'               => array(),
    941946            'search_terms'       => false,
    942947            'search_columns'     => array(),
     
    973978        if ( empty( $r['show_hidden'] ) ) {
    974979            $where_conditions['hidden'] = "g.status != 'hidden'";
     980        }
     981
     982        if ( ! empty( $r['slug'] ) ) {
     983            if ( ! is_array( $r['slug'] ) ) {
     984                $r['slug'] = preg_split( '/[\s,]+/', $r['slug'] );
     985            }
     986            $r['slug'] = array_map( 'sanitize_title', $r['slug'] );
     987            $slug_in = "'" . implode( "','", $r['slug'] ) . "'";
     988            $where_conditions['slug'] = "g.slug IN ({$slug_in})";
    975989        }
    976990
Note: See TracChangeset for help on using the changeset viewer.