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 / Connection / TaxonomyConnectionResolver.php

TaxonomyConnectionResolver.php in WPGraphQL trunk, at src/Data/Connection/TaxonomyConnectionResolver.php

73 lines 1.4 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 TaxonomyConnectionResolver
6 *
7 * @package WPGraphQL\Data\Connection
8 * @extends \WPGraphQL\Data\Connection\AbstractConnectionResolver<string[]>
9 */
10 class TaxonomyConnectionResolver extends AbstractConnectionResolver {
11
12 /**
13 * {@inheritDoc}
14 */
15 public function get_ids_from_query() {
16 /**
17 * @todo This is for b/c. We can just use $this->get_query().
18 */
19 $queried = isset( $this->query ) ? $this->query : $this->get_query();
20
21 $ids = [];
22
23 if ( empty( $queried ) ) {
24 return $ids;
25 }
26
27 foreach ( $queried as $item ) {
28 $ids[] = $item;
29 }
30
31 return $ids;
32 }
33
34 /**
35 * {@inheritDoc}
36 */
37 protected function prepare_query_args( array $args ): array {
38 // If any args are added to filter/sort the connection.
39 return [];
40 }
41
42 /**
43 * {@inheritDoc}
44 */
45 protected function query( array $query_args ) {
46 if ( isset( $query_args['name'] ) ) {
47 return [ $query_args['name'] ];
48 }
49
50 if ( isset( $query_args['in'] ) ) {
51 return is_array( $query_args['in'] ) ? $query_args['in'] : [ $query_args['in'] ];
52 }
53
54 return \WPGraphQL::get_allowed_taxonomies( 'names', $query_args );
55 }
56
57 /**
58 * {@inheritDoc}
59 */
60 protected function loader_name(): string {
61 return 'taxonomy';
62 }
63
64 /**
65 * {@inheritDoc}
66 *
67 * @param string $offset The offset (taxonomy name) to check.
68 */
69 public function is_valid_offset( $offset ) {
70 return (bool) get_taxonomy( $offset );
71 }
72 }
73