Opened 17 years ago
Closed 17 years ago
#6332 closed defect (bug) (fixed)
deactivate_plugins() bug (wp-admin/include/plugins.php)
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | 2.5 | Priority: | low |
Severity: | minor | Version: | 2.5 |
Component: | Administration | Keywords: | |
Focuses: | Cc: |
Description
there's an issue with the Array-fu! stuff:
$plugin = 'invalid_plugin.php'; $current = array('active_plugin.php'); var_dump($current); // array('active_plugin.php') array_splice($current, array_search( $plugin, $current), 1 ); // Array-fu! var_dump($current); // array()
this line:
array_splice($current, array_search( $plugin, $current), 1 ); // Array-fu!
should be replaced by:
if ( ( $key = array_search( $plugin, $current) ) !== false ) array_splice($current, $key, 1 ); // Fixed Array-fu!
as it stands, deactivating an invalid plugin removes the first plugin from the list. and deactivating a whole list of invalid plugins produces unpredictable results.
Attachments (2)
Change History (12)
#1
@
17 years ago
- Summary changed from deactivate_plugins() bug (file: / wp-admin/include/plugins.php) to activate_plugin() and deactivate_plugins() bugs (file: / wp-admin/include/plugins.php)
#2
@
17 years ago
- Summary changed from activate_plugin() and deactivate_plugins() bugs (file: / wp-admin/include/plugins.php) to deactivate_plugins() bug (wp-admin/include/plugins.php)
Nevermind the comment on activate_plugin(). I was mistaking, the check is done already.
#6
@
17 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
The fix may not have been needed.
The code Denis-de-Bernardy quoted, just so happens to be pre-[7416], which was supposed to fix that.
As it stands, Denis-de-Bernardy's patch never comes into play, if the function gets to that stage, array_search() has allready been perfomed and checked its not false.
#7
@
17 years ago
attachment 6332.diff added.
Use is_plugin_active() instead. Also removed double-searching from the code from [7456]
var_dump(get_option('active_plugins')); deactivate_plugins('false.php'); var_dump(get_option('active_plugins')); array 0 => string 'add-from-server/add-from-server.php' (length=35) 1 => string 'erm.php' (length=7) 2 => string 'php-run/php-run.php' (length=19) 3 => string 'remove-max-width/remove-max-width.php' (length=37) array 0 => string 'add-from-server/add-from-server.php' (length=35) 1 => string 'erm.php' (length=7) 2 => string 'php-run/php-run.php' (length=19) 3 => string 'remove-max-width/remove-max-width.php' (length=37)
#9
@
17 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
(In [7456]) Better plugin-deactivation array-fu from Denis-de-Bernardy. fixes #6332
Turns out that killed the plugins editor deactivation routines.
I've updated the plugins editor to use plugin API's instead in the process to work out the problem, So i'm going to attach the full changes instead of the single line.
See Patch.
other issue in this area of the WP code. unless I'm mistaking, activating a plugin that is already active will generate an error. to fix, replace this line in activate_plugin():
@include(ABSPATH . PLUGINDIR . '/' . $plugin); error: cannot redeclare function/class
with:
@include_once(ABSPATH . PLUGINDIR . '/' . $plugin); no error
and/or, check if the plugin isn't active already before going through the entire procedure.