PluginProbe
WPGraphQL / trunk
WPGraphQL vtrunk
2.22.3 2.22.2 2.22.1 2.22.0 2.21.1 2.21.0 2.20.0 2.19.0 2.18.0 2.17.0 2.16.0 2.15.1 2.15.0 2.14.1 2.14.0 2.13.0 2.2.0 2.3.0 2.3.3 2.3.6 2.3.8 2.5.0 2.5.1 2.5.2 2.5.3 All 177 releases
wp-graphql / src / Data / Loader / PluginLoader.php

PluginLoader.php in WPGraphQL trunk, at src/Data/Loader/PluginLoader.php

66 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WPGraphQL\Data\Loader;
4
5 use WPGraphQL\Model\Plugin;
6
7 /**
8 * Class PluginLoader
9 *
10 * @package WPGraphQL\Data\Loader
11 */
12 class PluginLoader extends AbstractDataLoader {
13
14 /**
15 * {@inheritDoc}
16 *
17 * @param array<string,mixed> $entry The plugin data
18 *
19 * @return \WPGraphQL\Model\Plugin
20 * @throws \Exception
21 */
22 protected function get_model( $entry, $key ) {
23 return new Plugin( $entry );
24 }
25
26 /**
27 * {@inheritDoc}
28 *
29 * @param string[] $keys Array of plugin names to load
30 *
31 * @return array<string,array<string,mixed>|null>
32 * @throws \Exception
33 */
34 public function loadKeys( array $keys ) {
35 if ( empty( $keys ) ) {
36 return $keys;
37 }
38
39 if ( ! function_exists( 'get_plugins' ) ) {
40 require_once ABSPATH . 'wp-admin/includes/plugin.php';
41 }
42
43 // This is missing must use and drop in plugins, so we need to fetch and merge them separately.
44 $site_plugins = apply_filters( 'all_plugins', get_plugins() );
45 $mu_plugins = apply_filters( 'show_advanced_plugins', true, 'mustuse' ) ? get_mu_plugins() : [];
46 $dropin_plugins = apply_filters( 'show_advanced_plugins', true, 'dropins' ) ? get_dropins() : [];
47
48 $plugins = array_merge( $site_plugins, $mu_plugins, $dropin_plugins );
49
50 $loaded = [];
51 if ( ! empty( $plugins ) ) {
52 foreach ( $keys as $key ) {
53 if ( isset( $plugins[ $key ] ) ) {
54 $plugin = $plugins[ $key ];
55 $plugin['Path'] = $key;
56 $loaded[ $key ] = $plugin;
57 } else {
58 $loaded[ $key ] = null;
59 }
60 }
61 }
62
63 return $loaded;
64 }
65 }
66