+/**
+ * WordPress Administration Update API
+ *
+ * @package WordPress
+ * @subpackage Administration
+ */
+
+/**
+ * Selects the first update version from the update_core option
+ *
+ * @return object the response from the API
+ */
+function get_preferred_from_update_core() {
+ $updates = get_core_updates();
+ if ( ! is_array( $updates ) )
+ return false;
+ if ( empty( $updates ) )
+ return (object) array( 'response' => 'latest' );
+ return $updates[0];
+}
+
+/**
+ * Get available core updates
+ *
+ * @param array $options Set $options['dismissed'] to true to show dismissed upgrades too,
+ * set $options['available'] to false to skip not-dismissed updates.
+ * @return array Array of the update objects
+ */
+function get_core_updates( $options = array() ) {
+ $options = array_merge( array( 'available' => true, 'dismissed' => false ), $options );
+ $dismissed = get_site_option( 'dismissed_update_core' );
+
+ if ( ! is_array( $dismissed ) )
+ $dismissed = array();
+
+ $from_api = get_site_transient( 'update_core' );
+
+ if ( ! isset( $from_api->updates ) || ! is_array( $from_api->updates ) )
+ return false;
+
+ $updates = $from_api->updates;
+ $result = array();
+ foreach ( $updates as $update ) {
+ if ( $update->response == 'autoupdate' )
+ continue;
+
+ if ( array_key_exists( $update->current . '|' . $update->locale, $dismissed ) ) {
+ if ( $options['dismissed'] ) {
+ $update->dismissed = true;
+ $result[] = $update;
+ }
+ } else {
+ if ( $options['available'] ) {
+ $update->dismissed = false;
+ $result[] = $update;
+ }
+ }
+ }
+ return $result;
+}
+
+/**
+ * Gets the best available (and enabled) Auto-Update for WordPress Core.
+ *
+ * If there's 1.2.3 and 1.3 on offer, it'll choose 1.3 if the install allows it, else, 1.2.3
+ *
+ * @since 3.7.0
+ *
+ * @return bool|array False on failure, otherwise the core update offering.
+ */
+function find_core_auto_update() {
+ $updates = get_site_transient( 'update_core' );
+ if ( ! $updates || empty( $updates->updates ) )
+ return false;
+
+ include_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;
+}
+
+/**
+ * Gets and caches the checksums for the given version of WordPress.
+ *
+ * @since 3.7.0
+ *
+ * @param string $version Version string to query.
+ * @param string $locale Locale to query.
+ * @return bool|array False on failure. An array of checksums on success.
+ */
+function get_core_checksums( $version, $locale ) {
+ $return = array();