WordPress supports the automatic checking of WordPress core code, plug-ins and theme versions in the background, and supports automatic updating. This is a great function, which enables WordPress sites to keep the latest version, especially when there are security vulnerabilities.
Problems with WordPress automatic update
However, this has also caused some other problems:
1. The update server of WordPress is abroad, and the acceleration service has not been started in China, so when WordPress checks for updates in the background, it may not be connected smoothly for various reasons, and then it is stuck all the time, causing the WordPress background to be very slow sometimes.
2. Automatic update is a good thing, but some plug-ins or themes change too much, causing background crash, which is not a good thing, especially if the production environment collapses, which is not a good thing. Therefore, for some sensitive systems, it is better to upgrade on the test server and test them before upgrading on the official production server.
To sum up, it is better to turn off the automatic update function of WordPress on the official server, and then update to the official server after upgrading and updating on the test server Ensure stable service , can also Make WordPress run faster in the background 。
Turn off automatic update and update check
How to turn off WordPress automatic update and background update check?
First, WordPress provides a constant: AUTOMATIC_UPDATER_DISABLED , on wp-config.php If this value is set to false in the file, the custom update function can be turned off.
If you don't want to change wp-config.php WordPress also provides a automatic_updater_disabled Interface, through which you can also turn off automatic updates:
add_filter ( automatic_updater_disabled , __return_true );
However, if you have access to the background, WordPress will regularly detect whether the WordPress core, plug-ins and themes have been updated. This function is achieved through timed jobs, which include three timed jobs:
wp_version_check : Check whether the WordPress core code is the latest version. wp_update_plugins : Check whether the WordPress plug-in is the latest version. wp_update_themes : Check whether the WordPress theme is the latest version.
These three scheduled jobs are run every two days. No matter whether you visit the background or not, they will run to check whether your site needs to be updated. We can close the regular update check job through the following code:
remove_action ( init , wp_schedule_update_checks );
wp_clear_scheduled_hook ( wp_version_check );
wp_clear_scheduled_hook ( wp_update_plugins );
wp_clear_scheduled_hook ( wp_update_themes );
In addition to regular jobs, if you visit the WordPress background, WordPress will check whether the WordPress core, plug-ins and themes are updated every 12 hours. This is the reason why WordPress is sometimes very slow. Many people think that WordPress is very slow because they have not visited the background of WordPress for a long time. As soon as they visit WordPress, they first check for updates, so it seems very slow. It is obvious that because you visit it, they will check every 12 hours.
Therefore, the function of detecting updates every 12 hours should be turned off, which is the key to speed up in the background:
remove_action ( admin_init , _maybe_update_core );
remove_action ( admin_init , _maybe_update_plugins );
remove_action ( admin_init , _maybe_update_themes );
After we block it like this, will WordPress updates not be available in the background? No, when we enter the WordPress background plug-in management page, theme management interface, and the update sub page under the dashboard, whenever we enter these three interfaces, WordPress will detect whether there is a new version.
Of course, you can also remove the function of detecting updates when you enter these pages, but I don't think it is necessary to enter specific pages to do specific corresponding things. I think it is completely OK, so there is no relevant code here.
These codes can be added to the functions.php File can also be directly checked in the WPJAM Basic plug-in to block the automatic update function.
After this process, if there is an update, it needs to be updated manually. It is recommended to use SSH to install, upgrade and migrate the WordPress blog.
The function of blocking WordPress automatic update and update check has been integrated into the WPJAM Basic plug-in, and has been provided for free download. Click to read the original text.