Skip to content

Instantly share code, notes, and snippets.

@devuri
Created November 5, 2020 20:11
Show Gist options
  • Save devuri/faf9a049958e2a12e98a7dbb9c2497a8 to your computer and use it in GitHub Desktop.
Save devuri/faf9a049958e2a12e98a7dbb9c2497a8 to your computer and use it in GitHub Desktop.
How to extend core major versions auto-updates feature?
<?php
// https://make.wordpress.org/core/2020/11/02/introducing-auto-updates-interface-for-core-major-versions-in-wordpress-5-6/
function my_plugin_after_core_auto_updates_settings_fields( $auto_update_settings ) {
if ( isset( $_POST['core-auto-updates-settings'] ) && wp_verify_nonce( $_POST['set_core_auto_updates_settings'], 'core-auto-updates-nonce' ) ) {
if ( isset( $_POST['my-plugin-core-auto-updates-minor'] ) && 1 === (int) $_POST['my-plugin-core-auto-updates-minor'] ) {
update_site_option( 'my_plugin_auto_update_core_minor', 1 );
} else {
update_site_option( 'my_plugin_auto_update_core_minor', 0 );
}
}
$minor_auto_updates_settings = get_site_option( 'my_plugin_auto_update_core_minor' );
?>
<p>
<input type="checkbox" name="my-plugin-core-auto-updates-minor" id="my-plugin-core-auto-updates-minor" value="1" <?php checked( $minor_auto_updates_settings, 1 ); ?> />
<label for="my-plugin-core-auto-updates-minor">
<?php _e( 'Automatically keep this site up-to-date with minor updates.', 'my-plugin' ); ?>
</label>
</p>
<?php
}
add_action( 'after_core_auto_updates_settings_fields', 'my_plugin_after_core_auto_updates_settings_fields', 10, 1 );
@devuri
Copy link
Author

devuri commented Nov 5, 2020

How to extend core major versions auto-updates feature?

The feature also checks for dev (development versions of WordPress) and for minor updates. There is an action hook running right before the submit button of that settings section to add some options if needed. Using the after_core_auto_updates_settings_fields action hook, developers can add other settings or texts.

For example, the following snippet adds an option to opt-in/out for minor releases auto-updates:

full release: https://make.wordpress.org/core/2020/11/02/introducing-auto-updates-interface-for-core-major-versions-in-wordpress-5-6/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment