PageRenderTime 22ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/wp-admin/update.php

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