| 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 |
|