PluginProbe
WPGraphQL / 2.22.1
WPGraphQL v2.22.1
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 / Connection / EnqueuedStylesheetConnectionResolver.php

EnqueuedStylesheetConnectionResolver.php in WPGraphQL 2.22.1, at src/Data/Connection/EnqueuedStylesheetConnectionResolver.php

81 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace WPGraphQL\Data\Connection;
3
4 /**
5 * Class EnqueuedStylesheetConnectionResolver
6 *
7 * @package WPGraphQL\Data\Connection
8 * @extends \WPGraphQL\Data\Connection\AbstractConnectionResolver<string[]>
9 */
10 class EnqueuedStylesheetConnectionResolver extends AbstractConnectionResolver {
11 /**
12 * {@inheritDoc}
13 */
14 public function get_ids_from_query() {
15 $ids = [];
16 $queried = $this->get_query();
17
18 if ( empty( $queried ) ) {
19 return $ids;
20 }
21
22 foreach ( $queried as $key => $item ) {
23 $ids[ $key ] = $item;
24 }
25
26 return $ids;
27 }
28
29 /**
30 * {@inheritDoc}
31 */
32 protected function prepare_query_args( array $args ): array {
33 return $args;
34 }
35
36 /**
37 * {@inheritDoc}
38 */
39 protected function query( array $query_args ) {
40 $queue = $this->source->enqueuedStylesheetsQueue ? $this->source->enqueuedStylesheetsQueue : [];
41 $handles = $query_args['where']['handlesIn'] ?? null;
42
43 if ( ! is_array( $handles ) ) {
44 return $queue;
45 }
46
47 return array_values( array_intersect( $queue, $handles ) );
48 }
49
50 /**
51 * {@inheritDoc}
52 */
53 protected function loader_name(): string {
54 return 'enqueued_stylesheet';
55 }
56
57 /**
58 * {@inheritDoc}
59 */
60 protected function max_query_amount(): int {
61 return 1000;
62 }
63
64 /**
65 * {@inheritDoc}
66 *
67 * @param ?\_WP_Dependency $model
68 */
69 protected function is_valid_model( $model ) {
70 return isset( $model->handle );
71 }
72
73 /**
74 * {@inheritDoc}
75 */
76 public function is_valid_offset( $offset ) {
77 global $wp_styles;
78 return isset( $wp_styles->registered[ $offset ] );
79 }
80 }
81