PageRenderTime 23ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-admin/update.php

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