| [ Index ] |
PHP Cross Reference of Wordpress 2.9.1 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * WordPress Administration Update API 4 * 5 * @package WordPress 6 * @subpackage Administration 7 */ 8 9 // The admin side of our 1.1 update system 10 11 /** 12 * Selects the first update version from the update_core option 13 * 14 * @return object the response from the API 15 */ 16 function get_preferred_from_update_core() { 17 $updates = get_core_updates(); 18 if ( !is_array( $updates ) ) 19 return false; 20 if ( empty( $updates ) ) 21 return (object)array('response' => 'latest'); 22 return $updates[0]; 23 } 24 25 /** 26 * Get available core updates 27 * 28 * @param array $options Set $options['dismissed'] to true to show dismissed upgrades too, 29 * set $options['available'] to false to skip not-dimissed updates. 30 * @return array Array of the update objects 31 */ 32 function get_core_updates( $options = array() ) { 33 $options = array_merge( array('available' => true, 'dismissed' => false ), $options ); 34 $dismissed = get_option( 'dismissed_update_core' ); 35 if ( !is_array( $dismissed ) ) $dismissed = array(); 36 $from_api = get_transient( 'update_core' ); 37 if ( empty($from_api) ) 38 return false; 39 if ( !isset( $from_api->updates ) || !is_array( $from_api->updates ) ) return false; 40 $updates = $from_api->updates; 41 if ( !is_array( $updates ) ) return false; 42 $result = array(); 43 foreach($updates as $update) { 44 if ( array_key_exists( $update->current.'|'.$update->locale, $dismissed ) ) { 45 if ( $options['dismissed'] ) { 46 $update->dismissed = true; 47 $result[]= $update; 48 } 49 } else { 50 if ( $options['available'] ) { 51 $update->dismissed = false; 52 $result[]= $update; 53 } 54 } 55 } 56 return $result; 57 } 58 59 function dismiss_core_update( $update ) { 60 $dismissed = get_option( 'dismissed_update_core' ); 61 $dismissed[ $update->current.'|'.$update->locale ] = true; 62 return update_option( 'dismissed_update_core', $dismissed ); 63 } 64 65 function undismiss_core_update( $version, $locale ) { 66 $dismissed = get_option( 'dismissed_update_core' ); 67 $key = $version.'|'.$locale; 68 if ( !isset( $dismissed[$key] ) ) return false; 69 unset( $dismissed[$key] ); 70 return update_option( 'dismissed_update_core', $dismissed ); 71 } 72 73 function find_core_update( $version, $locale ) { 74 $from_api = get_transient( 'update_core' ); 75 if ( !is_array( $from_api->updates ) ) return false; 76 $updates = $from_api->updates; 77 foreach($updates as $update) { 78 if ( $update->current == $version && $update->locale == $locale ) 79 return $update; 80 } 81 return false; 82 } 83 84 function core_update_footer( $msg = '' ) { 85 if ( !current_user_can('manage_options') ) 86 return sprintf( __( 'Version %s' ), $GLOBALS['wp_version'] ); 87 88 $cur = get_preferred_from_update_core(); 89 if ( ! isset( $cur->current ) ) 90 $cur->current = ''; 91 92 if ( ! isset( $cur->url ) ) 93 $cur->url = ''; 94 95 if ( ! isset( $cur->response ) ) 96 $cur->response = ''; 97 98 switch ( $cur->response ) { 99 case 'development' : 100 return sprintf( __( 'You are using a development version (%1$s). Cool! Please <a href="%2$s">stay updated</a>.' ), $GLOBALS['wp_version'], 'update-core.php'); 101 break; 102 103 case 'upgrade' : 104 if ( current_user_can('manage_options') ) { 105 return sprintf( '<strong>'.__( '<a href="%1$s">Get Version %2$s</a>' ).'</strong>', 'update-core.php', $cur->current); 106 break; 107 } 108 109 case 'latest' : 110 default : 111 return sprintf( __( 'Version %s' ), $GLOBALS['wp_version'] ); 112 break; 113 } 114 } 115 add_filter( 'update_footer', 'core_update_footer' ); 116 117 function update_nag() { 118 global $pagenow; 119 120 if ( 'update-core.php' == $pagenow ) 121 return; 122 123 $cur = get_preferred_from_update_core(); 124 125 if ( ! isset( $cur->response ) || $cur->response != 'upgrade' ) 126 return false; 127 128 if ( current_user_can('manage_options') ) 129 $msg = sprintf( __('WordPress %1$s is available! <a href="%2$s">Please update now</a>.'), $cur->current, 'update-core.php' ); 130 else 131 $msg = sprintf( __('WordPress %1$s is available! Please notify the site administrator.'), $cur->current ); 132 133 echo "<div id='update-nag'>$msg</div>"; 134 } 135 add_action( 'admin_notices', 'update_nag', 3 ); 136 137 // Called directly from dashboard 138 function update_right_now_message() { 139 $cur = get_preferred_from_update_core(); 140 141 $msg = sprintf( __('You are using <span class="b">WordPress %s</span>.'), $GLOBALS['wp_version'] ); 142 if ( isset( $cur->response ) && $cur->response == 'upgrade' && current_user_can('manage_options') ) 143 $msg .= " <a href='update-core.php' class='button'>" . sprintf( __('Update to %s'), $cur->current ? $cur->current : __( 'Latest' ) ) . '</a>'; 144 145 echo "<span id='wp-version-message'>$msg</span>"; 146 } 147 148 function get_plugin_updates() { 149 $all_plugins = get_plugins(); 150 $upgrade_plugins = array(); 151 $current = get_transient( 'update_plugins' ); 152 foreach ( (array)$all_plugins as $plugin_file => $plugin_data) { 153 if ( isset( $current->response[ $plugin_file ] ) ) { 154 $upgrade_plugins[ $plugin_file ] = (object) $plugin_data; 155 $upgrade_plugins[ $plugin_file ]->update = $current->response[ $plugin_file ]; 156 } 157 } 158 159 return $upgrade_plugins; 160 } 161 162 function wp_plugin_update_rows() { 163 $plugins = get_transient( 'update_plugins' ); 164 if ( isset($plugins->response) && is_array($plugins->response) ) { 165 $plugins = array_keys( $plugins->response ); 166 foreach( $plugins as $plugin_file ) { 167 add_action( "after_plugin_row_$plugin_file", 'wp_plugin_update_row', 10, 2 ); 168 } 169 } 170 } 171 add_action( 'admin_init', 'wp_plugin_update_rows' ); 172 173 function wp_plugin_update_row( $file, $plugin_data ) { 174 $current = get_transient( 'update_plugins' ); 175 if ( !isset( $current->response[ $file ] ) ) 176 return false; 177 178 $r = $current->response[ $file ]; 179 180 $plugins_allowedtags = array('a' => array('href' => array(),'title' => array()),'abbr' => array('title' => array()),'acronym' => array('title' => array()),'code' => array(),'em' => array(),'strong' => array()); 181 $plugin_name = wp_kses( $plugin_data['Name'], $plugins_allowedtags ); 182 183 $details_url = admin_url('plugin-install.php?tab=plugin-information&plugin=' . $r->slug . '&TB_iframe=true&width=600&height=800'); 184 185 echo '<tr class="plugin-update-tr"><td colspan="3" class="plugin-update"><div class="update-message">'; 186 if ( ! current_user_can('update_plugins') ) 187 printf( __('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%3$s">View version %4$s Details</a>.'), $plugin_name, esc_url($details_url), esc_attr($plugin_name), $r->new_version ); 188 else if ( empty($r->package) ) 189 printf( __('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%3$s">View version %4$s Details</a> <em>automatic upgrade unavailable for this plugin</em>.'), $plugin_name, esc_url($details_url), esc_attr($plugin_name), $r->new_version ); 190 else 191 printf( __('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%3$s">View version %4$s Details</a> or <a href="%5$s">upgrade automatically</a>.'), $plugin_name, esc_url($details_url), esc_attr($plugin_name), $r->new_version, wp_nonce_url('update.php?action=upgrade-plugin&plugin=' . $file, 'upgrade-plugin_' . $file) ); 192 193 do_action( "in_plugin_update_message-$file", $plugin_data, $r ); 194 195 echo '</div></td></tr>'; 196 } 197 198 function wp_update_plugin($plugin, $feedback = '') { 199 200 if ( !empty($feedback) ) 201 add_filter('update_feedback', $feedback); 202 203 include ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; 204 $upgrader = new Plugin_Upgrader(); 205 return $upgrader->upgrade($plugin); 206 } 207 208 function get_theme_updates() { 209 $themes = get_themes(); 210 $current = get_transient('update_themes'); 211 $update_themes = array(); 212 213 foreach ( $themes as $theme ) { 214 $theme = (object) $theme; 215 if ( isset($current->response[ $theme->Stylesheet ]) ) { 216 $update_themes[$theme->Stylesheet] = $theme; 217 $update_themes[$theme->Stylesheet]->update = $current->response[ $theme->Stylesheet ]; 218 } 219 } 220 221 return $update_themes; 222 } 223 224 function wp_update_theme($theme, $feedback = '') { 225 226 if ( !empty($feedback) ) 227 add_filter('update_feedback', $feedback); 228 229 include ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; 230 $upgrader = new Theme_Upgrader(); 231 return $upgrader->upgrade($theme); 232 } 233 234 235 function wp_update_core($current, $feedback = '') { 236 237 if ( !empty($feedback) ) 238 add_filter('update_feedback', $feedback); 239 240 include ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; 241 $upgrader = new Core_Upgrader(); 242 return $upgrader->upgrade($current); 243 244 } 245 246 function maintenance_nag() { 247 global $upgrading; 248 if ( ! isset( $upgrading ) ) 249 return false; 250 251 if ( current_user_can('manage_options') ) 252 $msg = sprintf( __('An automated WordPress update has failed to complete - <a href="%s">please attempt the update again now</a>.'), 'update-core.php' ); 253 else 254 $msg = __('An automated WordPress update has failed to complete! Please notify the site administrator.'); 255 256 echo "<div id='update-nag'>$msg</div>"; 257 } 258 add_action( 'admin_notices', 'maintenance_nag' ); 259 260 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Fri Jan 8 00:19:48 2010 | Cross-referenced by PHPXref 0.7 |