Ticket #4176: reactivate-plugins.2.diff
File reactivate-plugins.2.diff, 5.6 KB (added by , 17 years ago) |
---|
-
wp-admin/plugins.php
11 11 if ( ! file_exists(ABSPATH . PLUGINDIR . '/' . $plugin) ) 12 12 wp_die(__('Plugin file does not exist.')); 13 13 if (!in_array($plugin, $current)) { 14 wp_redirect('plugins.php?error=true '); // we'll override this later if the plugin can be included without fatal error14 wp_redirect('plugins.php?error=true&plugin='.urlencode($plugin)); // we'll override this later if the plugin can be included without fatal error 15 15 ob_start(); 16 16 @include(ABSPATH . PLUGINDIR . '/' . $plugin); 17 17 $current[] = $plugin; … … 21 21 ob_end_clean(); 22 22 } 23 23 wp_redirect('plugins.php?activate=true'); // overrides the ?error=true one above 24 } else 24 } elseif ('deactivate' == $_GET['action']) { 25 25 check_admin_referer('deactivate-plugin_' . $_GET['plugin']); 26 26 $current = get_option('active_plugins'); 27 27 array_splice($current, array_search( $_GET['plugin'], $current), 1 ); // Array-fu! 28 28 update_option('active_plugins', $current); 29 29 do_action('deactivate_' . trim( $_GET['plugin'] )); 30 30 wp_redirect('plugins.php?deactivate=true'); 31 } elseif ( $_GET['action'] == 'deactivate-all') {31 } elseif ('deactivate-all' == $_GET['action']) { 32 32 check_admin_referer('deactivate-all'); 33 33 $current = get_option('active_plugins'); 34 34 35 35 foreach ($current as $plugin) { 36 array_splice($current, array_search($plugin, $current), 1);37 36 do_action('deactivate_' . $plugin); 38 37 } 39 38 40 39 update_option('active_plugins', array()); 40 update_option('deactivated_plugins', $current); 41 41 wp_redirect('plugins.php?deactivate-all=true'); 42 } elseif ('reactivate-all' == $_GET['action']) { 43 check_admin_referer('reactivate-all'); 44 $prev_plugins = get_option('deactivated_plugins'); 45 $current = array(); 46 $errors = array(); 47 48 // We'll keep track of errors in the $errors array, 49 // and report them after we're done. 50 foreach ($prev_plugins as $plugin) { 51 if ( validate_file($plugin) ) 52 $errors[$plugin] = __('Invalid plugin.'); 53 elseif ( ! file_exists(ABSPATH . PLUGINDIR . '/' . $plugin) ) 54 $errors[$plugin] = __('Plugin file does not exist.'); 55 elseif (!in_array($plugin, $current)) { 56 // A fatal error in any one plugin means NO 57 // plugins will be reactivated. Sorry, but that's 58 // just the way it is. :-/ 59 wp_redirect('plugins.php?error=true&plugin='.urlencode($plugin)); // we'll override this later if the plugin can be included without fatal error 60 $errors[$plugin] = __('Plugin generated a fatal error.'); // we'll override this later if the plugin can be included without fatal error 61 ob_start(); 62 @include(ABSPATH . PLUGINDIR . '/' . $plugin); 63 $current[] = $plugin; 64 do_action('activate_' . $plugin); 65 unset($errors[$plugin]); 66 ob_end_clean(); 67 } 68 } 69 70 sort($current); 71 72 update_option('deactivated_plugins', array()); 73 update_option('active_plugins', $current); 74 update_option('problem_plugins', $errors); 75 wp_redirect('plugins.php?reactivate-all=true'); // overrides the ?error=true one above 76 42 77 } 43 78 exit; 44 79 } … … 73 108 ?> 74 109 75 110 <?php if ( isset($_GET['error']) ) : ?> 76 <div id="message" class="updated fade"><p><?php _e('Plugin could not be activated because it triggered a <strong>fatal error</strong>.') ?></p></div> 111 <?php 112 $plugin = $_GET['plugin']; 113 $plugin = wp_specialchars($plugin); 114 ?> 115 <div id="message" class="updated fade"><p><?php _e('Plugin could not be activated because it triggered a <strong>fatal error</strong>. ('. $plugin . ')') ?></p></div> 77 116 <?php elseif ( isset($_GET['activate']) ) : ?> 78 117 <div id="message" class="updated fade"><p><?php _e('Plugin <strong>activated</strong>.') ?></p></div> 79 118 <?php elseif ( isset($_GET['deactivate']) ) : ?> 80 119 <div id="message" class="updated fade"><p><?php _e('Plugin <strong>deactivated</strong>.') ?></p></div> 81 120 <?php elseif (isset($_GET['deactivate-all'])) : ?> 82 121 <div id="message" class="updated fade"><p><?php _e('All plugins <strong>deactivated</strong>.'); ?></p></div> 122 <?php elseif (isset($_GET['reactivate-all'])) : ?> 123 <div id="message" class="updated fade"> 124 <p><?php _e('All plugins <strong>reactivated</strong>.'); ?></p> 125 <?php 126 $errors = get_option('problem_plugins'); 127 if (! empty($errors)) { 128 // Display any errors: 129 ?> 130 <p><?php _e('The following plugins generated errors:'); ?></p> 131 <ul> 132 <?php foreach ($errors as $plugin => $errmsg) { 133 ?> 134 <li><?php echo $plugin . ': ' . $errmsg ?></li> 135 <?php 136 } 137 ?> 138 </ul> 139 <?php 140 } 141 ?> 142 </div> 83 143 <?php endif; ?> 84 144 85 145 <div class="wrap"> … … 152 212 153 213 <tr> 154 214 <td colspan="3"> </td> 155 <td colspan="2" style="width:12em;"><a href="<?php echo wp_nonce_url('plugins.php?action=deactivate-all', 'deactivate-all'); ?>" class="delete"><?php _e('Deactivate All Plugins'); ?></a></td> 215 <td colspan="2" style="width:12em;"> 216 <?php 217 $active = get_option('active_plugins'); 218 $inactive = get_option('deactivated_plugins'); 219 if (!empty($active)) { 220 ?> 221 <a href="<?php echo wp_nonce_url('plugins.php?action=deactivate-all', 'deactivate-all'); ?>" class="delete"><?php _e('Deactivate All Plugins'); ?></a> 222 <?php 223 } elseif (empty($active) && !empty($inactive)) { 224 ?> 225 <a href="<?php echo wp_nonce_url('plugins.php?action=reactivate-all', 'reactivate-all'); ?>" class="delete"><?php _e('Reactivate All Plugins'); ?></a> 226 <?php 227 } // endif active/inactive plugin check 228 ?> 229 </td> 156 230 </tr> 157 231 158 232 </table>