Skip to:
Content

Opened 9 years ago

Closed 9 years ago

#2262 closed defect (bug) (fixed)

Patch for bp_core_new_subnav_item and bp_core_remove_subnav_item

Reported by: calvin_42 Owned by:
Milestone: 1.2.5 Priority: normal
Severity: Version:
Component: Core Keywords: reporter-feedback
Cc:

Description

Version : all / trunk
Happen : every time
What : bp_core_remove_subnav_item doesn't remove_action of the old screen_function.

Sorry my SVN diff tool doesn't work so I will write down the diff myself :


Function bp_core_new_subnav_item - Line 740

Replace line 813 with

'user_has_access' => $user_has_access,
'screen_function' => $screenfunction

Function bp_core_remove_subnav_item- Line 885

Replace block line 888-890 with

$screen_function= $bp->bp_options_nav[$parent_id][$slug]['screen_function'];

	if ( $screen_function) {

Change History (4)

#1 @cnorris23
9 years ago

  • Keywords reporter-feedback added

Can you give an example or two of how you tested this? I'll provide the patch, but I want to make sure I can test the patch before I post it.

#2 @calvin_42
9 years ago

In the following example, I want to create a hook to change the default redirection groups/group-slug/admin -> groups/group-slug/admin/edit-details into groups/group-slug/admin/membership-requests. I have to use

remove_action( 'wp', 'groups_screen_group_admin', 3 );

in order for it to work. bp_core_remove_subnav_item() should have done it but it's not the case.

/**
 * bp_group_groups_admin_new_screen_function()
 *
 * Reorder the 'Admin' tab
 * Define a new screen function to change the default redirection
 */
function bp_group_groups_admin_new_screen_function() {
	global $bp, $wp_filter;
	
	/* Execute next line because of bp_core_remove_subnav_item bug */
	/* See http://trac.buddypress.org/ticket/2262 */
	/* TODO : Check if the bug is corrected in a future version of BuddyPress */
	remove_action( 'wp', 'groups_screen_group_admin', 3 );
	
	if ( !$bp->is_single_item )
		return;
		
	if ( !$bp->is_item_mod && !$bp->is_item_admin )
		return;

	/* If the user is a group mod or more, then show the group admin nav item */
	if ( $bp->is_item_mod || $bp->is_item_admin ) {		
		bp_core_remove_subnav_item( $bp->groups->slug, 'admin' );
		
		$group_link = $bp->root_domain . '/' . $bp->groups->slug . '/' . $bp->groups->current_group->slug . '/';
		
		bp_core_new_subnav_item( array( 'name' => __( 'Admin', 'buddypress' ), 'slug' => 'admin', 'parent_url' => $group_link, 
		'parent_slug' => $bp->groups->slug, 'screen_function' => 'groups_screen_group_admin_new', 'position' => 70,
		'user_has_access' => ( $bp->is_item_admin + (int)$bp->is_item_mod ), 'item_css_id' => 'admin' ) );
	}
	
}
add_action('groups_setup_nav','bp_group_groups_admin_new_screen_function', 10);

/**
 * groups_screen_group_admin_new()
 *
 * Screen function for Admin Tab
 */
function groups_screen_group_admin_new() {
	global $bp;

	if ( $bp->current_component != BP_GROUPS_SLUG || 'admin' != $bp->current_action )
		return false;

	if ( !empty( $bp->action_variables[0] ) )
		return false;
	
	$current_tab = $bp->is_item_admin ? 'membership-requests' : 'edit-details';

	bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . 'admin/' . $current_tab . '/' );
}

#3 @calvin_42
9 years ago

  • Milestone changed from 1.3 to 1.2.5

#4 @johnjamesjacoby
9 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [3057]) Fixes #2262 props calvin_42

Note: See TracTickets for help on using tickets.