BP_Group_Extension::get_group_id()

Get the current group ID.

Description

Check for:

  • current group
  • new group
  • group admin

Return

(int)

Source

File: bp-groups/classes/class-bp-group-extension.php

483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
public static function get_group_id() {
 
    // Usually this will work.
    $group_id = bp_get_current_group_id();
 
    // On the admin, get the group id out of the $_GET params.
    if ( empty( $group_id ) && is_admin() && ( isset( $_GET['page'] ) && ( 'bp-groups' === $_GET['page'] ) ) && ! empty( $_GET['gid'] ) ) {
        $group_id = (int) $_GET['gid'];
    }
 
    // This fallback will only be hit when the create step is very
    // early.
    if ( empty( $group_id ) && bp_get_new_group_id() ) {
        $group_id = bp_get_new_group_id();
    }
 
    // On some setups, the group id has to be fetched out of the
    // $_POST array
    // @todo Figure out why this is happening during group creation.
    if ( empty( $group_id ) && isset( $_POST['group_id'] ) ) {
        $group_id = (int) $_POST['group_id'];
    }
 
    return $group_id;
}

Changelog

Changelog
Version Description
BuddyPress 1.8.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.