WC_Helper_Updater::get_plugins_without_subscription │ public static │ WC 11.3.0

Active WooCommerce.com plugins that have no subscription on this store.

A connected store uses the same check as the Plugins screen "Subscribe" notice. A store that isn't connected has no subscription for any of them. Returns null when an active plugin needs checking but the subscription list is unknown: the last fetch failed (for example, rate limited), or it isn't cached and $fetch is false.

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

Хуков нет.

Возвращает

array|null. Plugin data from WC_Helper::get_local_woo_plugins(), keyed by plugin file.

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

$result = WC_Helper_Updater::get_plugins_without_subscription( $fetch ): ?array;
$fetch(true|false)
Whether to fetch the subscription list from WooCommerce.com when it isn't cached. False keeps this call local; a page that can't afford to block passes it.
По умолчанию: true

Список изменений

С версии 11.3.0 Введена.

Код WC_Helper_Updater::get_plugins_without_subscription() WC 11.3.0

public static function get_plugins_without_subscription( bool $fetch = true ): ?array {
	$plugins = array_filter(
		WC_Helper::get_local_woo_plugins(),
		static function ( $plugin_file ) {
			return WC_Woo_Update_Manager_Plugin::WOO_UPDATE_MANAGER_PLUGIN_MAIN_FILE !== $plugin_file
				&& is_plugin_active( $plugin_file );
		},
		ARRAY_FILTER_USE_KEY
	);

	if ( empty( $plugins ) || ! WC_Helper::is_site_connected() ) {
		return $plugins;
	}

	if ( ! $fetch && ! WC_Helper::has_cached_subscriptions() ) {
		return null;
	}

	$plugins = array_filter(
		$plugins,
		static function ( $plugin ) {
			return empty( self::get_subscriptions_for_product( $plugin['_product_id'] ) );
		}
	);

	// Read after the subscriptions fetch above, so a failure from it is already recorded.
	if ( null !== WC_Helper::get_api_error() ) {
		return null;
	}

	return $plugins;
}