BuddyPress Group Custom MetaBox in edit group page
You may want to add your own custom field in BuddyPress Group editing page and have some functionality in BuddyPress Group. You can add this by creating your own custom meta-box in group edit page. Please Note that I just have created meta-box here. No more functionality. It doesn’t do anything yet. If you want to filter the meta-box to extend the group query, use bp ajax querystring.
BuddyPress allows admin users to edit/add user profile fields from the admin menu. This updated profile page proffers the capability to add your very own settings for the user. The page gives a simple illustration of how to add the custom meta boxes to the extended pages in BuddyPress. What you add to the meta box can be a varied of options.
NOTE: any meta boxes you add are only editable by the admin users. The informations does not show on the front-end of the user profile.
In your functions.php
file of your current active theme, add these codes.
// Buddypress Group MetaBox if( class_exists( 'BP_Group_Extension' ) ) : class bp_fan_club { public function __construct() { $this->setup_hooks(); } private function setup_hooks() { add_action( 'bp_groups_admin_meta_boxes', array( $this, 'bp_fan_club_page' ) ); } public function bp_fan_club_page() { add_meta_box( 'bp_fan_club', __( 'List on the Fan Club page' ), array( &$this, 'bp_fan_club_page_metabox'), get_current_screen()->id, 'side', 'core'); } public function bp_fan_club_page_metabox( $item = false ) { ?> <p> <input type="checkbox" id="bp_fan_club" name="bp_fan_club" > <?php _e( 'Mark this to List on the Fan Club Page' );?> </p> <?php wp_nonce_field(basename(__FILE__), "bpgroupmeta-box-nonce"); } public function bp_fan_club_option() { ?> <option value="featured"><?php _e( 'Featured' ); ?></option> <?php } } function bp_fan_club_group() { if( bp_is_active( 'groups') ) return new bp_fan_club(); } add_action( 'bp_init', 'bp_fan_club_group' ); endif;
Here we have used bp_groups_admin_meta_boxes hook to add your custom field via meta box in Buddypress Group editing page.
Learn more about adding meta-box
Now, Your meta box looks like this in BuddyPress Group edit page
BuddyPress Group Custom MetaBox
Now finally, the custom meta field is created in the back-end. But still, we haven’t extended the group query yet. I’ll write another topic on how to extend query after creating meta-box in another post. Do feel free to comment in the form below if you have any question in mind. I’ll try to get to you ASAP.
For more examples: visit Buddypress Meta Box