Changeset 6580 for trunk/wp-admin/includes/plugin.php
- Timestamp:
- 01/09/2008 09:37:27 AM (18 years ago)
- File:
-
- 1 edited
-
trunk/wp-admin/includes/plugin.php (modified) (3 diffs)
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
Note: See TracChangeset
for help on using the changeset viewer.