Changeset 6580
- Timestamp:
- 01/09/2008 09:37:27 AM (17 years ago)
- Location:
- trunk/wp-admin
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/plugin.php
r6354 r6580 87 87 } 88 88 89 function activate_plugin($plugin ) {89 function activate_plugin($plugin, $redirect = '') { 90 90 $current = get_option('active_plugins'); 91 91 $plugin = trim($plugin); 92 92 93 if ( validate_file($plugin) )94 return new WP_Error('plugin_invalid', __('Invalid plugin.'));95 if ( ! file_exists(ABSPATH . PLUGINDIR . '/' . $plugin) )96 return new WP_Error('plugin_not_found', __('Plugin file does not exist.')); 97 98 if (!in_array($plugin, $current)) {99 wp_redirect(add_query_arg('_error_nonce', wp_create_nonce('plugin-activation-error_' . $plugin), 'plugins.php?error=true&plugin=' . $plugin)); // we'll override this later if the plugin can be included without fatal error93 $valid = validate_plugin($plugin); 94 if ( is_wp_error($valid) ) 95 return $valid; 96 97 if ( !in_array($plugin, $current) ) { 98 if ( !empty($redirect) ) 99 wp_redirect(add_query_arg('_error_nonce', wp_create_nonce('plugin-activation-error_' . $plugin), $redirect)); // we'll override this later if the plugin can be included without fatal error 100 100 ob_start(); 101 101 @include(ABSPATH . PLUGINDIR . '/' . $plugin); … … 113 113 $current = get_option('active_plugins'); 114 114 115 if (!is_array($plugins))115 if ( !is_array($plugins) ) 116 116 $plugins = array($plugins); 117 117 118 foreach ($plugins as $plugin) {118 foreach ( $plugins as $plugin ) { 119 119 array_splice($current, array_search( $plugin, $current), 1 ); // Array-fu! 120 120 do_action('deactivate_' . trim( $plugin )); … … 126 126 function deactivate_all_plugins() { 127 127 $current = get_option('active_plugins'); 128 if ( empty($current) ) 129 return; 130 128 131 deactivate_plugins($current); 132 133 update_option('deactivated_plugins', $current); 134 } 135 136 function reactivate_all_plugins($redirect = '') { 137 $plugins = get_option('deactivated_plugins'); 138 139 if ( empty($plugins) ) 140 return; 141 142 if ( !empty($redirect) ) 143 wp_redirect(add_query_arg('_error_nonce', wp_create_nonce('plugin-activation-error_' . $plugin), $redirect)); 144 145 $errors = array(); 146 foreach ( (array) $plugins as $plugin ) { 147 $result = activate_plugin($plugin); 148 if ( is_wp_error($result) ) 149 $errors[$plugin] = $result; 150 } 151 152 delete_option('deactivated_plugins'); 153 154 if ( !empty($errors) ) 155 return new WP_Error('plugins_invalid', __('One of the plugins is invalid.'), $errors); 156 157 return true; 158 } 159 160 function validate_active_plugins() { 161 $check_plugins = get_option('active_plugins'); 162 163 // Sanity check. If the active plugin list is not an array, make it an 164 // empty array. 165 if ( !is_array($check_plugins) ) { 166 update_option('active_plugins', array()); 167 return; 168 } 169 170 // If a plugin file does not exist, remove it from the list of active 171 // plugins. 172 foreach ( $check_plugins as $check_plugin ) { 173 if ( !file_exists(ABSPATH . PLUGINDIR . '/' . $check_plugin) ) { 174 $current = get_option('active_plugins'); 175 $key = array_search($check_plugin, $current); 176 if ( false !== $key && NULL !== $key ) { 177 unset($current[$key]); 178 update_option('active_plugins', $current); 179 } 180 } 181 } 182 } 183 184 function validate_plugin($plugin) { 185 if ( validate_file($plugin) ) 186 return new WP_Error('plugin_invalid', __('Invalid plugin.')); 187 if ( ! file_exists(ABSPATH . PLUGINDIR . '/' . $plugin) ) 188 return new WP_Error('plugin_not_found', __('Plugin file does not exist.')); 189 190 return 0; 129 191 } 130 192 -
trunk/wp-admin/plugins.php
r6259 r6580 3 3 4 4 if ( isset($_GET['action']) ) { 5 if ( 'activate' == $_GET['action']) {5 if ( 'activate' == $_GET['action'] ) { 6 6 check_admin_referer('activate-plugin_' . $_GET['plugin']); 7 $result = activate_plugin($_GET['plugin'] );8 if ( is_wp_error( $result ) )7 $result = activate_plugin($_GET['plugin'], 'plugins.php?error=true&plugin=' . $plugin); 8 if ( is_wp_error( $result ) ) 9 9 wp_die( $result->get_error_message() ); 10 10 wp_redirect('plugins.php?activate=true'); // overrides the ?error=true one above 11 } elseif ( 'error_scrape' == $_GET['action']) {11 } elseif ( 'error_scrape' == $_GET['action'] ) { 12 12 $plugin = trim($_GET['plugin']); 13 13 check_admin_referer('plugin-activation-error_' . $plugin); 14 if ( validate_file($plugin) ) 15 wp_die(__('Invalid plugin.')); 16 if ( ! file_exists(ABSPATH . PLUGINDIR . '/' . $plugin) ) 17 wp_die(__('Plugin file does not exist.')); 14 $valid = validate_plugin($plugin); 15 if ( is_wp_error($valid) ) 16 wp_die($valid); 18 17 include(ABSPATH . PLUGINDIR . '/' . $plugin); 19 } elseif ( 'deactivate' == $_GET['action']) {18 } elseif ( 'deactivate' == $_GET['action'] ) { 20 19 check_admin_referer('deactivate-plugin_' . $_GET['plugin']); 21 20 deactivate_plugins($_GET['plugin']); 22 21 wp_redirect('plugins.php?deactivate=true'); 23 } elseif ( $_GET['action'] == 'deactivate-all') {22 } elseif ( 'deactivate-all' == $_GET['action'] ) { 24 23 check_admin_referer('deactivate-all'); 25 24 deactivate_all_plugins(); 26 25 wp_redirect('plugins.php?deactivate-all=true'); 26 } elseif ('reactivate-all' == $_GET['action']) { 27 check_admin_referer('reactivate-all'); 28 reactivate_all_plugins('plugins.php?errors=true'); 29 wp_redirect('plugins.php?reactivate-all=true'); // overrides the ?error=true one above 27 30 } 31 28 32 exit; 29 33 } … … 32 36 require_once('admin-header.php'); 33 37 34 // Clean up options 35 // If any plugins don't exist, axe 'em 38 validate_active_plugins(); 36 39 37 $check_plugins = get_option('active_plugins');38 39 // Sanity check. If the active plugin list is not an array, make it an40 // empty array.41 if ( !is_array($check_plugins) ) {42 $check_plugins = array();43 update_option('active_plugins', $check_plugins);44 }45 46 // If a plugin file does not exist, remove it from the list of active47 // plugins.48 foreach ($check_plugins as $check_plugin) {49 if (!file_exists(ABSPATH . PLUGINDIR . '/' . $check_plugin)) {50 $current = get_option('active_plugins');51 $key = array_search($check_plugin, $current);52 if ( false !== $key && NULL !== $key ) {53 unset($current[$key]);54 update_option('active_plugins', $current);55 }56 }57 }58 40 ?> 59 41 … … 68 50 ?> 69 51 </div> 52 <?php elseif ( isset($_GET['errors']) ) : ?> 53 <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> 70 54 <?php elseif ( isset($_GET['activate']) ) : ?> 71 55 <div id="message" class="updated fade"><p><?php _e('Plugin <strong>activated</strong>.') ?></p></div> … … 74 58 <?php elseif (isset($_GET['deactivate-all'])) : ?> 75 59 <div id="message" class="updated fade"><p><?php _e('All plugins <strong>deactivated</strong>.'); ?></p></div> 60 <?php elseif (isset($_GET['reactivate-all'])) : ?> 61 <div id="message" class="updated fade"><p><?php _e('All plugins <strong>reactivated</strong>.'); ?></p></div> 76 62 <?php endif; ?> 77 63 … … 149 135 <tr> 150 136 <td colspan="3"> </td> 151 <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> 137 <td colspan="2" style="width:12em;"> 138 <?php 139 $active = get_option('active_plugins'); 140 $inactive = get_option('deactivated_plugins'); 141 if ( !empty($active) ) { 142 ?> 143 <a href="<?php echo wp_nonce_url('plugins.php?action=deactivate-all', 'deactivate-all'); ?>" class="delete"><?php _e('Deactivate All Plugins'); ?></a> 144 <?php 145 } elseif ( empty($active) && !empty($inactive) ) { 146 ?> 147 <a href="<?php echo wp_nonce_url('plugins.php?action=reactivate-all', 'reactivate-all'); ?>" class="delete"><?php _e('Reactivate All Plugins'); ?></a> 148 <?php 149 } // endif active/inactive plugin check 150 ?> 152 151 </tr> 153 152
Note: See TracChangeset
for help on using the changeset viewer.