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

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

100 lines 2.7 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 Theme - Models data for themes
9 *
10 * @property ?string $author
11 * @property ?string $authorUri
12 * @property ?string $description
13 * @property ?string $id
14 * @property ?string $name
15 * @property ?string $screenshot
16 * @property ?string $slug
17 * @property ?string $themeUri
18 * @property string[]|null $tags
19 * @property ?string $version
20 *
21 * @package WPGraphQL\Model
22 *
23 * @extends \WPGraphQL\Model\Model<\WP_Theme>
24 */
25 class Theme extends Model {
26 /**
27 * Theme constructor.
28 *
29 * @param \WP_Theme $theme The incoming WP_Theme to be modeled
30 *
31 * @return void
32 * @throws \Exception
33 */
34 public function __construct( \WP_Theme $theme ) {
35 $this->data = $theme;
36 parent::__construct();
37 }
38
39 /**
40 * {@inheritDoc}
41 */
42 protected function is_private() {
43 // Don't assume a capabilities hierarchy, since it's likely headless sites might disable some capabilities site-wide.
44 if ( current_user_can( 'edit_themes' ) || current_user_can( 'switch_themes' ) || current_user_can( 'update_themes' ) ) {
45 return false;
46 }
47
48 if ( wp_get_theme()->get_stylesheet() !== $this->data->get_stylesheet() ) {
49 return true;
50 }
51
52 return false;
53 }
54
55 /**
56 * {@inheritDoc}
57 */
58 protected function init() {
59 if ( empty( $this->fields ) ) {
60 $this->fields = [
61 'author' => function () {
62 return ! empty( $this->data->author ) ? $this->data->author : null;
63 },
64 'authorUri' => function () {
65 $author_uri = $this->data->get( 'AuthorURI' );
66 return ! empty( $author_uri ) ? $author_uri : null;
67 },
68 'description' => function () {
69 return ! empty( $this->data->description ) ? $this->data->description : null;
70 },
71 'id' => function () {
72 return ! empty( $this->slug ) ? Relay::toGlobalId( 'theme', $this->slug ) : null;
73 },
74 'name' => function () {
75 $name = $this->data->get( 'Name' );
76 return ! empty( $name ) ? $name : null;
77 },
78 'screenshot' => function () {
79 $screenshot = $this->data->get_screenshot();
80 return ! empty( $screenshot ) ? $screenshot : null;
81 },
82 'slug' => function () {
83 $stylesheet = $this->data->get_stylesheet();
84 return ! empty( $stylesheet ) ? $stylesheet : null;
85 },
86 'themeUri' => function () {
87 $theme_uri = $this->data->get( 'ThemeURI' );
88 return ! empty( $theme_uri ) ? $theme_uri : null;
89 },
90 'tags' => function () {
91 return ! empty( $this->data->tags ) ? $this->data->tags : null;
92 },
93 'version' => function () {
94 return ! empty( $this->data->version ) ? (string) $this->data->version : null;
95 },
96 ];
97 }
98 }
99 }
100