Here we are going to expose how to Prevent Authors from Deleting Posts in WordPress? By default, most of the users with the author user role can delete their own posts when these posts are already published. Where the articles posted by the admin of a WordPress site are called posts.
While running a multi-author blog, you may want to stop authors from deleting their own posts specifically once it’s published. This post, help you how to simply prevent authors from deleting their own posts in WordPress.
Why Limit Authors From Deleting Posts in WordPress Website
WordPress is important for user role management system. WordPress site is assigned a user role for all registered user and all the user role comes with the permissions.
With an author role, a user can write posts and publish them on your website. Multi-author WordPress blogs use this role.
The author has the power in deleting posts. The website owner, prevent the authors from doing that. The simple way to do this by changing the author user role and its permission in WordPress.
Look at the methods to simply prevent authors from deleting their own posts.
Method 1: Prevent Authors From Deleting Posts By Using Plugin
This method is simple and recommended for all users.
- First of all, you can install and activate the Capability Manager Enhanced plugin.
- After activation, visit Users » Capabilities page. In this, you need to load any WordPress user role and change its capabilities and permissions.
- You can start by locating the ‘Select Role to View / Edit’ box in the right column.
- Next, select ‘Author’ user role from the drop-down menu. Click on the ‘Load’ button to load the author user role capabilities.
- The plugin loads the ‘Author’ user role capabilities. Beneath the deletion capabilities section, you can uncheck the box next to delete and delete published options. Just move ahead to the bottom of the page.
- Click on the save changes button to store your settings. The user will not able to deleting posts on your WordPress site by following these steps.
Allow Back Permissions
Directly you can be defined user role capability. Means that if you remove the capability from a user role it does not come back either if you directly defined it again.
By default, if you uninstalled the plugin, the capability will change it will not return automatically.
As a plugin is defined as a type of software that contains a group of functions that can be added to a WordPress website. They are used to provide additional functionality to your application.
If you grant authority to delete the back author permission. For doing this you will repeat the process and check the boxes next to delete. And by deleting posts published option also.
Now, if you uninstall the plugin you can return back to default WordPress capabilities firstly:
You need to visit Tools » Capability Manager page and click on ‘Reset to WordPress defaults’ link.
Method 2: Manually Prevent Authors From Deleting Their Own Posts in WordPress
This method needs to add code to your WordPress files.
Add the following code to your theme functions.php file or a site-specific plugin. As function.php file is also known as theme function file. It is used by WordPress theme to define classes, actions, functions, and filters that to be used by our templates.
$wp_roles->remove_cap( ‘author’, ‘delete_posts’ );
$wp_roles->remove_cap( ‘author’, ‘delete_published_posts’ );
Where a WordPress theme is a group of stylesheets and templates that are used to describe the appearance and display of a WordPress site. A WordPress theme changes the layout & design of your site. Also, Templates are those files which control how your WordPress site will be displayed on the Web.
The Code changes the author user role and removes their capability in deleting posts.
If you return back the permission you can simply remove the code it will not make any changes. Just redefine the removed capabilities by replacing the first code with the below-given code:
$wp_roles->add_cap( ‘author’, ‘delete_posts’ );
$wp_roles->add_cap( ‘author’, ‘delete_published_posts’ );
You know how to change permissions of an author and revoke access to delete option. Prevent the author from having access for deleting post option, you can use any method described above.
I suggest you go with the first method that uses the plugin. It will be simple and safe. As the second method is complicated for the user who doesn’t understand the code.
We have a well qualified team of professional who can solve your problem related to WordPress Security. Dial our Toll-Free number + 1 844 275 0975 for instant help and support.