| 1 |
<?php |
| 2 |
namespace WPGraphQL\Data\Loader; |
| 3 |
|
| 4 |
/** |
| 5 |
* Class EnqueuedScriptLoader |
| 6 |
* |
| 7 |
* @package WPGraphQL\Data\Loader |
| 8 |
*/ |
| 9 |
class EnqueuedScriptLoader extends AbstractDataLoader { |
| 10 |
|
| 11 |
/** |
| 12 |
* {@inheritDoc} |
| 13 |
* |
| 14 |
* @param string[] $keys Array of script handles to load |
| 15 |
* |
| 16 |
* @return array<string,mixed> |
| 17 |
*/ |
| 18 |
public function loadKeys( array $keys ) { |
| 19 |
/** @var \WP_Scripts $wp_scripts */ |
| 20 |
global $wp_scripts; |
| 21 |
|
| 22 |
$loaded = []; |
| 23 |
foreach ( $keys as $key ) { |
| 24 |
if ( isset( $wp_scripts->registered[ $key ] ) ) { |
| 25 |
$script = $wp_scripts->registered[ $key ]; |
| 26 |
$script->type = 'EnqueuedScript'; |
| 27 |
$loaded[ $key ] = $script; |
| 28 |
} else { |
| 29 |
$loaded[ $key ] = null; |
| 30 |
} |
| 31 |
} |
| 32 |
return $loaded; |
| 33 |
} |
| 34 |
} |
| 35 |
|