PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-admin/update.php

http://cartonbank.googlecode.com/
PHP | 253 lines | 176 code | 70 blank | 7 comment | 31 complexity | 7138f26c3435c6992334879be262610d MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0, LGPL-2.1, AGPL-1.0, LGPL-3.0
  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 ( 'update-selected' == $action ) {
  16. if ( ! current_user_can( 'update_plugins' ) )
  17. wp_die( __( 'You do not have sufficient permissions to update plugins for this site.' ) );
  18. check_admin_referer( 'bulk-update-plugins' );
  19. if ( isset( $_GET['plugins'] ) )
  20. $plugins = explode( ',', stripslashes($_GET['plugins']) );
  21. elseif ( isset( $_POST['checked'] ) )
  22. $plugins = (array) $_POST['checked'];
  23. else
  24. $plugins = array();
  25. $plugins = array_map('urldecode', $plugins);
  26. $url = 'update.php?action=update-selected&amp;plugins=' . urlencode(implode(',', $plugins));
  27. $nonce = 'bulk-update-plugins';
  28. require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
  29. wp_enqueue_script('jquery');
  30. iframe_header();
  31. $upgrader = new Plugin_Upgrader( new Bulk_Plugin_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
  32. $upgrader->bulk_upgrade( $plugins );
  33. iframe_footer();
  34. } elseif ( 'upgrade-plugin' == $action ) {
  35. if ( ! current_user_can('update_plugins') )
  36. wp_die(__('You do not have sufficient permissions to update plugins for this site.'));
  37. check_admin_referer('upgrade-plugin_' . $plugin);
  38. $title = __('Upgrade Plugin');
  39. $parent_file = 'plugins.php';
  40. $submenu_file = 'plugins.php';
  41. require_once('./admin-header.php');
  42. $nonce = 'upgrade-plugin_' . $plugin;
  43. $url = 'update.php?action=upgrade-plugin&plugin=' . $plugin;
  44. $upgrader = new Plugin_Upgrader( new Plugin_Upgrader_Skin( compact('title', 'nonce', 'url', 'plugin') ) );
  45. $upgrader->upgrade($plugin);
  46. include('./admin-footer.php');
  47. } elseif ('activate-plugin' == $action ) {
  48. if ( ! current_user_can('update_plugins') )
  49. wp_die(__('You do not have sufficient permissions to update plugins for this site.'));
  50. check_admin_referer('activate-plugin_' . $plugin);
  51. if ( ! isset($_GET['failure']) && ! isset($_GET['success']) ) {
  52. wp_redirect( 'update.php?action=activate-plugin&failure=true&plugin=' . $plugin . '&_wpnonce=' . $_GET['_wpnonce'] );
  53. activate_plugin( $plugin, '', ! empty( $_GET['networkwide'] ) );
  54. wp_redirect( 'update.php?action=activate-plugin&success=true&plugin=' . $plugin . '&_wpnonce=' . $_GET['_wpnonce'] );
  55. die();
  56. }
  57. iframe_header( __('Plugin Reactivation'), true );
  58. if ( isset($_GET['success']) )
  59. echo '<p>' . __('Plugin reactivated successfully.') . '</p>';
  60. if ( isset($_GET['failure']) ){
  61. echo '<p>' . __('Plugin failed to reactivate due to a fatal error.') . '</p>';
  62. if ( defined('E_RECOVERABLE_ERROR') )
  63. 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);
  64. else
  65. error_reporting(E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING);
  66. @ini_set('display_errors', true); //Ensure that Fatal errors are displayed.
  67. include(WP_PLUGIN_DIR . '/' . $plugin);
  68. }
  69. iframe_footer();
  70. } elseif ( 'install-plugin' == $action ) {
  71. if ( ! current_user_can('install_plugins') )
  72. wp_die(__('You do not have sufficient permissions to install plugins for this site.'));
  73. include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; //for plugins_api..
  74. check_admin_referer('install-plugin_' . $plugin);
  75. $api = plugins_api('plugin_information', array('slug' => $plugin, 'fields' => array('sections' => false) ) ); //Save on a bit of bandwidth.
  76. if ( is_wp_error($api) )
  77. wp_die($api);
  78. $title = __('Plugin Install');
  79. $parent_file = 'plugins.php';
  80. $submenu_file = 'plugin-install.php';
  81. require_once('./admin-header.php');
  82. $title = sprintf( __('Installing Plugin: %s'), $api->name . ' ' . $api->version );
  83. $nonce = 'install-plugin_' . $plugin;
  84. $url = 'update.php?action=install-plugin&plugin=' . $plugin;
  85. if ( isset($_GET['from']) )
  86. $url .= '&from=' . urlencode(stripslashes($_GET['from']));
  87. $type = 'web'; //Install plugin type, From Web or an Upload.
  88. $upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact('title', 'url', 'nonce', 'plugin', 'api') ) );
  89. $upgrader->install($api->download_link);
  90. include('./admin-footer.php');
  91. } elseif ( 'upload-plugin' == $action ) {
  92. if ( ! current_user_can('install_plugins') )
  93. wp_die(__('You do not have sufficient permissions to install plugins for this site.'));
  94. check_admin_referer('plugin-upload');
  95. $file_upload = new File_Upload_Upgrader('pluginzip', 'package');
  96. $title = __('Upload Plugin');
  97. $parent_file = 'plugins.php';
  98. $submenu_file = 'plugin-install.php';
  99. require_once('./admin-header.php');
  100. $title = sprintf( __('Installing Plugin from uploaded file: %s'), basename( $file_upload->filename ) );
  101. $nonce = 'plugin-upload';
  102. $url = add_query_arg(array('package' => $file_upload->filename ), 'update.php?action=upload-plugin');
  103. $type = 'upload'; //Install plugin type, From Web or an Upload.
  104. $upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact('type', 'title', 'nonce', 'url') ) );
  105. $upgrader->install( $file_upload->package );
  106. include('./admin-footer.php');
  107. } elseif ( 'upgrade-theme' == $action ) {
  108. if ( ! current_user_can('update_themes') )
  109. wp_die(__('You do not have sufficient permissions to update themes for this site.'));
  110. check_admin_referer('upgrade-theme_' . $theme);
  111. add_thickbox();
  112. wp_enqueue_script('theme-preview');
  113. $title = __('Upgrade Theme');
  114. $parent_file = 'themes.php';
  115. $submenu_file = 'themes.php';
  116. require_once('./admin-header.php');
  117. $nonce = 'upgrade-theme_' . $theme;
  118. $url = 'update.php?action=upgrade-theme&theme=' . $theme;
  119. $upgrader = new Theme_Upgrader( new Theme_Upgrader_Skin( compact('title', 'nonce', 'url', 'theme') ) );
  120. $upgrader->upgrade($theme);
  121. include('./admin-footer.php');
  122. } elseif ( 'update-selected-themes' == $action ) {
  123. if ( ! current_user_can( 'update_themes' ) )
  124. wp_die( __( 'You do not have sufficient permissions to update themes for this site.' ) );
  125. check_admin_referer( 'bulk-update-themes' );
  126. if ( isset( $_GET['themes'] ) )
  127. $themes = explode( ',', stripslashes($_GET['themes']) );
  128. elseif ( isset( $_POST['checked'] ) )
  129. $themes = (array) $_POST['checked'];
  130. else
  131. $themes = array();
  132. $themes = array_map('urldecode', $themes);
  133. $url = 'update.php?action=update-selected-themes&amp;themes=' . urlencode(implode(',', $themes));
  134. $nonce = 'bulk-update-themes';
  135. require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
  136. wp_enqueue_script('jquery');
  137. iframe_header();
  138. $upgrader = new Theme_Upgrader( new Bulk_Theme_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
  139. $upgrader->bulk_upgrade( $themes );
  140. iframe_footer();
  141. } elseif ( 'install-theme' == $action ) {
  142. if ( ! current_user_can('install_themes') )
  143. wp_die(__('You do not have sufficient permissions to install themes for this site.'));
  144. include_once ABSPATH . 'wp-admin/includes/theme-install.php'; //for themes_api..
  145. check_admin_referer('install-theme_' . $theme);
  146. $api = themes_api('theme_information', array('slug' => $theme, 'fields' => array('sections' => false) ) ); //Save on a bit of bandwidth.
  147. if ( is_wp_error($api) )
  148. wp_die($api);
  149. add_thickbox();
  150. wp_enqueue_script('theme-preview');
  151. $title = __('Install Themes');
  152. $parent_file = 'themes.php';
  153. $submenu_file = 'themes.php';
  154. require_once('./admin-header.php');
  155. $title = sprintf( __('Installing Theme: %s'), $api->name . ' ' . $api->version );
  156. $nonce = 'install-theme_' . $theme;
  157. $url = 'update.php?action=install-theme&theme=' . $theme;
  158. $type = 'web'; //Install theme type, From Web or an Upload.
  159. $upgrader = new Theme_Upgrader( new Theme_Installer_Skin( compact('title', 'url', 'nonce', 'plugin', 'api') ) );
  160. $upgrader->install($api->download_link);
  161. include('./admin-footer.php');
  162. } elseif ( 'upload-theme' == $action ) {
  163. if ( ! current_user_can('install_themes') )
  164. wp_die(__('You do not have sufficient permissions to install themes for this site.'));
  165. check_admin_referer('theme-upload');
  166. $file_upload = new File_Upload_Upgrader('themezip', 'package');
  167. $title = __('Upload Theme');
  168. $parent_file = 'themes.php';
  169. $submenu_file = 'theme-install.php';
  170. add_thickbox();
  171. wp_enqueue_script('theme-preview');
  172. require_once('./admin-header.php');
  173. $title = sprintf( __('Installing Theme from uploaded file: %s'), basename( $file_upload->filename ) );
  174. $nonce = 'theme-upload';
  175. $url = add_query_arg(array('package' => $file_upload->filename), 'update.php?action=upload-theme');
  176. $type = 'upload'; //Install plugin type, From Web or an Upload.
  177. $upgrader = new Theme_Upgrader( new Theme_Installer_Skin( compact('type', 'title', 'nonce', 'url') ) );
  178. $upgrader->install( $file_upload->package );
  179. include('./admin-footer.php');
  180. } else {
  181. do_action('update-custom_' . $action);
  182. }
  183. }