Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin
Created December 27, 2016 14:32
Show Gist options
  • Save tommcfarlin/1096d100351054b84ec778a516dde2f6 to your computer and use it in GitHub Desktop.
Save tommcfarlin/1096d100351054b84ec778a516dde2f6 to your computer and use it in GitHub Desktop.
[WordPress] Control Activation of a WooCommerce Extension
<?php
class Extension_For_WooCommerce {
public function init() {
add_action( 'admin_init', array( $this, 'start' ) );
add_action( 'admin_init', array( $this, 'stop' ) );
}
}
<?php
private function woocommerce_is_active() {
return is_plugin_active( 'woocommerce/woocommerce.php' );
}
<?php
public function start() {
if ( ! $this->woocommerce_is_active() ) {
return;
}
// Load dependencies.
}
<?php
public function stop() {
if ( ! $this->woocommerce_is_active() ) {
deactivate_plugins( plugin_basename( __FILE__ ) );
unset( $_GET['activate'] ); // Input var okay.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment