WC_Helper::get_local_woo_plugins │ public static │ WC 11.2.0

Obtain a list of data about locally installed Woo extensions.

Scanning every installed plugin is expensive, so the result is cached for the rest of the request. Pass false after installing or removing a plugin to rescan and refresh the cache.

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

Хуков нет.

Возвращает

array.

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

$result = WC_Helper::get_local_woo_plugins( $use_cache );
$use_cache(true|false)
Whether to return the cached list when one exists.
По умолчанию: true

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

С версии 11.2.0 Введена.
С версии 11.2.0 Added the $use_cache parameter.

Код WC_Helper::get_local_woo_plugins() WC 11.3.0

public static function get_local_woo_plugins( bool $use_cache = true ) {
	if ( $use_cache && null !== self::$local_woo_plugins_cache ) {
		return self::$local_woo_plugins_cache;
	}

	if ( ! function_exists( 'get_plugins' ) ) {
		require_once ABSPATH . 'wp-admin/includes/plugin.php';
	}

	$plugins = get_plugins();

	/**
	 * Check if plugins have WC headers, if not then clear cache and fetch again.
	 * WC Headers will not be present if `wc_enable_wc_plugin_headers` hook was added after a `get_plugins` call -- for example when WC is activated/updated.
	 * Also, get_plugins call is expensive, so we should clear this cache very conservatively.
	 */
	if ( ! empty( $plugins ) && ! array_key_exists( 'Woo', current( $plugins ) ) ) {
		wp_clean_plugins_cache( false );
		$plugins = get_plugins();
	}

	$woo_plugins = array();

	// Backwards compatibility for woothemes_queue_update().
	$_compat = array();
	if ( ! empty( $GLOBALS['woothemes_queued_updates'] ) ) {
		foreach ( $GLOBALS['woothemes_queued_updates'] as $_compat_plugin ) {
			$_compat[ $_compat_plugin->file ] = array(
				'product_id' => $_compat_plugin->product_id,
				'file_id'    => $_compat_plugin->file_id,
			);
		}
	}

	foreach ( $plugins as $filename => $data ) {
		if ( empty( $data['Woo'] ) && ! empty( $_compat[ $filename ] ) ) {
			$data['Woo'] = sprintf( '%d:%s', $_compat[ $filename ]['product_id'], $_compat[ $filename ]['file_id'] );
		}

		if ( empty( $data['Woo'] ) ) {
			continue;
		}

		list( $product_id, $file_id ) = explode( ':', $data['Woo'] );
		if ( empty( $product_id ) || empty( $file_id ) ) {
			continue;
		}

		// Omit the WooCommerce plugin used on Woo Express sites.
		if ( 'WooCommerce' === $data['Name'] ) {
			continue;
		}

		$data['_filename']        = $filename;
		$data['_product_id']      = absint( $product_id );
		$data['_file_id']         = $file_id;
		$data['_type']            = 'plugin';
		$data['slug']             = dirname( $filename );
		$woo_plugins[ $filename ] = $data;
	}

	self::$local_woo_plugins_cache = $woo_plugins;

	return $woo_plugins;
}