Skip to:
Content

BuddyPress.org

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#7872 closed defect (bug) (worksforme)

Errors with add_filter('bp_groups_default_extension',... in BP 3.0

Reported by: gcmaryland's profile gcmaryland Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Groups Keywords:
Cc:

Description

This error is related to https://buddypress.trac.wordpress.org/ticket/7837, but slightly different. This error occurs in both legacy and Nv, and applies to plug-ins adding custom meta data to groups.

Plug-ins using add_filter('bp_groups_default_extension',... are resulting in a page not found error in BP 3.0. These work fine in 2.9.4 with no errors.

At the moment, the work around is to use add_action( 'wp',... but it can cause header errors outside of individual groups.

Thanks for checking into this-

Change History (5)

#1 @r-a-y
7 years ago

  • Component changed from Templates to Groups
  • Keywords reporter-feedback added

Hmm, it's working for me.

I tried setting this to 'members', as well as other 3rd-party plugins like 'forum' and 'invite-anyone' and those pages are set as the default item on a group page.

If you set it to something like forum, you have to make sure that the group has a forum tied to it.

#2 @gcmaryland
7 years ago

Thanks @r-a-y for checking into this - I've found the bug to be somewhat randomly applied, and have even been able to get these plug-ins to work for 1-page load by activating them, removing the filter line, and reloading the specific custom page - however, this only works once, and then has to be repeated.

I've provided some scratch code that follows the model of most of the plug-ins with incompatibilities that we've found:

<?php
/*
Plugin Name: Sample Compatibility Checker
Description: Verify meta data plug-in compatability with BP 3.0.0
Version: 0.1
Requires at least: 3.3
Tested up to: 4.8.1
Author: null
Author URI: https://null
*/

//////////////////// BuddyPress Group Meta Management: https://codex.buddypress.org/plugindev/how-to-edit-group-meta-tutorial/
function bp_group_meta_init_checker() {
function custom_field($meta_key='') {

//get current group id and load meta_key value if passed. If not pass it blank
return groups_get_groupmeta( bp_get_group_id(), $meta_key) ;
}

// This function is our custom field's form that is called in create a group and when editing group details
function demo_checker_fields_markup() {
global $bp, $wpdb;
//////////////////// End BuddyPress Group Meta Management

//////////////////// Front-End Output
?>

// Output front-end editor settings.

<?php
//////////////////// End Front-End Output

//////////////////// Insert Group Meta
// This saves the custom group meta – props to Boone for the function
// Where $plain_fields = array.. you may add additional fields, eg
//  $plain_fields = array(
//      'field-one',
//      'field-two'
//  );
}
function demo_checker_fields_save( $group_id ) {
	global $bp, $wpdb;
	$plain_fields = array(
		// Fields
	);

	foreach( $plain_fields as $field ) {
		$key = $field;
		if ( isset( $_POST[$key] ) ) {
			$value = strip_tags($_POST[$key]);
			groups_update_groupmeta( $group_id, $field, $value );
		}

	}
}

add_filter( 'groups_custom_group_fields_editable', 'demo_checker_fields_markup' );
add_action( 'groups_group_details_edited', 'demo_checker_fields_save' );
add_action( 'groups_created_group',  'demo_checker_fields_save' );
//////////////////// Insert Group Meta

//////////////////// Begin Header Output
// Show the custom field in the group header

}

add_action( 'bp_include', 'bp_group_meta_init_checker' );

function demo_checker_page() {
	if ( class_exists( 'BP_Group_Extension' ) ) :
		class Checker_Page extends BP_Group_Extension {
			function __construct() {
				$args = array(
					'slug' => 'checker',
					'name' => 'Checker',
					'create_step_position' => 21
				);
				parent::init( $args );
			}
			function settings_screen( $group_id ) {
				// Settings Screen
			}    
			function display() {
				/* Use this function to display the actual content of your group extension when the nav item is selected */
				global $bp;
				echo "It works!";
			}
		} // end of class

		bp_register_group_extension( 'Checker_Page' );
		 
		endif;
}
	
add_filter('bp_groups_default_extension', 'demo_checker_page' );
	
?>

Again, these 404 errors only occur in 3.0.0, and not in 2.9.4. Thanks for checking into this!

#3 @r-a-y
7 years ago

  • Keywords reporter-feedback removed
  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed

You need to register your group extension outside the 'bp_groups_default_extension' filter.

The 'bp_groups_default_extension' filter is only used to set the slug that you want to use for the group homepage:

add_filter( 'bp_groups_default_extension', function() {
    return 'members';
} );

I'm going to close this one as this isn't a bug with BP v3.0, but feel free to continue replying.

#4 @gcmaryland
7 years ago

Thanks @r-a-y! I think I've found the issue. I believe that many of these plug-ins were running add_filter('bp_groups_default_extension', when they were really attempting to use add_action( 'bp_include',. I've updated several of these to use the action instead of a filter, and it's working like a charm with zero errors in debug.

I'd greatly appreciate a confirmation if this is correct, as I have numerous plug-ins across our networks that are all using this code. Strangely enough, the plug-ins using that filter never changed the homepage, but rather actually create sub nav items. If this is correct, I'll notify authors and link them to this thread. Thanks so much for your help!

#5 @r-a-y
7 years ago

I believe that many of these plug-ins were running add_filter('bp_groups_default_extension', when they were really attempting to use add_action( 'bp_include' )

Yes, this sounds correct to me.

Strangely enough, the plug-ins using that filter never changed the homepage, but rather actually create sub nav items.

It's because those plugins were not using the 'bp_groups_default_extension' filter the way it was intended in the first place.

Anyway, glad that this isn't a 3.0 bug!

Note: See TracTickets for help on using tickets.