Automattic\WooCommerce\Admin\Features\Blueprint

Init::get_installed_wp_org_plugins │ private │ WC 1.0

Get all installed WordPress.org plugins.

Method of the class: Init{}

Hooks from the method

Returns

array.

Usage

// private - for code of main (parent) class only
$result = $this->get_installed_wp_org_plugins();

Init::get_installed_wp_org_plugins() code WC 11.1.2

private function get_installed_wp_org_plugins() {
	// Try to get cached plugin list.
	$wp_org_plugins = get_transient( self::INSTALLED_WP_ORG_PLUGINS_TRANSIENT );
	if ( is_array( $wp_org_plugins ) ) {
		return $wp_org_plugins;
	}

	// Get all installed plugins.
	$all_plugins  = $this->wp_get_plugins();
	$plugin_slugs = array();

	// Build a map of plugin file => slug.
	foreach ( $all_plugins as $key => $plugin ) {
		$slug = dirname( $key );
		/**
		 * Apply the WP Core "wp_plugin_dependencies_slug" filter to get the correct plugin slug.
		 */
		$slug = apply_filters( 'wp_plugin_dependencies_slug', $slug ); // phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingSinceComment

		$plugin_slugs[]              = $slug;
		$all_plugins[ $key ]['slug'] = $slug;
	}

	try {
		$api_response = $this->wp_plugins_api(
			'plugin_information',
			array(
				'fields' => array(
					'short_description' => false,
					'sections'          => false,
					'description'       => false,
					'tested'            => false,
					'requires'          => false,
					'rating'            => false,
					'ratings'           => false,
					'downloaded'        => false,
					'downloadlink'      => false,
					'last_updated'      => false,
					'added'             => false,
					'tags'              => false,
					'compatibility'     => false,
					'homepage'          => false,
					'versions'          => false,
					'donate_link'       => false,
					'reviews'           => false,
					'banners'           => false,
					'icons'             => false,
					'active_installs'   => false,
				),
				'slugs'  => $plugin_slugs,
			)
		);
	} catch ( \Throwable $e ) {
		// A third party filtering the plugins API result can throw. Don't let that take down the admin screen.
		$this->log_api_failure( 'plugins_api', $e );
		return $all_plugins;
	}

	// If API fails, return all plugins.
	if ( is_wp_error( $api_response ) ) {
		return $all_plugins;
	}

	// Filter plugins: only keep those with a valid API response (no 'error' for their slug).
	$wp_org_plugins = array_filter(
		$all_plugins,
		function ( $plugin ) use ( $api_response ) {
			$slug = $plugin['slug'];
			return isset( $api_response->{$slug} ) && ! isset( $api_response->{$slug}['error'] );
		}
	);

	set_transient( self::INSTALLED_WP_ORG_PLUGINS_TRANSIENT, $wp_org_plugins );
	return $wp_org_plugins;
}