Skip Navigation

[Gelöst] How do I restrict fields and access buttons from regular users?

This support ticket is created vor 7 Jahren, 8 Monaten. 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.

Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.

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)

Dieses Thema enthält 4 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von Nigel vor 7 Jahren, 8 Monaten.

Assistiert von: Nigel.

Author
Artikel
#494871
Screen Shot 2017-02-27 at 4.34.28 PM.png

In the screenshot you can see these two buttons next to Add Media button, but I do not want regular users to see those two buttons. How do I restrict them?

#494963

Nigel
Supporter

Sprachen: Englisch (English ) Spanisch (Español )

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

Hi Sidian

We already have a report of this which occurs under specific circumstances, where the form has the "Allow Media Insert" button checked, and where the users have higher roles.

What is the role of the users who will be accessing this form?

The buttons are visible to users with a role of author or higher. (As administrator, you would see these buttons, but if your users have a lesser role they may not.)

I am escalating this thread and adding it to the existing internal ticket. In the meantime, if your form does not need the "Allow Media Insert" button, disabling it will also remove the unwanted buttons.

#495899

The users are using Author roles.

I would like to keep the Insert Media button but also get rid of the other two buttons.

#496991

Will this be fixed soon?

#497392

Nigel
Supporter

Sprachen: Englisch (English ) Spanisch (Español )

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

Hi Sidian

I heard back from the developers that the buttons were made visible on the front-end to users with a role of author or above by design.

I believe the rationale for the change relates to making Toolset work with front-end page-builders.

They agreed that the current implementation probably needs improving so that the appearance of the buttons is optional, and what changes to make are currently being discussed.

There are some undocumented filters you can use to disable the buttons.

Here is some sample code to do that (which you will need to add to your theme's functions.php file or using a plugin such as Code Snippets).

/**
 * 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 will need
 * to add a test, e.g. for the page 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 );

	if ( 19 == $postID ) {
		// 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' );
			return $roles;
		} );
	}
}
add_action( 'init', 'remove_toolset_buttons' );

Not that you must include a test for where you want to disable the buttons (e.g. in the code above they are being disabled for page with id of 19), otherwise they will be disabled globally.

Sorry for the inconvenience, we will hopefully have a more user friendly solution before too long.