This script was generated in response to a thread on the wp-hackers mailing list.
The question at hand is how to make one plugin dependant on another plugin’s installation and activation while maintaining the use of the register_activation_hook() function.
The following code is a proof of concept. It can be improved and will be improved after I get through with WordCampRDU this weekend. I slapped it out while on a 2 1/2 hour phone call with a client and only had time to confirm it works and post it here.
How to use this proof of concept:
- Copy the code below and paste it into the top of “Hello Dolly”
- Try to activate “Hello Dolly” without “Akismet” activated.
- Activate “Akismet” and try to activate “Hello Dolly”
- Deactivate “Akismet” and confirm that “Hello Dolly” has been deactivated
Still To Do:
- Investigate the active plugins option to see if I can prevent hardcoding the plugin’s file location
- Enable a way to notify the admin that a dependent plugin has been deactivated at the same time the required plugin was deactivated.
- Copy the WordPress Core’s implementation of deactivating a plugin to allow for multiple dependencies and to take advantage of existing action hooks.
The Code: ( a modified hello.php )