From 6b9c68faa85ba2aa9301e7a8fa6b1ef07d9c59bf Mon Sep 17 00:00:00 2001 From: leogermani Date: Fri, 26 Mar 2021 16:53:17 +0000 Subject: [PATCH] Deprecate is_active and filter connection status (#19303) * deprecate is_active and filter connection status * Connection: Fix typo * Connection: Add unit test for jetpack_connection_status filter Co-authored-by: Foteini Giannaropoulou Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/690635239 --- CHANGELOG.md | 3 +++ src/class-manager.php | 9 ++++++--- tests/php/test-rest-endpoints.php | 23 +++++++++++++++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b0e72c..6827d75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,9 @@ This is an alpha version! The changes listed here are not final. - Update package dependencies. - User-less connection: Reconnect without asking the user to connect their WPCOM account +### Deprecated +- add deprecation notice and remove user-less check in is_active + ### Fixed - Only check offline mode when needed in map_meta_cap filters - Use `composer update` rather than `install` in scripts, as composer.lock isn't checked in. diff --git a/src/class-manager.php b/src/class-manager.php index 8977b34..4799d5f 100644 --- a/src/class-manager.php +++ b/src/class-manager.php @@ -484,12 +484,15 @@ private function internal_verify_xml_rpc_signature() { /** * Returns true if the current site is connected to WordPress.com and has the minimum requirements to enable Jetpack UI. * + * This method is deprecated since Jetpack 9.6.0. Please use has_connected_owner instead. + * + * Since this method has a wide spread use, we decided not to throw any deprecation warnings for now. + * + * @deprecated 9.6.0 + * @see Manager::has_connected_owner * @return Boolean is the site connected? */ public function is_active() { - if ( ( new Status() )->is_no_user_testing_mode() ) { - return $this->is_connected(); - } return (bool) $this->get_tokens()->get_access_token( true ); } diff --git a/tests/php/test-rest-endpoints.php b/tests/php/test-rest-endpoints.php index 4a7b2aa..38659ce 100644 --- a/tests/php/test-rest-endpoints.php +++ b/tests/php/test-rest-endpoints.php @@ -164,6 +164,29 @@ public function test_connection() { } } + /** + * Testing the `/jetpack/v4/connection` endpoint jetpack_connection_status filter. + */ + public function test_connection_jetpack_connection_status_filter() { + add_filter( + 'jetpack_connection_status', + function ( $status_data ) { + $this->assertTrue( is_array( $status_data ) ); + return array(); + } + ); + try { + $this->request = new WP_REST_Request( 'GET', '/jetpack/v4/connection' ); + + $response = $this->server->dispatch( $this->request ); + $data = $response->get_data(); + + $this->assertSame( array(), $data ); + } finally { + remove_all_filters( 'jetpack_connection_status' ); + } + } + /** * Testing the `/jetpack/v4/connection/plugins` endpoint. */