1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* The Jetpack Connection package Utils class file. |
4
|
|
|
* |
5
|
|
|
* @package automattic/jetpack-connection |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Automattic\Jetpack\Connection; |
9
|
|
|
|
10
|
|
|
use Automattic\Jetpack\Tracking; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Provides utility methods for the Connection package. |
14
|
|
|
*/ |
15
|
|
|
class Utils { |
16
|
|
|
|
17
|
|
|
const DEFAULT_JETPACK__API_VERSION = 1; |
18
|
|
|
const DEFAULT_JETPACK__API_BASE = 'https://jetpack.wordpress.com/jetpack.'; |
19
|
|
|
const DEFAULT_JETPACK__WPCOM_JSON_API_BASE = 'https://public-api.wordpress.com'; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* This method used to set the URL scheme to HTTP when HTTPS requests can't be made. |
23
|
|
|
* Now it returns the exact same URL you pass as an argument. |
24
|
|
|
* |
25
|
|
|
* @param string $url The url. |
26
|
|
|
* @return string The exact same url. |
27
|
|
|
* |
28
|
|
|
* @deprecated 9.1.0 Jetpack can't function properly on servers that don't support outbound HTTPS requests. |
29
|
|
|
*/ |
30
|
|
|
public static function fix_url_for_bad_hosts( $url ) { |
31
|
|
|
_deprecated_function( __METHOD__, 'jetpack-9.1.0' ); |
32
|
|
|
return $url; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Enters a user token into the user_tokens option |
37
|
|
|
* |
38
|
|
|
* @deprecated 9.5 Use Automattic\Jetpack\Connection\Tokens->update_user_token() instead. |
39
|
|
|
* |
40
|
|
|
* @param int $user_id The user id. |
41
|
|
|
* @param string $token The user token. |
42
|
|
|
* @param bool $is_master_user Whether the user is the master user. |
43
|
|
|
* @return bool |
44
|
|
|
*/ |
45
|
|
|
public static function update_user_token( $user_id, $token, $is_master_user ) { |
46
|
|
|
_deprecated_function( __METHOD__, 'jetpack-9.5', 'Automattic\\Jetpack\\Connection\\Tokens->update_user_token' ); |
47
|
|
|
return ( new Tokens() )->update_user_token( $user_id, $token, $is_master_user ); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Filters the value of the api constant. |
52
|
|
|
* |
53
|
|
|
* @param String $constant_value The constant value. |
54
|
|
|
* @param String $constant_name The constant name. |
55
|
|
|
* @return mixed | null |
56
|
|
|
*/ |
57
|
|
|
public static function jetpack_api_constant_filter( $constant_value, $constant_name ) { |
58
|
|
|
if ( ! is_null( $constant_value ) ) { |
59
|
|
|
// If the constant value was already set elsewhere, use that value. |
60
|
|
|
return $constant_value; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
if ( defined( "self::DEFAULT_$constant_name" ) ) { |
64
|
|
|
return constant( "self::DEFAULT_$constant_name" ); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
return null; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Add a filter to initialize default values of the constants. |
72
|
|
|
*/ |
73
|
|
|
public static function init_default_constants() { |
74
|
|
|
add_filter( |
75
|
|
|
'jetpack_constant_default_value', |
76
|
|
|
array( __CLASS__, 'jetpack_api_constant_filter' ), |
77
|
|
|
10, |
78
|
|
|
2 |
79
|
|
|
); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Filters the registration request body to include tracking properties. |
84
|
|
|
* |
85
|
|
|
* @param array $properties Already prepared tracking properties. |
86
|
|
|
* @return array amended properties. |
87
|
|
|
*/ |
88
|
|
View Code Duplication |
public static function filter_register_request_body( $properties ) { |
89
|
|
|
$tracking = new Tracking(); |
90
|
|
|
$tracks_identity = $tracking->tracks_get_identity( get_current_user_id() ); |
91
|
|
|
|
92
|
|
|
return array_merge( |
93
|
|
|
$properties, |
94
|
|
|
array( |
95
|
|
|
'_ui' => $tracks_identity['_ui'], |
96
|
|
|
'_ut' => $tracks_identity['_ut'], |
97
|
|
|
) |
98
|
|
|
); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
} |
102
|
|
|
|