/wp-admin/update.php

https://github.com/alx/pressmark · PHP · 198 lines · 136 code · 55 blank · 7 comment · 24 complexity · c0b96fb41ed8a4c663831f1965317f13 MD5 · raw file

  1. <?php
  2. /**
  3. * Update/Install Plugin/Theme administration panel.
  4. *
  5. * @package WordPress
  6. * @subpackage Administration
  7. */
  8. /** WordPress Administration Bootstrap */
  9. require_once('admin.php');
  10. include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
  11. if ( isset($_GET['action']) ) {
  12. $plugin = isset($_REQUEST['plugin']) ? trim($_REQUEST['plugin']) : '';
  13. $theme = isset($_REQUEST['theme']) ? urldecode($_REQUEST['theme']) : '';
  14. $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
  15. if ( 'upgrade-plugin' == $action ) {
  16. if ( ! current_user_can('update_plugins') )
  17. wp_die(__('You do not have sufficient permissions to update plugins for this blog.'));
  18. check_admin_referer('upgrade-plugin_' . $plugin);
  19. $title = __('Upgrade Plugin');
  20. $parent_file = 'plugins.php';
  21. $submenu_file = 'plugins.php';
  22. require_once('admin-header.php');
  23. $nonce = 'upgrade-plugin_' . $plugin;
  24. $url = 'update.php?action=upgrade-plugin&plugin=' . $plugin;
  25. $upgrader = new Plugin_Upgrader( new Plugin_Upgrader_Skin( compact('title', 'nonce', 'url', 'plugin') ) );
  26. $upgrader->upgrade($plugin);
  27. include('admin-footer.php');
  28. } elseif ('activate-plugin' == $action ) {
  29. if ( ! current_user_can('update_plugins') )
  30. wp_die(__('You do not have sufficient permissions to update plugins for this blog.'));
  31. check_admin_referer('activate-plugin_' . $plugin);
  32. if( ! isset($_GET['failure']) && ! isset($_GET['success']) ) {
  33. wp_redirect( 'update.php?action=activate-plugin&failure=true&plugin=' . $plugin . '&_wpnonce=' . $_GET['_wpnonce'] );
  34. activate_plugin($plugin);
  35. wp_redirect( 'update.php?action=activate-plugin&success=true&plugin=' . $plugin . '&_wpnonce=' . $_GET['_wpnonce'] );
  36. die();
  37. }
  38. iframe_header( __('Plugin Reactivation'), true );
  39. if( isset($_GET['success']) )
  40. echo '<p>' . __('Plugin reactivated successfully.') . '</p>';
  41. if( isset($_GET['failure']) ){
  42. echo '<p>' . __('Plugin failed to reactivate due to a fatal error.') . '</p>';
  43. if ( defined('E_RECOVERABLE_ERROR') )
  44. error_reporting(E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING | E_RECOVERABLE_ERROR);
  45. else
  46. error_reporting(E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING);
  47. @ini_set('display_errors', true); //Ensure that Fatal errors are displayed.
  48. include(WP_PLUGIN_DIR . '/' . $plugin);
  49. }
  50. iframe_footer();
  51. } elseif ( 'install-plugin' == $action ) {
  52. if ( ! current_user_can('install_plugins') )
  53. wp_die(__('You do not have sufficient permissions to install plugins for this blog.'));
  54. include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; //for plugins_api..
  55. check_admin_referer('install-plugin_' . $plugin);
  56. $api = plugins_api('plugin_information', array('slug' => $plugin, 'fields' => array('sections' => false) ) ); //Save on a bit of bandwidth.
  57. if ( is_wp_error($api) )
  58. wp_die($api);
  59. $title = __('Plugin Install');
  60. $parent_file = 'plugins.php';
  61. $submenu_file = 'plugin-install.php';
  62. require_once('admin-header.php');
  63. $title = sprintf( __('Installing Plugin: %s'), $api->name . ' ' . $api->version );
  64. $nonce = 'install-plugin_' . $plugin;
  65. $url = 'update.php?action=install-plugin&plugin=' . $plugin;
  66. $type = 'web'; //Install plugin type, From Web or an Upload.
  67. $upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact('title', 'url', 'nonce', 'plugin', 'api') ) );
  68. $upgrader->install($api->download_link);
  69. include('admin-footer.php');
  70. } elseif ( 'upload-plugin' == $action ) {
  71. if ( ! current_user_can('install_plugins') )
  72. wp_die(__('You do not have sufficient permissions to install plugins for this blog.'));
  73. check_admin_referer('plugin-upload');
  74. $file_upload = new File_Upload_Upgrader('pluginzip', 'package');
  75. $title = __('Upload Plugin');
  76. $parent_file = 'plugins.php';
  77. $submenu_file = 'plugin-install.php';
  78. require_once('admin-header.php');
  79. $title = sprintf( __('Installing Plugin from uploaded file: %s'), basename( $file_upload->filename ) );
  80. $nonce = 'plugin-upload';
  81. $url = add_query_arg(array('package' => $file_upload->filename ), 'update.php?action=upload-plugin');
  82. $type = 'upload'; //Install plugin type, From Web or an Upload.
  83. $upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact('type', 'title', 'nonce', 'url') ) );
  84. $upgrader->install( $file_upload->package );
  85. include('admin-footer.php');
  86. } elseif ( 'upgrade-theme' == $action ) {
  87. if ( ! current_user_can('update_themes') )
  88. wp_die(__('You do not have sufficient permissions to update themes for this blog.'));
  89. check_admin_referer('upgrade-theme_' . $theme);
  90. add_thickbox();
  91. wp_enqueue_script('theme-preview');
  92. $title = __('Upgrade Theme');
  93. $parent_file = 'themes.php';
  94. $submenu_file = 'themes.php';
  95. require_once('admin-header.php');
  96. $nonce = 'upgrade-theme_' . $theme;
  97. $url = 'update.php?action=upgrade-theme&theme=' . $theme;
  98. $upgrader = new Theme_Upgrader( new Theme_Upgrader_Skin( compact('title', 'nonce', 'url', 'theme') ) );
  99. $upgrader->upgrade($theme);
  100. include('admin-footer.php');
  101. } elseif ( 'install-theme' == $action ) {
  102. if ( ! current_user_can('install_themes') )
  103. wp_die(__('You do not have sufficient permissions to install themes for this blog.'));
  104. include_once ABSPATH . 'wp-admin/includes/theme-install.php'; //for themes_api..
  105. check_admin_referer('install-theme_' . $theme);
  106. $api = themes_api('theme_information', array('slug' => $theme, 'fields' => array('sections' => false) ) ); //Save on a bit of bandwidth.
  107. if ( is_wp_error($api) )
  108. wp_die($api);
  109. add_thickbox();
  110. wp_enqueue_script('theme-preview');
  111. $title = __('Install Themes');
  112. $parent_file = 'themes.php';
  113. $submenu_file = 'theme-install.php';
  114. require_once('admin-header.php');
  115. $title = sprintf( __('Installing theme: %s'), $api->name . ' ' . $api->version );
  116. $nonce = 'install-theme_' . $theme;
  117. $url = 'update.php?action=install-theme&theme=' . $theme;
  118. $type = 'web'; //Install theme type, From Web or an Upload.
  119. $upgrader = new Theme_Upgrader( new Theme_Installer_Skin( compact('title', 'url', 'nonce', 'plugin', 'api') ) );
  120. $upgrader->install($api->download_link);
  121. include('admin-footer.php');
  122. } elseif ( 'upload-theme' == $action ) {
  123. if ( ! current_user_can('install_themes') )
  124. wp_die(__('You do not have sufficient permissions to install themes for this blog.'));
  125. check_admin_referer('theme-upload');
  126. $file_upload = new File_Upload_Upgrader('themezip', 'package');
  127. $title = __('Upload Theme');
  128. $parent_file = 'themes.php';
  129. $submenu_file = 'theme-install.php';
  130. add_thickbox();
  131. wp_enqueue_script('theme-preview');
  132. require_once('admin-header.php');
  133. $title = sprintf( __('Installing Theme from uploaded file: %s'), basename( $file_upload->filename ) );
  134. $nonce = 'theme-upload';
  135. $url = add_query_arg(array('package' => $file_upload->filename), 'update.php?action=upload-theme');
  136. $type = 'upload'; //Install plugin type, From Web or an Upload.
  137. $upgrader = new Theme_Upgrader( new Theme_Installer_Skin( compact('type', 'title', 'nonce', 'url') ) );
  138. $upgrader->install( $file_upload->package );
  139. include('admin-footer.php');
  140. } else {
  141. do_action('update-custom_' . $action);
  142. }
  143. }