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 / MenuConnectionResolver.php

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

50 lines 1.3 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\Connection;
4
5 /**
6 * Class MenuConnectionResolver
7 *
8 * @package WPGraphQL\Data\Connection
9 */
10 class MenuConnectionResolver extends TermObjectConnectionResolver {
11
12 /**
13 * {@inheritDoc}
14 *
15 * @throws \Exception
16 */
17 protected function prepare_query_args( array $args ): array {
18 $term_args = [
19 'hide_empty' => false,
20 'include' => [],
21 'taxonomy' => 'nav_menu',
22 'fields' => 'ids',
23 ];
24
25 if ( ! empty( $args['where']['slug'] ) ) {
26 $term_args['slug'] = $args['where']['slug'];
27 $term_args['include'] = null;
28 }
29
30 $theme_locations = get_nav_menu_locations();
31
32 // If a location is specified in the args, use it
33 if ( ! empty( $args['where']['location'] ) ) {
34 // Exclude unset and non-existent locations
35 $term_args['include'] = ! empty( $theme_locations[ $args['where']['location'] ] ) ? $theme_locations[ $args['where']['location'] ] : -1;
36 // If the current user cannot edit theme options
37 } elseif ( ! current_user_can( 'edit_theme_options' ) ) {
38 $term_args['include'] = array_values( $theme_locations );
39 }
40
41 if ( ! empty( $args['where']['id'] ) ) {
42 $term_args['include'] = $args['where']['id'];
43 }
44
45 $query_args = parent::prepare_query_args( $args );
46
47 return array_merge( $query_args, $term_args );
48 }
49 }
50