This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.
When working with WordPress, hooks are like those magic spells that let you customize your site without touching the core files. One such hook is the plugins_auto_update_enabled filter. This nifty filter lets you control whether plugins auto-update on your site. Let’s dive into how you can use it effectively!
Example 1: Enabling Auto-Updates for All Plugins
Want to ensure all your plugins stay up to date without lifting a finger? This example shows you how to enable auto-updates for all plugins effortlessly.
function weplugins_modify_plugins_auto_update_enabled_defaults($enabled) { // Let's make sure all plugins auto-update return true; } add_filter("plugins_auto_update_enabled", "weplugins_modify_plugins_auto_update_enabled_defaults", 10, 1);
Example 2: Conditional Auto-Update
Perhaps you only want certain plugins to auto-update based on specific conditions. Here’s how you can achieve that.
function weplugins_modify_plugins_auto_update_enabled_conditionally($enabled) { // Auto-update only if the site is in maintenance mode if (defined('MAINTENANCE_MODE') && MAINTENANCE_MODE) { return true; } return $enabled; } add_filter("plugins_auto_update_enabled", "weplugins_modify_plugins_auto_update_enabled_conditionally", 10, 1);
Example 3: Disabling Auto-Updates
Auto-updates can sometimes be a hassle. If you prefer to handle updates manually, here’s how you can disable them.
function weplugins_disable_plugins_auto_update($enabled) { // Turn off auto-updates for all plugins return false; } add_filter("plugins_auto_update_enabled", "weplugins_disable_plugins_auto_update", 10, 1);
If you ever need to remove a filter, you can simply use remove_filter. Remember to provide the same callback function name, priority, and number of arguments as when you added it.
Need help customizing your WordPress site or working with hooks like this? Contact Us and our team will be happy to assist you!
Explore the latest in WordPress
Trying to stay on top of it all? Get the best tools, resources and inspiration sent to your inbox every Wednesday.