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 / Model / Taxonomy.php

Taxonomy.php in WPGraphQL trunk, at src/Model/Taxonomy.php

154 lines 4.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 ) {
45 $this->data = $taxonomy;
46
47 $allowed_restricted_fields = [
48 'id',
49 'name',
50 'description',
51 'hierarchical',
52 'object_type',
53 'restBase',
54 'graphql_single_name',
55 'graphqlSingleName',
56 'graphql_plural_name',
57 'graphqlPluralName',
58 'showInGraphql',
59 'isRestricted',
60 ];
61
62 $capability = isset( $this->data->cap->edit_terms ) ? $this->data->cap->edit_terms : 'edit_terms';
63
64 parent::__construct( $capability, $allowed_restricted_fields );
65 }
66
67 /**
68 * {@inheritDoc}
69 */
70 protected function is_private() {
71 if ( false === $this->data->public && ( ! isset( $this->data->cap->edit_terms ) || ! current_user_can( $this->data->cap->edit_terms ) ) ) {
72 return true;
73 }
74
75 return false;
76 }
77
78 /**
79 * {@inheritDoc}
80 */
81 protected function init() {
82 if ( empty( $this->fields ) ) {
83 $this->fields = [
84 'description' => function () {
85 return ! empty( $this->data->description ) ? $this->data->description : '';
86 },
87 'graphqlPluralName' => function () {
88 return ! empty( $this->data->graphql_plural_name ) ? $this->data->graphql_plural_name : null;
89 },
90 'graphqlSingleName' => function () {
91 return ! empty( $this->data->graphql_single_name ) ? $this->data->graphql_single_name : null;
92 },
93 'hierarchical' => function () {
94 return true === $this->data->hierarchical;
95 },
96 'id' => function () {
97 return ! empty( $this->name ) ? Relay::toGlobalId( 'taxonomy', $this->name ) : null;
98 },
99 'label' => function () {
100 return ! empty( $this->data->label ) ? $this->data->label : null;
101 },
102 'name' => function () {
103 return ! empty( $this->data->name ) ? $this->data->name : null;
104 },
105 'object_type' => function () {
106 return ! empty( $this->data->object_type ) ? $this->data->object_type : null;
107 },
108 'public' => function () {
109 // @todo this is a bug
110 return ! empty( $this->data->public ) ? (bool) $this->data->public : true;
111 },
112 'restBase' => function () {
113 return ! empty( $this->data->rest_base ) ? $this->data->rest_base : null;
114 },
115 'restControllerClass' => function () {
116 return ! empty( $this->data->rest_controller_class ) ? $this->data->rest_controller_class : null;
117 },
118 'showCloud' => function () {
119 return true === $this->data->show_tagcloud;
120 },
121 'showInAdminColumn' => function () {
122 return true === $this->data->show_admin_column;
123 },
124 'showInGraphql' => function () {
125 return true === $this->data->show_in_graphql;
126 },
127 'showInMenu' => function () {
128 return true === $this->data->show_in_menu;
129 },
130 'showInNavMenus' => function () {
131 return true === $this->data->show_in_nav_menus;
132 },
133 'showInQuickEdit' => function () {
134 return true === $this->data->show_in_quick_edit;
135 },
136 'showInRest' => function () {
137 return true === $this->data->show_in_rest;
138 },
139 'showUi' => function () {
140 return true === $this->data->show_ui;
141 },
142
143 // Aliases
144 'graphql_plural_name' => function () {
145 return $this->graphqlPluralName;
146 },
147 'graphql_single_name' => function () {
148 return $this->graphqlSingleName;
149 },
150 ];
151 }
152 }
153 }
154