Automattic\WooCommerce\Internal\Admin

Marketing::get_recommended_plugins()publicWC 1.0

Load recommended plugins from WooCommerce.com

Method of the class: Marketing{}

No Hooks.

Return

Array.

Usage

$Marketing = new Marketing();
$Marketing->get_recommended_plugins();

Marketing::get_recommended_plugins() code WC 7.3.0

public function get_recommended_plugins() {
	$plugins = get_transient( self::RECOMMENDED_PLUGINS_TRANSIENT );

	if ( false === $plugins ) {
		$request = wp_remote_get(
			'https://woocommerce.com/wp-json/wccom/marketing-tab/1.2/recommendations.json',
			array(
				'user-agent' => 'WooCommerce/' . WC()->version . '; ' . get_bloginfo( 'url' ),
			)
		);
		$plugins = [];

		if ( ! is_wp_error( $request ) && 200 === $request['response']['code'] ) {
			$plugins = json_decode( $request['body'], true );
		}

		set_transient(
			self::RECOMMENDED_PLUGINS_TRANSIENT,
			$plugins,
			// Expire transient in 15 minutes if remote get failed.
			// Cache an empty result to avoid repeated failed requests.
			empty( $plugins ) ? 900 : 3 * DAY_IN_SECONDS
		);
	}

	return array_values( $plugins );
}