WC_WCCOM_Site_Installation_Step_Activate_Product::activate_plugin()privateWC 1.0

Activate plugin.

Method of the class: WC_WCCOM_Site_Installation_Step_Activate_Product{}

No Hooks.

Return

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->activate_plugin( $product_id );
$product_id(int) (required)
Product ID.

WC_WCCOM_Site_Installation_Step_Activate_Product::activate_plugin() code WC 8.7.0

private function activate_plugin( $product_id ) {
	// Clear plugins cache used in `WC_Helper::get_local_woo_plugins`.
	wp_clean_plugins_cache();
	$filename = false;

	// If product is WP.org one, find out its filename.
	$dir_name = $this->get_wporg_product_dir_name();
	if ( false !== $dir_name ) {
		$filename = \WC_WCCOM_Site_Installer::get_wporg_plugin_main_file( $dir_name );
	}

	if ( false === $filename ) {
		$plugins = wp_list_filter(
			WC_Helper::get_local_woo_plugins(),
			array(
				'_product_id' => $product_id,
			)
		);

		$filename = is_array( $plugins ) && ! empty( $plugins ) ? key( $plugins ) : '';
	}

	if ( empty( $filename ) ) {
		throw new Installer_Error( Installer_Error_Codes::UNKNOWN_FILENAME );
	}

	$result = activate_plugin( $filename );

	if ( is_wp_error( $result ) ) {
		throw new Installer_Error( Installer_Error_Codes::PLUGIN_ACTIVATION_ERROR, $result->get_error_message() );
	}
}