1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Jetpack's JITM Engine class. |
4
|
|
|
* |
5
|
|
|
* @package automattic/jetpack-jitm |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Automattic\Jetpack\JITMS; |
9
|
|
|
|
10
|
|
|
use Automattic\Jetpack\JITMS\Message; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class JITM\Engine |
14
|
|
|
* |
15
|
|
|
* Determines the rules of a JITM, which should display and when. |
16
|
|
|
*/ |
17
|
|
|
class Engine { |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Returns the pre-connection JITMs rules |
21
|
|
|
* |
22
|
|
|
* @return array Pre-connection JITMs rules. |
23
|
|
|
*/ |
24
|
|
|
private function preconnection_rules() { |
25
|
|
|
|
26
|
|
|
return array( |
27
|
|
|
( new Message( 'jpsetup-posts' ) ) |
28
|
|
|
->message_path( '/wp:edit-post:admin_notices/' ) |
29
|
|
|
->show( |
30
|
|
|
__( 'Do you know which of these posts gets the most traffic?', 'jetpack' ), |
31
|
|
|
__( 'Setup Jetpack to get in-depth stats about your content and visitors.', 'jetpack' ) |
32
|
|
|
) |
33
|
|
|
->with_cta( |
34
|
|
|
__( 'Setup Jetpack', 'jetpack' ), |
35
|
|
|
esc_url( \Jetpack::init()->build_connect_url( true, false, 'pre-connection-jitm-posts' ) ) |
36
|
|
|
), |
37
|
|
|
( new Message( 'jpsetup-upload' ) ) |
38
|
|
|
->message_path( '/wp:upload:admin_notices/' ) |
39
|
|
|
->show( |
40
|
|
|
__( 'Do you want lightning-fast images?', 'jetpack' ), |
41
|
|
|
__( 'Setup Jetpack, enable Site Accelerator, and start serving your images lightning fast, for free.', 'jetpack' ) |
42
|
|
|
) |
43
|
|
|
->with_cta( |
44
|
|
|
__( 'Setup Jetpack', 'jetpack' ), |
45
|
|
|
esc_url( \Jetpack::init()->build_connect_url( true, false, 'pre-connection-jitm-upload' ) ) |
46
|
|
|
), |
47
|
|
|
( new Message( 'jpsetup-widgets' ) ) |
48
|
|
|
->message_path( '/wp:widgets:admin_notices/' ) |
49
|
|
|
->show( |
50
|
|
|
__( 'Looking for even more widgets?', 'jetpack' ), |
51
|
|
|
__( 'Setup Jetpack for great additional widgets like business hours and maps.', 'jetpack' ) |
52
|
|
|
) |
53
|
|
|
->with_cta( |
54
|
|
|
__( 'Setup Jetpack', 'jetpack' ), |
55
|
|
|
esc_url( \Jetpack::init()->build_connect_url( true, false, 'pre-connection-jitm-widgets' ) ) |
56
|
|
|
), |
57
|
|
|
); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Gets the top messages |
62
|
|
|
* |
63
|
|
|
* @param string $message_path Message path. |
64
|
|
|
* |
65
|
|
|
* @return array Rendered messages. |
66
|
|
|
*/ |
67
|
|
|
public function render_messages( $message_path ) { |
68
|
|
|
$rules = $this->preconnection_rules(); |
69
|
|
|
|
70
|
|
|
$rendered_rules = array(); |
71
|
|
|
|
72
|
|
|
foreach ( $rules as $rule ) { |
73
|
|
|
|
74
|
|
|
if ( ! preg_match( $rule->message_path_regex, $message_path ) ) { |
|
|
|
|
75
|
|
|
continue; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
// TODO: add partner filter here. |
79
|
|
|
|
80
|
|
|
$rendered_rules[] = $rule->render(); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
return $rendered_rules; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
} |
87
|
|
|
|
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.