My client is not a computer person. I created a website for him. There is some important pages. My client is always delete this page. Then i want to reconfigure the code (the page id).
How do i disable delete options for particular pages.
PS: He may able to EDIT these page. Not Delete.
You can remove the capabilites
delete_pages
,delete_others_pages
anddelete_published_pages
from the role which the user is assigned to. This will prevent the complete user role from deleting pages.To restrict this behavior only to one user, you have to create and assign a dedicated, new role to the user. Look at the Members plugin from Justin Tadlock for more information.
Example: Remove the ability to delete pages from admin role
More resources
Capabilities
get_role()
Brian Fegter’s answer is almost perfect.
In my testing his answer will only work if you change the actions to “wp_trash_post” and “before_delete_post”
You can create an action to restrict users from trashing or deleting posts as follows. It’s not the prettiest, but it works. You will have to manually populate the user and page ID’s.
Here’s an example that I tested and found working of how to prevent deletion of a specific post or page by its’ ID. It should work for all wordpress users:
You could very easily hide the trash links from both the quick edit and the meta box. DO one using styles and the other using post_row_actions filter (you may be able to do both sith the filter – dunno)
https://developer.wordpress.org/reference/hooks/post_row_actions/
You could also use the filter page_row_actions (see https://developer.wordpress.org/reference/hooks/page_row_actions/) which is called for every page in the page list table.
You have to check the id of the post you don’t want to be edited or delete you can modify the action array for these pages. If your return an empty array, the page will still be listed in the page list table, but there are not links for edit,delete,…
Therefore the page could not be edited or deleted.
Your function should like this (Note: In my example code only the site admin has the right to modify the special page):