[ Root ] [ Search ] [ Index ]

PHP Cross Reference of WordPress 3.0

Provided by Yoast

title

Body

[close]

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

   1  <?php
   2  /**
   3   * Update/Install Plugin/Theme administration panel.
   4   *
   5   * @package WordPress
   6   * @subpackage Administration
   7   */
   8  
   9  /** WordPress Administration Bootstrap */
  10  require_once ('./admin.php');
  11  
  12  include_once  ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
  13  
  14  if ( isset($_GET['action']) ) {
  15      $plugin = isset($_REQUEST['plugin']) ? trim($_REQUEST['plugin']) : '';
  16      $theme = isset($_REQUEST['theme']) ? urldecode($_REQUEST['theme']) : '';
  17      $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
  18  
  19      if ( 'update-selected' == $action ) {
  20          if ( ! current_user_can( 'update_plugins' ) )
  21              wp_die( __( 'You do not have sufficient permissions to update plugins for this site.' ) );
  22  
  23          check_admin_referer( 'bulk-update-plugins' );
  24  
  25          if ( isset( $_GET['plugins'] ) )
  26              $plugins = explode( ',', stripslashes($_GET['plugins']) );
  27          elseif ( isset( $_POST['checked'] ) )
  28              $plugins = (array) $_POST['checked'];
  29          else
  30              $plugins = array();
  31  
  32          $plugins = array_map('urldecode', $plugins);
  33  
  34          $url = 'update.php?action=update-selected&amp;plugins=' . urlencode(implode(',', $plugins));
  35          $nonce = 'bulk-update-plugins';
  36  
  37          require_once ( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
  38          wp_enqueue_script('jquery');
  39          iframe_header();
  40  
  41          $upgrader = new Plugin_Upgrader( new Bulk_Plugin_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
  42          $upgrader->bulk_upgrade( $plugins );
  43  
  44          iframe_footer();
  45  
  46      } elseif ( 'upgrade-plugin' == $action ) {
  47          if ( ! current_user_can('update_plugins') )
  48              wp_die(__('You do not have sufficient permissions to update plugins for this site.'));
  49  
  50          check_admin_referer('upgrade-plugin_' . $plugin);
  51  
  52          $title = __('Upgrade Plugin');
  53          $parent_file = 'plugins.php';
  54          $submenu_file = 'plugins.php';
  55          require_once ('./admin-header.php');
  56  
  57          $nonce = 'upgrade-plugin_' . $plugin;
  58          $url = 'update.php?action=upgrade-plugin&plugin=' . $plugin;
  59  
  60          $upgrader = new Plugin_Upgrader( new Plugin_Upgrader_Skin( compact('title', 'nonce', 'url', 'plugin') ) );
  61          $upgrader->upgrade($plugin);
  62  
  63          include ('./admin-footer.php');
  64  
  65      } elseif ('activate-plugin' == $action ) {
  66          if ( ! current_user_can('update_plugins') )
  67              wp_die(__('You do not have sufficient permissions to update plugins for this site.'));
  68  
  69          check_admin_referer('activate-plugin_' . $plugin);
  70          if ( ! isset($_GET['failure']) && ! isset($_GET['success']) ) {
  71              wp_redirect( 'update.php?action=activate-plugin&failure=true&plugin=' . $plugin . '&_wpnonce=' . $_GET['_wpnonce'] );
  72              activate_plugin( $plugin, '', ! empty( $_GET['networkwide'] ) );
  73              wp_redirect( 'update.php?action=activate-plugin&success=true&plugin=' . $plugin . '&_wpnonce=' . $_GET['_wpnonce'] );
  74              die();
  75          }
  76          iframe_header( __('Plugin Reactivation'), true );
  77          if ( isset($_GET['success']) )
  78              echo '<p>' . __('Plugin reactivated successfully.') . '</p>';
  79  
  80          if ( isset($_GET['failure']) ){
  81              echo '<p>' . __('Plugin failed to reactivate due to a fatal error.') . '</p>';
  82  
  83              if ( defined('E_RECOVERABLE_ERROR') )
  84                  error_reporting(E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING | E_RECOVERABLE_ERROR);
  85              else
  86                  error_reporting(E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING);
  87  
  88              @ini_set('display_errors', true); //Ensure that Fatal errors are displayed.
  89              include(WP_PLUGIN_DIR . '/' . $plugin);
  90          }
  91          iframe_footer();
  92      } elseif ( 'install-plugin' == $action ) {
  93  
  94          if ( ! current_user_can('install_plugins') )
  95              wp_die(__('You do not have sufficient permissions to install plugins for this site.'));
  96  
  97          include_once  ABSPATH . 'wp-admin/includes/plugin-install.php'; //for plugins_api..
  98  
  99          check_admin_referer('install-plugin_' . $plugin);
 100          $api = plugins_api('plugin_information', array('slug' => $plugin, 'fields' => array('sections' => false) ) ); //Save on a bit of bandwidth.
 101  
 102          if ( is_wp_error($api) )
 103               wp_die($api);
 104  
 105          $title = __('Plugin Install');
 106          $parent_file = 'plugins.php';
 107          $submenu_file = 'plugin-install.php';
 108          require_once ('./admin-header.php');
 109  
 110          $title = sprintf( __('Installing Plugin: %s'), $api->name . ' ' . $api->version );
 111          $nonce = 'install-plugin_' . $plugin;
 112          $url = 'update.php?action=install-plugin&plugin=' . $plugin;
 113          if ( isset($_GET['from']) )
 114              $url .= '&from=' . urlencode(stripslashes($_GET['from']));
 115  
 116          $type = 'web'; //Install plugin type, From Web or an Upload.
 117  
 118          $upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact('title', 'url', 'nonce', 'plugin', 'api') ) );
 119          $upgrader->install($api->download_link);
 120  
 121          include ('./admin-footer.php');
 122  
 123      } elseif ( 'upload-plugin' == $action ) {
 124  
 125          if ( ! current_user_can('install_plugins') )
 126              wp_die(__('You do not have sufficient permissions to install plugins for this site.'));
 127  
 128          check_admin_referer('plugin-upload');
 129  
 130          $file_upload = new File_Upload_Upgrader('pluginzip', 'package');
 131  
 132          $title = __('Upload Plugin');
 133          $parent_file = 'plugins.php';
 134          $submenu_file = 'plugin-install.php';
 135          require_once ('./admin-header.php');
 136  
 137          $title = sprintf( __('Installing Plugin from uploaded file: %s'), basename( $file_upload->filename ) );
 138          $nonce = 'plugin-upload';
 139          $url = add_query_arg(array('package' => $file_upload->filename ), 'update.php?action=upload-plugin');
 140          $type = 'upload'; //Install plugin type, From Web or an Upload.
 141  
 142          $upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact('type', 'title', 'nonce', 'url') ) );
 143          $upgrader->install( $file_upload->package );
 144  
 145          include ('./admin-footer.php');
 146  
 147      } elseif ( 'upgrade-theme' == $action ) {
 148  
 149          if ( ! current_user_can('update_themes') )
 150              wp_die(__('You do not have sufficient permissions to update themes for this site.'));
 151  
 152          check_admin_referer('upgrade-theme_' . $theme);
 153  
 154          add_thickbox();
 155          wp_enqueue_script('theme-preview');
 156          $title = __('Upgrade Theme');
 157          $parent_file = 'themes.php';
 158          $submenu_file = 'themes.php';
 159          require_once ('./admin-header.php');
 160  
 161          $nonce = 'upgrade-theme_' . $theme;
 162          $url = 'update.php?action=upgrade-theme&theme=' . $theme;
 163  
 164          $upgrader = new Theme_Upgrader( new Theme_Upgrader_Skin( compact('title', 'nonce', 'url', 'theme') ) );
 165          $upgrader->upgrade($theme);
 166  
 167          include ('./admin-footer.php');
 168      } elseif ( 'update-selected-themes' == $action ) {
 169          if ( ! current_user_can( 'update_themes' ) )
 170              wp_die( __( 'You do not have sufficient permissions to update themes for this site.' ) );
 171  
 172          check_admin_referer( 'bulk-update-themes' );
 173  
 174          if ( isset( $_GET['themes'] ) )
 175              $themes = explode( ',', stripslashes($_GET['themes']) );
 176          elseif ( isset( $_POST['checked'] ) )
 177              $themes = (array) $_POST['checked'];
 178          else
 179              $themes = array();
 180  
 181          $themes = array_map('urldecode', $themes);
 182  
 183          $url = 'update.php?action=update-selected-themes&amp;themes=' . urlencode(implode(',', $themes));
 184          $nonce = 'bulk-update-themes';
 185  
 186          require_once ( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
 187          wp_enqueue_script('jquery');
 188          iframe_header();
 189  
 190          $upgrader = new Theme_Upgrader( new Bulk_Theme_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
 191          $upgrader->bulk_upgrade( $themes );
 192  
 193          iframe_footer();
 194      } elseif ( 'install-theme' == $action ) {
 195  
 196          if ( ! current_user_can('install_themes') )
 197              wp_die(__('You do not have sufficient permissions to install themes for this site.'));
 198  
 199          include_once  ABSPATH . 'wp-admin/includes/theme-install.php'; //for themes_api..
 200  
 201          check_admin_referer('install-theme_' . $theme);
 202          $api = themes_api('theme_information', array('slug' => $theme, 'fields' => array('sections' => false) ) ); //Save on a bit of bandwidth.
 203  
 204          if ( is_wp_error($api) )
 205               wp_die($api);
 206  
 207          add_thickbox();
 208          wp_enqueue_script('theme-preview');
 209          $title = __('Install Themes');
 210          $parent_file = 'themes.php';
 211          $submenu_file = 'themes.php';
 212          require_once ('./admin-header.php');
 213  
 214          $title = sprintf( __('Installing Theme: %s'), $api->name . ' ' . $api->version );
 215          $nonce = 'install-theme_' . $theme;
 216          $url = 'update.php?action=install-theme&theme=' . $theme;
 217          $type = 'web'; //Install theme type, From Web or an Upload.
 218  
 219          $upgrader = new Theme_Upgrader( new Theme_Installer_Skin( compact('title', 'url', 'nonce', 'plugin', 'api') ) );
 220          $upgrader->install($api->download_link);
 221  
 222          include ('./admin-footer.php');
 223  
 224      } elseif ( 'upload-theme' == $action ) {
 225  
 226          if ( ! current_user_can('install_themes') )
 227              wp_die(__('You do not have sufficient permissions to install themes for this site.'));
 228  
 229          check_admin_referer('theme-upload');
 230  
 231          $file_upload = new File_Upload_Upgrader('themezip', 'package');
 232  
 233          $title = __('Upload Theme');
 234          $parent_file = 'themes.php';
 235          $submenu_file = 'theme-install.php';
 236          add_thickbox();
 237          wp_enqueue_script('theme-preview');
 238          require_once ('./admin-header.php');
 239  
 240          $title = sprintf( __('Installing Theme from uploaded file: %s'), basename( $file_upload->filename ) );
 241          $nonce = 'theme-upload';
 242          $url = add_query_arg(array('package' => $file_upload->filename), 'update.php?action=upload-theme');
 243          $type = 'upload'; //Install plugin type, From Web or an Upload.
 244  
 245          $upgrader = new Theme_Upgrader( new Theme_Installer_Skin( compact('type', 'title', 'nonce', 'url') ) );
 246          $upgrader->install( $file_upload->package );
 247  
 248          include ('./admin-footer.php');
 249  
 250      } else {
 251          do_action('update-custom_' . $action);
 252      }
 253  }


Generated: Thu Oct 14 05:11:12 2010 Cross-referenced by PHPXref 0.7