Skip Navigation

[Resolved] How to hide the right screen add button of the custom type ?

This support ticket is created 6 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.

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)

Tagged: 

This topic contains 5 replies, has 2 voices.

Last updated by FuChan 6 years, 1 month ago.

Assisted by: Nigel.

Author
Posts
#1140989
1 (4).png
1 (3).png
1 (2).png
1 (1).png

Hi support,

How to hide the right screen add button and delete button of the custom type ?

see attachment:
1.list post page
2.edit content page

Thank you.

#1141286

Nigel
Supporter

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

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

Hi there

Presumably somebody should be able to see the buttons to add/edit/delete posts of this type, or it would be impossible to create any posts in the first place.

I'm assuming that you want administrators to be able to add/delete posts, but no-one else.

In which case you could use the following code to modify the settings for the post type in question.

Note that you cannot add this code to Toolset > Settings > Custom Code, you need to add it to your theme's functions.php file.

You will need to edit it to specify the slug of the custom post type ("thing" in my example):

/**
 * Remove Add New and Trash/Delete capabilities
 */
function tssupp_re_register($args, $type) {

	if ( $type == 'thing' ) {

		$args['capabilities'] = array(
			'create_posts' => 'administrator',
			'delete_post' => 'administrator',
			'delete_posts' => 'administrator',
			'delete_others_posts' => 'administrator',
			'delete_private_posts' => 'administrator',
			'delete_published_posts' => 'administrator',
		);
		$args['map_meta_cap'] = true;

	}
	return $args;
}
add_filter('register_post_type_args', 'tssupp_re_register', 20, 2);
#1141975

Hi Nigel,

I use the code add to functions.php file ,but the delete/trash capabilities can not remove.

(The code only removes the add new capabilities ,then the Add button still show the right admin screen. I do not want to let my customer see the Add new button and Trash/Delete link.)

Video record:
hidden link

Thank you.

/**
 * Remove Add New and Trash/Delete capabilities
 */
function tssupp_re_register($args, $type) {
 
    if ( $type == 'slide-mant' ) {
 
        $args['capabilities'] = array(
            'create_posts' => 'partner',
            'delete_post' => 'partner',
            'delete_posts' => 'partner',
            'delete_others_posts' => 'partner',
            'delete_private_posts' => 'partner',
            'delete_published_posts' => 'partner',
        );
        $args['map_meta_cap'] = true;
 
    }
    return $args;
}
add_filter('register_post_type_args', 'tssupp_re_register', 20, 2);

#1142167

Nigel
Supporter

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

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

To clarify, where in my code I had "administrator" that was the role that should still be able to see the Add New buttons and trash links, all other roles will not see them.

So where you have changed the code to use 'partner', that means that the only role that should see the Add New buttons and trash links is the partner role, and they should be hidden for everyone else.

In my test site it works just how I expect. The administrator can see the links, but other roles cannot.

#1142850

Thank you, I have set it up.

#1142851

My issue is resolved now. Thank you!