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