[ Index ]

PHP Cross Reference of WordPress

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  
  13  /** WordPress Administration Bootstrap */
  14  require_once( dirname( __FILE__ ) . '/admin.php' );
  15  
  16  include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
  17  
  18  if ( isset( $_GET['action'] ) ) {
  19      $plugin = isset( $_REQUEST['plugin'] ) ? trim( $_REQUEST['plugin'] ) : '';
  20      $theme  = isset( $_REQUEST['theme'] ) ? urldecode( $_REQUEST['theme'] ) : '';
  21      $action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : '';
  22  
  23      if ( 'update-selected' == $action ) {
  24          if ( ! current_user_can( 'update_plugins' ) ) {
  25              wp_die( __( 'Sorry, you are not allowed to update plugins for this site.' ) );
  26          }
  27  
  28          check_admin_referer( 'bulk-update-plugins' );
  29  
  30          if ( isset( $_GET['plugins'] ) ) {
  31              $plugins = explode( ',', stripslashes( $_GET['plugins'] ) );
  32          } elseif ( isset( $_POST['checked'] ) ) {
  33              $plugins = (array) $_POST['checked'];
  34          } else {
  35              $plugins = array();
  36          }
  37  
  38          $plugins = array_map( 'urldecode', $plugins );
  39  
  40          $url   = 'update.php?action=update-selected&amp;plugins=' . urlencode( implode( ',', $plugins ) );
  41          $nonce = 'bulk-update-plugins';
  42  
  43          wp_enqueue_script( 'updates' );
  44          iframe_header();
  45  
  46          $upgrader = new Plugin_Upgrader( new Bulk_Plugin_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
  47          $upgrader->bulk_upgrade( $plugins );
  48  
  49          iframe_footer();
  50  
  51      } elseif ( 'upgrade-plugin' == $action ) {
  52          if ( ! current_user_can( 'update_plugins' ) ) {
  53              wp_die( __( 'Sorry, you are not allowed to update plugins for this site.' ) );
  54          }
  55  
  56          check_admin_referer( 'upgrade-plugin_' . $plugin );
  57  
  58          $title        = __( 'Update Plugin' );
  59          $parent_file  = 'plugins.php';
  60          $submenu_file = 'plugins.php';
  61  
  62          wp_enqueue_script( 'updates' );
  63          require_once( ABSPATH . 'wp-admin/admin-header.php' );
  64  
  65          $nonce = 'upgrade-plugin_' . $plugin;
  66          $url   = 'update.php?action=upgrade-plugin&plugin=' . urlencode( $plugin );
  67  
  68          $upgrader = new Plugin_Upgrader( new Plugin_Upgrader_Skin( compact( 'title', 'nonce', 'url', 'plugin' ) ) );
  69          $upgrader->upgrade( $plugin );
  70  
  71          include( ABSPATH . 'wp-admin/admin-footer.php' );
  72  
  73      } elseif ( 'activate-plugin' == $action ) {
  74          if ( ! current_user_can( 'update_plugins' ) ) {
  75              wp_die( __( 'Sorry, you are not allowed to update plugins for this site.' ) );
  76          }
  77  
  78          check_admin_referer( 'activate-plugin_' . $plugin );
  79          if ( ! isset( $_GET['failure'] ) && ! isset( $_GET['success'] ) ) {
  80              wp_redirect( admin_url( 'update.php?action=activate-plugin&failure=true&plugin=' . urlencode( $plugin ) . '&_wpnonce=' . $_GET['_wpnonce'] ) );
  81              activate_plugin( $plugin, '', ! empty( $_GET['networkwide'] ), true );
  82              wp_redirect( admin_url( 'update.php?action=activate-plugin&success=true&plugin=' . urlencode( $plugin ) . '&_wpnonce=' . $_GET['_wpnonce'] ) );
  83              die();
  84          }
  85          iframe_header( __( 'Plugin Reactivation' ), true );
  86          if ( isset( $_GET['success'] ) ) {
  87              echo '<p>' . __( 'Plugin reactivated successfully.' ) . '</p>';
  88          }
  89  
  90          if ( isset( $_GET['failure'] ) ) {
  91              echo '<p>' . __( 'Plugin failed to reactivate due to a fatal error.' ) . '</p>';
  92  
  93              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 );
  94              ini_set( 'display_errors', true ); //Ensure that Fatal errors are displayed.
  95              wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $plugin );
  96              include( WP_PLUGIN_DIR . '/' . $plugin );
  97          }
  98          iframe_footer();
  99      } elseif ( 'install-plugin' == $action ) {
 100  
 101          if ( ! current_user_can( 'install_plugins' ) ) {
 102              wp_die( __( 'Sorry, you are not allowed to install plugins on this site.' ) );
 103          }
 104  
 105          include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); //for plugins_api..
 106  
 107          check_admin_referer( 'install-plugin_' . $plugin );
 108          $api = plugins_api(
 109              'plugin_information',
 110              array(
 111                  'slug'   => $plugin,
 112                  'fields' => array(
 113                      'sections' => false,
 114                  ),
 115              )
 116          );
 117  
 118          if ( is_wp_error( $api ) ) {
 119              wp_die( $api );
 120          }
 121  
 122          $title        = __( 'Plugin Installation' );
 123          $parent_file  = 'plugins.php';
 124          $submenu_file = 'plugin-install.php';
 125          require_once( ABSPATH . 'wp-admin/admin-header.php' );
 126  
 127          /* translators: %s: Plugin name and version. */
 128          $title = sprintf( __( 'Installing Plugin: %s' ), $api->name . ' ' . $api->version );
 129          $nonce = 'install-plugin_' . $plugin;
 130          $url   = 'update.php?action=install-plugin&plugin=' . urlencode( $plugin );
 131          if ( isset( $_GET['from'] ) ) {
 132              $url .= '&from=' . urlencode( stripslashes( $_GET['from'] ) );
 133          }
 134  
 135          $type = 'web'; //Install plugin type, From Web or an Upload.
 136  
 137          $upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact( 'title', 'url', 'nonce', 'plugin', 'api' ) ) );
 138          $upgrader->install( $api->download_link );
 139  
 140          include( ABSPATH . 'wp-admin/admin-footer.php' );
 141  
 142      } elseif ( 'upload-plugin' == $action ) {
 143  
 144          if ( ! current_user_can( 'upload_plugins' ) ) {
 145              wp_die( __( 'Sorry, you are not allowed to install plugins on this site.' ) );
 146          }
 147  
 148          check_admin_referer( 'plugin-upload' );
 149  
 150          $file_upload = new File_Upload_Upgrader( 'pluginzip', 'package' );
 151  
 152          $title        = __( 'Upload Plugin' );
 153          $parent_file  = 'plugins.php';
 154          $submenu_file = 'plugin-install.php';
 155          require_once( ABSPATH . 'wp-admin/admin-header.php' );
 156  
 157          /* translators: %s: File name. */
 158          $title = sprintf( __( 'Installing Plugin from uploaded file: %s' ), esc_html( basename( $file_upload->filename ) ) );
 159          $nonce = 'plugin-upload';
 160          $url   = add_query_arg( array( 'package' => $file_upload->id ), 'update.php?action=upload-plugin' );
 161          $type  = 'upload'; //Install plugin type, From Web or an Upload.
 162  
 163          $upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact( 'type', 'title', 'nonce', 'url' ) ) );
 164          $result   = $upgrader->install( $file_upload->package );
 165  
 166          if ( $result || is_wp_error( $result ) ) {
 167              $file_upload->cleanup();
 168          }
 169  
 170          include( ABSPATH . 'wp-admin/admin-footer.php' );
 171  
 172      } elseif ( 'upgrade-theme' == $action ) {
 173  
 174          if ( ! current_user_can( 'update_themes' ) ) {
 175              wp_die( __( 'Sorry, you are not allowed to update themes for this site.' ) );
 176          }
 177  
 178          check_admin_referer( 'upgrade-theme_' . $theme );
 179  
 180          wp_enqueue_script( 'updates' );
 181  
 182          $title        = __( 'Update Theme' );
 183          $parent_file  = 'themes.php';
 184          $submenu_file = 'themes.php';
 185          require_once( ABSPATH . 'wp-admin/admin-header.php' );
 186  
 187          $nonce = 'upgrade-theme_' . $theme;
 188          $url   = 'update.php?action=upgrade-theme&theme=' . urlencode( $theme );
 189  
 190          $upgrader = new Theme_Upgrader( new Theme_Upgrader_Skin( compact( 'title', 'nonce', 'url', 'theme' ) ) );
 191          $upgrader->upgrade( $theme );
 192  
 193          include( ABSPATH . 'wp-admin/admin-footer.php' );
 194      } elseif ( 'update-selected-themes' == $action ) {
 195          if ( ! current_user_can( 'update_themes' ) ) {
 196              wp_die( __( 'Sorry, you are not allowed to update themes for this site.' ) );
 197          }
 198  
 199          check_admin_referer( 'bulk-update-themes' );
 200  
 201          if ( isset( $_GET['themes'] ) ) {
 202              $themes = explode( ',', stripslashes( $_GET['themes'] ) );
 203          } elseif ( isset( $_POST['checked'] ) ) {
 204              $themes = (array) $_POST['checked'];
 205          } else {
 206              $themes = array();
 207          }
 208  
 209          $themes = array_map( 'urldecode', $themes );
 210  
 211          $url   = 'update.php?action=update-selected-themes&amp;themes=' . urlencode( implode( ',', $themes ) );
 212          $nonce = 'bulk-update-themes';
 213  
 214          wp_enqueue_script( 'updates' );
 215          iframe_header();
 216  
 217          $upgrader = new Theme_Upgrader( new Bulk_Theme_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
 218          $upgrader->bulk_upgrade( $themes );
 219  
 220          iframe_footer();
 221      } elseif ( 'install-theme' == $action ) {
 222  
 223          if ( ! current_user_can( 'install_themes' ) ) {
 224              wp_die( __( 'Sorry, you are not allowed to install themes on this site.' ) );
 225          }
 226  
 227          include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' ); //for themes_api..
 228  
 229          check_admin_referer( 'install-theme_' . $theme );
 230          $api = themes_api(
 231              'theme_information',
 232              array(
 233                  'slug'   => $theme,
 234                  'fields' => array(
 235                      'sections' => false,
 236                      'tags'     => false,
 237                  ),
 238              )
 239          ); //Save on a bit of bandwidth.
 240  
 241          if ( is_wp_error( $api ) ) {
 242              wp_die( $api );
 243          }
 244  
 245          $title        = __( 'Install Themes' );
 246          $parent_file  = 'themes.php';
 247          $submenu_file = 'themes.php';
 248          require_once( ABSPATH . 'wp-admin/admin-header.php' );
 249  
 250          /* translators: %s: Theme name and version. */
 251          $title = sprintf( __( 'Installing Theme: %s' ), $api->name . ' ' . $api->version );
 252          $nonce = 'install-theme_' . $theme;
 253          $url   = 'update.php?action=install-theme&theme=' . urlencode( $theme );
 254          $type  = 'web'; //Install theme type, From Web or an Upload.
 255  
 256          $upgrader = new Theme_Upgrader( new Theme_Installer_Skin( compact( 'title', 'url', 'nonce', 'plugin', 'api' ) ) );
 257          $upgrader->install( $api->download_link );
 258  
 259          include( ABSPATH . 'wp-admin/admin-footer.php' );
 260  
 261      } elseif ( 'upload-theme' == $action ) {
 262  
 263          if ( ! current_user_can( 'upload_themes' ) ) {
 264              wp_die( __( 'Sorry, you are not allowed to install themes on this site.' ) );
 265          }
 266  
 267          check_admin_referer( 'theme-upload' );
 268  
 269          $file_upload = new File_Upload_Upgrader( 'themezip', 'package' );
 270  
 271          $title        = __( 'Upload Theme' );
 272          $parent_file  = 'themes.php';
 273          $submenu_file = 'theme-install.php';
 274  
 275          require_once( ABSPATH . 'wp-admin/admin-header.php' );
 276  
 277          /* translators: %s: File name. */
 278          $title = sprintf( __( 'Installing Theme from uploaded file: %s' ), esc_html( basename( $file_upload->filename ) ) );
 279          $nonce = 'theme-upload';
 280          $url   = add_query_arg( array( 'package' => $file_upload->id ), 'update.php?action=upload-theme' );
 281          $type  = 'upload'; //Install plugin type, From Web or an Upload.
 282  
 283          $upgrader = new Theme_Upgrader( new Theme_Installer_Skin( compact( 'type', 'title', 'nonce', 'url' ) ) );
 284          $result   = $upgrader->install( $file_upload->package );
 285  
 286          if ( $result || is_wp_error( $result ) ) {
 287              $file_upload->cleanup();
 288          }
 289  
 290          include( ABSPATH . 'wp-admin/admin-footer.php' );
 291  
 292      } else {
 293          /**
 294           * Fires when a custom plugin or theme update request is received.
 295           *
 296           * The dynamic portion of the hook name, `$action`, refers to the action
 297           * provided in the request for wp-admin/update.php. Can be used to
 298           * provide custom update functionality for themes and plugins.
 299           *
 300           * @since 2.8.0
 301           */
 302          do_action( "update-custom_{$action}" ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
 303      }
 304  }


Generated: Wed Dec 11 01:00:03 2019 Cross-referenced by PHPXref 0.7.1