Skip to content

Commit

Permalink
Groups integration: Update tab visibility for BP 12.
Browse files Browse the repository at this point in the history
Use a callback for determining tab visibility when BP 12 is used.

See buddypress/buddypress@72fb806
  • Loading branch information
dcavins committed Dec 19, 2023
1 parent b861439 commit fb278dd
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions includes/integration-groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,7 @@ class BP_Docs_Group_Extension extends BP_Group_Extension {
* @since 1.0-beta
*/
public function __construct() {
global $bp;
$bp = buddypress();

$bp_docs_tab_name = bp_docs_get_group_tab_name();

Expand All @@ -1067,13 +1067,34 @@ public function __construct() {
$this->visibility = 'public';
$this->enable_nav_item = $this->enable_nav_item();

/**
* In BP 12, the current group is not yet known at __construct time
* because the URL parsing hasn't occurred yet. We use a callback that is
* accessed later.
*/
$this->show_tab_callback = array( $this, 'enable_nav_item' );

// Create some default settings if the create step is skipped
if ( apply_filters( 'bp_docs_force_enable_at_group_creation', false ) ) {
add_action( 'groups_created_group', array( &$this, 'enable_at_group_creation' ) );
}

// Backward compatibility for group-based Doc URLs
add_action( 'bp_actions', array( $this, 'url_backpat' ) );

$args = array(
'slug' => $this->slug,
'name' => $this->name ,
'nav_item_position' => $this->nav_item_position,
'access' => 'anyone',
'show_tab_callback' => $this->show_tab_callback,
'screens' => array(
'edit' => array(),
'create' => array(),
'admin' => array(),
),
);
parent::init( $args );
}

/**
Expand Down Expand Up @@ -1289,7 +1310,9 @@ function admin_markup() {
function enable_nav_item() {
global $bp;

$enable_nav_item = false;
$enable_nav_item = false;
$this->settings = bp_docs_get_group_settings( $this->group_id );
$this->group_enable = ! empty( $this->settings['group-enable'] ) ? true : false;

// The nav item should only be enabled when BP Docs is enabled for the group
if ( $this->group_enable ) {
Expand Down

0 comments on commit fb278dd

Please sign in to comment.