Skip to:
Content
Pages
Categories
Search
Top
Bottom

Adding a meta box to edit group in admin panel


  • pratibhasvaksha
    Participant

    @pratibhasvaksha

    Hi,

    I have added two extra fields in the group creation form to accept the extra information. I used this tutorial to create the extra fields. https://codex.buddypress.org/plugindev/how-to-edit-group-meta-tutorial/

    Now, I wanted to add the same fields in edit group so that we can directly edit the respective information from there. I tried to find a solution but could not find one. Can anyone please guide me to add a meta box which displays and update the added information.

    Thank you!

Viewing 6 replies - 1 through 6 (of 6 total)

  • Venutius
    Moderator

    @venutius

    I think the hooks you are looking for are bp_before_group_details_creation_step and bp_before_group_details_admin.

    Hooking on these will allow you to insert your fields into the group creation and editing page for the group details.


    pratibhasvaksha
    Participant

    @pratibhasvaksha

    @venutius
    Hi, Thank you so much for reply!
    I tried it but it’s not working. I just need them to display on the group admin to edit/remove the fields data.


    Venutius
    Moderator

    @venutius

    What did you try? do you have the code?


    pratibhasvaksha
    Participant

    @pratibhasvaksha

    @venutius
    This is the code which I’m using to add two fields in group creation form.

    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) ;
    }
    
    function group_header_fields_save( $group_id ) {
      global $bp, $wpdb;
      $plain_fields = array(
        'group-month',
        'group-year'
      );
      foreach( $plain_fields as $field ) {
        $key = $field;
        if ( isset( $_POST[$key] ) ) {
          $value = $_POST[$key];
          groups_update_groupmeta( $group_id, $field, $value );
        }
      }
    }
    add_action( 'groups_group_details_edited', 'group_header_fields_save' );
    add_action( 'groups_created_group',  'group_header_fields_save' );
    
    // Show the custom field in the group header
    function show_field_in_header( ) {
      echo "<p> Month: " . custom_field('group-month') . "</p>";
      echo "<p> Year: " . custom_field('group-year') . "</p>";
    }
    add_action('bp_group_header_meta' , 'show_field_in_header') ;

    I’ve manually added the code to display the fields in create.php file. In frontend, the field is visible on group listing (groups-loop.php) and on single group page.

    Now, I want to add a meta box to the group edit to update the field information directly from the admin panel.

    I’ll be grateful If you can help me out! Looking forward to your reply.

    Thanks!


    pratibhasvaksha
    Participant

    @pratibhasvaksha

    @venutius
    Hi! Could you please guide me or provide me any reference?


    shanebp
    Moderator

    @shanebp

    He already gave you guidance…

    I think the hooks you are looking for are bp_before_group_details_creation_step and bp_before_group_details_admin.

    And you said:

    I tried it but it’s not working.

    But the code you posted does not use either one of those hooks.
    Before asking for more help – Please show how you used those hooks.

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