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