Last active
August 29, 2015 13:56
-
-
Save wpsmith/9172230 to your computer and use it in GitHub Desktop.
PHP: Deactivates a plugin (itself) if another plugin (plugin parent) is deactivated.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'update_option_active_sitewide_plugins', 'pluginprefix_deactivate_self', 10, 2 ); | |
add_action( 'update_option_active_plugins', 'pluginprefix_deactivate_self', 10, 2 ); | |
/** | |
* Deactivate ourself if Addthis is deactivated. | |
* | |
* @param mixed $old_value The old option value. | |
* @param mixed $value The new option value. | |
*/ | |
function pluginprefix_deactivate_self( $plugin, $network_deactivating ) { | |
// The parameter/argument is the plugin basename for the parent plugin | |
// In this case, we are watching the AddThis plugin | |
// Note, this code will not work if the folder uploaded is a different slug (e.g., uploaded manually with custom folder name) | |
_wps_deactivate_self( 'addthis/addthis_social_widget.php' ); | |
} | |
if ( !function_exists( '_wps_deactivate_self' ) ) { | |
/** | |
* Deactivate ourself if parent plugin is deactivated. | |
* | |
* @param string $plugin_basename Plugin basename of the parent plugin. | |
*/ | |
function _wps_deactivate_self( $plugin_basename ) { | |
// Check if parent plugin is active | |
if ( !is_plugin_active( $plugin_basename ) ) { | |
// Parent is not active, so let's deactivate | |
deactivate_plugins( plugin_basename( __FILE__ ), true ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment