Automating WordPress Website Maintenance.

Assumptions, Prerequisites & Basic Knowledge
I assume you have decent web design and development knowledge, including HTML and CSS for Ice on Cake, and a working knowledge of PHP. I believe you have deployed your WordPress website on an online live server.

Introduction to Automated WordPress Maintenance
This tutorial & my blog post will help you to automate your workflow of updating 100s of WordPress websites without any extra effort. Even when you are sleeping or working on your next big project, your website will do all the work without any from your side. All scripts listed below will help you automate updating WordPress Major & Minor Core Source Code, Themes, Plugins, Database, WordPress site-wide trash cleanup & SPAM Comments removal.

First Step:
Towards Automated WordPress Source Code / Core update inclusion of official major & minor releases. introduced Automatic Minor Core updates in 3.7. These features remove hassle & extra steps from updating the website to the next dot release of WordPress Website Installation.

Automatic Major Core Updates are not activated by default. You have to modify your theme’s functions.php file by adding source code like this

// Enable major updates
add_filter( 'allow_major_auto_core_updates', '__return_true' );

Further Reading:
How to selectively or turn on & off ‘WordPress Automatic Background Updates’ while modifying code in the WordPress root wp-config.php file & Your theme’s functions.php file

Second Step:
Towards Automated WordPress Theme & Plugin Update / Management.

WordPress Automatic Update has a feature whereby you can selectively auto-update WordPress Themes & Plugins. The first step is to turn on & off plugins that only you required to use daily for working on your website & other plugins that don’t require you to run your website. Just delete them or at least disable them to remove confusion & for simplicity of use. So, in the case of plugins & themes, you should keep only the files that you require & and delete them.

You must enable automated updates for WordPress Themes & Plugins by implementing the following code in your active theme’s functions.php file

Enable Automatic Plugin Updates

// Enable automatic updates for plugins
add_filter( 'auto_update_plugin', '__return_true' );

Enable Automatic Theme Updates

// Enable automatic updates for themes
add_filter( 'auto_update_theme', '__return_true' );

Further Reading:
How to selectively or turn on & off ‘WordPress Automatic Background Updates’ while modifying code in the WordPress root wp-config.php file & Your theme’s functions.php file

Third Step: Towards Successful WordPress Database Management & Performance
WordPress Post Revisions have more to do with database size. I deleted my old WordPress with over 1,000 Revisions and immediately reduced the database size to 1/3, i.e. one-third of the original size.

Plugin Suggestion:
Plugin to manage Post Revisions: I used the WP-Optimise WordPress Plugin to delete old post revisions with just a few taps.

Source Code Update Suggestion:
As we know, WordPress Post Revision is quite an old feature that was introduced a long time ago. However, it now costs more for database size as it creates new revisions. WordPress creates a backup of your post with every hit of the save button and auto-save. So naturally, it overburdens the installation with a bloated database with useless backup data.

Solution & Implementation:
You can use the following post revision code in your installation’s wp-config file to control the number of revisions WordPress can make, from unlimited to 3 or 0. Turning it off will remove the WordPress Post Revision Feature.

/* Limit the number of posts revisions that WordPress stores in the database */
define( 'WP_POST_REVISIONS', 3 );

Further Reading:
How to reduce MySQL Database size by managing WordPress Post Revisions count (WordPress Tip for Optimum Performance)

Fourth Step: Towards Total Comments & SPAM Removal Management

Plugin Suggestion: Akismet
Akismet is critical to success; I am happy it blocked around 53,000 SPAM messages from my website by activating all websites using their unique API key.

Note: I have checked and selected ‘Auto-delete spam submitted on posts more than a month old’ in Akismet settings so that I don’t have to clean up spam detected by Akismet manually. It will auto-delete 30-day-old spam on its own.

Source Code Update Suggestion:
Use the following .htaccess code to limit direct access to wp-comments-post to limit spamming

# Block SPAM Comments

RewriteEngine On
RewriteCond %{REQUEST_URI} .wp-comments-post.php*
RewriteCond %{HTTP_REFERER} !.** [OR]
RewriteCond %{HTTP_USER_AGENT} ^$
RewriteRule (.*) ^http://%{REMOTE_ADDR}/$ [R=301,L]

Further Reading:
Securing WordPress Installation & Boosting WordPress Website Performance with Easy .htaccess Code Settings or hacks (Note: These are the settings – hacks that I deployed on my website, too)

Fifth Step:
Automatically empty WordPress site-wide trash to minimise blotting of WordPress Installation with Scrapped Data.

Whenever you delete a post, media, comments, themes, or plugin, it goes to WordPress Trash, but it needs another extra effort to press the button to empty the trash; you forget it stays there forever, and it then blots your installation by increasing the database size with useless deleted data. So, the idea is to make WordPress auto-delete and empty the trash in 10 days.

Implement the following code to your website’s wp-config.php file to enable auto-delete WordPress trash & auto-empty it regularly.

/* Automatically delete WordPress trash after 10 days */
define( 'EMPTY_TRASH_DAYS', 10 );

Further Reading:
How do Automatically Empty WordPress Trash, including deleted posts, pages, attachments & comments, from the WordPress trash bin? A minor tweak for optimum performance & avoiding bloated WordPress installation with useless data.

Sixth Step:
Empty ‘wp_commentsmeta’ table to speed up WordPress Website admin & visitor site load time.

As I stated earlier, plugins like Akismet keep logs of comments in the wp_commentsmeta database table, which may cause problems with loading speed. Just emptying this table for all top-level domains and subdomains can substantially increase the speed of your WordPress Website.

Note: You can perform this task once a year or only when the wp_commentsmeta table becomes bloated and has a size of more than 2 to 3 MB (megabytes).

Further Reading:
How to Fix ‘Warning: require_once() [function.require-once]: Unable to allocate memory for pool.’ A warning was thrown at you while trying to log in to your WordPress admin page.

So, I use all six of the above steps in all my WordPress website installations to Automate website maintenance, remove any extra effort from my side, and streamline the process for years to come.

I hope this helps,

Thanks & Regards
Mandar Apte

Published by Mandar Apte

Mandar is a Mumbai-based multi-disciplinary designer with UX/UI, Logo, Symbol, and Brand Identity design expertise. He currently runs his Mudrkashar Linguistic Apple iPhone, iPad, and Mac app business in the heart of Mumbai city.

Leave a comment

Leave a Reply

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