PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.1
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.1
16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 All 504 releases
jetpack / jetpack_vendor / automattic / jetpack-connection / src / class-plugin.php

class-plugin.php in Jetpack – WP Security, Backup, Speed, & Growth 16.3-a.1, at jetpack_vendor/automattic/jetpack-connection/src/class-plugin.php

110 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 * Users Connection Admin instance.
36 *
37 * @var Users_Connection_Admin
38 */
39 private $users_connection_admin;
40
41 /**
42 * Initialize the plugin manager.
43 *
44 * @param string $slug Plugin slug.
45 */
46 public function __construct( $slug ) {
47 $this->slug = $slug;
48
49 // Initialize Users_Connection_Admin
50 $this->users_connection_admin = new Users_Connection_Admin();
51 }
52
53 /**
54 * Get the plugin slug.
55 *
56 * @return string
57 */
58 public function get_slug() {
59 return $this->slug;
60 }
61
62 /**
63 * Add the plugin connection info into Jetpack.
64 *
65 * @param string $name Plugin name, required.
66 * @param array $args Plugin arguments, optional.
67 *
68 * @return $this
69 * @see $this->arguments_whitelist
70 */
71 public function add( $name, array $args = array() ) {
72 $args = compact( 'name' ) + array_intersect_key( $args, array_flip( $this->arguments_whitelist ) );
73
74 Plugin_Storage::upsert( $this->slug, $args );
75
76 return $this;
77 }
78
79 /**
80 * Remove the plugin connection info from Jetpack.
81 *
82 * @return $this
83 */
84 public function remove() {
85 Plugin_Storage::delete( $this->slug );
86
87 return $this;
88 }
89
90 /**
91 * Determine if this plugin connection is the only one active at the moment, if any.
92 *
93 * @return bool
94 */
95 public function is_only() {
96 $plugins = Plugin_Storage::get_all();
97
98 if ( is_wp_error( $plugins ) ) {
99 if ( 'too_early' === $plugins->get_error_code() ) {
100 _doing_it_wrong( __METHOD__, esc_html( $plugins->get_error_code() . ': ' . $plugins->get_error_message() ), '6.16.1' );
101 } else {
102 wp_trigger_error( __METHOD__, $plugins->get_error_code() . ': ' . $plugins->get_error_message() );
103 }
104 return false;
105 }
106
107 return ! $plugins || ( array_key_exists( $this->slug, $plugins ) && 1 === count( $plugins ) );
108 }
109 }
110