Last active
August 10, 2019 15:23
-
-
Save llgruff/ae676951f966fc86f1b892a1d6e0f679 to your computer and use it in GitHub Desktop.
Configuring Automatic Background Updates in WordPress (for functions.php)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Configuring Automatic Background Updates | |
* @link //codex.wordpress.org/Configuring_Automatic_Background_Updates | |
*/ | |
# Example. To enable ALL automatic updates | |
add_filter( 'automatic_updates_is_vcs_checkout','__return_false', 1 ); | |
add_filter( 'auto_update_core', '__return_true' ); | |
add_filter( 'auto_update_theme', '__return_true' ); | |
add_filter( 'auto_update_plugin', '__return_true' ); | |
add_filter( 'auto_update_translation', '__return_true' ); | |
add_filter( 'auto_core_update_send_email', '__return_true' ); | |
# Example. Enable auto-update of a particular plugin list | |
function main_auto_update_plugins ( $update, $item ) { | |
// Array of plugin slugs to always auto-update | |
$plugins = array ( | |
'backwpup', | |
'better-wp-security', | |
'cmb2', | |
'contact-form-7', | |
'disable-embeds', | |
'disable-emojis', | |
'disable-json-api', | |
'wp-super-cache', | |
); | |
if ( in_array( $item->slug, $plugins ) ) { | |
// Always update plugins in this array | |
return true; | |
} else { | |
// Else, use the normal API response to decide whether to update or not | |
return $update; | |
} | |
} | |
add_filter( 'auto_update_plugin', 'main_auto_update_plugins', 10, 2 ); | |
# Example. Disable auto-update of a particular plugin | |
function main_not_update_plugin($item) { | |
unset($item->response['wp-mediatagger/mediatagger.php']); | |
return $item; | |
} | |
add_filter( 'site_transient_update_plugins', 'main_not_update_plugin' ); | |
# Recommend! «Easy Updates Manager» plugin | |
/** | |
* Easy Updates Manager | |
* Manage all your WordPress updates, including individual updates, automatic updates, logs, and loads more. Also works with WordPress Multisite. | |
* @link //wordpress.org/plugins/stops-core-theme-and-plugin-updates/ | |
*/ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment