Changeset 8049 for trunk/wp-admin/plugins.php
- Timestamp:
- 06/04/2008 06:09:31 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/wp-admin/plugins.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/plugins.php
r7999 r8049 2 2 require_once('admin.php'); 3 3 4 if ( isset($_GET['action']) ) { 5 if ( isset($_GET['plugin']) ) 6 $plugin = trim($_GET['plugin']); 7 8 if ( 'activate' == $_GET['action'] ) { 9 check_admin_referer('activate-plugin_' . $_GET['plugin']); 10 $result = activate_plugin($_GET['plugin'], 'plugins.php?error=true&plugin=' . $plugin); 11 if ( is_wp_error( $result ) ) 12 wp_die( $result->get_error_message() ); 13 wp_redirect('plugins.php?activate=true'); // overrides the ?error=true one above 14 } elseif ( 'error_scrape' == $_GET['action'] ) { 15 check_admin_referer('plugin-activation-error_' . $plugin); 16 $valid = validate_plugin($plugin); 17 if ( is_wp_error($valid) ) 18 wp_die($valid); 19 error_reporting( E_ALL ^ E_NOTICE ); 20 @ini_set('display_errors', true); //Ensure that Fatal errors are displayed. 21 include(WP_PLUGIN_DIR . '/' . $plugin); 22 } elseif ( 'deactivate' == $_GET['action'] ) { 23 check_admin_referer('deactivate-plugin_' . $_GET['plugin']); 24 deactivate_plugins($_GET['plugin']); 25 wp_redirect('plugins.php?deactivate=true'); 26 } elseif ( 'deactivate-all' == $_GET['action'] ) { 27 check_admin_referer('deactivate-all'); 28 deactivate_all_plugins(); 29 wp_redirect('plugins.php?deactivate-all=true'); 30 } elseif ('reactivate-all' == $_GET['action']) { 31 check_admin_referer('reactivate-all'); 32 reactivate_all_plugins('plugins.php?errors=true'); 33 wp_redirect('plugins.php?reactivate-all=true'); // overrides the ?error=true one above 34 } 35 36 exit; 4 $action = ''; 5 foreach( array('activate-selected', 'deactivate-selected', 'delete-selected') as $action_key ) { 6 if( isset($_POST[$action_key]) ) { 7 $action = $action_key; 8 break; 9 } 37 10 } 11 12 if( isset($_GET['action']) ) 13 $action = $_GET['action']; 14 15 $plugin = $_REQUEST['plugin']; 16 17 if( !empty($action) ) { 18 switch( $action ) { 19 case 'activate': 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); 28 } 29 wp_redirect('plugins.php?activate=true'); // overrides the ?error=true one above 30 exit; 31 break; 32 case 'activate-selected': 33 check_admin_referer('mass-manage-plugins'); 34 activate_plugins($_POST['checked'], 'plugins.php?error=true'); 35 36 $recent = (array)get_option('recently_activated'); 37 foreach( (array)$_POST['checked'] as $plugin => $time) { 38 if( isset($recent[ $plugin ]) ) 39 unset($recent[ $plugin ]); 40 } 41 if( $recent != get_option('recently_activated') ) //If array changed, update it. 42 update_option('recently_activated', $recent); 43 44 wp_redirect('plugins.php?activate-multi=true'); 45 exit; 46 break; 47 case 'error_scrape': 48 check_admin_referer('plugin-activation-error_' . $plugin); 49 $valid = validate_plugin($plugin); 50 if ( is_wp_error($valid) ) 51 wp_die($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); 55 exit; 56 break; 57 case 'deactivate': 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'); 62 exit; 63 break; 64 case 'deactivate-selected': 65 check_admin_referer('mass-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'); 72 exit; 73 break; 74 case 'delete-selected': 75 check_admin_referer('mass-manage-plugins'); 76 $plugins = $_REQUEST['checked']; 77 include(ABSPATH . 'wp-admin/update.php'); 78 79 $title = __('Delete Plugin'); 80 $parent_file = 'plugins.php'; 81 82 $delete_result = delete_plugins($plugins); 83 84 //HACK TIME! 85 // Proper way needed, perhaps get_plugins() to convert to wp_cache_get() any reason why it hasnt allready? 86 // This clears the cached plugin list 87 global $wp_plugins; 88 $wp_plugins = null; 89 90 91 92 //TODO: Implement!.. STAT! 93 break; 94 default: 95 var_dump("Unknown Action $action"); 96 } 97 } 98 99 wp_enqueue_script('admin-forms'); 38 100 39 101 $title = __('Manage Plugins'); … … 47 109 <div id="message" class="updated fade"><p><?php _e('Plugin could not be activated because it triggered a <strong>fatal error</strong>.') ?></p> 48 110 <?php 49 $plugin = trim($_GET['plugin']);50 111 if ( wp_verify_nonce($_GET['_error_nonce'], 'plugin-activation-error_' . $plugin) ) { ?> 51 <iframe style="border:0" width="100%" height="70px" src="<?php bloginfo('wpurl'); ?>/wp-admin/plugins.php?action=error_scrape&plugin=<?php echo attribute_escape($plugin); ?>&_wpnonce=<?php echo attribute_escape($_GET['_error_nonce']); ?>"></iframe>112 <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> 52 113 <?php 53 114 } 54 115 ?> 55 116 </div> 56 <?php elseif ( isset($_GET['errors']) ) : ?> 57 <div id="message" class="updated fade"><p><?php _e('Some plugins could not be reactivated because they triggered a <strong>fatal error</strong>.') ?></p></div> 117 <?php elseif ( 'delete-selected' == $action ) : 118 if ( is_wp_error($delete_result) ) : ?> 119 <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> 120 <?php else : ?> 121 <div id="message" class="updated fade"><p><?php _e('The selected plugins have been <strong>deleted</strong>.'); ?></p></div> 122 <?php endif; ?> 58 123 <?php elseif ( isset($_GET['activate']) ) : ?> 59 124 <div id="message" class="updated fade"><p><?php _e('Plugin <strong>activated</strong>.') ?></p></div> 125 <?php elseif (isset($_GET['activate-multi'])) : ?> 126 <div id="message" class="updated fade"><p><?php _e('Selected plugins <strong>activated</strong>.'); ?></p></div> 60 127 <?php elseif ( isset($_GET['deactivate']) ) : ?> 61 128 <div id="message" class="updated fade"><p><?php _e('Plugin <strong>deactivated</strong>.') ?></p></div> 62 <?php elseif (isset($_GET['deactivate-all'])) : ?> 63 <div id="message" class="updated fade"><p><?php _e('All plugins <strong>deactivated</strong>.'); ?></p></div> 64 <?php elseif (isset($_GET['reactivate-all'])) : ?> 65 <div id="message" class="updated fade"><p><?php _e('Plugins <strong>reactivated</strong>.'); ?></p></div> 129 <?php elseif (isset($_GET['deactivate-multi'])) : ?> 130 <div id="message" class="updated fade"><p><?php _e('Selected plugins <strong>deactivated</strong>.'); ?></p></div> 66 131 <?php endif; ?> 67 132 … … 71 136 <?php 72 137 73 $plugins = get_plugins(); 74 75 if (empty($plugins)) { 76 echo '<p>'; 77 _e("Couldn’t open plugins directory or there are no plugins available."); // TODO: make more helpful 78 echo '</p>'; 79 } else { 80 ?> 138 $active_plugins = array(); 139 $available_plugins = array(); 140 $recent_plugins = array(); 141 $recently_activated = (array)get_option('recently_activated'); 142 143 //Clean out any plugins which were deactivated over a week ago. 144 foreach( $recently_activated as $key => $time ) 145 if( $time + (7*24*60*60) < time() ) //1 week 146 unset($recently_activated[ $key ]); 147 if( $recently_activated != get_option('recently_activated') ) //If array changed, update it. 148 update_option('recently_activated', $recently_activated); 149 150 $all_plugins = get_plugins(); 151 152 $plugins_allowedtags = array('a' => array('href' => array(),'title' => array()),'abbr' => array('title' => array()),'acronym' => array('title' => array()),'code' => array(),'em' => array(),'strong' => array()); 153 154 foreach( (array)$all_plugins as $plugin_file => $plugin_data) { 155 156 // Sanitize all displayed data 157 $plugin_data['Title'] = wp_kses($plugin_data['Title'], $plugins_allowedtags); 158 $plugin_data['Version'] = wp_kses($plugin_data['Version'], $plugins_allowedtags); 159 $plugin_data['Description'] = wp_kses($plugin_data['Description'], $plugins_allowedtags); 160 $plugin_data['Author'] = wp_kses($plugin_data['Author'], $plugins_allowedtags); 161 if( ! empty($plugin_data['Author']) ) 162 $plugin_data['Description'] .= ' <cite>' . sprintf( __('By %s'), $plugin_data['Author'] ) . '.</cite>'; 163 164 if ( is_plugin_active($plugin_file) ) { 165 $active_plugins[ $plugin_file ] = $plugin_data; 166 } else { 167 if ( isset( $recently_activated[ $plugin_file ] ) ) //Was the plugin recently activated? 168 $recent_plugins[ $plugin_file ] = $plugin_data; 169 else 170 $available_plugins[ $plugin_file ] = $plugin_data; 171 } 172 } 173 174 ?> 175 176 <?php 177 function print_plugins_table($plugins, $context = '') { 178 ?> 179 <table class="widefat" id="<?php echo $context ?>-plugins-table"> 180 <thead> 181 <tr> 182 <th scope="col" class="check-column"><input type="checkbox" /></th> 183 <th scope="col"><?php _e('Plugin'); ?></th> 184 <th scope="col" class="num"><?php _e('Version'); ?></th> 185 <th scope="col"><?php _e('Description'); ?></th> 186 <th scope="col" class="action-links"><?php _e('Action'); ?></th> 187 </tr> 188 </thead> 189 <tbody class="plugins"> 190 <?php 191 192 if( empty($plugins) ) { 193 echo '<tr> 194 <td colspan="6">' . __('No plugins to show') . '</td> 195 </tr>'; 196 } 197 foreach( (array)$plugins as $plugin_file => $plugin_data) { 198 $action_links = array(); 199 200 if( 'active' == $context ) 201 $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>'; 202 else //Available or Recently deactivated 203 $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>'; 204 205 if ( current_user_can('edit_plugins') && is_writable(WP_PLUGIN_DIR . '/' . $plugin_file) ) 206 $action_links[] = '<a href="plugin-editor.php?file=' . $plugin_file . '" title="' . __('Open this file in the Plugin Editor') . '" class="edit">' . __('Edit') . '</a>'; 207 208 $action_links = apply_filters('plugin_action_links', $action_links, $plugin_file, $plugin_data, $context); 209 210 echo " 211 <tr class='$context'> 212 <th scope='row' class='check-column'><input type='checkbox' name='checked[]' value='" . attribute_escape($plugin_file) . "' /></th> 213 <td class='name'>{$plugin_data['Title']}</td> 214 <td class='vers'>{$plugin_data['Version']}</td> 215 <td class='desc'><p>{$plugin_data['Description']}</p></td> 216 <td class='togl action-links'>"; 217 if ( !empty($action_links) ) 218 echo implode(' | ', $action_links); 219 echo '</td> 220 </tr>'; 221 do_action( 'after_plugin_row', $plugin_file, $plugin_data, $context ); 222 } 223 ?> 224 </tbody> 225 </table> 226 <?php 227 } //End print_plugins_table() 228 ?> 229 230 <h3 id="currently-active"><?php _e('Currently Active Plugins') ?></h3> 231 <form method="post" action="<?php echo admin_url('plugins.php') ?>"> 232 <?php wp_nonce_field('mass-manage-plugins') ?> 81 233 82 234 <div class="tablenav"> 83 235 <div class="alignleft"> 84 <?php 85 $active = get_option('active_plugins'); 86 $inactive = get_option('deactivated_plugins'); 87 if ( !empty($active) ) { 88 ?> 89 <a class="button-secondary delete" href="<?php echo wp_nonce_url('plugins.php?action=deactivate-all', 'deactivate-all'); ?>"><?php _e('Deactivate All Plugins'); ?></a> 90 <?php 91 } elseif ( empty($active) && !empty($inactive) ) { 92 ?> 93 <a class="button-secondary delete" href="<?php echo wp_nonce_url('plugins.php?action=reactivate-all', 'reactivate-all'); ?>"><?php _e('Reactivate Plugins'); ?></a> 94 <?php 95 } // endif active/inactive plugin check 96 ?> 97 </div> 98 <br class="clear" /> 99 </div> 100 236 <input type="submit" name="deactivate-selected" value="<?php _e('Deactivate') ?>" class="button-secondary" /> 237 </div> 238 </div> 101 239 <br class="clear" /> 102 103 <table class="widefat"> 104 <thead> 105 <tr> 106 <th><?php _e('Plugin'); ?></th> 107 <th class="num"><?php _e('Version'); ?></th> 108 <th><?php _e('Description'); ?></th> 109 <th class="status"><?php _e('Status') ?></th> 110 <th class="action-links"><?php _e('Action'); ?></th> 111 </tr> 112 </thead> 113 <tbody id="plugins"> 114 <?php 115 foreach($plugins as $plugin_file => $plugin_data) { 116 $action_links = array(); 117 118 $style = ''; 119 120 if ( is_plugin_active($plugin_file) ) { 121 $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>"; 122 $style = 'active'; 123 } else { 124 $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>"; 125 } 126 if ( current_user_can('edit_plugins') && is_writable(WP_PLUGIN_DIR . '/' . $plugin_file) ) 127 $action_links[] = "<a href='plugin-editor.php?file=$plugin_file' title='".__('Open this file in the Plugin Editor')."' class='edit'>".__('Edit')."</a>"; 128 129 $plugins_allowedtags = array('a' => array('href' => array(),'title' => array()),'abbr' => array('title' => array()),'acronym' => array('title' => array()),'code' => array(),'em' => array(),'strong' => array()); 130 131 // Sanitize all displayed data 132 $plugin_data['Title'] = wp_kses($plugin_data['Title'], $plugins_allowedtags); 133 $plugin_data['Version'] = wp_kses($plugin_data['Version'], $plugins_allowedtags); 134 $plugin_data['Description'] = wp_kses($plugin_data['Description'], $plugins_allowedtags); 135 $plugin_data['Author'] = wp_kses($plugin_data['Author'], $plugins_allowedtags); 136 $author = ( empty($plugin_data['Author']) ) ? '' : ' <cite>' . sprintf( __('By %s'), $plugin_data['Author'] ) . '.</cite>'; 137 138 if ( $style != '' ) 139 $style = ' class="' . $style . '"'; 140 141 $action_links = apply_filters('plugin_action_links', $action_links, $plugin_file, $plugin_info); 142 143 echo " 144 <tr$style> 145 <td class='name'>{$plugin_data['Title']}</td> 146 <td class='vers'>{$plugin_data['Version']}</td> 147 <td class='desc'><p>{$plugin_data['Description']}$author</p></td> 148 <td class='status'>"; 149 if ( is_plugin_active($plugin_file) ) 150 echo __('<span class="active">Active</span>'); 151 else 152 _e('<span class="inactive">Inactive</span>'); 153 echo "</td> 154 <td class='togl action-links'>$toggle"; 155 if ( !empty($action_links) ) 156 echo implode(' | ', $action_links); 157 echo "</td> 158 </tr>"; 159 do_action( 'after_plugin_row', $plugin_file ); 160 } 161 ?> 162 </tbody> 163 </table> 164 165 <?php 166 } 167 ?> 240 <?php print_plugins_table($active_plugins, 'active') ?> 241 </form> 168 242 169 243 <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> 244 245 <?php if ( ! empty($recent_plugins) ) : ?> 246 <h3 id="recent-plugins"><?php _e('Recently Active Plugins') ?></h3> 247 <form method="post" action="<?php echo admin_url('plugins.php') ?>"> 248 <?php wp_nonce_field('mass-manage-plugins') ?> 249 250 <div class="tablenav"> 251 <div class="alignleft"> 252 <input type="submit" name="activate-selected" value="<?php _e('Activate') ?>" class="button-secondary" /> 253 <?php if( current_user_can('edit_plugins') ) : ?> 254 <input type="submit" name="delete-selected" value="<?php _e('Delete') ?>" class="button-secondary" /> 255 <?php endif; ?> 256 </div> 257 </div> 258 <br class="clear" /> 259 <?php print_plugins_table($recent_plugins, 'recent') ?> 260 </form> 261 <?php endif; ?> 262 263 <h3 id="available-plugins"><?php _e('Available Plugins') ?></h3> 264 <form method="post" action="<?php echo admin_url('plugins.php') ?>"> 265 <?php wp_nonce_field('mass-manage-plugins') ?> 266 267 <div class="tablenav"> 268 <div class="alignleft"> 269 <input type="submit" name="activate-selected" value="<?php _e('Activate') ?>" class="button-secondary" /> 270 <?php if( current_user_can('edit_plugins') ) : ?> 271 <input type="submit" name="delete-selected" value="<?php _e('Delete') ?>" class="button-secondary" /> 272 <?php endif; ?> 273 </div> 274 </div> 275 <br class="clear" /> 276 <?php print_plugins_table($available_plugins, 'available') ?> 277 </form> 170 278 171 279 <h2><?php _e('Get More Plugins'); ?></h2>
Note: See TracChangeset
for help on using the changeset viewer.