find_core_auto_update() WordPress Function

The find_core_auto_update() function enables you to search for and install updates for your WordPress site automatically. This function is especially useful if you have multiple WordPress sites and want to keep them all up-to-date without having to manually check for and install updates.

find_core_auto_update() #

Gets the best available (and enabled) Auto-Update for WordPress core.


Description

If there’s 1.2.3 and 1.3 on offer, it’ll choose 1.3 if the installation allows it, else, 1.2.3.


Top ↑

Return

(object|false) The core update offering on success, false on failure.


Top ↑

Source

File: wp-admin/includes/update.php

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, '>' ) ) {
			$auto_update = $update;
		}
	}
	return $auto_update;
}


Top ↑

Changelog

Changelog
VersionDescription
3.7.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.