Automattic\WooCommerce\Admin\Features\Blueprint
Init::get_installed_wp_org_plugins
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() Init::get installed wp org plugins code WC 9.9.5
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; } $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, ) ); // 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; }