Completed
Push — update/conversation-remove-par... ( 498b22...5ced53 )
by
unknown
18:38 queued 07:08
created

Jetpack_Client_Server::authorize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
use Automattic\Jetpack\Connection\Webhooks;
4
5
/**
6
 * Client = Plugin
7
 * Client Server = API Methods the Plugin must respond to
8
 */
9
class Jetpack_Client_Server {
10
11
	/**
12
	 * Handle the client authorization error.
13
	 *
14
	 * @param WP_Error $error The error object.
15
	 */
16
	public static function client_authorize_error( $error ) {
17
		if ( $error instanceof WP_Error ) {
18
			Jetpack::state( 'error', $error->get_error_code() );
0 ignored issues
show
Bug introduced by
The method get_error_code() does not seem to exist on object<WP_Error>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
19
		}
20
	}
21
22
	/**
23
	 * The user is already authorized, we set the Jetpack state and adjust the redirect URL.
24
	 *
25
	 * @return string
26
	 */
27
	public static function client_authorize_already_authorized_url() {
28
		Jetpack::state( 'message', 'already_authorized' );
29
		return Jetpack::admin_url();
30
	}
31
32
	/**
33
	 * The authorization processing has started.
34
	 */
35
	public static function client_authorize_processing() {
36
		Jetpack::log( 'authorize' );
37
	}
38
39
	/**
40
	 * The authorization has completed (successfully or not), and the redirect URL is empty.
41
	 * We set the Jetpack Dashboard as the default URL.
42
	 *
43
	 * @return string
44
	 */
45
	public static function client_authorize_fallback_url() {
46
		return Jetpack::admin_url();
47
	}
48
49
	/**
50
	 * Authorization handler.
51
	 *
52
	 * @deprecated since Jetpack 9.5.0
53
	 * @see Webhooks::handle_authorize()
54
	 */
55
	public function client_authorize() {
56
		_deprecated_function( __METHOD__, 'jetpack-9.5.0', 'Automattic\\Jetpack\\Connection\\Webhooks::handle_authorize' );
57
		( new Webhooks() )->handle_authorize();
0 ignored issues
show
Bug introduced by
The call to Webhooks::__construct() misses a required argument $connection.

This check looks for function calls that miss required arguments.

Loading history...
58
	}
59
60
	public static function deactivate_plugin( $probable_file, $probable_title ) {
61
		include_once ABSPATH . 'wp-admin/includes/plugin.php';
62
		if ( is_plugin_active( $probable_file ) ) {
63
			deactivate_plugins( $probable_file );
64
			return 1;
65
		} else {
66
			// If the plugin is not in the usual place, try looking through all active plugins.
67
			$active_plugins = Jetpack::get_active_plugins();
68
			foreach ( $active_plugins as $plugin ) {
69
				$data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin );
70
				if ( $data['Name'] == $probable_title ) {
71
					deactivate_plugins( $plugin );
72
					return 1;
73
				}
74
			}
75
		}
76
77
		return 0;
78
	}
79
80
	/**
81
	 * @deprecated since Jetpack 9.5.0
82
	 * @see Jetpack::init()
83
	 */
84
	public function get_jetpack() {
85
		_deprecated_function( __METHOD__, 'jetpack-9.5.0', 'Jetpack::init' );
86
		return Jetpack::init();
87
	}
88
89
	/**
90
	 * No longer used.
91
	 *
92
	 * @deprecated since Jetpack 9.5.0
93
	 */
94
	public function do_exit() {
95
		_deprecated_function( __METHOD__, 'jetpack-9.5.0' );
96
		exit;
97
	}
98
}
99