BuddyDev

Search

[Resolved] Custom Fields Per Role in BuddyBlog Pro

  • Participant
    Level: Initiated
    Posts: 8
    Chris Hall on #45810

    Is it possible to add a field (like a checkbox for example) to a custom form in BuddyBlog Pro that is only available to people in a certain role?

  • Keymaster
    (BuddyDev Team)
    Posts: 24211
    Brajesh Singh on #45811

    Hi Chris,
    Thank you for the question.

    I am sorry, we don’t have conditional fields yet.

    If you want to have two forms with different fields(for same post type) with different roles, that is still doable.

    Please create 2 forms with different fields and let me know their ids as well as the role they should be used for.

    I can provide you couple of lines of code to achieve that.

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 8
    Chris Hall on #45831

    Thank you!

    27931 – Subscriber

    27932 – Staff, Administrator

  • Keymaster
    (BuddyDev Team)
    Posts: 24211
    Brajesh Singh on #45843

    Hi Chris,
    Thank you.

    Which post type are you using? Is it the default Post post type?

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 8
    Chris Hall on #45844

    The post type is named ccwky_announcements

  • Keymaster
    (BuddyDev Team)
    Posts: 24211
    Brajesh Singh on #45856

    Hi Chris,
    hope you are doing well.

    Please upgrade to BuddyBlog Pro 1.2.9 and put this code in wp-content/plugins/bp-custom.php or in your themes functions.php (Or if you are using a code snippet manager, you can put it using that)

    
    
    /**
     * Filters BuddyBlog Pro form for roles.
     */
    add_filter( 'bblpro_post_type_associated_form_id', function ( $form_id, $post_type ) {
    
    	if ( ! is_user_logged_in() || 'ccwky_announcements' !== $post_type ) {
    		return $form_id;
    	}
    
    	$roles = wp_get_current_user()->roles;
    	if ( in_array( 'subscriber', $roles ) ) {
    		$form_id = 27931;
    	} else if ( array_intersect( array( 'staff', 'administrator' ), $roles ) ) {
    		$form_id = 27932;
    	}
    
    	return $form_id;
    }, 10, 2 );
    
    

    It will show the specific forms for the roles.

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 8
    Chris Hall on #45948

    I just wanted to follow up and say thank you.

    This is working great!

  • Keymaster
    (BuddyDev Team)
    Posts: 24211
    Brajesh Singh on #45950

    Thank you Chris.
    I am glad it worked.

    Regards
    Brajesh

The topic ‘ [Resolved] Custom Fields Per Role in BuddyBlog Pro’ is closed to new replies.

This topic is: resolved