• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wp-graphql / wp-graphql / 14716683875

28 Apr 2025 07:58PM UTC coverage: 84.287% (+1.6%) from 82.648%
14716683875

push

github

actions-user
release: merge develop into master for v2.3.0

15905 of 18870 relevant lines covered (84.29%)

257.23 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.88
/src/Type/Union/MenuItemObjectUnion.php
1
<?php
2

3
namespace WPGraphQL\Type\Union;
4

5
use WPGraphQL\Model\Post;
6
use WPGraphQL\Model\Term;
7
use WPGraphQL\Registry\TypeRegistry;
8

9
/**
10
 * Class MenuItemObjectUnion
11
 *
12
 * @package WPGraphQL\Type\Union
13
 * @deprecated
14
 */
15
class MenuItemObjectUnion {
16

17
        /**
18
         * Registers the Type
19
         *
20
         * @param \WPGraphQL\Registry\TypeRegistry $type_registry
21
         *
22
         * @return void
23
         * @throws \Exception
24
         */
25
        public static function register_type( TypeRegistry $type_registry ) {
593✔
26
                register_graphql_union_type(
593✔
27
                        'MenuItemObjectUnion',
593✔
28
                        [
593✔
29
                                'typeNames'   => self::get_possible_types(),
593✔
30
                                'description' => static function () {
593✔
31
                                        return __( 'Deprecated in favor of MenuItemLinkeable Interface', 'wp-graphql' );
14✔
32
                                },
593✔
33
                                'resolveType' => static function ( $obj ) use ( $type_registry ) {
593✔
34
                                        _doing_it_wrong( 'MenuItemObjectUnion', esc_attr__( 'The MenuItemObjectUnion GraphQL type is deprecated in favor of MenuItemLinkeable Interface', 'wp-graphql' ), '0.10.3' );
14✔
35
                                        // Post object
36
                                        if ( $obj instanceof Post && isset( $obj->post_type ) && ! empty( $obj->post_type ) ) {
14✔
37
                                                /** @var \WP_Post_Type $post_type_object */
38
                                                $post_type_object = get_post_type_object( $obj->post_type );
14✔
39

40
                                                return $type_registry->get_type( $post_type_object->graphql_single_name );
14✔
41
                                        }
42

43
                                        // Taxonomy term
44
                                        if ( $obj instanceof Term && ! empty( $obj->taxonomyName ) ) {
×
45
                                                /** @var \WP_Taxonomy $tax_object */
46
                                                $tax_object = get_taxonomy( $obj->taxonomyName );
×
47

48
                                                return $type_registry->get_type( $tax_object->graphql_single_name );
×
49
                                        }
50

51
                                        return $obj;
×
52
                                },
593✔
53
                        ]
593✔
54
                );
593✔
55
        }
56

57
        /**
58
         * Returns a list of possible types for the union
59
         *
60
         * @return string[]
61
         */
62
        public static function get_possible_types() {
593✔
63

64
                /**
65
                 * The possible types for MenuItems should be just the TermObjects and PostTypeObjects that are
66
                 * registered to "show_in_graphql" and "show_in_nav_menus"
67
                 */
68
                $args = [
593✔
69
                        'show_in_nav_menus' => true,
593✔
70
                        'graphql_kind'      => 'object',
593✔
71
                ];
593✔
72

73
                $possible_types = [];
593✔
74

75
                /**
76
                 * Add post types that are allowed in WPGraphQL.
77
                 */
78
                foreach ( \WPGraphQL::get_allowed_post_types( 'objects', $args ) as $post_type_object ) {
593✔
79
                        if ( isset( $post_type_object->graphql_single_name ) ) {
593✔
80
                                $possible_types[] = $post_type_object->graphql_single_name;
593✔
81
                        }
82
                }
83

84
                // Add taxonomies that are allowed in WPGraphQL.
85
                foreach ( \WPGraphQL::get_allowed_taxonomies( 'objects', $args ) as $tax_object ) {
593✔
86
                        if ( isset( $tax_object->graphql_single_name ) ) {
593✔
87
                                $possible_types[] = $tax_object->graphql_single_name;
593✔
88
                        }
89
                }
90

91
                return $possible_types;
593✔
92
        }
93
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc