2 require_once('admin.php');
5 foreach( array('activate-selected', 'deactivate-selected', 'delete-selected', 'clear-recent-list') as $action_key ) {
6 if( isset($_POST[$action_key]) ) {
12 if( isset($_GET['action']) )
13 $action = $_GET['action'];
15 $plugin = $_REQUEST['plugin'];
17 if( !empty($action) ) {
20 check_admin_referer('activate-plugin_' . $plugin);
21 $result = activate_plugin($plugin, 'plugins.php?error=true&plugin=' . $plugin);
22 if ( is_wp_error( $result ) )
23 wp_die( $result->get_error_message() );
24 $recent = (array)get_option('recently_activated');
25 if( isset($recent[ $plugin ]) ){
26 unset($recent[ $plugin ]);
27 update_option('recently_activated', $recent);
29 wp_redirect('plugins.php?activate=true'); // overrides the ?error=true one above
32 case 'activate-selected':
33 check_admin_referer('bulk-manage-plugins');
34 activate_plugins($_POST['checked'], 'plugins.php?error=true');
36 $recent = (array)get_option('recently_activated');
37 foreach( (array)$_POST['checked'] as $plugin => $time) {
38 if( isset($recent[ $plugin ]) )
39 unset($recent[ $plugin ]);
41 if( $recent != get_option('recently_activated') ) //If array changed, update it.
42 update_option('recently_activated', $recent);
44 wp_redirect('plugins.php?activate-multi=true');
48 check_admin_referer('plugin-activation-error_' . $plugin);
49 $valid = validate_plugin($plugin);
50 if ( is_wp_error($valid) )
52 error_reporting( E_ALL ^ E_NOTICE );
53 @ini_set('display_errors', true); //Ensure that Fatal errors are displayed.
54 include(WP_PLUGIN_DIR . '/' . $plugin);
58 check_admin_referer('deactivate-plugin_' . $plugin);
59 deactivate_plugins($plugin);
60 update_option('recently_activated', array($plugin => time()) + (array)get_option('recently_activated'));
61 wp_redirect('plugins.php?deactivate=true');
64 case 'deactivate-selected':
65 check_admin_referer('bulk-manage-plugins');
66 deactivate_plugins($_POST['checked']);
67 $deactivated = array();
68 foreach( (array)$_POST['checked'] as $plugin )
69 $deactivated[ $plugin ] = time();
70 update_option('recently_activated', $deactivated + (array)get_option('recently_activated'));
71 wp_redirect('plugins.php?deactivate-multi=true');
74 case 'delete-selected':
75 if( ! current_user_can('delete_plugins') )
76 wp_die(__('You do not have sufficient permissions to delete plugins for this blog.'));
78 check_admin_referer('bulk-manage-plugins');
80 $plugins = $_REQUEST['checked']; //$_POST = from the plugin form; $_GET = from the FTP details screen.
81 include(ABSPATH . 'wp-admin/update.php');
83 $title = __('Delete Plugin');
84 $parent_file = 'plugins.php';
86 if( ! isset($_REQUEST['verify-delete']) ) {
87 wp_enqueue_script('jquery');
88 require_once('admin-header.php');
91 <h2><?php _e('Delete Plugin(s)'); ?></h2>
93 $files_to_delete = $plugin_info = array();
94 foreach( (array) $plugins as $plugin ) {
95 if( '.' == dirname($plugin) ) {
96 $files_to_delete[] = WP_PLUGIN_DIR . '/' . $plugin;
97 if( $data = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin) )
98 $plugin_info[ $plugin ] = $data;
100 //Locate all the files in that folder:
101 $files = list_files( WP_PLUGIN_DIR . '/' . dirname($plugin) );
103 $files_to_delete = array_merge($files_to_delete, $files);
105 //Get plugins list from that folder
106 if ( $folder_plugins = get_plugins( '/' . dirname($plugin)) )
107 $plugin_info = array_merge($plugin_info, $folder_plugins);
111 <p><?php _e('Deleting the selected plugins will remove the following plugin(s) and their files:'); ?></p>
115 foreach( $plugin_info as $plugin )
116 echo '<li>', $plugin['Title'], ' ', __('By'), ' ', $plugin['Author'], '</li>';
120 <p><?php _e('Are you sure you wish to delete these files?') ?></p>
121 <form method="post" action="<?php echo clean_url($_SERVER['REQUEST_URI']); ?>" style="display:inline;">
122 <input type="hidden" name="verify-delete" value="1" />
123 <input type="hidden" name="delete-selected" value="1" />
125 foreach( (array)$plugins as $plugin ) {
126 $plugin = attribute_escape($plugin);
127 echo "<input type='hidden' name='checked[]' value='$plugin' />";
130 <?php wp_nonce_field('bulk-manage-plugins') ?>
131 <input type="submit" name="submit" value="<?php _e('Yes, Delete these files') ?>" class="button" />
133 <form method="post" action="<?php echo clean_url(wp_get_referer()); ?>" style="display:inline;">
134 <input type="submit" name="submit" value="<?php _e('No, Return me to the plugin list') ?>" class="button" />
137 <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>
138 <div id="files-list" style="display:none;">
141 foreach( (array)$files_to_delete as $file ) {
142 $file = str_replace(ABSPATH, '', $file);
143 echo "<li>$file</li>";
150 require_once('admin-footer.php');
152 } //Endif verify-delete
153 $delete_result = delete_plugins($plugins);
155 wp_cache_delete('plugins', 'plugins');
157 case 'clear-recent-list':
158 update_option('recently_activated', array());
163 wp_enqueue_script('admin-forms');
165 $title = __('Manage Plugins');
166 require_once('admin-header.php');
168 $invalid = validate_active_plugins();
169 if( !empty($invalid) )
170 foreach($invalid as $plugin_file => $error)
171 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>';
174 <?php if ( isset($_GET['error']) ) : ?>
175 <div id="message" class="updated fade"><p><?php _e('Plugin could not be activated because it triggered a <strong>fatal error</strong>.') ?></p>
177 if ( wp_verify_nonce($_GET['_error_nonce'], 'plugin-activation-error_' . $plugin) ) { ?>
178 <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 elseif ( 'delete-selected' == $action ) :
184 if ( is_wp_error($delete_result) ) : ?>
185 <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>
187 <div id="message" class="updated fade"><p><?php _e('The selected plugins have been <strong>deleted</strong>.'); ?></p></div>
189 <?php elseif ( isset($_GET['activate']) ) : ?>
190 <div id="message" class="updated fade"><p><?php _e('Plugin <strong>activated</strong>.') ?></p></div>
191 <?php elseif (isset($_GET['activate-multi'])) : ?>
192 <div id="message" class="updated fade"><p><?php _e('Selected plugins <strong>activated</strong>.'); ?></p></div>
193 <?php elseif ( isset($_GET['deactivate']) ) : ?>
194 <div id="message" class="updated fade"><p><?php _e('Plugin <strong>deactivated</strong>.') ?></p></div>
195 <?php elseif (isset($_GET['deactivate-multi'])) : ?>
196 <div id="message" class="updated fade"><p><?php _e('Selected plugins <strong>deactivated</strong>.'); ?></p></div>
200 <h2><?php _e('Plugin Management'); ?></h2>
201 <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>
204 $all_plugins = get_plugins();
205 $active_plugins = array();
206 $inactive_plugins = array();
207 $recent_plugins = array();
208 $recently_activated = (array)get_option('recently_activated');
210 //Clean out any plugins which were deactivated over a week ago.
211 foreach( $recently_activated as $key => $time )
212 if( $time + (7*24*60*60) < time() ) //1 week
213 unset($recently_activated[ $key ]);
214 if( $recently_activated != get_option('recently_activated') ) //If array changed, update it.
215 update_option('recently_activated', $recently_activated);
217 $plugins_allowedtags = array('a' => array('href' => array(),'title' => array()),'abbr' => array('title' => array()),'acronym' => array('title' => array()),'code' => array(),'em' => array(),'strong' => array());
219 foreach( (array)$all_plugins as $plugin_file => $plugin_data) {
221 // Sanitize all displayed data
222 $plugin_data['Title'] = wp_kses($plugin_data['Title'], $plugins_allowedtags);
223 $plugin_data['Version'] = wp_kses($plugin_data['Version'], $plugins_allowedtags);
224 $plugin_data['Description'] = wp_kses($plugin_data['Description'], $plugins_allowedtags);
225 $plugin_data['Author'] = wp_kses($plugin_data['Author'], $plugins_allowedtags);
226 if( ! empty($plugin_data['Author']) )
227 $plugin_data['Description'] .= ' <cite>' . sprintf( __('By %s'), $plugin_data['Author'] ) . '.</cite>';
229 //Filter into individual sections
230 if ( is_plugin_active($plugin_file) ) {
231 $active_plugins[ $plugin_file ] = $plugin_data;
233 if ( isset( $recently_activated[ $plugin_file ] ) ) //Was the plugin recently activated?
234 $recent_plugins[ $plugin_file ] = $plugin_data;
236 $inactive_plugins[ $plugin_file ] = $plugin_data;
243 function print_plugins_table($plugins, $context = '') {
245 <table class="widefat" id="<?php echo $context ?>-plugins-table">
248 <th scope="col" class="check-column"><input type="checkbox" /></th>
249 <th scope="col"><?php _e('Plugin'); ?></th>
250 <th scope="col" class="num"><?php _e('Version'); ?></th>
251 <th scope="col"><?php _e('Description'); ?></th>
252 <th scope="col" class="action-links"><?php _e('Action'); ?></th>
255 <tbody class="plugins">
258 if( empty($plugins) ) {
260 <td colspan="6">' . __('No plugins to show') . '</td>
263 foreach( (array)$plugins as $plugin_file => $plugin_data) {
264 $action_links = array();
266 if( 'active' == $context )
267 $action_links[] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&plugin=' . $plugin_file, 'deactivate-plugin_' . $plugin_file) . '" title="' . __('Deactivate this plugin') . '" class="delete">' . __('Deactivate') . '</a>';
268 else //Available or Recently deactivated
269 $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>';
271 if ( current_user_can('edit_plugins') && is_writable(WP_PLUGIN_DIR . '/' . $plugin_file) )
272 $action_links[] = '<a href="plugin-editor.php?file=' . $plugin_file . '" title="' . __('Open this file in the Plugin Editor') . '" class="edit">' . __('Edit') . '</a>';
274 $action_links = apply_filters('plugin_action_links', $action_links, $plugin_file, $plugin_data, $context);
277 <tr class='$context'>
278 <th scope='row' class='check-column'><input type='checkbox' name='checked[]' value='" . attribute_escape($plugin_file) . "' /></th>
279 <td class='name'>{$plugin_data['Title']}</td>
280 <td class='vers'>{$plugin_data['Version']}</td>
281 <td class='desc'><p>{$plugin_data['Description']}</p></td>
282 <td class='togl action-links'>";
283 if ( !empty($action_links) )
284 echo implode(' | ', $action_links);
287 do_action( 'after_plugin_row', $plugin_file, $plugin_data, $context );
293 } //End print_plugins_table()
296 <?php if ( ! empty($active_plugins) ) : ?>
297 <h3 id="currently-active"><?php _e('Currently Active Plugins') ?></h3>
298 <form method="post" action="<?php echo admin_url('plugins.php') ?>">
299 <?php wp_nonce_field('bulk-manage-plugins') ?>
301 <div class="tablenav">
302 <div class="alignleft">
303 <input type="submit" name="deactivate-selected" value="<?php _e('Deactivate') ?>" class="button-secondary" />
307 <?php print_plugins_table($active_plugins, 'active') ?>
310 <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>
313 <?php if ( ! empty($recent_plugins) ) : ?>
314 <h3 id="recent-plugins"><?php _e('Recently Active Plugins') ?></h3>
315 <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>
316 <form method="post" action="<?php echo admin_url('plugins.php') ?>">
317 <?php wp_nonce_field('bulk-manage-plugins') ?>
319 <div class="tablenav">
320 <div class="alignleft">
321 <input type="submit" name="activate-selected" value="<?php _e('Activate') ?>" class="button-secondary" />
322 <?php if( current_user_can('delete_plugins') ) : ?>
323 <input type="submit" name="delete-selected" value="<?php _e('Delete') ?>" class="button-secondary" />
325 <input type="submit" name="clear-recent-list" value="<?php _e('Clear List') ?>" class="button-secondary" />
329 <?php print_plugins_table($recent_plugins, 'recent') ?>
333 <?php if ( ! empty($inactive_plugins) ) : ?>
334 <h3 id="inactive-plugins"><?php _e('Inactive Plugins') ?></h3>
335 <form method="post" action="<?php echo admin_url('plugins.php') ?>">
336 <?php wp_nonce_field('bulk-manage-plugins') ?>
338 <div class="tablenav">
339 <div class="alignleft">
340 <input type="submit" name="activate-selected" value="<?php _e('Activate') ?>" class="button-secondary" />
341 <?php if( current_user_can('delete_plugins') ) : ?>
342 <input type="submit" name="delete-selected" value="<?php _e('Delete') ?>" class="button-secondary" />
347 <?php print_plugins_table($inactive_plugins, 'inactive') ?>
351 <?php if ( empty($all_plugins) ) : ?>
352 <p><?php _e('You do not appear to have any plugins available at this time.') ?></p>
355 <h2><?php _e('Get More Plugins'); ?></h2>
356 <p><?php _e('You can find additional plugins for your site in the <a href="http://wordpress.org/extend/plugins/">WordPress plugin directory</a>.'); ?></p>
357 <p><?php printf(__('To install a plugin you generally just need to upload the plugin file into your <code>%s</code> directory. Once a plugin is uploaded, you may activate it here.'), WP_PLUGIN_DIR); ?></p>
362 include('admin-footer.php');