[ XREF Home ] [ Index ]

PHP Cross Reference of WordPress Trunk

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


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