WC_Helper::activated_plugin()public staticWC 1.0

Runs when any plugin is activated.

Depending on the activated plugin attempts to look through available subscriptions and auto-activate one if possible, so the user does not need to visit the Helper UI at all after installing a new extension.

Method of the class: WC_Helper{}

Return

null. Nothing (null).

Usage

$result = WC_Helper::activated_plugin( $filename );
$filename(string) (required)
The filename of the activated plugin.

WC_Helper::activated_plugin() code WC 9.7.1

public static function activated_plugin( $filename ) {
	$plugins = self::get_local_woo_plugins();

	// Not a local woo plugin.
	if ( empty( $plugins[ $filename ] ) ) {
		return;
	}

	// Make sure we have a connection.
	$auth = WC_Helper_Options::get( 'auth' );
	if ( empty( $auth ) ) {
		return;
	}

	$plugin       = $plugins[ $filename ];
	$product_id   = $plugin['_product_id'];
	$subscription = self::get_available_subscription( $product_id );

	// No valid subscription found.
	if ( ! $subscription ) {
		return;
	}

	$product_key                                    = $subscription['product_key'];
	list( $activation_response, $activated, $body ) = self::wccom_activate( $product_key );

	if ( $activated ) {
		self::log( 'Auto-activated a subscription for ' . $filename );
		/**
		 * Fires when the Helper activates a product successfully.
		 *
		 * @param int    $product_id Product ID being activated.
		 * @param string $product_key Subscription product key.
		 * @param array  $activation_response The response object from wp_safe_remote_request().
		 * @since 9.7
		 */
		do_action( 'woocommerce_helper_subscription_activate_success', $product_id, $product_key, $activation_response );
	} else {
		self::log( 'Could not activate a subscription upon plugin activation: ' . $filename );

		/**
		 * Fires when the Helper fails to activate a product.
		 *
		 * @param int    $product_id Product ID being activated.
		 * @param string $product_key Subscription product key.
		 * @param array  $activation_response The response object from wp_safe_remote_request().
		 * @since 9.7
		 */
		do_action( 'woocommerce_helper_subscription_activate_error', $product_id, $product_key, $activation_response );
	}

	self::_flush_subscriptions_cache();
	self::_flush_updates_cache();
}