Skip Navigation

[Resolved] Hiding options in the Post Form Content Field

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to hide the Fields and Views, Forms, and Access buttons above WYSIWYG editors in my Forms from all Users except Admins.

Solution: Add the following custom code snippet in your child theme's functions.php file:

// https://toolset.com/forums/topic/hiding-options-in-the-post-form-content-field/
// hide advanced form buttons from non-admins
function remove_toolset_buttons(){
    global $current_user, $wp_roles;
    $admin = 'administrator'; // roles that can see the buttons
 
    // get non-administrator role slugs
    if ( ! isset( $wp_roles ) )
        $wp_roles = new WP_Roles();
    $all_roles = $wp_roles->get_names();
    $editable_roles = apply_filters('editable_roles', $all_roles);
    $editable_role_names = array();
    foreach($editable_roles as $role=>$details) {
        $editable_role_names[]= $role;
    }
    // remove f&v, forms, conditional output buttons
    if ( !in_array( $admin, $current_user->roles ) ) {
        add_filter( 'toolset_editor_add_form_buttons', '__return_false' );
        add_filter( 'toolset_cred_button_before_print', '__return_false' );
    }
 
    // remove the Access button
    add_filter( 'toolset_editor_add_access_button', function() use ($editable_role_names){
        return $editable_role_names;
    });
}
add_action( 'init', 'remove_toolset_buttons' );
This support ticket is created 3 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 2 replies, has 2 voices.

Last updated by igorL-3 3 years, 4 months ago.

Assisted by: Christian Cox.

Author
Posts
#2143121
Screenshot 2021-08-15 at 17.17.43.jpg

Tell us what you are trying to do?
I have created a submission form. In the Content field where the user is able to enter text there are a number of options that I want to hid so that they are not abatable to the user. I have attached a screenshot of the form with the options circled.
How do I hide options like: FIELDS AND VIEWS, TOOLSET FORMS, CONDITIONAL OUTPUT, etc… so that only say admin would see those.

Thank you in advance

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site?

#2143255

Hello, since there is no built-in interface for managing the display of these buttons/capabilities in wp-admin, you'll need a custom code snippet in your child theme's functions.php file:

// https://toolset.com/forums/topic/hiding-options-in-the-post-form-content-field/
// hide advanced form buttons from non-admins
function remove_toolset_buttons(){
    global $current_user, $wp_roles;
    $admin = 'administrator'; // roles that can see the buttons

    // get non-administrator role slugs
    if ( ! isset( $wp_roles ) )
        $wp_roles = new WP_Roles();
    $all_roles = $wp_roles->get_names();
    $editable_roles = apply_filters('editable_roles', $all_roles);
    $editable_role_names = array();
    foreach($editable_roles as $role=>$details) {
        $editable_role_names[]= $role;
    }
    // remove f&v, forms, conditional output buttons
    if ( !in_array( $admin, $current_user->roles ) ) {
        add_filter( 'toolset_editor_add_form_buttons', '__return_false' );
        add_filter( 'toolset_cred_button_before_print', '__return_false' );
    }

    // remove the Access button
    add_filter( 'toolset_editor_add_access_button', function() use ($editable_role_names){
        return $editable_role_names;
    });
}
add_action( 'init', 'remove_toolset_buttons' );

Please note that the snippets added in Toolset > Settings > Custom Code are not fired early enough to support this code. It must be executed before those snippets are run, so the best place for this code is in functions.php.

#2143597

My issue is resolved now. Thank you!