jetpack
Last commit date
3rd-party
2 months ago
_inc
1 month ago
css
4 months ago
extensions
1 month ago
images
2 months ago
jetpack_vendor
1 month ago
json-endpoints
2 months ago
modules
1 month ago
sal
2 months ago
src
3 months ago
vendor
1 month ago
views
1 month ago
CHANGELOG.md
1 month ago
LICENSE.txt
5 months ago
SECURITY.md
2 years ago
class-jetpack-connection-status.php
2 years ago
class-jetpack-gallery-settings.php
6 months ago
class-jetpack-newsletter-dashboard-widget.php
6 months ago
class-jetpack-pre-connection-jitms.php
2 years ago
class-jetpack-stats-dashboard-widget.php
3 months ago
class-jetpack-xmlrpc-methods.php
6 months ago
class.frame-nonce-preview.php
6 months ago
class.jetpack-admin.php
3 months ago
class.jetpack-autoupdate.php
6 months ago
class.jetpack-cli.php
5 months ago
class.jetpack-client-server.php
2 years ago
class.jetpack-gutenberg.php
2 months ago
class.jetpack-heartbeat.php
3 months ago
class.jetpack-modules-list-table.php
6 months ago
class.jetpack-network-sites-list-table.php
6 months ago
class.jetpack-network.php
1 month ago
class.jetpack-plan.php
2 years ago
class.jetpack-post-images.php
2 months ago
class.jetpack-twitter-cards.php
3 months ago
class.jetpack-user-agent.php
2 years ago
class.jetpack.php
2 months ago
class.json-api-endpoints.php
4 months ago
class.json-api.php
5 months ago
class.photon.php
3 years ago
composer.json
1 month ago
enhanced-open-graph.php
3 months ago
functions.compat.php
3 months ago
functions.cookies.php
2 years ago
functions.global.php
6 months ago
functions.is-mobile.php
2 years ago
functions.opengraph.php
2 months ago
functions.photon.php
2 years ago
jetpack.php
1 month ago
json-api-config.php
3 years ago
json-endpoints.php
2 years ago
load-jetpack.php
2 months ago
locales.php
6 months ago
readme.txt
1 month ago
unauth-file-upload.php
6 months ago
uninstall.php
6 months ago
wpml-config.xml
3 years ago
class.jetpack-client-server.php
111 lines
| 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 | /** |
| 10 | * Client = Plugin |
| 11 | * Client Server = API Methods the Plugin must respond to |
| 12 | */ |
| 13 | class Jetpack_Client_Server { |
| 14 | |
| 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 | /** |
| 38 | * Handle the client authorization error. |
| 39 | * |
| 40 | * @param WP_Error $error The error object. |
| 41 | */ |
| 42 | public static function client_authorize_error( $error ) { |
| 43 | if ( $error instanceof WP_Error ) { |
| 44 | Jetpack::state( 'error', $error->get_error_code() ); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * The user is already authorized, we set the Jetpack state and adjust the redirect URL. |
| 50 | * |
| 51 | * @return string |
| 52 | */ |
| 53 | public static function client_authorize_already_authorized_url() { |
| 54 | Jetpack::state( 'message', 'already_authorized' ); |
| 55 | return Jetpack::admin_url(); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * The authorization processing has started. |
| 60 | */ |
| 61 | public static function client_authorize_processing() { |
| 62 | Jetpack::log( 'authorize' ); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * The authorization has completed (successfully or not), and the redirect URL is empty. |
| 67 | * We set the Jetpack Dashboard as the default URL. |
| 68 | * |
| 69 | * @return string |
| 70 | */ |
| 71 | public static function client_authorize_fallback_url() { |
| 72 | return Jetpack::admin_url(); |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Deactivate a plugin. |
| 77 | * |
| 78 | * @param string $probable_file Expected plugin file. |
| 79 | * @param string $probable_title Expected plugin title. |
| 80 | * @return int 1 if a plugin was deactivated, 0 if not. |
| 81 | */ |
| 82 | public static function deactivate_plugin( $probable_file, $probable_title ) { |
| 83 | include_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 84 | if ( is_plugin_active( $probable_file ) ) { |
| 85 | deactivate_plugins( $probable_file ); |
| 86 | return 1; |
| 87 | } else { |
| 88 | // If the plugin is not in the usual place, try looking through all active plugins. |
| 89 | $active_plugins = Jetpack::get_active_plugins(); |
| 90 | foreach ( $active_plugins as $plugin ) { |
| 91 | $data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin ); |
| 92 | if ( $data['Name'] === $probable_title ) { |
| 93 | deactivate_plugins( $plugin ); |
| 94 | return 1; |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | return 0; |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Filters the result of test_connection REST method |
| 104 | * |
| 105 | * @return string The current Jetpack version number |
| 106 | */ |
| 107 | public static function connection_check() { |
| 108 | return JETPACK__VERSION; |
| 109 | } |
| 110 | } |
| 111 |