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

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

85 lines 2.2 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 Plugin - Models the Plugin object
9 *
10 * @property ?string $author
11 * @property ?string $authorUri
12 * @property ?string $description
13 * @property ?string $id
14 * @property ?string $name
15 * @property ?string $path
16 * @property ?string $pluginUri
17 * @property ?string $version
18 *
19 * @package WPGraphQL\Model
20 *
21 * @extends \WPGraphQL\Model\Model<array<string,mixed>>
22 */
23 class Plugin extends Model {
24 /**
25 * Plugin constructor.
26 *
27 * @param array<string,mixed> $plugin The incoming Plugin data to be modeled.
28 */
29 public function __construct( $plugin ) {
30 $this->data = $plugin;
31 parent::__construct();
32 }
33
34 /**
35 * {@inheritDoc}
36 */
37 protected function is_private() {
38 if ( is_multisite() ) {
39 // update_, install_, and delete_ are handled above with is_super_admin().
40 $menu_perms = get_site_option( 'menu_items', [] );
41 if ( empty( $menu_perms['plugins'] ) && ! current_user_can( 'manage_network_plugins' ) ) {
42 return true;
43 }
44 } elseif ( ! current_user_can( 'activate_plugins' ) ) {
45 return true;
46 }
47
48 return false;
49 }
50
51 /**
52 * {@inheritDoc}
53 */
54 protected function init() {
55 if ( empty( $this->fields ) ) {
56 $this->fields = [
57 'author' => function () {
58 return ! empty( $this->data['Author'] ) ? $this->data['Author'] : null;
59 },
60 'authorUri' => function () {
61 return ! empty( $this->data['AuthorURI'] ) ? $this->data['AuthorURI'] : null;
62 },
63 'description' => function () {
64 return ! empty( $this->data['Description'] ) ? $this->data['Description'] : null;
65 },
66 'id' => function () {
67 return ! empty( $this->path ) ? Relay::toGlobalId( 'plugin', $this->path ) : null;
68 },
69 'name' => function () {
70 return ! empty( $this->data['Name'] ) ? $this->data['Name'] : null;
71 },
72 'path' => function () {
73 return ! empty( $this->data['Path'] ) ? $this->data['Path'] : null;
74 },
75 'pluginUri' => function () {
76 return ! empty( $this->data['PluginURI'] ) ? $this->data['PluginURI'] : null;
77 },
78 'version' => function () {
79 return ! empty( $this->data['Version'] ) ? $this->data['Version'] : null;
80 },
81 ];
82 }
83 }
84 }
85