Plugin reactivation. Props dougal. see #4176
git-svn-id: http://svn.automattic.com/wordpress/trunk@6580 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
3388050bf9
commit
cf879c0c55
|
@ -86,17 +86,17 @@ function get_plugins() {
|
|||
return $wp_plugins;
|
||||
}
|
||||
|
||||
function activate_plugin($plugin) {
|
||||
function activate_plugin($plugin, $redirect = '') {
|
||||
$current = get_option('active_plugins');
|
||||
$plugin = trim($plugin);
|
||||
|
||||
if ( validate_file($plugin) )
|
||||
return new WP_Error('plugin_invalid', __('Invalid plugin.'));
|
||||
if ( ! file_exists(ABSPATH . PLUGINDIR . '/' . $plugin) )
|
||||
return new WP_Error('plugin_not_found', __('Plugin file does not exist.'));
|
||||
$valid = validate_plugin($plugin);
|
||||
if ( is_wp_error($valid) )
|
||||
return $valid;
|
||||
|
||||
if (!in_array($plugin, $current)) {
|
||||
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 error
|
||||
if ( !in_array($plugin, $current) ) {
|
||||
if ( !empty($redirect) )
|
||||
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
|
||||
ob_start();
|
||||
@include(ABSPATH . PLUGINDIR . '/' . $plugin);
|
||||
$current[] = $plugin;
|
||||
|
@ -112,10 +112,10 @@ function activate_plugin($plugin) {
|
|||
function deactivate_plugins($plugins) {
|
||||
$current = get_option('active_plugins');
|
||||
|
||||
if(!is_array($plugins))
|
||||
if ( !is_array($plugins) )
|
||||
$plugins = array($plugins);
|
||||
|
||||
foreach($plugins as $plugin) {
|
||||
foreach ( $plugins as $plugin ) {
|
||||
array_splice($current, array_search( $plugin, $current), 1 ); // Array-fu!
|
||||
do_action('deactivate_' . trim( $plugin ));
|
||||
}
|
||||
|
@ -125,7 +125,69 @@ function deactivate_plugins($plugins) {
|
|||
|
||||
function deactivate_all_plugins() {
|
||||
$current = get_option('active_plugins');
|
||||
if ( empty($current) )
|
||||
return;
|
||||
|
||||
deactivate_plugins($current);
|
||||
|
||||
update_option('deactivated_plugins', $current);
|
||||
}
|
||||
|
||||
function reactivate_all_plugins($redirect = '') {
|
||||
$plugins = get_option('deactivated_plugins');
|
||||
|
||||
if ( empty($plugins) )
|
||||
return;
|
||||
|
||||
if ( !empty($redirect) )
|
||||
wp_redirect(add_query_arg('_error_nonce', wp_create_nonce('plugin-activation-error_' . $plugin), $redirect));
|
||||
|
||||
$errors = array();
|
||||
foreach ( (array) $plugins as $plugin ) {
|
||||
$result = activate_plugin($plugin);
|
||||
if ( is_wp_error($result) )
|
||||
$errors[$plugin] = $result;
|
||||
}
|
||||
|
||||
delete_option('deactivated_plugins');
|
||||
|
||||
if ( !empty($errors) )
|
||||
return new WP_Error('plugins_invalid', __('One of the plugins is invalid.'), $errors);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function validate_active_plugins() {
|
||||
$check_plugins = get_option('active_plugins');
|
||||
|
||||
// Sanity check. If the active plugin list is not an array, make it an
|
||||
// empty array.
|
||||
if ( !is_array($check_plugins) ) {
|
||||
update_option('active_plugins', array());
|
||||
return;
|
||||
}
|
||||
|
||||
// If a plugin file does not exist, remove it from the list of active
|
||||
// plugins.
|
||||
foreach ( $check_plugins as $check_plugin ) {
|
||||
if ( !file_exists(ABSPATH . PLUGINDIR . '/' . $check_plugin) ) {
|
||||
$current = get_option('active_plugins');
|
||||
$key = array_search($check_plugin, $current);
|
||||
if ( false !== $key && NULL !== $key ) {
|
||||
unset($current[$key]);
|
||||
update_option('active_plugins', $current);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function validate_plugin($plugin) {
|
||||
if ( validate_file($plugin) )
|
||||
return new WP_Error('plugin_invalid', __('Invalid plugin.'));
|
||||
if ( ! file_exists(ABSPATH . PLUGINDIR . '/' . $plugin) )
|
||||
return new WP_Error('plugin_not_found', __('Plugin file does not exist.'));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
|
|
|
@ -2,59 +2,41 @@
|
|||
require_once('admin.php');
|
||||
|
||||
if ( isset($_GET['action']) ) {
|
||||
if ('activate' == $_GET['action']) {
|
||||
if ( 'activate' == $_GET['action'] ) {
|
||||
check_admin_referer('activate-plugin_' . $_GET['plugin']);
|
||||
$result = activate_plugin($_GET['plugin']);
|
||||
if( is_wp_error( $result ) )
|
||||
$result = activate_plugin($_GET['plugin'], 'plugins.php?error=true&plugin=' . $plugin);
|
||||
if ( is_wp_error( $result ) )
|
||||
wp_die( $result->get_error_message() );
|
||||
wp_redirect('plugins.php?activate=true'); // overrides the ?error=true one above
|
||||
} elseif ('error_scrape' == $_GET['action']) {
|
||||
} elseif ( 'error_scrape' == $_GET['action'] ) {
|
||||
$plugin = trim($_GET['plugin']);
|
||||
check_admin_referer('plugin-activation-error_' . $plugin);
|
||||
if ( validate_file($plugin) )
|
||||
wp_die(__('Invalid plugin.'));
|
||||
if ( ! file_exists(ABSPATH . PLUGINDIR . '/' . $plugin) )
|
||||
wp_die(__('Plugin file does not exist.'));
|
||||
$valid = validate_plugin($plugin);
|
||||
if ( is_wp_error($valid) )
|
||||
wp_die($valid);
|
||||
include(ABSPATH . PLUGINDIR . '/' . $plugin);
|
||||
} elseif ('deactivate' == $_GET['action']) {
|
||||
} elseif ( 'deactivate' == $_GET['action'] ) {
|
||||
check_admin_referer('deactivate-plugin_' . $_GET['plugin']);
|
||||
deactivate_plugins($_GET['plugin']);
|
||||
wp_redirect('plugins.php?deactivate=true');
|
||||
} elseif ($_GET['action'] == 'deactivate-all') {
|
||||
} elseif ( 'deactivate-all' == $_GET['action'] ) {
|
||||
check_admin_referer('deactivate-all');
|
||||
deactivate_all_plugins();
|
||||
wp_redirect('plugins.php?deactivate-all=true');
|
||||
} elseif ('reactivate-all' == $_GET['action']) {
|
||||
check_admin_referer('reactivate-all');
|
||||
reactivate_all_plugins('plugins.php?errors=true');
|
||||
wp_redirect('plugins.php?reactivate-all=true'); // overrides the ?error=true one above
|
||||
}
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
$title = __('Manage Plugins');
|
||||
require_once('admin-header.php');
|
||||
|
||||
// Clean up options
|
||||
// If any plugins don't exist, axe 'em
|
||||
validate_active_plugins();
|
||||
|
||||
$check_plugins = get_option('active_plugins');
|
||||
|
||||
// Sanity check. If the active plugin list is not an array, make it an
|
||||
// empty array.
|
||||
if ( !is_array($check_plugins) ) {
|
||||
$check_plugins = array();
|
||||
update_option('active_plugins', $check_plugins);
|
||||
}
|
||||
|
||||
// If a plugin file does not exist, remove it from the list of active
|
||||
// plugins.
|
||||
foreach ($check_plugins as $check_plugin) {
|
||||
if (!file_exists(ABSPATH . PLUGINDIR . '/' . $check_plugin)) {
|
||||
$current = get_option('active_plugins');
|
||||
$key = array_search($check_plugin, $current);
|
||||
if ( false !== $key && NULL !== $key ) {
|
||||
unset($current[$key]);
|
||||
update_option('active_plugins', $current);
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<?php if ( isset($_GET['error']) ) : ?>
|
||||
|
@ -67,12 +49,16 @@ foreach ($check_plugins as $check_plugin) {
|
|||
}
|
||||
?>
|
||||
</div>
|
||||
<?php elseif ( isset($_GET['errors']) ) : ?>
|
||||
<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>
|
||||
<?php elseif ( isset($_GET['activate']) ) : ?>
|
||||
<div id="message" class="updated fade"><p><?php _e('Plugin <strong>activated</strong>.') ?></p></div>
|
||||
<?php elseif ( isset($_GET['deactivate']) ) : ?>
|
||||
<div id="message" class="updated fade"><p><?php _e('Plugin <strong>deactivated</strong>.') ?></p></div>
|
||||
<?php elseif (isset($_GET['deactivate-all'])) : ?>
|
||||
<div id="message" class="updated fade"><p><?php _e('All plugins <strong>deactivated</strong>.'); ?></p></div>
|
||||
<?php elseif (isset($_GET['reactivate-all'])) : ?>
|
||||
<div id="message" class="updated fade"><p><?php _e('All plugins <strong>reactivated</strong>.'); ?></p></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="wrap">
|
||||
|
@ -148,7 +134,20 @@ if (empty($plugins)) {
|
|||
|
||||
<tr>
|
||||
<td colspan="3"> </td>
|
||||
<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>
|
||||
<td colspan="2" style="width:12em;">
|
||||
<?php
|
||||
$active = get_option('active_plugins');
|
||||
$inactive = get_option('deactivated_plugins');
|
||||
if ( !empty($active) ) {
|
||||
?>
|
||||
<a href="<?php echo wp_nonce_url('plugins.php?action=deactivate-all', 'deactivate-all'); ?>" class="delete"><?php _e('Deactivate All Plugins'); ?></a>
|
||||
<?php
|
||||
} elseif ( empty($active) && !empty($inactive) ) {
|
||||
?>
|
||||
<a href="<?php echo wp_nonce_url('plugins.php?action=reactivate-all', 'reactivate-all'); ?>" class="delete"><?php _e('Reactivate All Plugins'); ?></a>
|
||||
<?php
|
||||
} // endif active/inactive plugin check
|
||||
?>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
|
|
Loading…
Reference in New Issue