• 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

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
class Taxonomy extends Model {
37

38
        /**
39
         * Stores the incoming WP_Taxonomy object to be modeled
40
         *
41
         * @var \WP_Taxonomy $data
42
         */
43
        protected $data;
44

45
        /**
46
         * Taxonomy constructor.
47
         *
48
         * @param \WP_Taxonomy $taxonomy The incoming Taxonomy to model.
49
         */
50
        public function __construct( \WP_Taxonomy $taxonomy ) {
15✔
51
                $this->data = $taxonomy;
15✔
52

53
                $allowed_restricted_fields = [
15✔
54
                        'id',
15✔
55
                        'name',
15✔
56
                        'description',
15✔
57
                        'hierarchical',
15✔
58
                        'object_type',
15✔
59
                        'restBase',
15✔
60
                        'graphql_single_name',
15✔
61
                        'graphqlSingleName',
15✔
62
                        'graphql_plural_name',
15✔
63
                        'graphqlPluralName',
15✔
64
                        'showInGraphql',
15✔
65
                        'isRestricted',
15✔
66
                ];
15✔
67

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

70
                parent::__construct( $capability, $allowed_restricted_fields );
15✔
71
        }
72

73
        /**
74
         * {@inheritDoc}
75
         */
76
        protected function is_private() {
15✔
77
                if ( false === $this->data->public && ( ! isset( $this->data->cap->edit_terms ) || ! current_user_can( $this->data->cap->edit_terms ) ) ) {
15✔
78
                        return true;
×
79
                }
80

81
                return false;
15✔
82
        }
83

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

149
                                // Aliases
150
                                'graphql_plural_name' => function () {
15✔
151
                                        return $this->graphqlPluralName;
×
152
                                },
15✔
153
                                'graphql_single_name' => function () {
15✔
154
                                        return $this->graphqlSingleName;
×
155
                                },
15✔
156
                        ];
15✔
157
                }
158
        }
159
}
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