| 1 |
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 |
/** |
| 3 |
* Client = Plugin |
| 4 |
* Client Server = API Methods the Plugin must respond to |
| 5 |
* |
| 6 |
* @package automattic/jetpack |
| 7 |
*/ |
| 8 |
|
| 9 |
use Automattic\Jetpack\Connection\Webhooks; |
| 10 |
|
| 11 |
/** |
| 12 |
* Client = Plugin |
| 13 |
* Client Server = API Methods the Plugin must respond to |
| 14 |
*/ |
| 15 |
class Jetpack_Client_Server { |
| 16 |
|
| 17 |
/** |
| 18 |
* Handle the client authorization error. |
| 19 |
* |
| 20 |
* @param WP_Error $error The error object. |
| 21 |
*/ |
| 22 |
public static function client_authorize_error( $error ) { |
| 23 |
if ( $error instanceof WP_Error ) { |
| 24 |
Jetpack::state( 'error', $error->get_error_code() ); |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* The user is already authorized, we set the Jetpack state and adjust the redirect URL. |
| 30 |
* |
| 31 |
* @return string |
| 32 |
*/ |
| 33 |
public static function client_authorize_already_authorized_url() { |
| 34 |
Jetpack::state( 'message', 'already_authorized' ); |
| 35 |
return Jetpack::admin_url(); |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* The authorization processing has started. |
| 40 |
*/ |
| 41 |
public static function client_authorize_processing() { |
| 42 |
Jetpack::log( 'authorize' ); |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* The authorization has completed (successfully or not), and the redirect URL is empty. |
| 47 |
* We set the Jetpack Dashboard as the default URL. |
| 48 |
* |
| 49 |
* @return string |
| 50 |
*/ |
| 51 |
public static function client_authorize_fallback_url() { |
| 52 |
return Jetpack::admin_url(); |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 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 |
* Deactivate a plugin. |
| 68 |
* |
| 69 |
* @param string $probable_file Expected plugin file. |
| 70 |
* @param string $probable_title Expected plugin title. |
| 71 |
* @return int 1 if a plugin was deactivated, 0 if not. |
| 72 |
*/ |
| 73 |
public static function deactivate_plugin( $probable_file, $probable_title ) { |
| 74 |
include_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 75 |
if ( is_plugin_active( $probable_file ) ) { |
| 76 |
deactivate_plugins( $probable_file ); |
| 77 |
return 1; |
| 78 |
} else { |
| 79 |
// If the plugin is not in the usual place, try looking through all active plugins. |
| 80 |
$active_plugins = Jetpack::get_active_plugins(); |
| 81 |
foreach ( $active_plugins as $plugin ) { |
| 82 |
$data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin ); |
| 83 |
if ( $data['Name'] === $probable_title ) { |
| 84 |
deactivate_plugins( $plugin ); |
| 85 |
return 1; |
| 86 |
} |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
return 0; |
| 91 |
} |
| 92 |
|
| 93 |
/** |
| 94 |
* Get the Jetpack instance. |
| 95 |
* |
| 96 |
* @deprecated since Jetpack 9.5.0 |
| 97 |
* @see Jetpack::init() |
| 98 |
*/ |
| 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; |
| 112 |
} |
| 113 |
} |
| 114 |
|