Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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 –  m0r7if3r 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

1 Answer 1

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

 
discard

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.