Remove redundant checks in some update functions. Adds some readability/coding standards cleanup.

Props miqrogroove, azaozz.
Fixes #22828.

Built from https://develop.svn.wordpress.org/trunk@25256


git-svn-id: http://core.svn.wordpress.org/trunk@25224 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Scott Taylor 2013-09-05 17:05:15 +00:00
parent 4be84bbdfb
commit bb0761e475
1 changed files with 25 additions and 16 deletions

View File

@ -15,10 +15,10 @@
*/
function get_preferred_from_update_core() {
$updates = get_core_updates();
if ( !is_array( $updates ) )
if ( ! is_array( $updates ) )
return false;
if ( empty( $updates ) )
return (object)array('response' => 'latest');
return (object) array( 'response' => 'latest' );
return $updates[0];
}
@ -30,26 +30,29 @@ function get_preferred_from_update_core() {
* @return array Array of the update objects
*/
function get_core_updates( $options = array() ) {
$options = array_merge( array('available' => true, 'dismissed' => false ), $options );
$options = array_merge( array( 'available' => true, 'dismissed' => false ), $options );
$dismissed = get_site_option( 'dismissed_update_core' );
if ( !is_array( $dismissed ) ) $dismissed = array();
if ( ! is_array( $dismissed ) )
$dismissed = array();
$from_api = get_site_transient( 'update_core' );
if ( empty($from_api) )
if ( ! isset( $from_api->updates ) || ! is_array( $from_api->updates ) )
return false;
if ( !isset( $from_api->updates ) || !is_array( $from_api->updates ) ) return false;
$updates = $from_api->updates;
if ( !is_array( $updates ) ) return false;
$result = array();
foreach($updates as $update) {
if ( array_key_exists( $update->current.'|'.$update->locale, $dismissed ) ) {
foreach ( $updates as $update ) {
if ( array_key_exists( $update->current . '|' . $update->locale, $dismissed ) ) {
if ( $options['dismissed'] ) {
$update->dismissed = true;
$result[]= $update;
$result[] = $update;
}
} else {
if ( $options['available'] ) {
$update->dismissed = false;
$result[]= $update;
$result[] = $update;
}
}
}
@ -58,23 +61,29 @@ function get_core_updates( $options = array() ) {
function dismiss_core_update( $update ) {
$dismissed = get_site_option( 'dismissed_update_core' );
$dismissed[ $update->current.'|'.$update->locale ] = true;
$dismissed[ $update->current . '|' . $update->locale ] = true;
return update_site_option( 'dismissed_update_core', $dismissed );
}
function undismiss_core_update( $version, $locale ) {
$dismissed = get_site_option( 'dismissed_update_core' );
$key = $version.'|'.$locale;
if ( !isset( $dismissed[$key] ) ) return false;
$key = $version . '|' . $locale;
if ( ! isset( $dismissed[$key] ) )
return false;
unset( $dismissed[$key] );
return update_site_option( 'dismissed_update_core', $dismissed );
}
function find_core_update( $version, $locale ) {
$from_api = get_site_transient( 'update_core' );
if ( !is_array( $from_api->updates ) ) return false;
if ( ! isset( $from_api->updates ) || ! is_array( $from_api->updates ) )
return false;
$updates = $from_api->updates;
foreach($updates as $update) {
foreach ( $updates as $update ) {
if ( $update->current == $version && $update->locale == $locale )
return $update;
}