WC_Helper::activate_plugin
Activate a plugin for a product key.
Method of the class: WC_Helper{}
No Hooks.
Returns
true|false. True if activated, false otherwise.
Usage
$result = WC_Helper::activate_plugin( $product_key );
- $product_key(string) (required)
- Subscription product key.
WC_Helper::activate_plugin() WC Helper::activate plugin code WC 10.3.3
public static function activate_plugin( $product_key ) {
$subscription = self::get_subscription( $product_key );
if ( ! $subscription ) {
throw new Exception( esc_html( __( 'Subscription not found', 'woocommerce' ) ) );
}
$product_id = $subscription['product_id'];
$local = self::_get_local_from_product_id( $product_id );
if ( is_plugin_active( $local['_filename'] ) ) {
return true;
}
$response = false;
if ( $local && 'plugin' === $local['_type'] && current_user_can( 'activate_plugins' ) ) {
$response = activate_plugin( $local['_filename'] );
if ( is_wp_error( $response ) ) {
self::log( sprintf( 'Error activating plugin (%s)', $response->get_error_message() ) );
}
$response = null === $response;
}
return $response;
}