Skip Navigation

[Resolved] Hide Toolset buttons from the post content rich text editor for non-admins

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

Problem:
How to remove Toolset buttons from the rich text editor in Toolset Forms?

Solution:
You will need to add the following code to your theme's functions.php file, editing it as required:

/**
* Remove Toolset buttons on front-end editors
* which appear for role author+ when insert
* media option set on CRED forms
*
* The filters work globally, so you need
* to specify the pages where the
* CRED form is added
*/
function remove_toolset_buttons(){
 
    // $post not available with init hook
    $postID = url_to_postid( $_SERVER['REQUEST_URI'] , '_wpg_def_keyword', true );
    $target_pages = array( 10, 25, 66 ); // Edit for pages with CRED forms
 
 
    if ( in_array( $postID, $target_pages ) ) {
        // remove the Fields and Views button
        add_filter( 'toolset_editor_add_form_buttons', '__return_false' );
 
        // remove the CRED button
        add_filter( 'toolset_cred_button_before_print', '__return_false' );
 
        // remove the Access button for certain roles
        add_filter( 'toolset_editor_add_access_button', function(){
            $roles = array( 'author', 'subscriber' );
            return $roles;
        } );
    }
}
add_action( 'init', 'remove_toolset_buttons' );
This support ticket is created 6 years, 5 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 4 replies, has 2 voices.

Last updated by PiotrO586 6 years, 4 months ago.

Assisted by: Nigel.

Author
Posts
#920415
screen.png

Hi,

In my form for adding/editing posts I enabled Add Media button. However, along with this button, the Toolset buttons appear for non-admin accounts. How to disable/hide them for non-admins? Is there any special hook?

#920689

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Piotr

The steps required for this are described in another ticket: https://toolset.com/forums/topic/removing-buttons-for-certain-user-roles-for-the-post-editor/

Can you try that and if you have any problems let me know.

I haven't tried it myself, I'd need to take a deeper look if you say it doesn't work as expected.

#921029

Hi Nigel,

I tried it, but no luck. Your link seems to concern back-end? Anyway, I meant front-end form and rich text editor included therein.

#921249

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Sorry, I mis-read your message, the above solution was for the back-end, yes.

For front-end forms you need to do the following:

/**
* Remove Toolset buttons on front-end editors
* which appear for role author+ when insert
* media option set on CRED forms
*
* The filters work globally, so you need
* to specify the pages where the
* CRED form is added
*/
function remove_toolset_buttons(){

	// $post not available with init hook
	$postID = url_to_postid( $_SERVER['REQUEST_URI'] , '_wpg_def_keyword', true );
	$target_pages = array( 10, 25, 66 ); // Edit for pages with CRED forms


	if ( in_array( $postID, $target_pages ) ) {
		// remove the Fields and Views button
		add_filter( 'toolset_editor_add_form_buttons', '__return_false' );

		// remove the CRED button
		add_filter( 'toolset_cred_button_before_print', '__return_false' );

		// remove the Access button for certain roles
		add_filter( 'toolset_editor_add_access_button', function(){
			$roles = array( 'author', 'subscriber' );
			return $roles;
		} );
	}
}
add_action( 'init', 'remove_toolset_buttons' );

Can you try again?

#921465

Thank you Nigel, this works fine.