| @@ -5,10 +5,8 @@ | ||
| 5 | 5 | * |
| 6 | 6 | * @package automattic/jetpack |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -use Automattic\Jetpack\Connection\Webhooks; | |
| 10 | - | |
| 11 | 9 | /** |
| 12 | 10 | * Client = Plugin |
| 13 | 11 | * Client Server = API Methods the Plugin must respond to |
| 14 | 12 | */ |
| @@ -14,8 +12,30 @@ | ||
| 14 | 12 | */ |
| 15 | 13 | class Jetpack_Client_Server { |
| 16 | 14 | |
| 17 | 15 | /** |
| 16 | + * Whether the class has been initialized. | |
| 17 | + * | |
| 18 | + * @var bool | |
| 19 | + */ | |
| 20 | + private static $did_init = false; | |
| 21 | + | |
| 22 | + /** | |
| 23 | + * Initialize the hooks, but only once. | |
| 24 | + * | |
| 25 | + * @return void | |
| 26 | + */ | |
| 27 | + public static function init() { | |
| 28 | + if ( static::$did_init ) { | |
| 29 | + return; | |
| 30 | + } | |
| 31 | + | |
| 32 | + add_filter( 'jetpack_rest_connection_check_response', array( static::class, 'connection_check' ) ); | |
| 33 | + | |
| 34 | + static::$did_init = true; | |
| 35 | + } | |
| 36 | + | |
| 37 | + /** | |
| 18 | 38 | * Handle the client authorization error. |
| 19 | 39 | * |
| 20 | 40 | * @param WP_Error $error The error object. |
| 21 | 41 | */ |
| @@ -52,19 +72,8 @@ | ||
| 52 | 72 | return Jetpack::admin_url(); |
| 53 | 73 | } |
| 54 | 74 | |
| 55 | 75 | /** |
| 56 | - * Authorization handler. | |
| 57 | - * | |
| 58 | - * @deprecated since Jetpack 9.5.0 | |
| 59 | - * @see Webhooks::handle_authorize() | |
| 60 | - */ | |
| 61 | - public function client_authorize() { | |
| 62 | - _deprecated_function( __METHOD__, 'jetpack-9.5.0', 'Automattic\\Jetpack\\Connection\\Webhooks::handle_authorize' ); | |
| 63 | - ( new Webhooks() )->handle_authorize(); | |
| 64 | - } | |
| 65 | - | |
| 66 | - /** | |
| 67 | 76 | * Deactivate a plugin. |
| 68 | 77 | * |
| 69 | 78 | * @param string $probable_file Expected plugin file. |
| 70 | 79 | * @param string $probable_title Expected plugin title. |
| @@ -90,24 +99,12 @@ | ||
| 90 | 99 | return 0; |
| 91 | 100 | } |
| 92 | 101 | |
| 93 | 102 | /** |
| 94 | - * Get the Jetpack instance. | |
| 103 | + * Filters the result of test_connection REST method | |
| 95 | 104 | * |
| 96 | - * @deprecated since Jetpack 9.5.0 | |
| 97 | - * @see Jetpack::init() | |
| 105 | + * @return string The current Jetpack version number | |
| 98 | 106 | */ |
| 99 | - public function get_jetpack() { | |
| 100 | - _deprecated_function( __METHOD__, 'jetpack-9.5.0', 'Jetpack::init' ); | |
| 101 | - return Jetpack::init(); | |
| 102 | - } | |
| 103 | - | |
| 104 | - /** | |
| 105 | - * No longer used. | |
| 106 | - * | |
| 107 | - * @deprecated since Jetpack 9.5.0 | |
| 108 | - */ | |
| 109 | - public function do_exit() { | |
| 110 | - _deprecated_function( __METHOD__, 'jetpack-9.5.0' ); | |
| 111 | - exit; | |
| 107 | + public static function connection_check() { | |
| 108 | + return JETPACK__VERSION; | |
| 112 | 109 | } |
| 113 | 110 | } |