|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Jetpack's Pre-Connection JITM class. |
|
4
|
|
|
* |
|
5
|
|
|
* @package automattic/jetpack-jitm |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace Automattic\Jetpack\JITMS; |
|
9
|
|
|
|
|
10
|
|
|
use Automattic\Jetpack\Connection\Client; |
|
11
|
|
|
use Automattic\Jetpack\Partner; |
|
12
|
|
|
use Automattic\Jetpack\JITMS\JITM; |
|
13
|
|
|
use Automattic\Jetpack\JITMS\Engine; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Jetpack just in time messaging through out the admin |
|
17
|
|
|
* |
|
18
|
|
|
* @since 5.6.0 |
|
19
|
|
|
*/ |
|
20
|
|
|
class Pre_Connection_JITM extends JITM { |
|
21
|
|
|
|
|
22
|
|
|
const PACKAGE_VERSION = '1.0'; // TODO: Keep in sync with version specified in composer.json. |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Determines if JITMs are enabled. |
|
26
|
|
|
* |
|
27
|
|
|
* @return bool Enable JITMs. |
|
28
|
|
|
*/ |
|
29
|
|
|
public function register() { |
|
30
|
|
|
add_action( 'current_screen', array( $this, 'prepare_jitms' ) ); |
|
31
|
|
|
return true; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Retrieve the current message to display keyed on query string and message path |
|
36
|
|
|
* |
|
37
|
|
|
* @param string $message_path The message path to ask for. |
|
38
|
|
|
* @param string $query The query string originally from the front end. |
|
39
|
|
|
* @param bool $full_jp_logo_exists If there is a full Jetpack logo already on the page. |
|
40
|
|
|
* |
|
41
|
|
|
* @return array The JITM's to show, or an empty array if there is nothing to show |
|
42
|
|
|
*/ |
|
43
|
|
|
public function get_messages( $message_path, $query, $full_jp_logo_exists ) { |
|
44
|
|
|
$jitm_engine = new Engine(); |
|
45
|
|
|
|
|
46
|
|
|
$query_string = array(); |
|
47
|
|
|
if ( isset( $query ) ) { |
|
48
|
|
|
foreach ( explode( ',', $query ) as $query_item ) { |
|
49
|
|
|
$query_item = explode( '=', $query_item ); |
|
50
|
|
|
$query_string[ $query_item[0] ] = isset( $query_item[1] ) ? $query_item[1] : null; |
|
51
|
|
|
} |
|
52
|
|
|
unset( $query_item ); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
$mobile_browser = jetpack_is_mobile( 'smart' ); |
|
56
|
|
|
$user = wp_get_current_user(); |
|
57
|
|
|
|
|
58
|
|
|
// Unauthenticated or invalid requests just bail. |
|
59
|
|
|
if ( ! $user ) { |
|
60
|
|
|
return array(); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
$user_roles = implode( ',', $user->roles ); |
|
64
|
|
|
|
|
65
|
|
|
$envelopes = $jitm_engine->get_top_messages( $message_path, $user->ID, $user_roles, $query_string, $mobile_browser ); |
|
|
|
|
|
|
66
|
|
|
|
|
67
|
|
|
if ( ! is_array( $envelopes ) ) { |
|
68
|
|
|
return array(); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
$hidden_jitms = \Jetpack_Options::get_option( 'hide_jitm' ); |
|
72
|
|
|
|
|
73
|
|
|
unset( $envelopes['last_response_time'] ); |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Allow adding your own custom JITMs after a set of JITMs has been received. |
|
77
|
|
|
* |
|
78
|
|
|
* @since 6.9.0 |
|
79
|
|
|
* @since 8.3.0 - Added Message path. |
|
80
|
|
|
* |
|
81
|
|
|
* @param array $envelopes array of existing JITMs. |
|
82
|
|
|
* @param string $message_path The message path to ask for. |
|
83
|
|
|
*/ |
|
84
|
|
|
$envelopes = apply_filters( 'jetpack_jitm_received_envelopes', $envelopes, $message_path ); |
|
85
|
|
|
|
|
86
|
|
|
foreach ( $envelopes as $idx => &$envelope ) { |
|
87
|
|
|
|
|
88
|
|
|
$dismissed_feature = isset( $hidden_jitms[ $envelope->feature_class ] ) && is_array( $hidden_jitms[ $envelope->feature_class ] ) ? $hidden_jitms[ $envelope->feature_class ] : null; |
|
89
|
|
|
|
|
90
|
|
|
// If the this feature class has been dismissed and the request has not passed the ttl, skip it as it's been dismissed. |
|
91
|
|
View Code Duplication |
if ( is_array( $dismissed_feature ) && ( time() - $dismissed_feature['last_dismissal'] < $envelope->expires || $dismissed_feature['number'] >= $envelope->max_dismissal ) ) { |
|
92
|
|
|
unset( $envelopes[ $idx ] ); |
|
93
|
|
|
continue; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
$normalized_site_url = \Jetpack::build_raw_urls( get_home_url() ); |
|
97
|
|
|
|
|
98
|
|
|
$url_params = array( |
|
99
|
|
|
'source' => "jitm-$envelope->id", |
|
100
|
|
|
'site' => $normalized_site_url, |
|
101
|
|
|
'u' => $user->ID, |
|
102
|
|
|
); |
|
103
|
|
|
|
|
104
|
|
|
// Get affiliate code and add it to the array of URL parameters. |
|
105
|
|
|
$aff = Partner::init()->get_partner_code( Partner::AFFILIATE_CODE ); |
|
106
|
|
|
if ( '' !== $aff ) { |
|
107
|
|
|
$url_params['aff'] = $aff; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
$envelope->url = add_query_arg( $url_params, 'https://jetpack.com/redirect/' ); |
|
111
|
|
|
|
|
112
|
|
View Code Duplication |
if ( $envelope->cta['hook'] ) { |
|
113
|
|
|
$envelope->url = apply_filters( 'jitm_' . $envelope->cta['hook'], $envelope->url ); |
|
114
|
|
|
unset( $envelope->cta['hook'] ); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
View Code Duplication |
if ( isset( $envelope->content['hook'] ) ) { |
|
118
|
|
|
$envelope->content = apply_filters( 'jitm_' . $envelope->content['hook'], $envelope->content ); |
|
119
|
|
|
unset( $envelope->content['hook'] ); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
// No point in showing an empty message. |
|
123
|
|
|
if ( empty( $envelope->content['message'] ) ) { |
|
124
|
|
|
unset( $envelopes[ $idx ] ); |
|
125
|
|
|
continue; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
$envelope->content['icon'] = $this->generate_icon( $envelope->content['icon'], $full_jp_logo_exists ); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
return $envelopes; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
} |
|
135
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: