Skip to content

Commit

Permalink
Deprecate is_active and filter connection status (#19303)
Browse files Browse the repository at this point in the history
* deprecate is_active and filter connection status

* Connection: Fix typo

* Connection: Add unit test for jetpack_connection_status filter

Co-authored-by: Foteini Giannaropoulou <giannaropoulou.foteini@gmail.com>

Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/690635239
  • Loading branch information
leogermani authored and matticbot committed Mar 26, 2021
1 parent 0f75088 commit 6b9c68f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 6 additions & 3 deletions src/class-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

Expand Down
23 changes: 23 additions & 0 deletions tests/php/test-rest-endpoints.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down

0 comments on commit 6b9c68f

Please sign in to comment.