PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 8.9.4
Jetpack – WP Security, Backup, Speed, & Growth v8.9.4
16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 All 501 releases
jetpack / class.jetpack-client-server.php
class.jetpack-client-server.php
113 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 use Automattic\Jetpack\Connection\Client;
4 use Automattic\Jetpack\Connection\Manager as Connection_Manager;
5 use Automattic\Jetpack\Connection\Utils as Connection_Utils;
6 use Automattic\Jetpack\Roles;
7 use Automattic\Jetpack\Tracking;
8
9 /**
10 * Client = Plugin
11 * Client Server = API Methods the Plugin must respond to
12 */
13 class Jetpack_Client_Server {
14
15 /**
16 * Authorizations
17 */
18 function client_authorize() {
19 $data = stripslashes_deep( $_GET );
20 $data['auth_type'] = 'client';
21 $roles = new Roles();
22 $role = $roles->translate_current_user_to_role();
23 $redirect = isset( $data['redirect'] ) ? esc_url_raw( (string) $data['redirect'] ) : '';
24
25 check_admin_referer( "jetpack-authorize_{$role}_{$redirect}" );
26
27 $tracking = new Tracking();
28
29 $manager = new Connection_Manager();
30 $result = $manager->authorize( $data );
31
32 if ( is_wp_error( $result ) ) {
33 Jetpack::state( 'error', $result->get_error_code() );
34
35 $tracking->record_user_event(
36 'jpc_client_authorize_fail',
37 array(
38 'error_code' => $result->get_error_code(),
39 'error_message' => $result->get_error_message(),
40 )
41 );
42 } else {
43 /**
44 * Fires after the Jetpack client is authorized to communicate with WordPress.com.
45 *
46 * @since 4.2.0
47 *
48 * @param int Jetpack Blog ID.
49 */
50 do_action( 'jetpack_client_authorized', Jetpack_Options::get_option( 'id' ) );
51 }
52
53 if ( wp_validate_redirect( $redirect ) ) {
54 // Exit happens below in $this->do_exit()
55 wp_safe_redirect( $redirect );
56 } else {
57 // Exit happens below in $this->do_exit()
58 wp_safe_redirect( Jetpack::admin_url() );
59 }
60
61 $tracking->record_user_event( 'jpc_client_authorize_success' );
62
63 $this->do_exit();
64 }
65
66 /*
67 * @deprecated 8.0 Use Automattic\Jetpack\Connection\Manager::authorize() instead.
68 */
69 function authorize( $data = array() ) {
70 _deprecated_function( __METHOD__, 'jetpack-8.0', 'Automattic\\Jetpack\\Connection\\Manager::authorize' );
71 $manager = new Connection_Manager();
72 return $manager->authorize( $data );
73 }
74
75 public static function deactivate_plugin( $probable_file, $probable_title ) {
76 include_once ABSPATH . 'wp-admin/includes/plugin.php';
77 if ( is_plugin_active( $probable_file ) ) {
78 deactivate_plugins( $probable_file );
79 return 1;
80 } else {
81 // If the plugin is not in the usual place, try looking through all active plugins.
82 $active_plugins = Jetpack::get_active_plugins();
83 foreach ( $active_plugins as $plugin ) {
84 $data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin );
85 if ( $data['Name'] == $probable_title ) {
86 deactivate_plugins( $plugin );
87 return 1;
88 }
89 }
90 }
91
92 return 0;
93 }
94
95 /**
96 * @deprecated since 8.0.0 Use Automattic\Jetpack\Connection\Manager::get_token() instead.
97 *
98 * @return object|WP_Error
99 */
100 function get_token( $data ) {
101 _deprecated_function( __METHOD__, 'jetpack-8.0', 'Automattic\\Jetpack\\Connection\\Manager\\get_token' );
102 return Jetpack::connection()->get_token( $data );
103 }
104
105 public function get_jetpack() {
106 return Jetpack::init();
107 }
108
109 public function do_exit() {
110 exit;
111 }
112 }
113