Make WordPress Core

Opened 17 years ago

Closed 17 years ago

#6332 closed defect (bug) (fixed)

deactivate_plugins() bug (wp-admin/include/plugins.php)

Reported by: denis-de-bernardy's profile Denis-de-Bernardy 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)

6332.diff (843 bytes) - added by DD32 17 years ago.
use is_plugin_active() instead.
6332.2.diff (5.9 KB) - added by DD32 17 years ago.
updates to utilise internal functions

Download all attachments as: .zip

Change History (12)

#1 @Denis-de-Bernardy
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)

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.

#2 @Denis-de-Bernardy
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.

#3 @markjaquith
17 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [7456]) Better plugin-deactivation array-fu from Denis-de-Bernardy. fixes #6332

#4 @lloydbudd
17 years ago

  • Milestone set to 2.5

#5 @Denis-de-Bernardy
17 years ago

thanks very much!

#6 @DD32
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.

@DD32
17 years ago

use is_plugin_active() instead.

#7 @DD32
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)

#8 @ryan
17 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

(In [7488]) Use is_plugin_active() and remove double searching. Props DD32. fixes #6332

#9 @DD32
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.

@DD32
17 years ago

updates to utilise internal functions

#10 @ryan
17 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

(In [7525]) Fix plugin error scraping in the plugin editor. Props DD32. fixes #6332

Note: See TracTickets for help on using tickets.