WC_Helper::activate_pluginpublic staticWC 1.0

Activate a plugin for a product key.

Метод класса: WC_Helper{}

Хуков нет.

Возвращает

bool. True if activated, false otherwise.

Использование

$result = WC_Helper::activate_plugin( $product_key );
$product_key(строка) (обязательный)
Subscription product key.

Код WC_Helper::activate_plugin() WC 11.1.0

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;
}