Projects : mp-wp : mp-wp_genesis
1 | <?php |
2 | /** |
3 | * Plugins administration panel. |
4 | * |
5 | * @package WordPress |
6 | * @subpackage Administration |
7 | */ |
8 | |
9 | /** WordPress Administration Bootstrap */ |
10 | require_once('admin.php'); |
11 | |
12 | $action = ''; |
13 | foreach( array('activate-selected', 'deactivate-selected', 'delete-selected', 'clear-recent-list') as $action_key ) { |
14 | if( isset($_POST[$action_key]) ) { |
15 | $action = $action_key; |
16 | break; |
17 | } |
18 | } |
19 | |
20 | if( isset($_REQUEST['action']) && !empty($_REQUEST['action']) ) |
21 | $action = $_REQUEST['action']; |
22 | |
23 | $plugin = isset($_REQUEST['plugin']) ? $_REQUEST['plugin'] : ''; |
24 | |
25 | if( !empty($action) ) { |
26 | switch( $action ) { |
27 | case 'activate': |
28 | check_admin_referer('activate-plugin_' . $plugin); |
29 | $result = activate_plugin($plugin, 'plugins.php?error=true&plugin=' . $plugin); |
30 | if ( is_wp_error( $result ) ) |
31 | wp_die($result); |
32 | $recent = (array)get_option('recently_activated'); |
33 | if ( isset($recent[ $plugin ]) ) { |
34 | unset($recent[ $plugin ]); |
35 | update_option('recently_activated', $recent); |
36 | } |
37 | wp_redirect('plugins.php?activate=true'); // overrides the ?error=true one above |
38 | exit; |
39 | break; |
40 | case 'activate-selected': |
41 | check_admin_referer('bulk-manage-plugins'); |
42 | activate_plugins($_POST['checked'], 'plugins.php?error=true'); |
43 | |
44 | $recent = (array)get_option('recently_activated'); |
45 | foreach( (array)$_POST['checked'] as $plugin => $time) { |
46 | if ( isset($recent[ $plugin ]) ) |
47 | unset($recent[ $plugin ]); |
48 | } |
49 | if( $recent != get_option('recently_activated') ) //If array changed, update it. |
50 | update_option('recently_activated', $recent); |
51 | |
52 | wp_redirect('plugins.php?activate-multi=true'); |
53 | exit; |
54 | break; |
55 | case 'error_scrape': |
56 | check_admin_referer('plugin-activation-error_' . $plugin); |
57 | $valid = validate_plugin($plugin); |
58 | if ( is_wp_error($valid) ) |
59 | wp_die($valid); |
60 | error_reporting( E_ALL ^ E_NOTICE ); |
61 | @ini_set('display_errors', true); //Ensure that Fatal errors are displayed. |
62 | include(WP_PLUGIN_DIR . '/' . $plugin); |
63 | do_action('activate_' . $plugin); |
64 | exit; |
65 | break; |
66 | case 'deactivate': |
67 | check_admin_referer('deactivate-plugin_' . $plugin); |
68 | deactivate_plugins($plugin); |
69 | update_option('recently_activated', array($plugin => time()) + (array)get_option('recently_activated')); |
70 | wp_redirect('plugins.php?deactivate=true'); |
71 | exit; |
72 | break; |
73 | case 'deactivate-selected': |
74 | check_admin_referer('bulk-manage-plugins'); |
75 | deactivate_plugins($_POST['checked']); |
76 | $deactivated = array(); |
77 | foreach ( (array)$_POST['checked'] as $plugin ) |
78 | $deactivated[ $plugin ] = time(); |
79 | update_option('recently_activated', $deactivated + (array)get_option('recently_activated')); |
80 | wp_redirect('plugins.php?deactivate-multi=true'); |
81 | exit; |
82 | break; |
83 | case 'delete-selected': |
84 | if ( ! current_user_can('delete_plugins') ) |
85 | wp_die(__('You do not have sufficient permissions to delete plugins for this blog.')); |
86 | |
87 | check_admin_referer('bulk-manage-plugins'); |
88 | |
89 | $plugins = $_REQUEST['checked']; //$_POST = from the plugin form; $_GET = from the FTP details screen. |
90 | include(ABSPATH . 'wp-admin/update.php'); |
91 | |
92 | $title = __('Delete Plugin'); |
93 | $parent_file = 'plugins.php'; |
94 | |
95 | if ( ! isset($_REQUEST['verify-delete']) ) { |
96 | wp_enqueue_script('jquery'); |
97 | require_once('admin-header.php'); |
98 | ?> |
99 | <div class="wrap"> |
100 | <h2><?php _e('Delete Plugin(s)'); ?></h2> |
101 | <?php |
102 | $files_to_delete = $plugin_info = array(); |
103 | foreach ( (array) $plugins as $plugin ) { |
104 | if ( '.' == dirname($plugin) ) { |
105 | $files_to_delete[] = WP_PLUGIN_DIR . '/' . $plugin; |
106 | if( $data = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin) ) |
107 | $plugin_info[ $plugin ] = $data; |
108 | } else { |
109 | //Locate all the files in that folder: |
110 | $files = list_files( WP_PLUGIN_DIR . '/' . dirname($plugin) ); |
111 | if( $files ) { |
112 | $files_to_delete = array_merge($files_to_delete, $files); |
113 | } |
114 | //Get plugins list from that folder |
115 | if ( $folder_plugins = get_plugins( '/' . dirname($plugin)) ) |
116 | $plugin_info = array_merge($plugin_info, $folder_plugins); |
117 | } |
118 | } |
119 | ?> |
120 | <p><?php _e('Deleting the selected plugins will remove the following plugin(s) and their files:'); ?></p> |
121 | <ul> |
122 | <?php |
123 | foreach ( $plugin_info as $plugin ) |
124 | echo '<li>', sprintf(__('%s by %s'), $plugin['Name'], $plugin['Author']), '</li>'; |
125 | ?> |
126 | </ul> |
127 | <p><?php _e('Are you sure you wish to delete these files?') ?></p> |
128 | <form method="post" action="<?php echo clean_url($_SERVER['REQUEST_URI']); ?>" style="display:inline;"> |
129 | <input type="hidden" name="verify-delete" value="1" /> |
130 | <input type="hidden" name="delete-selected" value="1" /> |
131 | <?php |
132 | foreach ( (array)$plugins as $plugin ) |
133 | echo '<input type="hidden" name="checked[]" value="' . attribute_escape($plugin) . '" />'; |
134 | ?> |
135 | <?php wp_nonce_field('bulk-manage-plugins') ?> |
136 | <input type="submit" name="submit" value="<?php _e('Yes, Delete these files') ?>" class="button" /> |
137 | </form> |
138 | <form method="post" action="<?php echo clean_url(wp_get_referer()); ?>" style="display:inline;"> |
139 | <input type="submit" name="submit" value="<?php _e('No, Return me to the plugin list') ?>" class="button" /> |
140 | </form> |
141 | |
142 | <p><a href="#" onclick="jQuery('#files-list').toggle(); return false;"><?php _e('Click to view entire list of files which will be deleted'); ?></a></p> |
143 | <div id="files-list" style="display:none;"> |
144 | <ul> |
145 | <?php |
146 | foreach ( (array)$files_to_delete as $file ) |
147 | echo '<li>' . str_replace(WP_PLUGIN_DIR, '', $file) . '</li>'; |
148 | ?> |
149 | </ul> |
150 | </div> |
151 | </div> |
152 | <?php |
153 | require_once('admin-footer.php'); |
154 | exit; |
155 | } //Endif verify-delete |
156 | $delete_result = delete_plugins($plugins); |
157 | |
158 | wp_cache_delete('plugins', 'plugins'); |
159 | break; |
160 | case 'clear-recent-list': |
161 | update_option('recently_activated', array()); |
162 | break; |
163 | } |
164 | } |
165 | |
166 | wp_enqueue_script('plugin-install'); |
167 | add_thickbox(); |
168 | |
169 | $title = __('Manage Plugins'); |
170 | require_once('admin-header.php'); |
171 | |
172 | $invalid = validate_active_plugins(); |
173 | if ( !empty($invalid) ) |
174 | foreach ( $invalid as $plugin_file => $error ) |
175 | echo '<div id="message" class="error"><p>' . sprintf(__('The plugin <code>%s</code> has been <strong>deactivated</strong> due to an error: %s'), wp_specialchars($plugin_file), $error->get_error_message()) . '</p></div>'; |
176 | ?> |
177 | |
178 | <?php if ( isset($_GET['error']) ) : ?> |
179 | <div id="message" class="updated fade"><p><?php _e('Plugin could not be activated because it triggered a <strong>fatal error</strong>.') ?></p> |
180 | <?php |
181 | if ( wp_verify_nonce($_GET['_error_nonce'], 'plugin-activation-error_' . $plugin) ) { ?> |
182 | <iframe style="border:0" width="100%" height="70px" src="<?php echo admin_url('plugins.php?action=error_scrape&plugin=' . attribute_escape($plugin) . '&_wpnonce=' . attribute_escape($_GET['_error_nonce'])); ?>"></iframe> |
183 | <?php |
184 | } |
185 | ?> |
186 | </div> |
187 | <?php elseif ( 'delete-selected' == $action ) : |
188 | if ( is_wp_error($delete_result) ) : ?> |
189 | <div id="message" class="updated fade"><p><?php printf( __('Plugin could not be deleted due to an error: %s'), $delete_result->get_error_message() ); ?></p></div> |
190 | <?php else : ?> |
191 | <div id="message" class="updated fade"><p><?php _e('The selected plugins have been <strong>deleted</strong>.'); ?></p></div> |
192 | <?php endif; ?> |
193 | <?php elseif ( isset($_GET['activate']) ) : ?> |
194 | <div id="message" class="updated fade"><p><?php _e('Plugin <strong>activated</strong>.') ?></p></div> |
195 | <?php elseif (isset($_GET['activate-multi'])) : ?> |
196 | <div id="message" class="updated fade"><p><?php _e('Selected plugins <strong>activated</strong>.'); ?></p></div> |
197 | <?php elseif ( isset($_GET['deactivate']) ) : ?> |
198 | <div id="message" class="updated fade"><p><?php _e('Plugin <strong>deactivated</strong>.') ?></p></div> |
199 | <?php elseif (isset($_GET['deactivate-multi'])) : ?> |
200 | <div id="message" class="updated fade"><p><?php _e('Selected plugins <strong>deactivated</strong>.'); ?></p></div> |
201 | <?php endif; ?> |
202 | |
203 | <div class="wrap"> |
204 | <?php screen_icon(); ?> |
205 | <h2><?php echo wp_specialchars( $title ); ?></h2> |
206 | |
207 | <p><?php _e('Plugins extend and expand the functionality of WordPress. Once a plugin is installed, you may activate it or deactivate it here.'); ?></p> |
208 | <?php |
209 | |
210 | $all_plugins = get_plugins(); |
211 | $active_plugins = array(); |
212 | $inactive_plugins = array(); |
213 | $recent_plugins = array(); |
214 | $recently_activated = (array) get_option('recently_activated'); |
215 | |
216 | //Clean out any plugins which were deactivated over a week ago. |
217 | foreach ( $recently_activated as $key => $time ) |
218 | if ( $time + (7*24*60*60) < time() ) //1 week |
219 | unset($recently_activated[ $key ]); |
220 | if ( $recently_activated != get_option('recently_activated') ) //If array changed, update it. |
221 | update_option('recently_activated', $recently_activated); |
222 | |
223 | foreach ( (array)$all_plugins as $plugin_file => $plugin_data) { |
224 | |
225 | //Translate, Apply Markup, Sanitize HTML |
226 | $plugin_data = _get_plugin_data_markup_translate($plugin_data, true, true); |
227 | |
228 | //Filter into individual sections |
229 | if ( is_plugin_active($plugin_file) ) { |
230 | $active_plugins[ $plugin_file ] = $plugin_data; |
231 | } else { |
232 | if ( isset( $recently_activated[ $plugin_file ] ) ) //Was the plugin recently activated? |
233 | $recent_plugins[ $plugin_file ] = $plugin_data; |
234 | else |
235 | $inactive_plugins[ $plugin_file ] = $plugin_data; |
236 | } |
237 | } |
238 | |
239 | ?> |
240 | |
241 | <?php |
242 | /** |
243 | * @ignore |
244 | * |
245 | * @param array $plugins |
246 | * @param string $context |
247 | */ |
248 | function print_plugins_table($plugins, $context = '') { |
249 | ?> |
250 | <table class="widefat" cellspacing="0" id="<?php echo $context ?>-plugins-table"> |
251 | <thead> |
252 | <tr> |
253 | <th scope="col" class="check-column"><input type="checkbox" /></th> |
254 | <th scope="col"><?php _e('Plugin'); ?></th> |
255 | <th scope="col" class="num"><?php _e('Version'); ?></th> |
256 | <th scope="col"><?php _e('Description'); ?></th> |
257 | <th scope="col" class="action-links"><?php _e('Action'); ?></th> |
258 | </tr> |
259 | </thead> |
260 | |
261 | <tfoot> |
262 | <tr> |
263 | <th scope="col" class="check-column"><input type="checkbox" /></th> |
264 | <th scope="col"><?php _e('Plugin'); ?></th> |
265 | <th scope="col" class="num"><?php _e('Version'); ?></th> |
266 | <th scope="col"><?php _e('Description'); ?></th> |
267 | <th scope="col" class="action-links"><?php _e('Action'); ?></th> |
268 | </tr> |
269 | </tfoot> |
270 | |
271 | <tbody class="plugins"> |
272 | <?php |
273 | |
274 | if ( empty($plugins) ) { |
275 | echo '<tr> |
276 | <td colspan="6">' . __('No plugins to show') . '</td> |
277 | </tr>'; |
278 | } |
279 | foreach ( (array)$plugins as $plugin_file => $plugin_data) { |
280 | $action_links = array(); |
281 | |
282 | if ( 'active' == $context ) |
283 | $action_links[] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&plugin=' . $plugin_file, 'deactivate-plugin_' . $plugin_file) . '" title="' . __('Deactivate this plugin') . '">' . __('Deactivate') . '</a>'; |
284 | else //Inactive or Recently deactivated |
285 | $action_links[] = '<a href="' . wp_nonce_url('plugins.php?action=activate&plugin=' . $plugin_file, 'activate-plugin_' . $plugin_file) . '" title="' . __('Activate this plugin') . '" class="edit">' . __('Activate') . '</a>'; |
286 | |
287 | if ( current_user_can('edit_plugins') && is_writable(WP_PLUGIN_DIR . '/' . $plugin_file) ) |
288 | $action_links[] = '<a href="plugin-editor.php?file=' . $plugin_file . '" title="' . __('Open this file in the Plugin Editor') . '" class="edit">' . __('Edit') . '</a>'; |
289 | |
290 | $action_links = apply_filters( 'plugin_action_links', $action_links, $plugin_file, $plugin_data, $context ); |
291 | $action_links = apply_filters( "plugin_action_links_$plugin_file", $action_links, $plugin_file, $plugin_data, $context ); |
292 | |
293 | echo " |
294 | <tr class='$context'> |
295 | <th scope='row' class='check-column'><input type='checkbox' name='checked[]' value='" . attribute_escape($plugin_file) . "' /></th> |
296 | <td class='name'>{$plugin_data['Title']}</td> |
297 | <td class='vers'>{$plugin_data['Version']}</td> |
298 | <td class='desc'><p>{$plugin_data['Description']}</p></td> |
299 | <td class='togl action-links'>"; |
300 | if ( !empty($action_links) ) |
301 | echo implode(' | ', $action_links); |
302 | echo '</td> |
303 | </tr>'; |
304 | do_action( 'after_plugin_row', $plugin_file, $plugin_data, $context ); |
305 | do_action( "after_plugin_row_$plugin_file", $plugin_file, $plugin_data, $context ); |
306 | } |
307 | ?> |
308 | </tbody> |
309 | </table> |
310 | <?php |
311 | } //End print_plugins_table() |
312 | |
313 | /** |
314 | * @ignore |
315 | * |
316 | * @param string $context |
317 | */ |
318 | function print_plugin_actions($context) { |
319 | ?> |
320 | <div class="alignleft actions"> |
321 | <select name="action"> |
322 | <option value="" selected="selected"><?php _e('Bulk Actions'); ?></option> |
323 | <?php if( 'active' != $context ) : ?> |
324 | <option value="activate-selected"><?php _e('Activate'); ?></option> |
325 | <?php endif; ?> |
326 | <?php if ( 'active' == $context ) : ?> |
327 | <option value="deactivate-selected"><?php _e('Deactivate'); ?></option> |
328 | <?php endif; ?> |
329 | <?php if( current_user_can('delete_plugins') && ( 'recent' == $context || 'inactive' == $context ) ) : ?> |
330 | <option value="delete-selected"><?php _e('Delete'); ?></option> |
331 | <?php endif; ?> |
332 | </select> |
333 | <input type="submit" name="doaction_active" value="<?php _e('Apply'); ?>" class="button-secondary action" /> |
334 | <?php if( 'recent' == $context ) : ?> |
335 | <input type="submit" name="clear-recent-list" value="<?php _e('Clear List') ?>" class="button-secondary" /> |
336 | <?php endif; ?> |
337 | </div> |
338 | <?php |
339 | } |
340 | ?> |
341 | |
342 | <?php if ( ! empty($active_plugins) ) : ?> |
343 | <h3 id="currently-active"><?php _e('Currently Active Plugins') ?></h3> |
344 | <form method="post" action="<?php echo admin_url('plugins.php') ?>"> |
345 | <?php wp_nonce_field('bulk-manage-plugins') ?> |
346 | |
347 | <div class="tablenav"> |
348 | <?php print_plugin_actions('active') ?> |
349 | </div> |
350 | <div class="clear"></div> |
351 | <?php print_plugins_table($active_plugins, 'active') ?> |
352 | </form> |
353 | |
354 | <p><?php printf(__('If something goes wrong with a plugin and you can’t use WordPress, delete or rename that file in the <code>%s</code> directory and it will be automatically deactivated.'), WP_PLUGIN_DIR); ?></p> |
355 | <?php endif; ?> |
356 | |
357 | <?php if ( ! empty($recent_plugins) ) : ?> |
358 | <h3 id="recent-plugins"><?php _e('Recently Active Plugins') ?></h3> |
359 | <p><?php _e('The following plugins were recently active. When a plugin has been inactive for more than 7 days it will be moved to the Inactive plugin list.') ?></p> |
360 | <form method="post" action="<?php echo admin_url('plugins.php') ?>"> |
361 | <?php wp_nonce_field('bulk-manage-plugins') ?> |
362 | |
363 | <div class="tablenav"> |
364 | <?php print_plugin_actions('recent') ?> |
365 | </div> |
366 | <div class="clear"></div> |
367 | <?php print_plugins_table($recent_plugins, 'recent') ?> |
368 | </form> |
369 | <?php endif; ?> |
370 | |
371 | <?php if ( ! empty($inactive_plugins) ) : ?> |
372 | <h3 id="inactive-plugins"><?php _e('Inactive Plugins') ?></h3> |
373 | <form method="post" action="<?php echo admin_url('plugins.php') ?>"> |
374 | <?php wp_nonce_field('bulk-manage-plugins') ?> |
375 | |
376 | <div class="tablenav"> |
377 | <?php print_plugin_actions('inactive') ?> |
378 | </div> |
379 | <div class="clear"></div> |
380 | <?php print_plugins_table($inactive_plugins, 'inactive') ?> |
381 | </form> |
382 | <?php endif; ?> |
383 | |
384 | <?php if ( empty($all_plugins) ) : ?> |
385 | <p><?php _e('You do not appear to have any plugins available at this time.') ?></p> |
386 | <?php endif; ?> |
387 | |
388 | <h2><?php _e('Get More Plugins'); ?></h2> |
389 | <p><?php _e('You can find additional plugins for your site by using the new <a href="plugin-install.php">Plugin Browser/Installer</a> functionality, Or by browsing the <a href="http://wordpress.org/extend/plugins/">WordPress Plugin Directory</a> directly and installing manually.'); ?></p> |
390 | <p><?php printf(__('To <em>manually</em> install a plugin you generally just need to upload the plugin file into your <code>%s</code> directory.'), WP_PLUGIN_DIR); ?></p> |
391 | <p><?php _e('Once a plugin has been installed, you may activate it here.'); ?></p> |
392 | |
393 | </div> |
394 | |
395 | <?php |
396 | include('admin-footer.php'); |
397 | ?> |