BuddyDev

Search

[Resolved] Automatic field creation when creating a user group by group slug

Tagged: 

  • Participant
    Level: Enlightened
    Posts: 33
    Vlad on #38074

    Hello,
    Question about Buddypress.
    I am interested in automatic field creation
    in a specific group of profile fields,
    when creating a user group.
    Field name slug by user group.
    To allow the group administrator to edit this field for users,
    so the field is removed when the user group is deleted.

    There can be creation of a field after creating a group, by clicking the button for the group administrator.

    Thanks in advance for any help.

  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #38129

    Hi Vlad,
    Thank you for the question.

    1. Creating a profile field group when a group is created and use Group name as field name- this is easy
    2. To allow the group administrator to edit this field for users – This is not simple and will most probably need a custom interface as the groups mods don’t have the ability to edit user’s profile.

    3. so the field is removed when the user group is deleted. – Is easy

    4. There can be creation of a field after creating a group, by clicking the button for the group administrator. – This will need custom interface too.

    We can assist you with code for point 1 & 3. The requirements for point 2 & 4 is beyond what we can offer as support here.

    Please let me know if you need code for 1 & 3.

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 33
    Vlad on #38133

    Thanks for answering Brajesh,

    Yes, I need a code for 1 and 3.

    1. I need 1 field in the profile of the site members,
    in the specified field group.
    Field name – slug by user group.

    3. The field is removed from the profile for all site members,
    when deleting a user group.

    Write how much the work on item 2 will cost,
    and how much the work on item 4 will cost.

    Thanks for the help.

  • Participant
    Level: Enlightened
    Posts: 33
    Vlad on #38193

    Hello Brajesh,

    Sorry for my English.
    I’ll write again.

    Yes, I need a code for 1 and 3.

    1. I need to automatically create 1 field in the profile of the site members, in the specified group of fields,
    when creating a user group.
    Field name: slug of the user group.

    3. The field is removed from the profile of all site members,
    when deleting a user group.

    Thanks for the help.

  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #38245

    Hi Vlad,
    Thank you.

    Here is the code for those steps.

    
    // create profile
    add_action( 'groups_create_group', function ( $group_id, $member ) {
    
    	$profile_group_id = 1;// the profile fiedl group where the new field will be stored.
    	$group            = groups_get_group( $group_id );
    
    	$field_id = xprofile_insert_field(
    		array(
    			'field_group_id' => $profile_group_id,
    			'type'           => 'textbox', // Your field type.
    			'name'           => $group->name,
    			'description'    => sprintf( 'Details for group %s', $group->name ),
    			'is_required'    => false,
    			'can_delete'     => true,
    		)
    	);
    
    	// let us remember the field id for future usage.
    	if ( $field_id ) {
    		groups_update_groupmeta( $group_id, '_associated_profile_field_id', $field_id );
    	}
    }, 10, 2 );
    
    add_action( 'groups_before_delete_group', function ( $group_id ) {
    
    	$associated_profile_field_id = groups_get_groupmeta( $group_id, '_associated_profile_field_id', true );
    	if ( ! $associated_profile_field_id ) {
    		return;
    	}
    
    	xprofile_delete_field( $associated_profile_field_id );
    }
    );
    
    

    Please get in touch via our services section, we may be able to assist you next week onward with any custom code requirement. Our hourly fee for services is USD $90/hr.

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 33
    Vlad on #38251

    Thanks Brajesh,
    the code works as it should,
    you are a very good specialist
    helped me a lot.

    Items 2, 4.
    I did it with google.
    Found plugins:
    https://github.com/JonasSkjodt/buddypress-group-tabs
    https://wordpress.org/plugins/bp-devolved-authority/
    remade for myself.

    I am glad that I had a good time with you.

    Best regards, Vlad

  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #38262

    Hi Vlad,
    That’s good to know.

    Regards
    Brajesh

The topic ‘ [Resolved] Automatic field creation when creating a user group by group slug’ is closed to new replies.

This topic is: resolved