kollapsminoriteten/wp-content/plugins/jetpack/class.jetpack-client-server...

114 lines
2.8 KiB
PHP
Raw Normal View History

2022-04-02 10:26:41 +02:00
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
/**
* Client = Plugin
* Client Server = API Methods the Plugin must respond to
*
* @package automattic/jetpack
*/
2019-11-15 23:26:29 +01:00
2021-04-27 08:32:47 +02:00
use Automattic\Jetpack\Connection\Webhooks;
2019-11-15 23:26:29 +01:00
/**
* Client = Plugin
* Client Server = API Methods the Plugin must respond to
*/
class Jetpack_Client_Server {
/**
2021-04-27 08:32:47 +02:00
* Handle the client authorization error.
*
* @param WP_Error $error The error object.
2019-11-15 23:26:29 +01:00
*/
2021-04-27 08:32:47 +02:00
public static function client_authorize_error( $error ) {
if ( $error instanceof WP_Error ) {
Jetpack::state( 'error', $error->get_error_code() );
2019-11-15 23:26:29 +01:00
}
2021-04-27 08:32:47 +02:00
}
2019-11-15 23:26:29 +01:00
2021-04-27 08:32:47 +02:00
/**
* The user is already authorized, we set the Jetpack state and adjust the redirect URL.
*
* @return string
*/
public static function client_authorize_already_authorized_url() {
Jetpack::state( 'message', 'already_authorized' );
return Jetpack::admin_url();
}
2019-11-15 23:26:29 +01:00
2021-04-27 08:32:47 +02:00
/**
* The authorization processing has started.
*/
public static function client_authorize_processing() {
Jetpack::log( 'authorize' );
}
2019-11-15 23:26:29 +01:00
2021-04-27 08:32:47 +02:00
/**
* The authorization has completed (successfully or not), and the redirect URL is empty.
* We set the Jetpack Dashboard as the default URL.
*
* @return string
*/
public static function client_authorize_fallback_url() {
return Jetpack::admin_url();
2019-11-15 23:26:29 +01:00
}
2021-04-27 08:32:47 +02:00
/**
* Authorization handler.
*
* @deprecated since Jetpack 9.5.0
* @see Webhooks::handle_authorize()
2020-01-26 12:53:20 +01:00
*/
2021-04-27 08:32:47 +02:00
public function client_authorize() {
_deprecated_function( __METHOD__, 'jetpack-9.5.0', 'Automattic\\Jetpack\\Connection\\Webhooks::handle_authorize' );
( new Webhooks() )->handle_authorize();
2019-11-15 23:26:29 +01:00
}
2022-04-02 10:26:41 +02:00
/**
* Deactivate a plugin.
*
* @param string $probable_file Expected plugin file.
* @param string $probable_title Expected plugin title.
* @return int 1 if a plugin was deactivated, 0 if not.
*/
2019-11-15 23:26:29 +01:00
public static function deactivate_plugin( $probable_file, $probable_title ) {
include_once ABSPATH . 'wp-admin/includes/plugin.php';
if ( is_plugin_active( $probable_file ) ) {
deactivate_plugins( $probable_file );
return 1;
} else {
// If the plugin is not in the usual place, try looking through all active plugins.
$active_plugins = Jetpack::get_active_plugins();
foreach ( $active_plugins as $plugin ) {
$data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin );
2022-04-02 10:26:41 +02:00
if ( $data['Name'] === $probable_title ) {
2019-11-15 23:26:29 +01:00
deactivate_plugins( $plugin );
return 1;
}
}
}
return 0;
}
/**
2022-04-02 10:26:41 +02:00
* Get the Jetpack instance.
*
2021-04-27 08:32:47 +02:00
* @deprecated since Jetpack 9.5.0
* @see Jetpack::init()
2020-10-20 18:05:12 +02:00
*/
2019-11-15 23:26:29 +01:00
public function get_jetpack() {
2021-04-27 08:32:47 +02:00
_deprecated_function( __METHOD__, 'jetpack-9.5.0', 'Jetpack::init' );
2019-11-15 23:26:29 +01:00
return Jetpack::init();
}
2020-10-20 18:05:12 +02:00
/**
2021-04-27 08:32:47 +02:00
* No longer used.
*
* @deprecated since Jetpack 9.5.0
2020-10-20 18:05:12 +02:00
*/
2019-11-15 23:26:29 +01:00
public function do_exit() {
2021-04-27 08:32:47 +02:00
_deprecated_function( __METHOD__, 'jetpack-9.5.0' );
2019-11-15 23:26:29 +01:00
exit;
}
}