Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
WPCOMSH_Require_Connection_Owner
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 1
 filter_is_connection_ready
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2/**
3 * Force Jetpack connection to require a connected owner
4 *
5 * Since Jetpack 9.7, the connection is considered active as soon as a site level conneciton is established,
6 * making the user authorization step optional. For Atomic sites, we only want the Jetpack connection to work when
7 * there's an authorized user.
8 *
9 * @package wpcomsh
10 */
11
12/**
13 * Class WPCOMSH_Require_Connection_Owner.
14 */
15class WPCOMSH_Require_Connection_Owner {
16
17    /**
18     * Filters the Jetpack::is_connection_ready to ensure a connectino owner is always needed
19     *
20     * @param bool                                  $is_connection_ready True if connection is ready; elsewise false.
21     * @param Automattic\Jetpack\Connection\Manager $connection_manager Instance of the Manager class, can be used to check the connection status.
22     * @return bool
23     */
24    public static function filter_is_connection_ready( $is_connection_ready, $connection_manager ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter
25        return $connection_manager->has_connected_owner() || $connection_manager->is_user_connected();
26    }
27}
28add_filter( 'jetpack_is_connection_ready', array( 'WPCOMSH_Require_Connection_Owner', 'filter_is_connection_ready' ), 1000, 2 );