Here is my custom plugin code
custom-plugin.php code
<code>include_once FBPE_PLUGIN_PATH . 'inc/class-free-bulk-price-editor.php';
register_activation_hook(__FILE__, array('Free_Bulk_Price_Editor', 'activate'));
register_deactivation_hook(__FILE__, array('Free_Bulk_Price_Editor', 'deactivate'));
</code>
<code>include_once FBPE_PLUGIN_PATH . 'inc/class-free-bulk-price-editor.php';
register_activation_hook(__FILE__, array('Free_Bulk_Price_Editor', 'activate'));
register_deactivation_hook(__FILE__, array('Free_Bulk_Price_Editor', 'deactivate'));
</code>
include_once FBPE_PLUGIN_PATH . 'inc/class-free-bulk-price-editor.php';
register_activation_hook(__FILE__, array('Free_Bulk_Price_Editor', 'activate'));
register_deactivation_hook(__FILE__, array('Free_Bulk_Price_Editor', 'deactivate'));
class file code:
<code>class Free_Bulk_Price_Editor {
public static function is_woocommerce_active() {
return class_exists('WooCommerce');
}
public static function activate() {
if (!self::is_woocommerce_active()) {
deactivate_plugins('free-bulk-wp-price-upgrade/free-bulk-wp-price-upgrade.php');
wp_admin_notice( 'There was an error!', [ 'type' => 'error' ] );
return;
}
}
}
</code>
<code>class Free_Bulk_Price_Editor {
public static function is_woocommerce_active() {
return class_exists('WooCommerce');
}
public static function activate() {
if (!self::is_woocommerce_active()) {
deactivate_plugins('free-bulk-wp-price-upgrade/free-bulk-wp-price-upgrade.php');
wp_admin_notice( 'There was an error!', [ 'type' => 'error' ] );
return;
}
}
}
</code>
class Free_Bulk_Price_Editor {
public static function is_woocommerce_active() {
return class_exists('WooCommerce');
}
public static function activate() {
if (!self::is_woocommerce_active()) {
deactivate_plugins('free-bulk-wp-price-upgrade/free-bulk-wp-price-upgrade.php');
wp_admin_notice( 'There was an error!', [ 'type' => 'error' ] );
return;
}
}
}
this not work according to my requirements i want my plugin only active when WooCommerce is active. Please help to solve this out
I want to build custom wordpress plugin and want my plugin is active only when WooCommerce is active other wise show error to user that WooCommerce is required to active this plugin.
New contributor
Kunal Verma is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.