Skip to:
Content

BuddyPress.org

Changeset 11525


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

Use BP_Groups_Group::get() in BP_Groups_Group::group_exists()

Retire the one-off, direct database query in
BP_Groups_Group::group_exists() in favor of using
`BP_Groups_Group::get()’ internally. Also, the new form takes advantage
of the built-in incremented caching in `BP_Groups_Group::get()’.

Fixes #7477.

File:
1 edited

Legend:

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

    r11524 r11525  
    613613     *
    614614     * @param string      $slug       Slug to check.
    615      * @param string|bool $table_name Optional. Name of the table to check
    616      *                                against. Default: $bp->groups->table_name.
     615     * @param string|bool $table_name Deprecated.
    617616     * @return int|null Group ID if found; null if not.
    618617     */
     
    620619        global $wpdb;
    621620
    622         if ( empty( $table_name ) )
    623             $table_name = buddypress()->groups->table_name;
    624 
    625         if ( empty( $slug ) )
     621        if ( empty( $slug ) ) {
    626622            return false;
    627 
    628         $query = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$table_name} WHERE slug = %s", strtolower( $slug ) ) );
    629 
    630         return is_numeric( $query ) ? (int) $query : $query;
     623        }
     624
     625        $args = array(
     626            'slug'               => $slug,
     627            'per_page'           => 1,
     628            'page'               => 1,
     629            'update_meta_cache'  => false,
     630            'show_hidden'        => true,
     631        );
     632
     633        $groups = BP_Groups_Group::get( $args );
     634
     635        $group_id = null;
     636        if ( $groups['groups'] ) {
     637            $group_id = current( $groups['groups'] )->id;
     638        }
     639
     640        return $group_id;
    631641    }
    632642
Note: See TracChangeset for help on using the changeset viewer.