Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[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