Skip Navigation

[Resolved] Hiding the 'Access' button for posts when a user is a custom type

This support ticket is created 5 years, 1 month 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.

Our next available supporter will start replying to tickets in about 1.01 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 5 replies, has 2 voices.

Last updated by MattI4840 5 years, 1 month ago.

Assisted by: Waqar.

Author
Posts
#1204010
access.JPG

Tell us what you are trying to do?

I created a custom role called 'Parent' based off the Author role, as you'll see in the attached image there is a button in the editor that I need to revoke access to for this role.

Is there any documentation that you are following?

https://toolset.com/forums/topic/removehide-toolset-buttons-from-add-new-postcustom-field-for-non-admin-users/

I've looked through the info in this thread, but it doesn't outline what permissions need to be toggled to remove the access to that button.

Is there a similar example that we can see?

Not that I know of

What is the link to your site?

hidden link

#1204689

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Matt,

Thank you for contacting us and I'll be happy to assist.

To revoke the availability of the 'Access' button, from the users of a specific role, you can use "toolset_editor_access_button_disable_by_role" filter, as explained at:
https://toolset.com/documentation/user-guides/access-control-texts-inside-page-content/#hide-the-access-button-in-wordpress-editors-for-specific-user-roles

For example, if you'd like to hide it from user role "Parent" (with slug "parent"), you can add the following code, at the bottom of your active theme's "functions.php" file:


add_filter('toolset_editor_access_button_disable_by_role','wpcf_hide_access_button');
function wpcf_hide_access_button( $roles=array() ){
	return array('parent');
}

I hope this helps.

regards,
Waqar

#1205705

Hi Waqar,

I tried to implement this a few different ways without success. I first attempted to place the code you provided in the child theme's function file without any luck. I then placed it in the functions file for the plugin I created to modify the admin css for users in the parent role, again with no luck.

I also looked at the documentation and thought perhaps the slug I was using was incorrect so I attempted to revoke it for all roles, in both of the functions files I mentioned above and that didn't resolve the issue either. I'm not sure where I'm going wrong, let me know if you need further info.

I was going to provide the plugin but it doesn't look like I'm able to attach anything that isn't an image extension to this. I can also provide ftp and admin access but again it doesn't look like I can make this post private to do so for some reason.

Thanks,
Matt

#1206022

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Matt,

Thanks for writing back.

This is strange and the code snippet works on my test website, as expected.

To rule out any theme or plugin conflict, I'll recommend temporarily disabling all non-Toolset plugins, switching to a default WordPress theme like Twenty Nineteen and then adding the code in active theme's "functions.php" file or Toolset's own custom code area ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ).

In case the issue still persists, you're welcome to share temporary admin login details, in reply to this message.
(your next reply will be private, which means that only you and our support team will have access to it)

Important note: Please make a complete backup copy of the website, before sharing the access details.

regards,
Waqar

#1207445

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Matt,

Thank you for waiting, while I performed some more tests.

The suggested code to remove the access button continues to works as expected on my test websites, but not on yours.

I noticed that your website is using a custom theme and plugins to show the post editor tabs/fields, on the player post type.

As per our support policy ( https://toolset.com/toolset-support-policy/ ), it won't be possible to troubleshoot the custom developed code, but I can suggest an alternative.

You can hide the toolset buttons ( "Access", "Toolset Forms" and "Fields and Views" ), using custom CSS code.

1. First, you can make sure that the user's role is included in the admin area's body class, using a code snippet:


// include a user's role in the body class in the admin area
add_filter( 'admin_body_class', 'include_role_admin_body_class' );
function include_role_admin_body_class( $classes ) {
	global $current_user;
	foreach( $current_user->roles as $role )
		$classes .= ' role-' . $role;
	return trim( $classes );
}

2. Next, you can target that user role class through custom CSS code, to hide these buttons, only when the user with the "parent" role is logged-in:


// include custom CSS code to hide the Toolset buttons in the admin area
add_action('admin_head', 'hide_toolset_buttons');
function hide_toolset_buttons() {
echo '<style>
body.role-parent .button.js-wpv-fields-and-views-in-toolbar,
body.role-parent .button.js-cred-in-toolbar,
body.role-parent .button.js-wpcf-access-editor-button {
display: none !important;	
}
</style>';
}

Note: The above code snippets too, can be added in active theme's "functions.php" file or Toolset's own custom code area ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ).

For more personalized assistance around custom code, you can also consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/

regards,
Waqar

#1207632

My issue is resolved now, the css route worked exactly how you outlined, more fantastic support from Waqar and Toolset! Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.