Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
05/17/2017 06:57:32 PM (9 years ago)
Author:
dcavins
Message:

Introduce groups_get_id_by_previous_slug().

Introduce groups_get_id_by_previous_slug() function to find groups
that once had the requested slug.

See #6014.

File:
1 edited

Legend:

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

    r11544 r11558  
    707707    public static function get_id_from_slug( $slug ) {
    708708        return BP_Groups_Group::group_exists( $slug );
     709    }
     710
     711    /**
     712     * Get whether a group exists for an old slug.
     713     *
     714     * @since 2.9.0
     715     *
     716     * @param string      $slug       Slug to check.
     717     *
     718     * @return int|null|false Group ID if found; null if not; false if missing parameters.
     719     */
     720    public static function get_id_by_previous_slug( $slug ) {
     721        global $wpdb;
     722
     723        if ( empty( $slug ) ) {
     724            return false;
     725        }
     726
     727        $args = array(
     728            'meta_query'         => array(
     729                array(
     730                    'key'   => 'previous_slug',
     731                    'value' => $slug
     732                ),
     733            ),
     734            'orderby'            => 'meta_id',
     735            'order'              => 'DESC',
     736            'per_page'           => 1,
     737            'page'               => 1,
     738            'update_meta_cache'  => false,
     739            'show_hidden'        => true,
     740        );
     741        $groups = BP_Groups_Group::get( $args );
     742
     743        $group_id = null;
     744        if ( $groups['groups'] ) {
     745            $group_id = current( $groups['groups'] )->id;
     746        }
     747
     748        return $group_id;
    709749    }
    710750
Note: See TracChangeset for help on using the changeset viewer.