| 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 |
|