]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/plugins.php
Wordpress 3.0.3-scripts
[autoinstalls/wordpress.git] / wp-admin / plugins.php
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 if ( is_multisite() ) {
12         $menu_perms = get_site_option( 'menu_items', array() );
13
14         if ( empty($menu_perms['plugins']) && ! is_super_admin() )
15                 wp_die( __( 'Cheatin&#8217; uh?' ) );
16         else if ( $menu_perms['plugins'] != 1 && is_super_admin() )
17                 add_action( 'admin_notices', '_admin_notice_multisite_activate_plugins_page' );
18 }
19
20 if ( ! current_user_can( 'activate_plugins' ) )
21         wp_die( __( 'You do not have sufficient permissions to manage plugins for this site.' ) );
22
23 if ( isset($_POST['clear-recent-list']) )
24         $action = 'clear-recent-list';
25 elseif ( !empty($_REQUEST['action']) )
26         $action = $_REQUEST['action'];
27 elseif ( !empty($_REQUEST['action2']) )
28         $action = $_REQUEST['action2'];
29 else
30         $action = false;
31
32 $plugin = isset($_REQUEST['plugin']) ? $_REQUEST['plugin'] : '';
33
34 $default_status = get_user_option('plugins_last_view');
35 if ( empty($default_status) )
36         $default_status = 'all';
37 $status = isset($_REQUEST['plugin_status']) ? $_REQUEST['plugin_status'] : $default_status;
38 if ( !in_array($status, array('all', 'active', 'inactive', 'recent', 'upgrade', 'network', 'mustuse', 'dropins', 'search')) )
39         $status = 'all';
40 if ( $status != $default_status && 'search' != $status )
41         update_user_meta($current_user->ID, 'plugins_last_view', $status);
42
43 $page = isset($_REQUEST['paged']) ? $_REQUEST['paged'] : 1;
44
45 //Clean up request URI from temporary args for screen options/paging uri's to work as expected.
46 $_SERVER['REQUEST_URI'] = remove_query_arg(array('error', 'deleted', 'activate', 'activate-multi', 'deactivate', 'deactivate-multi', '_error_nonce'), $_SERVER['REQUEST_URI']);
47
48 if ( !empty($action) ) {
49         $network_wide = false;
50         if ( ( isset( $_GET['networkwide'] ) || 'network-activate-selected' == $action ) && is_multisite() && current_user_can( 'manage_network_plugins' ) )
51                 $network_wide = true;
52
53         switch ( $action ) {
54                 case 'activate':
55                         if ( ! current_user_can('activate_plugins') )
56                                 wp_die(__('You do not have sufficient permissions to activate plugins for this site.'));
57
58                         check_admin_referer('activate-plugin_' . $plugin);
59
60                         $result = activate_plugin($plugin, 'plugins.php?error=true&plugin=' . $plugin, $network_wide);
61                         if ( is_wp_error( $result ) ) {
62                                 if ( 'unexpected_output' == $result->get_error_code() ) {
63                                         $redirect = 'plugins.php?error=true&charsout=' . strlen($result->get_error_data()) . '&plugin=' . $plugin;
64                                         wp_redirect(add_query_arg('_error_nonce', wp_create_nonce('plugin-activation-error_' . $plugin), $redirect));
65                                         exit;
66                                 } else {
67                                         wp_die($result);
68                                 }
69                         }
70
71                         $recent = (array)get_option('recently_activated');
72                         if ( isset($recent[ $plugin ]) ) {
73                                 unset($recent[ $plugin ]);
74                                 update_option('recently_activated', $recent);
75                         }
76                         if ( isset($_GET['from']) && 'import' == $_GET['from'] ) {
77                                 wp_redirect("import.php?import=" . str_replace('-importer', '', dirname($plugin)) ); // overrides the ?error=true one above and redirects to the Imports page, striping the -importer suffix
78                         } else {
79                                 wp_redirect("plugins.php?activate=true&plugin_status=$status&paged=$page"); // overrides the ?error=true one above
80                         }
81                         exit;
82                         break;
83                 case 'activate-selected':
84                 case 'network-activate-selected':
85                         if ( ! current_user_can('activate_plugins') )
86                                 wp_die(__('You do not have sufficient permissions to activate plugins for this site.'));
87
88                         check_admin_referer('bulk-manage-plugins');
89
90                         $plugins = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
91                         $plugins = array_filter($plugins, create_function('$plugin', 'return !is_plugin_active($plugin);') ); // Only activate plugins which are not already active.
92                         if ( empty($plugins) ) {
93                                 wp_redirect("plugins.php?plugin_status=$status&paged=$page");
94                                 exit;
95                         }
96
97                         activate_plugins($plugins, 'plugins.php?error=true', $network_wide);
98
99                         $recent = (array)get_option('recently_activated');
100                         foreach ( $plugins as $plugin => $time)
101                                 if ( isset($recent[ $plugin ]) )
102                                         unset($recent[ $plugin ]);
103
104                         update_option('recently_activated', $recent);
105
106                         wp_redirect("plugins.php?activate-multi=true&plugin_status=$status&paged=$page");
107                         exit;
108                         break;
109                 case 'update-selected' :
110
111                         check_admin_referer( 'bulk-manage-plugins' );
112
113                         if ( isset( $_GET['plugins'] ) )
114                                 $plugins = explode( ',', $_GET['plugins'] );
115                         elseif ( isset( $_POST['checked'] ) )
116                                 $plugins = (array) $_POST['checked'];
117                         else
118                                 $plugins = array();
119
120                         $title = __( 'Upgrade Plugins' );
121                         $parent_file = 'plugins.php';
122
123                         require_once( './admin-header.php' );
124
125                         echo '<div class="wrap">';
126                         screen_icon();
127                         echo '<h2>' . esc_html( $title ) . '</h2>';
128
129
130                         $url = 'update.php?action=update-selected&amp;plugins=' . urlencode( join(',', $plugins) );
131                         $url = wp_nonce_url($url, 'bulk-update-plugins');
132
133                         echo "<iframe src='$url' style='width: 100%; height:100%; min-height:850px;'></iframe>";
134                         echo '</div>';
135                         require_once( './admin-footer.php' );
136                         exit;
137                         break;
138                 case 'error_scrape':
139                         if ( ! current_user_can('activate_plugins') )
140                                 wp_die(__('You do not have sufficient permissions to activate plugins for this site.'));
141
142                         check_admin_referer('plugin-activation-error_' . $plugin);
143
144                         $valid = validate_plugin($plugin);
145                         if ( is_wp_error($valid) )
146                                 wp_die($valid);
147
148                         if ( ! WP_DEBUG ) {
149                                 if ( defined('E_RECOVERABLE_ERROR') )
150                                         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);
151                                 else
152                                         error_reporting(E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING);
153                         }
154
155                         @ini_set('display_errors', true); //Ensure that Fatal errors are displayed.
156                         // Go back to "sandbox" scope so we get the same errors as before
157                         function plugin_sandbox_scrape( $plugin ) {
158                                 include( WP_PLUGIN_DIR . '/' . $plugin );
159                         }
160                         plugin_sandbox_scrape( $plugin );
161                         do_action('activate_' . $plugin);
162                         exit;
163                         break;
164                 case 'deactivate':
165                         if ( ! current_user_can('activate_plugins') )
166                                 wp_die(__('You do not have sufficient permissions to deactivate plugins for this site.'));
167
168                         check_admin_referer('deactivate-plugin_' . $plugin);
169                         deactivate_plugins($plugin);
170                         update_option('recently_activated', array($plugin => time()) + (array)get_option('recently_activated'));
171                         if (headers_sent())
172                                 echo "<meta http-equiv='refresh' content='" . esc_attr( "0;url=plugins.php?deactivate=true&plugin_status=$status&paged=$page" ) . "' />";
173                         else
174                                 wp_redirect("plugins.php?deactivate=true&plugin_status=$status&paged=$page");
175                         exit;
176                         break;
177                 case 'deactivate-selected':
178                         if ( ! current_user_can('activate_plugins') )
179                                 wp_die(__('You do not have sufficient permissions to deactivate plugins for this site.'));
180
181                         check_admin_referer('bulk-manage-plugins');
182
183                         $plugins = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
184                         $plugins = array_filter($plugins, 'is_plugin_active'); //Do not deactivate plugins which are already deactivated.
185                         if ( empty($plugins) ) {
186                                 wp_redirect("plugins.php?plugin_status=$status&paged=$page");
187                                 exit;
188                         }
189
190                         deactivate_plugins($plugins);
191
192                         $deactivated = array();
193                         foreach ( $plugins as $plugin )
194                                 $deactivated[ $plugin ] = time();
195
196                         update_option('recently_activated', $deactivated + (array)get_option('recently_activated'));
197                         wp_redirect("plugins.php?deactivate-multi=true&plugin_status=$status&paged=$page");
198                         exit;
199                         break;
200                 case 'delete-selected':
201                         if ( ! current_user_can('delete_plugins') )
202                                 wp_die(__('You do not have sufficient permissions to delete plugins for this site.'));
203
204                         check_admin_referer('bulk-manage-plugins');
205
206                         //$_POST = from the plugin form; $_GET = from the FTP details screen.
207                         $plugins = isset( $_REQUEST['checked'] ) ? (array) $_REQUEST['checked'] : array();
208                         $plugins = array_filter($plugins, create_function('$plugin', 'return !is_plugin_active($plugin);') ); //Do not allow to delete Activated plugins.
209                         if ( empty($plugins) ) {
210                                 wp_redirect("plugins.php?plugin_status=$status&paged=$page");
211                                 exit;
212                         }
213
214                         include(ABSPATH . 'wp-admin/update.php');
215
216                         $parent_file = 'plugins.php';
217
218                         if ( ! isset($_REQUEST['verify-delete']) ) {
219                                 wp_enqueue_script('jquery');
220                                 require_once('./admin-header.php');
221                                 ?>
222                         <div class="wrap">
223                                 <?php
224                                         $files_to_delete = $plugin_info = array();
225                                         foreach ( (array) $plugins as $plugin ) {
226                                                 if ( '.' == dirname($plugin) ) {
227                                                         $files_to_delete[] = WP_PLUGIN_DIR . '/' . $plugin;
228                                                         if( $data = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin) ) {
229                                                                 $plugin_info[ $plugin ] = $data;
230                                                                 $plugin_info[ $plugin ]['is_uninstallable'] = is_uninstallable_plugin( $plugin );
231                                                         }
232                                                 } else {
233                                                         // Locate all the files in that folder
234                                                         $files = list_files( WP_PLUGIN_DIR . '/' . dirname($plugin) );
235                                                         if ( $files ) {
236                                                                 $files_to_delete = array_merge($files_to_delete, $files);
237                                                         }
238                                                         // Get plugins list from that folder
239                                                         if ( $folder_plugins = get_plugins( '/' . dirname($plugin)) ) {
240                                                                 foreach( $folder_plugins as $plugin_file => $data ) {
241                                                                         $plugin_info[ $plugin_file ] = $data;
242                                                                         $plugin_info[ $plugin_file ]['is_uninstallable'] = is_uninstallable_plugin( $plugin );
243                                                                 }
244                                                         }
245                                                 }
246                                         }
247                                         screen_icon();
248                                         $plugins_to_delete = count( $plugin_info );
249                                         echo '<h2>' . _n( 'Delete Plugin', 'Delete Plugins', $plugins_to_delete ) . '</h2>';
250                                 ?>
251                                 <p><?php echo _n( 'You are about to remove the following plugin:', 'You are about to remove the following plugins:', $plugins_to_delete ); ?></p>
252                                         <ul class="ul-disc">
253                                                 <?php
254                                                 $data_to_delete = false;
255                                                 foreach ( $plugin_info as $plugin ) {
256                                                         if ( $plugin['is_uninstallable'] ) {
257                                                                 /* translators: 1: plugin name, 2: plugin author */
258                                                                 echo '<li>', sprintf( __( '<strong>%1$s</strong> by <em>%2$s</em> (will also <strong>delete its data</strong>)' ), esc_html($plugin['Name']), esc_html($plugin['Author']) ), '</li>';
259                                                                 $data_to_delete = true;
260                                                         } else {
261                                                                 /* translators: 1: plugin name, 2: plugin author */
262                                                                 echo '<li>', sprintf( __('<strong>%1$s</strong> by <em>%2$s</em>' ), esc_html($plugin['Name']), esc_html($plugin['Author']) ), '</li>';
263                                                         }
264                                                 }
265                                                 ?>
266                                         </ul>
267                                 <p><?php
268                                 if ( $data_to_delete )
269                                         _e('Are you sure you wish to delete these files and data?');
270                                 else
271                                         _e('Are you sure you wish to delete these files?');
272                                 ?></p>
273                                 <form method="post" action="<?php echo esc_url($_SERVER['REQUEST_URI']); ?>" style="display:inline;">
274                                         <input type="hidden" name="verify-delete" value="1" />
275                                         <input type="hidden" name="action" value="delete-selected" />
276                                         <?php
277                                                 foreach ( (array)$plugins as $plugin )
278                                                         echo '<input type="hidden" name="checked[]" value="' . esc_attr($plugin) . '" />';
279                                         ?>
280                                         <?php wp_nonce_field('bulk-manage-plugins') ?>
281                                         <input type="submit" name="submit" value="<?php $data_to_delete ? esc_attr_e('Yes, Delete these files and data') : esc_attr_e('Yes, Delete these files') ?>" class="button" />
282                                 </form>
283                                 <form method="post" action="<?php echo esc_url(wp_get_referer()); ?>" style="display:inline;">
284                                         <input type="submit" name="submit" value="<?php esc_attr_e('No, Return me to the plugin list') ?>" class="button" />
285                                 </form>
286
287                                 <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>
288                                 <div id="files-list" style="display:none;">
289                                         <ul class="code">
290                                         <?php
291                                                 foreach ( (array)$files_to_delete as $file )
292                                                         echo '<li>' . esc_html(str_replace(WP_PLUGIN_DIR, '', $file)) . '</li>';
293                                         ?>
294                                         </ul>
295                                 </div>
296                         </div>
297                                 <?php
298                                 require_once('./admin-footer.php');
299                                 exit;
300                         } //Endif verify-delete
301                         $delete_result = delete_plugins($plugins);
302
303                         set_transient('plugins_delete_result_'.$user_ID, $delete_result); //Store the result in a cache rather than a URL param due to object type & length
304                         wp_redirect("plugins.php?deleted=true&plugin_status=$status&paged=$page");
305                         exit;
306                         break;
307                 case 'clear-recent-list':
308                         update_option('recently_activated', array());
309                         break;
310         }
311 }
312
313 wp_enqueue_script('plugin-install');
314 add_thickbox();
315
316 add_contextual_help($current_screen,
317         '<p>' . __('Plugins extend and expand the functionality of WordPress. Once a plugin is installed, you may activate it or deactivate it here.') . '</p>' .
318         '<p>' . sprintf(__('You can find additional plugins for your site by using the <a href="%1$s">Plugin Browser/Installer</a> functionality or by browsing the <a href="%2$s" target="_blank">WordPress Plugin Directory</a> directly and installing new plugins manually. To manually install a plugin you generally just need to upload the plugin file into your <code>/wp-content/plugins</code> directory. Once a plugin has been installed, you can activate it here.'), 'plugin-install.php', 'http://wordpress.org/extend/plugins/') . '</p>' .
319         '<p>' . __('Most of the time, plugins play nicely with the core of WordPress and with other plugins. Sometimes, though, a plugin&#8217;s code will get in the way of another plugin, causing compatibility issues. If your site starts doing strange things, this may be the problem. Try deactivating all your plugins and re-activating them in various combinations until you isolate which one(s) caused the issue.') . '</p>' .
320         '<p>' . sprintf( __('If something goes wrong with a plugin and you can&#8217;t use WordPress, delete or rename that file in the <code>%s</code> directory and it will be automatically deactivated.'), WP_PLUGIN_DIR) . '</p>' .
321         '<p><strong>' . __('For more information:') . '</strong></p>' .
322         '<p>' . __('<a href="http://codex.wordpress.org/Managing_Plugins#Plugin_Management" target="_blank">Documentation on Managing Plugins</a>') . '</p>' .
323         '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
324 );
325
326 $title = __('Plugins');
327
328 require_once('./admin-header.php');
329
330 $invalid = validate_active_plugins();
331 if ( !empty($invalid) )
332         foreach ( $invalid as $plugin_file => $error )
333                 echo '<div id="message" class="error"><p>' . sprintf(__('The plugin <code>%s</code> has been <strong>deactivated</strong> due to an error: %s'), esc_html($plugin_file), $error->get_error_message()) . '</p></div>';
334 ?>
335
336 <?php if ( isset($_GET['error']) ) :
337
338         if ( isset($_GET['charsout']) )
339                 $errmsg = sprintf(__('The plugin generated %d characters of <strong>unexpected output</strong> during activation.  If you notice &#8220;headers already sent&#8221; messages, problems with syndication feeds or other issues, try deactivating or removing this plugin.'), $_GET['charsout']);
340         else
341                 $errmsg = __('Plugin could not be activated because it triggered a <strong>fatal error</strong>.');
342         ?>
343         <div id="message" class="updated"><p><?php echo $errmsg; ?></p>
344         <?php
345                 if ( !isset($_GET['charsout']) && wp_verify_nonce($_GET['_error_nonce'], 'plugin-activation-error_' . $plugin) ) { ?>
346         <iframe style="border:0" width="100%" height="70px" src="<?php echo admin_url('plugins.php?action=error_scrape&amp;plugin=' . esc_attr($plugin) . '&amp;_wpnonce=' . esc_attr($_GET['_error_nonce'])); ?>"></iframe>
347         <?php
348                 }
349         ?>
350         </div>
351 <?php elseif ( isset($_GET['deleted']) ) :
352                 $delete_result = get_transient('plugins_delete_result_'.$user_ID);
353                 delete_transient('plugins_delete_result'); //Delete it once we're done.
354
355                 if ( is_wp_error($delete_result) ) : ?>
356                 <div id="message" class="updated"><p><?php printf( __('Plugin could not be deleted due to an error: %s'), $delete_result->get_error_message() ); ?></p></div>
357                 <?php else : ?>
358                 <div id="message" class="updated"><p><?php _e('The selected plugins have been <strong>deleted</strong>.'); ?></p></div>
359                 <?php endif; ?>
360 <?php elseif ( isset($_GET['activate']) ) : ?>
361         <div id="message" class="updated"><p><?php _e('Plugin <strong>activated</strong>.') ?></p></div>
362 <?php elseif (isset($_GET['activate-multi'])) : ?>
363         <div id="message" class="updated"><p><?php _e('Selected plugins <strong>activated</strong>.'); ?></p></div>
364 <?php elseif ( isset($_GET['deactivate']) ) : ?>
365         <div id="message" class="updated"><p><?php _e('Plugin <strong>deactivated</strong>.') ?></p></div>
366 <?php elseif (isset($_GET['deactivate-multi'])) : ?>
367         <div id="message" class="updated"><p><?php _e('Selected plugins <strong>deactivated</strong>.'); ?></p></div>
368 <?php elseif ( 'update-selected' == $action ) : ?>
369         <div id="message" class="updated"><p><?php _e('No out of date plugins were selected.'); ?></p></div>
370 <?php endif; ?>
371
372 <div class="wrap">
373 <?php screen_icon(); ?>
374 <h2><?php echo esc_html( $title ); if ( current_user_can('install_plugins') ) { ?> <a href="plugin-install.php" class="button add-new-h2"><?php echo esc_html_x('Add New', 'plugin'); ?></a><?php } ?></h2>
375
376 <?php
377
378 $all_plugins = apply_filters( 'all_plugins', get_plugins() );
379 $search_plugins = array();
380 $active_plugins = array();
381 $inactive_plugins = array();
382 $recent_plugins = array();
383 $recently_activated = get_option('recently_activated', array());
384 $upgrade_plugins = array();
385 $network_plugins = array();
386 $mustuse_plugins = $dropins_plugins = array();
387 if ( ! is_multisite() || current_user_can('manage_network_plugins') ) {
388         if ( apply_filters( 'show_advanced_plugins', true, 'mustuse' ) )
389                 $mustuse_plugins = get_mu_plugins();
390         if ( apply_filters( 'show_advanced_plugins', true, 'dropins' ) )
391                 $dropins_plugins = get_dropins();
392 }
393
394 set_transient( 'plugin_slugs', array_keys($all_plugins), 86400 );
395
396 // Clean out any plugins which were deactivated over a week ago.
397 foreach ( $recently_activated as $key => $time )
398         if ( $time + (7*24*60*60) < time() ) //1 week
399                 unset($recently_activated[ $key ]);
400 if ( $recently_activated != get_option('recently_activated') ) //If array changed, update it.
401         update_option('recently_activated', $recently_activated);
402 $current = get_site_transient( 'update_plugins' );
403
404 foreach ( array( 'all_plugins', 'mustuse_plugins', 'dropins_plugins' ) as $plugin_array_name) {
405         foreach ( (array) $$plugin_array_name as $plugin_file => $plugin_data ) {
406                 // Translate, Apply Markup, Sanitize HTML
407                 $plugin_data = _get_plugin_data_markup_translate($plugin_file, $plugin_data, false, true);
408                 ${$plugin_array_name}[ $plugin_file ] = $plugin_data;
409         }
410 }
411 unset( $plugin_array_name );
412
413 foreach ( (array) $all_plugins as $plugin_file => $plugin_data) {
414         // Filter into individual sections
415         if ( is_multisite() && is_network_only_plugin( $plugin_file ) && !current_user_can( 'manage_network_plugins' ) ) {
416                 unset( $all_plugins[ $plugin_file ] );
417                 continue;
418         } elseif ( is_plugin_active_for_network($plugin_file) ) {
419                 $network_plugins[ $plugin_file ] = $plugin_data;
420         } elseif ( is_plugin_active($plugin_file) ) {
421                 $active_plugins[ $plugin_file ] = $plugin_data;
422         } else {
423                 if ( isset( $recently_activated[ $plugin_file ] ) ) // Was the plugin recently activated?
424                         $recent_plugins[ $plugin_file ] = $plugin_data;
425                 $inactive_plugins[ $plugin_file ] = $plugin_data;
426         }
427
428         if ( isset( $current->response[ $plugin_file ] ) )
429                 $upgrade_plugins[ $plugin_file ] = $plugin_data;
430 }
431
432 if ( !current_user_can('update_plugins') )
433         $upgrade_plugins = array();
434
435 $total_all_plugins = count($all_plugins);
436 $total_inactive_plugins = count($inactive_plugins);
437 $total_active_plugins = count($active_plugins);
438 $total_recent_plugins = count($recent_plugins);
439 $total_upgrade_plugins = count($upgrade_plugins);
440 $total_network_plugins = count($network_plugins);
441 $total_mustuse_plugins = count($mustuse_plugins);
442 $total_dropins_plugins = count($dropins_plugins);
443
444 // Searching.
445 if ( !empty($_GET['s']) ) {
446         function _search_plugins_filter_callback($plugin) {
447                 static $term;
448                 if ( is_null($term) )
449                         $term = stripslashes($_GET['s']);
450                 if (    stripos($plugin['Name'], $term) !== false ||
451                                 stripos($plugin['Description'], $term) !== false ||
452                                 stripos($plugin['Author'], $term) !== false ||
453                                 stripos($plugin['PluginURI'], $term) !== false ||
454                                 stripos($plugin['AuthorURI'], $term) !== false ||
455                                 stripos($plugin['Version'], $term) !== false )
456                         return true;
457                 else
458                         return false;
459         }
460         $status = 'search';
461         $search_plugins = array_filter($all_plugins, '_search_plugins_filter_callback');
462         $total_search_plugins = count($search_plugins);
463 }
464
465 $plugin_array_name = "${status}_plugins";
466 if ( empty($$plugin_array_name) && !in_array($status, array('all', 'search')) ) {
467         $status = 'all';
468         $plugin_array_name = "${status}_plugins";
469 }
470
471 $plugins = &$$plugin_array_name;
472
473 // Paging.
474 $total_this_page = "total_{$status}_plugins";
475 $total_this_page = $$total_this_page;
476 $plugins_per_page = (int) get_user_option( 'plugins_per_page' );
477 if ( empty( $plugins_per_page ) || $plugins_per_page < 1 )
478         $plugins_per_page = 999;
479 $plugins_per_page = apply_filters( 'plugins_per_page', $plugins_per_page );
480
481 $start = ($page - 1) * $plugins_per_page;
482
483 $page_links = paginate_links( array(
484         'base' => add_query_arg( 'paged', '%#%' ),
485         'format' => '',
486         'prev_text' => __('&laquo;'),
487         'next_text' => __('&raquo;'),
488         'total' => ceil($total_this_page / $plugins_per_page),
489         'current' => $page
490 ));
491 $page_links_text = sprintf( '<span class="displaying-num">' . __( 'Displaying %s&#8211;%s of %s' ) . '</span>%s',
492         number_format_i18n( $start + 1 ),
493         number_format_i18n( min( $page * $plugins_per_page, $total_this_page ) ),
494         '<span class="total-type-count">' . number_format_i18n( $total_this_page ) . '</span>',
495         $page_links
496 );
497
498 /**
499  * @ignore
500  *
501  * @param array $plugins
502  * @param string $context
503  */
504 function print_plugins_table($plugins, $context = '') {
505         global $page;
506         $checkbox = ! in_array( $context, array( 'mustuse', 'dropins' ) ) ? '<input type="checkbox" />' : '';
507 ?>
508 <table class="widefat" cellspacing="0" id="<?php echo $context ?>-plugins-table">
509         <thead>
510         <tr>
511                 <th scope="col" class="manage-column check-column"><?php echo $checkbox; ?></th>
512                 <th scope="col" class="manage-column"><?php _e('Plugin'); ?></th>
513                 <th scope="col" class="manage-column"><?php _e('Description'); ?></th>
514         </tr>
515         </thead>
516
517         <tfoot>
518         <tr>
519                 <th scope="col" class="manage-column check-column"><?php echo $checkbox; ?></th>
520                 <th scope="col" class="manage-column"><?php _e('Plugin'); ?></th>
521                 <th scope="col" class="manage-column"><?php _e('Description'); ?></th>
522         </tr>
523         </tfoot>
524
525         <tbody class="plugins">
526 <?php
527
528         if ( empty($plugins) ) {
529                 echo '<tr>
530                         <td colspan="3">' . __('No plugins to show') . '</td>
531                 </tr>';
532         }
533         foreach ( (array)$plugins as $plugin_file => $plugin_data) {
534                 // preorder
535                 $actions = array(
536                         'network_deactivate' => '', 'deactivate' => '',
537                         'network_only' => '', 'activate' => '',
538                         'network_activate' => '',
539                         'edit' => '',
540                         'delete' => '',
541                 );
542
543                 if ( 'mustuse' == $context ) {
544                         $is_active = true;
545                 } elseif ( 'dropins' == $context ) {
546                         $dropins = _get_dropins();
547                         $plugin_name = $plugin_file;
548                         if ( $plugin_file != $plugin_data['Name'] )
549                                 $plugin_name .= '<br/>' . $plugin_data['Name'];
550                         if ( true === ( $dropins[ $plugin_file ][1] ) ) { // Doesn't require a constant
551                                 $is_active = true;
552                                 $description = '<p><strong>' . $dropins[ $plugin_file ][0] . '</strong></p>';
553                         } elseif ( constant( $dropins[ $plugin_file ][1] ) ) { // Constant is true
554                                 $is_active = true;
555                                 $description = '<p><strong>' . $dropins[ $plugin_file ][0] . '</strong></p>';
556                         } else {
557                                 $is_active = false;
558                                 $description = '<p><strong>' . $dropins[ $plugin_file ][0] . ' <span class="attention">' . __('Inactive:') . '</span></strong> ' . sprintf( __( 'Requires <code>%s</code> in <code>wp-config.php</code>.' ), "define('" . $dropins[ $plugin_file ][1] . "', true);" ) . '</p>';
559                         }
560                         if ( $plugin_data['Description'] )
561                                 $description .= '<p>' . $plugin_data['Description'] . '</p>';
562                 } else {
563                         $is_active_for_network = is_plugin_active_for_network($plugin_file);
564                         $is_active = $is_active_for_network || is_plugin_active( $plugin_file );
565                         if ( $is_active_for_network && !is_super_admin() )
566                                 continue;
567
568                         if ( $is_active ) {
569                                 if ( $is_active_for_network ) {
570                                         if ( is_super_admin() )
571                                                 $actions['network_deactivate'] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&amp;networkwide=1&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page, 'deactivate-plugin_' . $plugin_file) . '" title="' . __('Deactivate this plugin') . '">' . __('Network Deactivate') . '</a>';
572                                 } else {
573                                         $actions['deactivate'] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page, 'deactivate-plugin_' . $plugin_file) . '" title="' . __('Deactivate this plugin') . '">' . __('Deactivate') . '</a>';
574                                 }
575                         } else {
576                                 if ( is_multisite() && is_network_only_plugin( $plugin_file ) )
577                                         $actions['network_only'] = '<span title="' . __('This plugin can only be activated for all sites in a network') . '">' . __('Network Only') . '</span>';
578                                 else
579                                         $actions['activate'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page, 'activate-plugin_' . $plugin_file) . '" title="' . __('Activate this plugin') . '" class="edit">' . __('Activate') . '</a>';
580
581                                 if ( is_multisite() && current_user_can( 'manage_network_plugins' ) )
582                                         $actions['network_activate'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;networkwide=1&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page, 'activate-plugin_' . $plugin_file) . '" title="' . __('Activate this plugin for all sites in this network') . '" class="edit">' . __('Network Activate') . '</a>';
583
584                                 if ( current_user_can('delete_plugins') )
585                                         $actions['delete'] = '<a href="' . wp_nonce_url('plugins.php?action=delete-selected&amp;checked[]=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page, 'bulk-manage-plugins') . '" title="' . __('Delete this plugin') . '" class="delete">' . __('Delete') . '</a>';
586                         } // end if $is_active
587
588                         if ( current_user_can('edit_plugins') && is_writable(WP_PLUGIN_DIR . '/' . $plugin_file) )
589                                 $actions['edit'] = '<a href="plugin-editor.php?file=' . $plugin_file . '" title="' . __('Open this file in the Plugin Editor') . '" class="edit">' . __('Edit') . '</a>';
590                 } // end if $context
591
592                 $actions = apply_filters( 'plugin_action_links', array_filter( $actions ), $plugin_file, $plugin_data, $context );
593                 $actions = apply_filters( "plugin_action_links_$plugin_file", $actions, $plugin_file, $plugin_data, $context );
594
595                 $class = $is_active ? 'active' : 'inactive';
596                 $checkbox = in_array( $context, array( 'mustuse', 'dropins' ) ) ? '' : "<input type='checkbox' name='checked[]' value='" . esc_attr($plugin_file) . "' />";
597                 if ( 'dropins' != $context ) {
598                         $description = '<p>' . $plugin_data['Description'] . '</p>';
599                         $plugin_name = $plugin_data['Name'];
600                 }
601                 echo "
602         <tr class='$class'>
603                 <th scope='row' class='check-column'>$checkbox</th>
604                 <td class='plugin-title'><strong>$plugin_name</strong></td>
605                 <td class='desc'>$description</td>
606         </tr>
607         <tr class='$class second'>
608                 <td></td>
609                 <td class='plugin-title'>";
610                 echo '<div class="row-actions-visible">';
611                 foreach ( $actions as $action => $link ) {
612                         $sep = end($actions) == $link ? '' : ' | ';
613                         echo "<span class='$action'>$link$sep</span>";
614                 }
615                 echo "</div></td>
616                 <td class='desc'>";
617                 $plugin_meta = array();
618                 if ( !empty($plugin_data['Version']) )
619                         $plugin_meta[] = sprintf(__('Version %s'), $plugin_data['Version']);
620                 if ( !empty($plugin_data['Author']) ) {
621                         $author = $plugin_data['Author'];
622                         if ( !empty($plugin_data['AuthorURI']) )
623                                 $author = '<a href="' . $plugin_data['AuthorURI'] . '" title="' . __( 'Visit author homepage' ) . '">' . $plugin_data['Author'] . '</a>';
624                         $plugin_meta[] = sprintf( __('By %s'), $author );
625                 }
626                 if ( ! empty($plugin_data['PluginURI']) )
627                         $plugin_meta[] = '<a href="' . $plugin_data['PluginURI'] . '" title="' . __( 'Visit plugin site' ) . '">' . __('Visit plugin site') . '</a>';
628
629                 $plugin_meta = apply_filters('plugin_row_meta', $plugin_meta, $plugin_file, $plugin_data, $context);
630                 echo implode(' | ', $plugin_meta);
631                 echo "</td>
632         </tr>\n";
633
634                 do_action( 'after_plugin_row', $plugin_file, $plugin_data, $context );
635                 do_action( "after_plugin_row_$plugin_file", $plugin_file, $plugin_data, $context );
636         }
637 ?>
638         </tbody>
639 </table>
640 <?php
641 } //End print_plugins_table()
642
643 /**
644  * @ignore
645  *
646  * @param string $context
647  */
648 function print_plugin_actions($context, $field_name = 'action' ) {
649         if ( in_array( $context, array( 'mustuse', 'dropins' ) ) )
650                 return;
651 ?>
652         <div class="alignleft actions">
653                 <select name="<?php echo $field_name; ?>">
654                         <option value="" selected="selected"><?php _e('Bulk Actions'); ?></option>
655         <?php if ( 'active' != $context ) : ?>
656                         <option value="activate-selected"><?php _e('Activate'); ?></option>
657         <?php endif; ?>
658         <?php if ( is_multisite() && 'network' != $context ) : ?>
659                         <option value="network-activate-selected"><?php _e('Network Activate'); ?></option>
660         <?php endif; ?>
661         <?php if ( 'inactive' != $context && 'recent' != $context ) : ?>
662                         <option value="deactivate-selected"><?php _e('Deactivate'); ?></option>
663         <?php endif; ?>
664         <?php if ( current_user_can( 'update_plugins' ) ) : ?>
665                         <option value="update-selected"><?php _e( 'Upgrade' ); ?></option>
666         <?php endif; ?>
667         <?php if ( current_user_can('delete_plugins') && ( 'active' != $context ) ) : ?>
668                         <option value="delete-selected"><?php _e('Delete'); ?></option>
669         <?php endif; ?>
670                 </select>
671                 <input type="submit" name="doaction_active" value="<?php esc_attr_e('Apply'); ?>" class="button-secondary action" />
672         <?php if ( 'recent' == $context ) : ?>
673                 <input type="submit" name="clear-recent-list" value="<?php esc_attr_e('Clear List') ?>" class="button-secondary" />
674         <?php endif; ?>
675         </div>
676 <?php
677 }
678 ?>
679
680 <form method="get" action="">
681 <p class="search-box">
682         <label class="screen-reader-text" for="plugin-search-input"><?php _e( 'Search Plugins' ); ?>:</label>
683         <input type="text" id="plugin-search-input" name="s" value="<?php _admin_search_query(); ?>" />
684         <input type="submit" value="<?php esc_attr_e( 'Search Installed Plugins' ); ?>" class="button" />
685 </p>
686 </form>
687
688 <?php do_action( 'pre_current_active_plugins', $all_plugins ) ?>
689
690 <form method="post" action="<?php echo admin_url('plugins.php') ?>">
691 <?php wp_nonce_field('bulk-manage-plugins') ?>
692 <input type="hidden" name="plugin_status" value="<?php echo esc_attr($status) ?>" />
693 <input type="hidden" name="paged" value="<?php echo esc_attr($page) ?>" />
694
695 <ul class="subsubsub">
696 <?php
697 $status_links = array();
698 $class = ( 'all' == $status ) ? ' class="current"' : '';
699 $status_links[] = "<li><a href='plugins.php?plugin_status=all' $class>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_all_plugins, 'plugins' ), number_format_i18n( $total_all_plugins ) ) . '</a>';
700 if ( ! empty($active_plugins) ) {
701         $class = ( 'active' == $status ) ? ' class="current"' : '';
702         $status_links[] = "<li><a href='plugins.php?plugin_status=active' $class>" . sprintf( _n( 'Active <span class="count">(%s)</span>', 'Active <span class="count">(%s)</span>', $total_active_plugins ), number_format_i18n( $total_active_plugins ) ) . '</a>';
703 }
704 if ( ! empty($recent_plugins) ) {
705         $class = ( 'recent' == $status ) ? ' class="current"' : '';
706         $status_links[] = "<li><a href='plugins.php?plugin_status=recent' $class>" . sprintf( _n( 'Recently Active <span class="count">(%s)</span>', 'Recently Active <span class="count">(%s)</span>', $total_recent_plugins ), number_format_i18n( $total_recent_plugins ) ) . '</a>';
707 }
708 if ( ! empty($inactive_plugins) ) {
709         $class = ( 'inactive' == $status ) ? ' class="current"' : '';
710         $status_links[] = "<li><a href='plugins.php?plugin_status=inactive' $class>" . sprintf( _n( 'Inactive <span class="count">(%s)</span>', 'Inactive <span class="count">(%s)</span>', $total_inactive_plugins ), number_format_i18n( $total_inactive_plugins ) ) . '</a>';
711 }
712 if ( ! empty($network_plugins) ) {
713         $class = ( 'network' == $status ) ? ' class="current"' : '';
714         $status_links[] = "<li><a href='plugins.php?plugin_status=network' $class>" . sprintf( _n( 'Network <span class="count">(%s)</span>', 'Network <span class="count">(%s)</span>', $total_network_plugins ), number_format_i18n( $total_network_plugins ) ) . '</a>';
715 }
716 if ( ! empty($mustuse_plugins) ) {
717         $class = ( 'mustuse' == $status ) ? ' class="current"' : '';
718         $status_links[] = "<li><a href='plugins.php?plugin_status=mustuse' $class>" . sprintf( _n( 'Must-Use <span class="count">(%s)</span>', 'Must-Use <span class="count">(%s)</span>', $total_mustuse_plugins ), number_format_i18n( $total_mustuse_plugins ) ) . '</a>';
719 }
720 if ( ! empty($dropins_plugins) ) {
721         $class = ( 'dropins' == $status ) ? ' class="current"' : '';
722         $status_links[] = "<li><a href='plugins.php?plugin_status=dropins' $class>" . sprintf( _n( 'Drop-ins <span class="count">(%s)</span>', 'Drop-ins <span class="count">(%s)</span>', $total_dropins_plugins ), number_format_i18n( $total_dropins_plugins ) ) . '</a>';
723 }
724 if ( ! empty($upgrade_plugins) ) {
725         $class = ( 'upgrade' == $status ) ? ' class="current"' : '';
726         $status_links[] = "<li><a href='plugins.php?plugin_status=upgrade' $class>" . sprintf( _n( 'Upgrade Available <span class="count">(%s)</span>', 'Upgrade Available <span class="count">(%s)</span>', $total_upgrade_plugins ), number_format_i18n( $total_upgrade_plugins ) ) . '</a>';
727 }
728 if ( ! empty($search_plugins) ) {
729         $class = ( 'search' == $status ) ? ' class="current"' : '';
730         $term = isset($_REQUEST['s']) ? urlencode(stripslashes($_REQUEST['s'])) : '';
731         $status_links[] = "<li><a href='plugins.php?s=$term' $class>" . sprintf( _n( 'Search Results <span class="count">(%s)</span>', 'Search Results <span class="count">(%s)</span>', $total_search_plugins ), number_format_i18n( $total_search_plugins ) ) . '</a>';
732 }
733 echo implode( " |</li>\n", $status_links ) . '</li>';
734 unset( $status_links );
735 ?>
736 </ul>
737
738 <?php
739 if ( 'mustuse' == $status )
740         echo '<div class="clear"></div><p>' . __( 'Files in the <code>/wp-content/mu-plugins</code> directory are executed automatically.' ) . '</p>';
741 elseif ( 'dropins' == $status )
742         echo '<div class="clear"></div><p>' . __( 'Drop-ins are advanced plugins in the <code>/wp-content</code> directory that replace WordPress functionality when present.' ) . '</p>';
743
744 if ( !empty( $plugins ) && ( ! in_array( $status, array( 'mustuse', 'dropins' ) ) || $page_links ) ) :
745 ?>
746 <div class="tablenav">
747 <?php
748 if ( $page_links )
749         echo '<div class="tablenav-pages">', $page_links_text, '</div>';
750
751 print_plugin_actions($status);
752 ?>
753 </div>
754 <div class="clear"></div>
755 <?php
756 endif;
757
758 if ( $total_this_page > $plugins_per_page )
759         $plugins = array_slice($plugins, $start, $plugins_per_page);
760
761 print_plugins_table($plugins, $status);
762
763 if ( !empty( $plugins ) && ! in_array( $status, array( 'mustuse', 'dropins' ) ) || $page_links ) {
764 ?>
765 <div class="tablenav">
766 <?php
767 if ( $page_links )
768         echo "<div class='tablenav-pages'>$page_links_text</div>";
769
770 print_plugin_actions($status, "action2");
771 ?>
772 </div>
773 <?php } ?>
774 </form>
775
776 <?php if ( empty($all_plugins) ) : ?>
777 <br class="clear" />
778 <p><?php _e('You do not appear to have any plugins available at this time.') ?></p>
779 <?php endif; ?>
780
781 </div>
782
783 <?php
784 include('./admin-footer.php');
785 ?>