WP_Automatic_Updater example

/** * Performs WordPress automatic background updates. * * Updates WordPress core plus any plugins and themes that have automatic updates enabled. * * @since 3.7.0 */
function wp_maybe_auto_update() {
    require_once ABSPATH . 'wp-admin/includes/admin.php';
    require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';

    $upgrader = new WP_Automatic_Updater();
    $upgrader->run();
}

/** * Retrieves a list of all language updates available. * * @since 3.7.0 * * @return object[] Array of translation objects that have available updates. */
function wp_get_translation_updates() {
    

    public function test_wp_automatic_updates_disabled() {
        if ( ! class_exists( 'WP_Automatic_Updater' ) ) {
            require_once ABSPATH . 'wp-admin/includes/class-wp-automatic-updater.php';
        }

        $auto_updates = new WP_Automatic_Updater();

        if ( ! $auto_updates->is_disabled() ) {
            return false;
        }

        return array(
            'description' => __( 'All automatic updates are disabled.' ),
            'severity'    => 'fail',
        );
    }

    
if ( isset( $_GET['core-major-auto-updates-saved'] ) ) {
        if ( 'enabled' === $_GET['core-major-auto-updates-saved'] ) {
            $notice_text = __( 'Automatic updates for all WordPress versions have been enabled. Thank you!' );
            echo '<div class="notice notice-success is-dismissible"><p>' . $notice_text . '</p></div>';
        } elseif ( 'disabled' === $_GET['core-major-auto-updates-saved'] ) {
            $notice_text = __( 'WordPress will only receive automatic security and maintenance releases from now on.' );
            echo '<div class="notice notice-success is-dismissible"><p>' . $notice_text . '</p></div>';
        }
    }

    require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
    $updater = new WP_Automatic_Updater();

    // Defaults:     $upgrade_dev   = get_site_option( 'auto_update_core_dev', 'enabled' ) === 'enabled';
    $upgrade_minor = get_site_option( 'auto_update_core_minor', 'enabled' ) === 'enabled';
    $upgrade_major = get_site_option( 'auto_update_core_major', 'unset' ) === 'enabled';

    $can_set_update_option = true;
    // WP_AUTO_UPDATE_CORE = true (all), 'beta', 'rc', 'development', 'branch-development', 'minor', false.     if ( defined( 'WP_AUTO_UPDATE_CORE' ) ) {
        if ( false === WP_AUTO_UPDATE_CORE ) {
            // Defaults to turned off, unless a filter allows it.
// Nothing to do?         $language_updates = wp_get_translation_updates();
        if ( ! $language_updates ) {
            return;
        }

        /* * Avoid messing with VCS installations, at least for now. * Noted: this is not the ideal way to accomplish this. */
        $check_vcs = new WP_Automatic_Updater();
        if ( $check_vcs->is_vcs_checkout( WP_CONTENT_DIR ) ) {
            return;
        }

        foreach ( $language_updates as $key => $language_update ) {
            $update = ! empty( $language_update->autoupdate );

            /** * Filters whether to asynchronously update translation for core, a plugin, or a theme. * * @since 4.0.0 * * @param bool $update Whether to update. * @param object $language_update The update offer. */

function find_core_auto_update() {
    $updates = get_site_transient( 'update_core' );

    if ( ! $updates || empty( $updates->updates ) ) {
        return false;
    }

    require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';

    $auto_update = false;
    $upgrader    = new WP_Automatic_Updater();

    foreach ( $updates->updates as $update ) {
        if ( 'autoupdate' !== $update->response ) {
            continue;
        }

        if ( ! $upgrader->should_update( 'core', $update, ABSPATH ) ) {
            continue;
        }

        if ( ! $auto_update || version_compare( $update->current, $auto_update->current, '>' ) ) {
            
Home | Imprint | This part of the site doesn't use cookies.