← All changes
|
jetpack_vendor/automattic/jetpack-connection/src/class-plugin-storage.php
+14
-53
13.7.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; |
| @@ -221,52 +213,20 @@ | ||
| 221 | 213 | */ |
| 222 | 214 | public static function update_active_plugins_option() { |
| 223 | 215 | // Note: Since this option is synced to wpcom, if you change its structure, you have to update the sanitizer at wpcom side. |
| 224 | 216 | update_option( self::ACTIVE_PLUGINS_OPTION_NAME, self::$plugins ); |
| 225 | - | |
| 226 | 217 | if ( ! class_exists( 'Automattic\Jetpack\Sync\Settings' ) || ! \Automattic\Jetpack\Sync\Settings::is_sync_enabled() ) { |
| 227 | 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 | + } | |
| 228 | 225 | } |
| 229 | 226 | } |
| 230 | 227 | |
| 231 | 228 | /** |
| 232 | - * Add the plugin to the set of disconnected ones. | |
| 233 | - * | |
| 234 | - * @deprecated since 1.39.0. | |
| 235 | - * | |
| 236 | - * @param string $slug Plugin slug. | |
| 237 | - * | |
| 238 | - * @return bool | |
| 239 | - */ | |
| 240 | - public static function disable_plugin( $slug ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable | |
| 241 | - return true; | |
| 242 | - } | |
| 243 | - | |
| 244 | - /** | |
| 245 | - * Remove the plugin from the set of disconnected ones. | |
| 246 | - * | |
| 247 | - * @deprecated since 1.39.0. | |
| 248 | - * | |
| 249 | - * @param string $slug Plugin slug. | |
| 250 | - * | |
| 251 | - * @return bool | |
| 252 | - */ | |
| 253 | - public static function enable_plugin( $slug ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable | |
| 254 | - return true; | |
| 255 | - } | |
| 256 | - | |
| 257 | - /** | |
| 258 | - * Get all plugins that were disconnected by user. | |
| 259 | - * | |
| 260 | - * @deprecated since 1.39.0. | |
| 261 | - * | |
| 262 | - * @return array | |
| 263 | - */ | |
| 264 | - public static function get_all_disabled_plugins() { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable | |
| 265 | - return array(); | |
| 266 | - } | |
| 267 | - | |
| 268 | - /** | |
| 269 | 229 | * Update active plugins option with current list of active plugins on WPCOM. |
| 270 | 230 | * This is a fallback to ensure this option is always up to date on WPCOM in case |
| 271 | 231 | * Sync is not present or disabled. |
| 272 | 232 | * |
| @@ -282,9 +242,10 @@ | ||
| 282 | 242 | |
| 283 | 243 | $body = wp_json_encode( |
| 284 | 244 | array( |
| 285 | 245 | 'active_connected_plugins' => self::$plugins, |
| 286 | - ) | |
| 246 | + ), | |
| 247 | + JSON_UNESCAPED_SLASHES | |
| 287 | 248 | ); |
| 288 | 249 | |
| 289 | 250 | Client::wpcom_json_api_request_as_blog( |
| 290 | 251 | sprintf( '/sites/%d/jetpack-active-connected-plugins', $site_id ), |