WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My plugin only installs correctly if the user first deactivates and then deletes a previously installed version. If they do not delete the previous version, the installation either does not complete or the plugin, once installed, does not work.

Although it would be nice to get at the heart of why this is occurring, it seems like for best user experience anyway the plugin should automatically deactivate and remove previous versions upon installation. Is this possible?

share|improve this question
possible duplicate of How to check if certain plugin exists and in expected version – mor7ifer Feb 28 '12 at 1:25
@m0r7if3r That is certainly relevant and a part of my question, but I'm trying to get at how to deactivate and remove the old plugin before (or when) the new plugin installs – josh Feb 28 '12 at 22:55

Quick and easy.

if ( is_plugin_active( 'plugin-folder-name/main-plugin-file.php' ) )
    deactivate_plugins( '/plugin-folder-name/main-plugin-file.php' );

It's important to note the is_plugin_active string is slightly different than the deactivate_plugins string.

share|improve this answer
Thanks, Matthew! This deactivates the plugin... would I then want to uninstall_plugins( '/plugin-folder-name/main-plugin-file.php' ); ? – josh Mar 9 '12 at 18:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.