Skip to content

Commit d4986c6

Browse files
kraftbjmatticbot
authored andcommitted
Revert: Deprecate Soft Disconnect (#24104)
* Revert "Deprecate soft disconnect (#23991)" This reverts commit abe478363162985c8b1d58f6efe49f0e6c62ce08. * changelog Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/2230691061
1 parent afa94bc commit d4986c6

File tree

4 files changed

+40
-40
lines changed

4 files changed

+40
-40
lines changed

jetpack_vendor/automattic/jetpack-connection/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ This is an alpha version! The changes listed here are not final.
1212
### Deprecated
1313
- Moved the options class into Connection.
1414

15+
### Fixed
16+
- Reverts #23991
17+
1518
## [1.39.0] - 2022-04-26
1619
### Changed
1720
- Make remove_connection a proxy method to ensure all trackings are triggered

jetpack_vendor/automattic/jetpack-connection/src/class-manager.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,6 +1636,7 @@ public function disconnect_site_wpcom( $ignore_connected_plugins = false ) {
16361636
* This function will automatically perform "soft" or "hard" disconnect depending on whether other plugins are using the connection.
16371637
* This is a proxy method to simplify the Connection package API.
16381638
*
1639+
* @see Manager::disable_plugin()
16391640
* @see Manager::disconnect_site()
16401641
*
16411642
* @param boolean $disconnect_wpcom Should disconnect_site_wpcom be called.
@@ -1644,6 +1645,7 @@ public function disconnect_site_wpcom( $ignore_connected_plugins = false ) {
16441645
*/
16451646
public function remove_connection( $disconnect_wpcom = true, $ignore_connected_plugins = false ) {
16461647

1648+
$this->disable_plugin();
16471649
$this->disconnect_site( $disconnect_wpcom, $ignore_connected_plugins );
16481650

16491651
return true;
@@ -2328,25 +2330,29 @@ public function get_connected_plugins() {
23282330
* Force plugin disconnect. After its called, the plugin will not be allowed to use the connection.
23292331
* Note: this method does not remove any access tokens.
23302332
*
2331-
* @deprecated since 1.39.0
23322333
* @return bool
23332334
*/
23342335
public function disable_plugin() {
2335-
_deprecated_function( __METHOD__, '1.39.0' );
2336-
return null;
2336+
if ( ! $this->plugin ) {
2337+
return false;
2338+
}
2339+
2340+
return $this->plugin->disable();
23372341
}
23382342

23392343
/**
23402344
* Force plugin reconnect after user-initiated disconnect.
23412345
* After its called, the plugin will be allowed to use the connection again.
23422346
* Note: this method does not initialize access tokens.
23432347
*
2344-
* @deprecated since 1.39.0.
23452348
* @return bool
23462349
*/
23472350
public function enable_plugin() {
2348-
_deprecated_function( __METHOD__, '1.39.0' );
2349-
return null;
2351+
if ( ! $this->plugin ) {
2352+
return false;
2353+
}
2354+
2355+
return $this->plugin->enable();
23502356
}
23512357

23522358
/**

jetpack_vendor/automattic/jetpack-connection/src/class-plugin-storage.php

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@ class Plugin_Storage {
1616

1717
const ACTIVE_PLUGINS_OPTION_NAME = 'jetpack_connection_active_plugins';
1818

19-
/**
20-
* Options where disabled plugins were stored
21-
*
22-
* @deprecated since 1.39.0.
23-
* @var string
24-
*/
2519
const PLUGINS_DISABLED_OPTION_NAME = 'jetpack_connection_disabled_plugins';
2620

2721
/**
@@ -99,20 +93,18 @@ public static function get_one( $slug ) {
9993
* Even if you don't use Jetpack Config, it may be introduced later by other plugins,
10094
* so please make sure not to run the method too early in the code.
10195
*
102-
* @since 1.39.0 deprecated the $connected_only argument.
103-
*
104-
* @param null $deprecated null plugins that were explicitly disconnected. Deprecated, there's no such a thing as disconnecting only specific plugins anymore.
96+
* @param bool $connected_only Exclude plugins that were explicitly disconnected.
10597
*
10698
* @return array|WP_Error
10799
*/
108-
public static function get_all( $deprecated = null ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
100+
public static function get_all( $connected_only = false ) {
109101
$maybe_error = self::ensure_configured();
110102

111103
if ( $maybe_error instanceof WP_Error ) {
112104
return $maybe_error;
113105
}
114106

115-
return self::$plugins;
107+
return $connected_only ? array_diff_key( self::$plugins, array_flip( self::get_all_disabled_plugins() ) ) : self::$plugins;
116108
}
117109

118110
/**
@@ -172,7 +164,6 @@ public static function configure() {
172164
}
173165

174166
// If a plugin was activated or deactivated.
175-
// self::$plugins is populated in Config::ensure_options_connection().
176167
$number_of_plugins_differ = count( self::$plugins ) !== count( (array) get_option( self::ACTIVE_PLUGINS_OPTION_NAME, array() ) );
177168

178169
if ( $number_of_plugins_differ || true === self::$refresh_connected_plugins ) {
@@ -200,41 +191,47 @@ public static function update_active_plugins_option() {
200191
/**
201192
* Add the plugin to the set of disconnected ones.
202193
*
203-
* @deprecated since 1.39.0.
204-
*
205194
* @param string $slug Plugin slug.
206195
*
207196
* @return bool
208197
*/
209-
public static function disable_plugin( $slug ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
210-
_deprecated_function( __METHOD__, '1.39.0' );
198+
public static function disable_plugin( $slug ) {
199+
$disconnects = self::get_all_disabled_plugins();
200+
201+
if ( ! in_array( $slug, $disconnects, true ) ) {
202+
$disconnects[] = $slug;
203+
update_option( self::PLUGINS_DISABLED_OPTION_NAME, $disconnects );
204+
}
205+
211206
return true;
212207
}
213208

214209
/**
215210
* Remove the plugin from the set of disconnected ones.
216211
*
217-
* @deprecated since 1.39.0.
218-
*
219212
* @param string $slug Plugin slug.
220213
*
221214
* @return bool
222215
*/
223-
public static function enable_plugin( $slug ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
224-
_deprecated_function( __METHOD__, '1.39.0' );
216+
public static function enable_plugin( $slug ) {
217+
$disconnects = self::get_all_disabled_plugins();
218+
219+
$slug_index = array_search( $slug, $disconnects, true );
220+
if ( false !== $slug_index ) {
221+
unset( $disconnects[ $slug_index ] );
222+
update_option( self::PLUGINS_DISABLED_OPTION_NAME, $disconnects );
223+
}
224+
225225
return true;
226226
}
227227

228228
/**
229229
* Get all plugins that were disconnected by user.
230230
*
231-
* @deprecated since 1.39.0.
232-
*
233231
* @return array
234232
*/
235-
public static function get_all_disabled_plugins() { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
236-
_deprecated_function( __METHOD__, '1.39.0' );
237-
return array();
233+
public static function get_all_disabled_plugins() {
234+
return (array) get_option( self::PLUGINS_DISABLED_OPTION_NAME, array() );
238235
}
239236

240237
/**

jetpack_vendor/automattic/jetpack-connection/src/class-plugin.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,25 +91,19 @@ public function is_only() {
9191
/**
9292
* Add the plugin to the set of disconnected ones.
9393
*
94-
* @deprecated since 1.39.0.
95-
*
9694
* @return bool
9795
*/
9896
public function disable() {
99-
_deprecated_function( __METHOD__, '1.39.0' );
100-
return true;
97+
return Plugin_Storage::disable_plugin( $this->slug );
10198
}
10299

103100
/**
104101
* Remove the plugin from the set of disconnected ones.
105102
*
106-
* @deprecated since 1.39.0.
107-
*
108103
* @return bool
109104
*/
110105
public function enable() {
111-
_deprecated_function( __METHOD__, '1.39.0' );
112-
return true;
106+
return Plugin_Storage::enable_plugin( $this->slug );
113107
}
114108

115109
/**
@@ -118,7 +112,7 @@ public function enable() {
118112
* @return bool
119113
*/
120114
public function is_enabled() {
121-
return in_array( $this->slug, Plugin_Storage::get_all(), true );
115+
return ! in_array( $this->slug, Plugin_Storage::get_all_disabled_plugins(), true );
122116
}
123117

124118
}

0 commit comments

Comments
 (0)