identity-crisis
1 year ago
sso
1 year ago
webhooks
1 year ago
class-authorize-json-api.php
1 year ago
class-client.php
1 year ago
class-connection-assets.php
1 year ago
class-connection-notice.php
1 year ago
class-error-handler.php
1 year ago
class-heartbeat.php
1 year ago
class-initial-state.php
1 year ago
class-manager.php
1 year ago
class-nonce-handler.php
2 years ago
class-package-version-tracker.php
1 year ago
class-package-version.php
1 year ago
class-partner-coupon.php
1 year ago
class-partner.php
1 year ago
class-plugin-storage.php
1 year ago
class-plugin.php
1 year ago
class-rest-authentication.php
1 year ago
class-rest-connector.php
1 year ago
class-secrets.php
1 year ago
class-server-sandbox.php
1 year ago
class-terms-of-service.php
2 years ago
class-tokens-locks.php
2 years ago
class-tokens.php
2 years ago
class-tracking.php
1 year ago
class-urls.php
1 year ago
class-utils.php
1 year ago
class-webhooks.php
1 year ago
class-xmlrpc-async-call.php
1 year ago
class-xmlrpc-connector.php
1 year ago
interface-manager.php
3 years ago
class-plugin.php
91 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Plugin connection management class. |
| 4 | * |
| 5 | * @package automattic/jetpack-connection |
| 6 | */ |
| 7 | |
| 8 | namespace Automattic\Jetpack\Connection; |
| 9 | |
| 10 | /** |
| 11 | * Plugin connection management class. |
| 12 | * The class represents a single plugin that uses Jetpack connection. |
| 13 | * Its functionality has been pretty simplistic so far: add to the storage (`Plugin_Storage`), remove it from there, |
| 14 | * and determine whether it's the last active connection. As the component grows, there'll be more functionality added. |
| 15 | */ |
| 16 | class Plugin { |
| 17 | |
| 18 | /** |
| 19 | * List of the keys allowed as arguments |
| 20 | * |
| 21 | * @var array |
| 22 | */ |
| 23 | private $arguments_whitelist = array( |
| 24 | 'url_info', |
| 25 | ); |
| 26 | |
| 27 | /** |
| 28 | * Plugin slug. |
| 29 | * |
| 30 | * @var string |
| 31 | */ |
| 32 | private $slug; |
| 33 | |
| 34 | /** |
| 35 | * Initialize the plugin manager. |
| 36 | * |
| 37 | * @param string $slug Plugin slug. |
| 38 | */ |
| 39 | public function __construct( $slug ) { |
| 40 | $this->slug = $slug; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Get the plugin slug. |
| 45 | * |
| 46 | * @return string |
| 47 | */ |
| 48 | public function get_slug() { |
| 49 | return $this->slug; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Add the plugin connection info into Jetpack. |
| 54 | * |
| 55 | * @param string $name Plugin name, required. |
| 56 | * @param array $args Plugin arguments, optional. |
| 57 | * |
| 58 | * @return $this |
| 59 | * @see $this->arguments_whitelist |
| 60 | */ |
| 61 | public function add( $name, array $args = array() ) { |
| 62 | $args = compact( 'name' ) + array_intersect_key( $args, array_flip( $this->arguments_whitelist ) ); |
| 63 | |
| 64 | Plugin_Storage::upsert( $this->slug, $args ); |
| 65 | |
| 66 | return $this; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Remove the plugin connection info from Jetpack. |
| 71 | * |
| 72 | * @return $this |
| 73 | */ |
| 74 | public function remove() { |
| 75 | Plugin_Storage::delete( $this->slug ); |
| 76 | |
| 77 | return $this; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Determine if this plugin connection is the only one active at the moment, if any. |
| 82 | * |
| 83 | * @return bool |
| 84 | */ |
| 85 | public function is_only() { |
| 86 | $plugins = Plugin_Storage::get_all(); |
| 87 | |
| 88 | return ! $plugins || ( array_key_exists( $this->slug, $plugins ) && 1 === count( $plugins ) ); |
| 89 | } |
| 90 | } |
| 91 |