How to Prevent Authors From Deleting Posts in WordPress

123

By default, users with the author user role can delete their own posts, even when these posts are already published. If you run a multi-author blog, then you may want to stop authors from deleting their own posts specially once it’s published. In this article, we will show you how to easily prevent authors from deleting their own posts in WordPress.

How to prevent authors from deleting posts in WordPress

Why Prevent Authors From Deleting Their Own Posts in WordPress

WordPress comes with a powerful user role management system. Each registered user on your WordPress website is assigned a user role, and each user role comes with different permissions.

Users with the ‘author‘ role can write posts and publish them on your website. This role is generally used by multi-author WordPress blogs.

Authors can also delete their own posts, including those already published. As a website owner, you may want to prevent authors from doing that. The easiest way to do that is by modifying the author user role and changing its permissions in WordPress.

Let’s take a look at how to easily prevent authors from deleting their own posts.

Method 1: Prevent Authors From Deleting Posts Using Plugin

This method is easier and recommended for all users.

First thing you need to do is install and activate the Capability Manager Enhanced plugin. For more details, see our step by step guide on how to install a WordPress plugin.

Upon activation, you need to visit Users » Capabilities page. Here you can load any WordPress user role and change its capabilities and permissions.

User roles and capabilities manager

You need to start by locating the ‘Select Role to View / Edit’ box in the right column, and then select ‘Author’ user role from the drop down menu. After that you need to click on the ‘Load’ button to load the author user role capabilities.

Load author user role

The plugin will now load the ‘Author’ user role capabilities. Under the deletion capabilities section, you need to uncheck the box next to delete and delete published options.

After that you can go to the bottom of the page and click on the save changes button to store your settings.

Now, users with the author user role will not longer be able to delete any posts on your WordPress site.

Giving Back Permissions

User role capabilities are defined explicitly. It means that once you remove a capability from a user role, it will not come back unless you explicitly define it again. Even if you uninstalled the plugin, the capability changes you made will not revert automatically.

If you want to give back authors permission to delete, then you will have to repeat the process and check the boxes next to the delete and delete published posts options.

If you want to uninstall the plugin and revert back to default WordPress capabilities, then first you need to visit Tools » Capability Manager page and click on ‘Reset to WordPress defaults’ link.

Reset user role permissions

Method 2: Manually Prevent Authors From Deleting Their Own Posts

This method requires you to add code to your WordPress files. If you haven’t done this before, then take a look at our guide on how to copy and paste code in WordPress.

You will need to add the following code to to your theme’s functions.php file or a site-specific plugin.

  function wpb_change_author_role(){  	global $wp_roles;  	$wp_roles->remove_cap( 'author', 'delete_posts' );  	$wp_roles->remove_cap( 'author', 'delete_published_posts' );    }  add_action('init', 'wpb_change_author_role');  

This code changes the author user role and removes their capability to delete their own posts.

If you want to revert back the permissions, then simply removing the code will not make any change. You will need to explicitly redefine the removed capabilities by replacing the first code snippet with the following code:

  function wpb_change_author_role(){  	global $wp_roles;  	$wp_roles->add_cap( 'author', 'delete_posts' );  	$wp_roles->add_cap( 'author', 'delete_published_posts' );    }  add_action('init', 'wpb_change_author_role');  

We hope this article helped you learn how to prevent authors from deleting their own posts in WordPress. You may also want to see our ultimate step by step WordPress security guide for beginners.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.