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

wp-graphql / wp-graphql / 15710056976

17 Jun 2025 02:27PM UTC coverage: 84.17% (-0.1%) from 84.287%
15710056976

push

github

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

15925 of 18920 relevant lines covered (84.17%)

258.66 hits per line

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

96.63
/src/Model/Taxonomy.php
1
<?php
2

3
namespace WPGraphQL\Model;
4

5
use GraphQLRelay\Relay;
6

7
/**
8
 * Class Taxonomy - Models data for taxonomies
9
 *
10
 * @property string        $description
11
 * @property ?string       $graphqlPluralName
12
 * @property ?string       $graphqlSingleName
13
 * @property bool          $hierarchical
14
 * @property ?string       $id
15
 * @property ?string       $label
16
 * @property ?string       $name
17
 * @property string[]|null $object_type
18
 * @property bool          $public
19
 * @property ?string       $restBase
20
 * @property ?string       $restControllerClass
21
 * @property bool          $showCloud
22
 * @property bool          $showInAdminColumn
23
 * @property ?bool         $showInGraphql
24
 * @property bool          $showInMenu
25
 * @property bool          $showInNavMenus
26
 * @property bool          $showInQuickEdit
27
 * @property bool          $showInRest
28
 * @property bool          $showUi
29
 *
30
 * Aliases:
31
 * @property ?string       $graphql_plural_name
32
 * @property ?string       $graphql_single_name
33
 *
34
 * @package WPGraphQL\Model
35
 *
36
 * @extends \WPGraphQL\Model\Model<\WP_Taxonomy>
37
 */
38
class Taxonomy extends Model {
39
        /**
40
         * Taxonomy constructor.
41
         *
42
         * @param \WP_Taxonomy $taxonomy The incoming Taxonomy to model.
43
         */
44
        public function __construct( \WP_Taxonomy $taxonomy ) {
15✔
45
                $this->data = $taxonomy;
15✔
46

47
                $allowed_restricted_fields = [
15✔
48
                        'id',
15✔
49
                        'name',
15✔
50
                        'description',
15✔
51
                        'hierarchical',
15✔
52
                        'object_type',
15✔
53
                        'restBase',
15✔
54
                        'graphql_single_name',
15✔
55
                        'graphqlSingleName',
15✔
56
                        'graphql_plural_name',
15✔
57
                        'graphqlPluralName',
15✔
58
                        'showInGraphql',
15✔
59
                        'isRestricted',
15✔
60
                ];
15✔
61

62
                $capability = isset( $this->data->cap->edit_terms ) ? $this->data->cap->edit_terms : 'edit_terms';
15✔
63

64
                parent::__construct( $capability, $allowed_restricted_fields );
15✔
65
        }
66

67
        /**
68
         * {@inheritDoc}
69
         */
70
        protected function is_private() {
15✔
71
                if ( false === $this->data->public && ( ! isset( $this->data->cap->edit_terms ) || ! current_user_can( $this->data->cap->edit_terms ) ) ) {
15✔
72
                        return true;
×
73
                }
74

75
                return false;
15✔
76
        }
77

78
        /**
79
         * {@inheritDoc}
80
         */
81
        protected function init() {
15✔
82
                if ( empty( $this->fields ) ) {
15✔
83
                        $this->fields = [
15✔
84
                                'description'         => function () {
15✔
85
                                        return ! empty( $this->data->description ) ? $this->data->description : '';
4✔
86
                                },
15✔
87
                                'graphqlPluralName'   => function () {
15✔
88
                                        return ! empty( $this->data->graphql_plural_name ) ? $this->data->graphql_plural_name : null;
4✔
89
                                },
15✔
90
                                'graphqlSingleName'   => function () {
15✔
91
                                        return ! empty( $this->data->graphql_single_name ) ? $this->data->graphql_single_name : null;
4✔
92
                                },
15✔
93
                                'hierarchical'        => function () {
15✔
94
                                        return true === $this->data->hierarchical;
4✔
95
                                },
15✔
96
                                'id'                  => function () {
15✔
97
                                        return ! empty( $this->name ) ? Relay::toGlobalId( 'taxonomy', $this->name ) : null;
15✔
98
                                },
15✔
99
                                'label'               => function () {
15✔
100
                                        return ! empty( $this->data->label ) ? $this->data->label : null;
2✔
101
                                },
15✔
102
                                'name'                => function () {
15✔
103
                                        return ! empty( $this->data->name ) ? $this->data->name : null;
15✔
104
                                },
15✔
105
                                'object_type'         => function () {
15✔
106
                                        return ! empty( $this->data->object_type ) ? $this->data->object_type : null;
4✔
107
                                },
15✔
108
                                'public'              => function () {
15✔
109
                                        // @todo this is a bug
110
                                        return ! empty( $this->data->public ) ? (bool) $this->data->public : true;
2✔
111
                                },
15✔
112
                                'restBase'            => function () {
15✔
113
                                        return ! empty( $this->data->rest_base ) ? $this->data->rest_base : null;
4✔
114
                                },
15✔
115
                                'restControllerClass' => function () {
15✔
116
                                        return ! empty( $this->data->rest_controller_class ) ? $this->data->rest_controller_class : null;
2✔
117
                                },
15✔
118
                                'showCloud'           => function () {
15✔
119
                                        return true === $this->data->show_tagcloud;
2✔
120
                                },
15✔
121
                                'showInAdminColumn'   => function () {
15✔
122
                                        return true === $this->data->show_admin_column;
2✔
123
                                },
15✔
124
                                'showInGraphql'       => function () {
15✔
125
                                        return true === $this->data->show_in_graphql;
4✔
126
                                },
15✔
127
                                'showInMenu'          => function () {
15✔
128
                                        return true === $this->data->show_in_menu;
2✔
129
                                },
15✔
130
                                'showInNavMenus'      => function () {
15✔
131
                                        return true === $this->data->show_in_nav_menus;
2✔
132
                                },
15✔
133
                                'showInQuickEdit'     => function () {
15✔
134
                                        return true === $this->data->show_in_quick_edit;
2✔
135
                                },
15✔
136
                                'showInRest'          => function () {
15✔
137
                                        return true === $this->data->show_in_rest;
2✔
138
                                },
15✔
139
                                'showUi'              => function () {
15✔
140
                                        return true === $this->data->show_ui;
2✔
141
                                },
15✔
142

143
                                // Aliases
144
                                'graphql_plural_name' => function () {
15✔
145
                                        return $this->graphqlPluralName;
×
146
                                },
15✔
147
                                'graphql_single_name' => function () {
15✔
148
                                        return $this->graphqlSingleName;
×
149
                                },
15✔
150
                        ];
15✔
151
                }
152
        }
153
}
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