Skip to:
Content
Pages
Categories
Search
Top
Bottom

Group Metabox data to display in Group header meta not in seperate tab


  • pratibhasvaksha
    Participant

    @pratibhasvaksha

    Hi
    I have used this tutorial to add a metabox to the edit group admin screen. https://codex.buddypress.org/plugindev/extend-groups-admin-ui/

    The data of the metabox is displaying under a new tab in the single group page. I wanted to display the data below group profile picture / bp_group_header_meta. I tried using this action ” add_action(‘bp_group_header_meta’ , ‘show_field_in_header’); ” but It’s not working.

    This is my working code:

    function extra_add_group_extension() {
      if ( class_exists( 'BP_Group_Extension' ) ) :
    
        class Group_Extension_Extra extends BP_Group_Extension {
    
          function __construct() {
            $args = array(
              'slug' => 'group-information',
              'name' => 'Group Information'
            );
            parent::init( $args );
          }
    
          function admin_screen( $group_id = NULL ) {
            $extra_info = groups_get_groupmeta( $group_id, 'group_ext_extra_info' );
            ?>
    
            <div>
              <h4 style="margin-bottom: 5px;"> Extra Group Information: </h4>
              <input type="text" name="group_ext_extra_info" value="<?php echo $extra_info; ?>" style="width: 100%;">
            </div>
    
            <?php 
          }
    
          function admin_screen_save( $group_id = NULL ) {
    
            if ( isset( $_POST['group_ext_extra_info'] ) ) {
              groups_update_groupmeta( $group_id, 'group_ext_extra_info', sanitize_text_field($_POST['group_ext_extra_info']) );
            }
          }
    
          function display() {
            $group_id = bp_get_group_id();
            $extra_info = groups_get_groupmeta( $group_id, 'group_ext_extra_info' );
    
            if($extra_info)
              echo "<h5> $extra_info <h5>";
          }
    
        }
    
        bp_register_group_extension( 'Group_Extension_Extra' );
    
        endif; // if ( class_exists( 'BP_Group_Extension' ) )
      }
      add_action('bp_init', 'extra_add_group_extension');
Viewing 2 replies - 1 through 2 (of 2 total)

  • Venutius
    Moderator

    @venutius

    You could just overload the buddypress/groups/single/cover-image-header.php file for your bp theme to display the new fields you have added.


    pratibhasvaksha
    Participant

    @pratibhasvaksha

    @venutius

    I’ve used this action add_action('bp_before_group_header_meta', 'show_info_in_header'); and it worked perfectly.

    Thank you so much for your help! Really appreciate it!

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Skip to toolbar