[ XREF Home ] [ Index ]

PHP Cross Reference of WordPress Trunk

Provided by Yoast

title

Body

[close]

/wp-admin/includes/ -> update.php (source)

   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_site_option( 'dismissed_update_core' );
  35      if ( !is_array( $dismissed ) ) $dismissed = array();
  36      $from_api = get_site_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_site_option( 'dismissed_update_core' );
  61      $dismissed[ $update->current.'|'.$update->locale ] = true;
  62      return update_site_option( 'dismissed_update_core', $dismissed );
  63  }
  64  
  65  function undismiss_core_update( $version, $locale ) {
  66      $dismissed = get_site_option( 'dismissed_update_core' );
  67      $key = $version.'|'.$locale;
  68      if ( !isset( $dismissed[$key] ) ) return false;
  69      unset( $dismissed[$key] );
  70      return update_site_option( 'dismissed_update_core', $dismissed );
  71  }
  72  
  73  function find_core_update( $version, $locale ) {
  74      $from_api = get_site_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 ( is_multisite() && !current_user_can('update_core') )
  86          return false;
  87  
  88      if ( !current_user_can('update_core') )
  89          return sprintf( __( 'Version %s' ), $GLOBALS['wp_version'] );
  90  
  91      $cur = get_preferred_from_update_core();
  92      if ( ! isset( $cur->current ) )
  93          $cur->current = '';
  94  
  95      if ( ! isset( $cur->url ) )
  96          $cur->url = '';
  97  
  98      if ( ! isset( $cur->response ) )
  99          $cur->response = '';
 100  
 101      switch ( $cur->response ) {
 102      case 'development' :
 103          return sprintf( __( 'You are using a development version (%1$s). Cool! Please <a href="%2$s">stay updated</a>.' ), $GLOBALS['wp_version'], network_admin_url( 'update-core.php' ) );
 104      break;
 105  
 106      case 'upgrade' :
 107          return sprintf( '<strong>'.__( '<a href="%1$s">Get Version %2$s</a>' ).'</strong>', network_admin_url( 'update-core.php' ), $cur->current);
 108      break;
 109  
 110      case 'latest' :
 111      default :
 112          return sprintf( __( 'Version %s' ), $GLOBALS['wp_version'] );
 113      break;
 114      }
 115  }
 116  add_filter( 'update_footer', 'core_update_footer' );
 117  
 118  function update_nag() {
 119      if ( is_multisite() && !current_user_can('update_core') )
 120          return false;
 121  
 122      global $pagenow;
 123  
 124      if ( 'update-core.php' == $pagenow )
 125          return;
 126  
 127      $cur = get_preferred_from_update_core();
 128  
 129      if ( ! isset( $cur->response ) || $cur->response != 'upgrade' )
 130          return false;
 131  
 132      if ( current_user_can('update_core') ) {
 133          $msg = sprintf( __('<a href="http://codex.wordpress.org/Version_%1$s">WordPress %1$s</a> is available! <a href="%2$s">Please update now</a>.'), $cur->current, network_admin_url( 'update-core.php' ) );
 134      } else {
 135          $msg = sprintf( __('<a href="http://codex.wordpress.org/Version_%1$s">WordPress %1$s</a> is available! Please notify the site administrator.'), $cur->current );
 136      }
 137      echo "<div class='update-nag'>$msg</div>";
 138  }
 139  add_action( 'admin_notices', 'update_nag', 3 );
 140  
 141  // Called directly from dashboard
 142  function update_right_now_message() {
 143      if ( is_multisite() && !current_user_can('update_core') )
 144          return false;
 145  
 146      $cur = get_preferred_from_update_core();
 147  
 148      $msg = sprintf( __('You are using <span class="b">WordPress %s</span>.'), $GLOBALS['wp_version'] );
 149  
 150      if ( isset( $cur->response ) && $cur->response == 'upgrade' && current_user_can('update_core') ) {
 151          $msg .= " <a href='" . network_admin_url( 'update-core.php' ) . "' class='button'>" . sprintf( __('Update to %s'), $cur->current ? $cur->current : __( 'Latest' ) ) . '</a>';
 152      }
 153  
 154      echo "<span id='wp-version-message'>$msg</span>";
 155  }
 156  
 157  function get_plugin_updates() {
 158      $all_plugins = get_plugins();
 159      $upgrade_plugins = array();
 160      $current = get_site_transient( 'update_plugins' );
 161      foreach ( (array)$all_plugins as $plugin_file => $plugin_data) {
 162          if ( isset( $current->response[ $plugin_file ] ) ) {
 163              $upgrade_plugins[ $plugin_file ] = (object) $plugin_data;
 164              $upgrade_plugins[ $plugin_file ]->update = $current->response[ $plugin_file ];
 165          }
 166      }
 167  
 168      return $upgrade_plugins;
 169  }
 170  
 171  function wp_plugin_update_rows() {
 172      if ( !current_user_can('update_plugins' ) )
 173          return;
 174  
 175      $plugins = get_site_transient( 'update_plugins' );
 176      if ( isset($plugins->response) && is_array($plugins->response) ) {
 177          $plugins = array_keys( $plugins->response );
 178          foreach( $plugins as $plugin_file ) {
 179              add_action( "after_plugin_row_$plugin_file", 'wp_plugin_update_row', 10, 2 );
 180          }
 181      }
 182  }
 183  add_action( 'admin_init', 'wp_plugin_update_rows' );
 184  
 185  function wp_plugin_update_row( $file, $plugin_data ) {
 186      $current = get_site_transient( 'update_plugins' );
 187      if ( !isset( $current->response[ $file ] ) )
 188          return false;
 189  
 190      $r = $current->response[ $file ];
 191  
 192      $plugins_allowedtags = array('a' => array('href' => array(),'title' => array()),'abbr' => array('title' => array()),'acronym' => array('title' => array()),'code' => array(),'em' => array(),'strong' => array());
 193      $plugin_name = wp_kses( $plugin_data['Name'], $plugins_allowedtags );
 194  
 195      $details_url = self_admin_url('plugin-install.php?tab=plugin-information&plugin=' . $r->slug . '&TB_iframe=true&width=600&height=800');
 196  
 197      $wp_list_table = _get_list_table('WP_Plugins_List_Table');
 198  
 199      if ( is_network_admin() || !is_multisite() ) {
 200          echo '<tr class="plugin-update-tr"><td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange"><div class="update-message">';
 201  
 202          if ( ! current_user_can('update_plugins') )
 203              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 );
 204          else if ( empty($r->package) )
 205              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 update is unavailable for this plugin.</em>'), $plugin_name, esc_url($details_url), esc_attr($plugin_name), $r->new_version );
 206          else
 207              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">update automatically</a>.'), $plugin_name, esc_url($details_url), esc_attr($plugin_name), $r->new_version, wp_nonce_url( self_admin_url('update.php?action=upgrade-plugin&plugin=') . $file, 'upgrade-plugin_' . $file) );
 208  
 209          do_action( "in_plugin_update_message-$file", $plugin_data, $r );
 210  
 211          echo '</div></td></tr>';
 212      }
 213  }
 214  
 215  function wp_update_plugin($plugin, $feedback = '') {
 216      if ( !empty($feedback) )
 217          add_filter('update_feedback', $feedback);
 218  
 219      include  ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
 220      $upgrader = new Plugin_Upgrader();
 221      return $upgrader->upgrade($plugin);
 222  }
 223  
 224  function get_theme_updates() {
 225      $themes = get_themes();
 226      $current = get_site_transient('update_themes');
 227      $update_themes = array();
 228  
 229      foreach ( $themes as $theme ) {
 230          $theme = (object) $theme;
 231          if ( isset($current->response[ $theme->Stylesheet ]) ) {
 232              $update_themes[$theme->Stylesheet] = $theme;
 233              $update_themes[$theme->Stylesheet]->update = $current->response[ $theme->Stylesheet ];
 234          }
 235      }
 236  
 237      return $update_themes;
 238  }
 239  
 240  function wp_update_theme($theme, $feedback = '') {
 241      if ( !empty($feedback) )
 242          add_filter('update_feedback', $feedback);
 243  
 244      include  ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
 245      $upgrader = new Theme_Upgrader();
 246      return $upgrader->upgrade($theme);
 247  }
 248  
 249  function wp_theme_update_rows() {
 250      if ( !current_user_can('update_themes' ) )
 251          return;
 252  
 253      $themes = get_site_transient( 'update_themes' );
 254      if ( isset($themes->response) && is_array($themes->response) ) {
 255          $themes = array_keys( $themes->response );
 256  
 257          foreach( $themes as $theme ) {
 258              add_action( "after_theme_row_$theme", 'wp_theme_update_row', 10, 2 );
 259          }
 260      }
 261  }
 262  add_action( 'admin_init', 'wp_theme_update_rows' );
 263  
 264  function wp_theme_update_row( $theme_key, $theme ) {
 265      $current = get_site_transient( 'update_themes' );
 266      if ( !isset( $current->response[ $theme_key ] ) )
 267          return false;
 268      $r = $current->response[ $theme_key ];
 269      $themes_allowedtags = array('a' => array('href' => array(),'title' => array()),'abbr' => array('title' => array()),'acronym' => array('title' => array()),'code' => array(),'em' => array(),'strong' => array());
 270      $theme_name = wp_kses( $theme['Name'], $themes_allowedtags );
 271  
 272      $details_url = self_admin_url("theme-install.php?tab=theme-information&theme=$theme_key&TB_iframe=true&width=600&height=400");
 273  
 274      $wp_list_table = _get_list_table('WP_MS_Themes_List_Table');
 275  
 276      echo '<tr class="plugin-update-tr"><td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange"><div class="update-message">';
 277      if ( ! current_user_can('update_themes') )
 278          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>.'), $theme['Name'], esc_url($details_url), esc_attr($theme['Name']), $r->new_version );
 279      else if ( empty( $r['package'] ) )
 280          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 update is unavailable for this plugin.</em>'), $theme['Name'], esc_url($details_url), esc_attr($theme['Name']), $r['new_version'] );
 281      else
 282          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">update automatically</a>.'), $theme['Name'], esc_url($details_url), esc_attr($theme['Name']), $r['new_version'], wp_nonce_url( self_admin_url('update.php?action=upgrade-theme&theme=') . $theme_key, 'upgrade-theme_' . $theme_key) );
 283  
 284      do_action( "in_theme_update_message-$theme_key", $theme, $r );
 285  
 286      echo '</div></td></tr>';
 287  }
 288  
 289  function wp_update_core($current, $feedback = '') {
 290      if ( !empty($feedback) )
 291          add_filter('update_feedback', $feedback);
 292  
 293      include  ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
 294      $upgrader = new Core_Upgrader();
 295      return $upgrader->upgrade($current);
 296  
 297  }
 298  
 299  function maintenance_nag() {
 300      global $upgrading;
 301      if ( ! isset( $upgrading ) )
 302          return false;
 303  
 304      if ( current_user_can('update_core') )
 305          $msg = sprintf( __('An automated WordPress update has failed to complete - <a href="%s">please attempt the update again now</a>.'), 'update-core.php' );
 306      else
 307          $msg = __('An automated WordPress update has failed to complete! Please notify the site administrator.');
 308  
 309      echo "<div class='update-nag'>$msg</div>";
 310  }
 311  add_action( 'admin_notices', 'maintenance_nag' );
 312  
 313  ?>


Generated: Wed Jun 1 08:30:02 2011 Cross-referenced by PHPXref 0.7
Provided by Yoast and awesome WordPress Hosting