Resources     Blog  

  1. Home
  2. WordPress Tutorials
  3. How to Stop Authors from Deleting WordPress Posts

How to Stop Authors from Deleting WordPress Posts

Having many authors on your team helps a website quickly generate content. However, sometimes posts will be deleted by authors whether it’s accidental or on purpose. As a result, your site could lose an important article that generates a lot of visitor traffic. This is why you should restrict deleting posts in WordPress.

While a backup of the entire site will give you the chance to recover deleted content, you shouldn’t have to perform this procedure if a single important article is removed. Depending on the size of the site, this has potential as being time consuming.

In this tutorial, I’m going to show you how to stop authors from deleting any WordPress post. You could go so far as to even deny authors the ability to delete their own published pieces.

Using Capability Manager Enhanced

Today, I’ll demonstrate the Capability Manager Enhanced plugin. This is the same plugin used when setting up and creating custom user roles. It’s a versatile tool that opens a lot of doors for productivity and content protection.

First, you will need to install and activate the “Capability Manager Enhanced” plugin if you don’t have it already.

CME

Once it’s activated, go to Tools and click, “Capability Manager.”

Capability Manager

This section gives you the ability to create backups of the roles you set. If you plan on moving the site later or want to restore from a previous setting, this is where you would perform those actions.

Backup Manager

You don’t need to do anything in this screen for now. I just want to show you where to find this particular tool.

Go to Users and click, “Capabilities.”

Users Capabilities

On the right side of the screen, click to expand the user role window.

User Role Window

Select Author from the list of roles. Your list is probably different than my own. It all depends on what plugins you have and if you made any custom roles. Make sure you select the correct one or you could hinder user performance for others.

Author

Click the “Load” button to the right of the user role. Otherwise, you will not edit authors. In fact, the tool loads up Subscribers by default.

Load User Role

Immediately, the options available for authors will display. Click the check boxes under Delete and Delete published to clear them. This will disable authors from deleting any content in WordPress.

Clear Delete

Scroll to the bottom of the page and click, “Save Changes.”

Role Save Changes

That’s all there is to it. Now, authors are unable to deleting posts whether they are published or not.

Best Practices and Ideas

Capability Manager Enhanced is an incredible WordPress user permission plugin. It offers the ability to modify who can do what in a myriad of situations. For instance, you can enable editors to export, import or even switch themes.

What are some good ideas about managing authors?

Creating New Roles

By using the “Create New Role” option, you can give specific authors more functionality. Let’s say you have authors who are more trustworthy or have seniority over others. Perhaps you could give them more flexibility and enhanced permissions when it comes to managing content.

You can also create roles to separate groups of authors. What if you have one group writing about a topic while a few other authors focus on another? It may help keep your content management organized.

Copy Author Role

Using the Copy Author Role option, you can protect the original settings of WordPress. This is done by creating a new role name and clicking, “Copy.”

This is a good alternative if you don’t want to make adjustments for a temp writer or guest blogger. Then, you can make changes to the copy instead.

I suggest using the copy tool for the sake of keeping permissions of the original role intact.

Always Create a Backup

Never underestimate the value of a good backup. It will help recover lost information in the event of a disaster. It can also help reusing the same capabilities on other sites with a click of the mouse.

Manually Preventing Authors from Deleting Posts

Instead of using a plugin, you can use coding to stop authors from deleting posts in WordPress. If you’re not experienced in making adjustments in PHP, I suggest using the plugin mentioned above. It doesn’t take much to crash a website if you enter the wrong coding elements.

With that being said, let me demonstrate how to make changes in WordPress.

Access the functions.php file for your website. You have several methods available to do this. You can use FTP applications like FileZilla, use the File Manager in cPanel or through the WordPress Editor.

For this tutorial, I’m simply going to load up the Editor so I can demonstrate the code.

Go to Appearance and click, “Editor.”

Editor

Make sure you’re working from your current theme. Click the functions.php file from the right column. It should be labeled something like “Theme Functions.”

Functions

Removing Ability to Delete

I suggest using a child theme whenever possible. It protects the primary theme from being altered incorrectly and makes it easy to recover if something goes wrong.

In many ways, it’s probably easier to use a plugin than to code the site. This is especially true since the plugin above is free and works perfectly.

However, if you’re intent on making adjustments yourself, add this code to the functions.php file:

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’);

Add Code

Click the “Update File” button on the bottom.

Update File

Adding Ability to Delete

Once you make coding adjustments in WordPress, you can’t simply delete them and force the system to revert. On the contrary, you’ll need to tell WordPress to give authors back the ability to delete posts. This is done by making a slight adjustment to the code above.

Paste this code over the other:

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’);

Add Delete

Take not of the “add_cap” areas of the code. This is the part that tells WordPress to “add” the ability as opposed to “remove.”

Once you click the “Update File” button, your authors will be able to delete posts again.

Manage Your Team

Capability Manager Enhanced is only one tool that helps users manage an online team. Whether it’s permissions or using an auto post scheduler, there is plenty available through WordPress. Find tools that work well for you. It will make a profound difference in efficiency over the long-term.

What abilities do you give your authors when it comes to creating content? Do custom roles play a part in your website development?

Author: Kaumil Patel

Kaumil Patel is the Chief Operating Officer of GreenGeeks and has over 13 years of experience in the web hosting industry working for and owning web hosting companies. Kaumil’s expertise is in marketing, business development, operations, acquisitions and mergers.

Was this article helpful?

Related Articles

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.