PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-beta
Jetpack – WP Security, Backup, Speed, & Growth v16.3-beta
16.3-beta 16.3-a.5 16.3-a.7 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 All 507 releases
← All changes | jetpack_vendor/automattic/jetpack-connection/src/class-plugin-storage.php +19 -55 13.5.2 → 16.3-beta View file →
@@ -6,8 +6,9 @@
6 6 */
7 7
8 8 namespace Automattic\Jetpack\Connection;
9 9
10 +use Jetpack_Options;
10 11 use WP_Error;
11 12
12 13 /**
13 14 * The class serves a single purpose - to store the data which plugins use the connection, along with some auxiliary information.
@@ -16,16 +17,8 @@
16 17
17 18 const ACTIVE_PLUGINS_OPTION_NAME = 'jetpack_connection_active_plugins';
18 19
19 20 /**
20 - * Options where disabled plugins were stored
21 - *
22 - * @deprecated since 1.39.0.
23 - * @var string
24 - */
25 - const PLUGINS_DISABLED_OPTION_NAME = 'jetpack_connection_disabled_plugins';
26 -
27 - /**
28 21 * Transient name used as flag to indicate that the active connected plugins list needs refreshing.
29 22 */
30 23 const ACTIVE_PLUGINS_REFRESH_FLAG = 'jetpack_connection_active_plugins_refresh';
31 24
@@ -91,15 +84,11 @@
91 84 * WARNING: the method cannot be called until Plugin_Storage::configure is called, which happens on plugins_loaded
92 85 * Even if you don't use Jetpack Config, it may be introduced later by other plugins,
93 86 * so please make sure not to run the method too early in the code.
94 87 *
95 - * @since 1.39.0 deprecated the $connected_only argument.
96 - *
97 - * @param null $deprecated null plugins that were explicitly disconnected. Deprecated, there's no such a thing as disconnecting only specific plugins anymore.
98 - *
99 88 * @return array|WP_Error
100 89 */
101 - public static function get_all( $deprecated = null ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
90 + public static function get_all() {
102 91 $maybe_error = self::ensure_configured();
103 92
104 93 if ( $maybe_error instanceof WP_Error ) {
105 94 return $maybe_error;
@@ -142,9 +131,12 @@
142 131 return new WP_Error( 'too_early', __( 'You cannot call this method until Jetpack Config is configured', 'jetpack-connection' ) );
143 132 }
144 133
145 134 if ( is_multisite() && get_current_blog_id() !== self::$current_blog_id ) {
146 - self::$plugins = (array) get_option( self::ACTIVE_PLUGINS_OPTION_NAME, array() );
135 + if ( self::$current_blog_id ) {
136 + // If blog ID got changed, pull the list of active plugins for that blog from the database.
137 + self::$plugins = (array) get_option( self::ACTIVE_PLUGINS_OPTION_NAME, array() );
138 + }
147 139 self::$current_blog_id = get_current_blog_id();
148 140 }
149 141
150 142 return true;
@@ -203,11 +195,14 @@
203 195 }
204 196
205 197 // If a plugin was activated or deactivated.
206 198 // self::$plugins is populated in Config::ensure_options_connection().
207 - $number_of_plugins_differ = count( self::$plugins ) !== count( (array) get_option( self::ACTIVE_PLUGINS_OPTION_NAME, array() ) );
199 + $configured_plugin_keys = array_keys( self::$plugins );
200 + $stored_plugin_keys = array_keys( (array) get_option( self::ACTIVE_PLUGINS_OPTION_NAME, array() ) );
201 + sort( $configured_plugin_keys );
202 + sort( $stored_plugin_keys );
208 203
209 - if ( $number_of_plugins_differ ) {
204 + if ( $configured_plugin_keys !== $stored_plugin_keys ) {
210 205 self::update_active_plugins_option();
211 206 }
212 207 }
213 208
@@ -218,52 +213,20 @@
218 213 */
219 214 public static function update_active_plugins_option() {
220 215 // Note: Since this option is synced to wpcom, if you change its structure, you have to update the sanitizer at wpcom side.
221 216 update_option( self::ACTIVE_PLUGINS_OPTION_NAME, self::$plugins );
222 -
223 217 if ( ! class_exists( 'Automattic\Jetpack\Sync\Settings' ) || ! \Automattic\Jetpack\Sync\Settings::is_sync_enabled() ) {
224 218 self::update_active_plugins_wpcom_no_sync_fallback();
219 + // Remove the checksum for active plugins, so it gets recalculated when sync gets activated.
220 + $jetpack_callables_sync_checksum = Jetpack_Options::get_raw_option( 'jetpack_callables_sync_checksum' );
221 + if ( isset( $jetpack_callables_sync_checksum['jetpack_connection_active_plugins'] ) ) {
222 + unset( $jetpack_callables_sync_checksum['jetpack_connection_active_plugins'] );
223 + Jetpack_Options::update_raw_option( 'jetpack_callables_sync_checksum', $jetpack_callables_sync_checksum );
224 + }
225 225 }
226 226 }
227 227
228 228 /**
229 - * Add the plugin to the set of disconnected ones.
230 - *
231 - * @deprecated since 1.39.0.
232 - *
233 - * @param string $slug Plugin slug.
234 - *
235 - * @return bool
236 - */
237 - public static function disable_plugin( $slug ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
238 - return true;
239 - }
240 -
241 - /**
242 - * Remove the plugin from the set of disconnected ones.
243 - *
244 - * @deprecated since 1.39.0.
245 - *
246 - * @param string $slug Plugin slug.
247 - *
248 - * @return bool
249 - */
250 - public static function enable_plugin( $slug ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
251 - return true;
252 - }
253 -
254 - /**
255 - * Get all plugins that were disconnected by user.
256 - *
257 - * @deprecated since 1.39.0.
258 - *
259 - * @return array
260 - */
261 - public static function get_all_disabled_plugins() { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
262 - return array();
263 - }
264 -
265 - /**
266 229 * Update active plugins option with current list of active plugins on WPCOM.
267 230 * This is a fallback to ensure this option is always up to date on WPCOM in case
268 231 * Sync is not present or disabled.
269 232 *
@@ -279,9 +242,10 @@
279 242
280 243 $body = wp_json_encode(
281 244 array(
282 245 'active_connected_plugins' => self::$plugins,
283 - )
246 + ),
247 + JSON_UNESCAPED_SLASHES
284 248 );
285 249
286 250 Client::wpcom_json_api_request_as_blog(
287 251 sprintf( '/sites/%d/jetpack-active-connected-plugins', $site_id ),