|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Jetpack's Pre-Connection JITMs class. |
|
4
|
|
|
* |
|
5
|
|
|
* @package jetpack |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Jetpack's Pre-Connection JITMs. These can be displayed with the JITM package. |
|
10
|
|
|
*/ |
|
11
|
|
|
class Jetpack_Pre_Connection_JITMs { |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Returns all the pre-connection messages. |
|
15
|
|
|
* |
|
16
|
|
|
* @return array An array containing the pre-connection JITM messages. |
|
17
|
|
|
*/ |
|
18
|
|
|
private function get_raw_messages() { |
|
19
|
|
|
$messages = array( |
|
20
|
|
|
array( |
|
21
|
|
|
'id' => 'jpsetup-upload', |
|
22
|
|
|
'message_path' => '/wp:upload:admin_notices/', |
|
23
|
|
|
'message' => __( 'Do you want lightning-fast images?', 'jetpack' ), |
|
24
|
|
|
'description' => __( 'Set up Jetpack, enable Site Accelerator, and start serving your images lightning fast, for free.', 'jetpack' ), |
|
25
|
|
|
'button_caption' => __( 'Set up Jetpack', 'jetpack' ), |
|
26
|
|
|
), |
|
27
|
|
|
array( |
|
28
|
|
|
'id' => 'jpsetup-widgets', |
|
29
|
|
|
'message_path' => '/wp:widgets:admin_notices/', |
|
30
|
|
|
'message' => __( 'Looking for even more widgets?', 'jetpack' ), |
|
31
|
|
|
'description' => __( 'Set up Jetpack for great additional widgets that display business contact info and maps, blog stats, and top posts.', 'jetpack' ), |
|
32
|
|
|
'button_caption' => __( 'Set up Jetpack', 'jetpack' ), |
|
33
|
|
|
), |
|
34
|
|
|
); |
|
35
|
|
|
|
|
36
|
|
|
if ( wp_count_posts()->publish >= 5 ) { |
|
37
|
|
|
$messages[] = array( |
|
38
|
|
|
'id' => 'jpsetup-posts', |
|
39
|
|
|
'message_path' => '/wp:edit-post:admin_notices/', |
|
40
|
|
|
'message' => __( 'Do you know which of these posts gets the most traffic?', 'jetpack' ), |
|
41
|
|
|
'description' => __( 'Set up Jetpack to get in-depth stats about your content and visitors.', 'jetpack' ), |
|
42
|
|
|
'button_caption' => __( 'Set up Jetpack', 'jetpack' ), |
|
43
|
|
|
); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
foreach ( $messages as $key => $message ) { |
|
47
|
|
|
/* |
|
48
|
|
|
* Add Connect URL to each message, with from including jitm id. |
|
49
|
|
|
*/ |
|
50
|
|
|
$jetpack_setup_url = Jetpack::init()->build_connect_url( |
|
51
|
|
|
true, |
|
52
|
|
|
false, |
|
53
|
|
|
sprintf( 'pre-connection-jitm-%s', $message['id'] ) |
|
54
|
|
|
); |
|
55
|
|
|
// Add parameter to URL. Since we mention accepting ToS when clicking, no need to ask again on wpcom. |
|
56
|
|
|
$jetpack_setup_url = add_query_arg( 'auth_approved', 'true', $jetpack_setup_url ); |
|
57
|
|
|
|
|
58
|
|
|
$messages[ $key ]['button_link'] = $jetpack_setup_url; |
|
59
|
|
|
|
|
60
|
|
|
/* |
|
61
|
|
|
* Add ToS acceptance message to JITM description |
|
62
|
|
|
*/ |
|
63
|
|
|
$messages[ $key ]['description'] .= sprintf( |
|
64
|
|
|
'<br /><br />%s', |
|
65
|
|
|
\jetpack_render_tos_blurb( false ) |
|
66
|
|
|
); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
return $messages; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Add the Jetpack pre-connection JITMs to the list of pre-connection JITM messages. |
|
74
|
|
|
* |
|
75
|
|
|
* @param array $pre_connection_messages An array of pre-connection JITMs. |
|
76
|
|
|
* |
|
77
|
|
|
* @return array The array of pre-connection JITMs. |
|
78
|
|
|
*/ |
|
79
|
|
|
public function add_pre_connection_jitms( $pre_connection_messages ) { |
|
80
|
|
|
$jetpack_messages = $this->get_raw_messages(); |
|
81
|
|
|
|
|
82
|
|
|
if ( ! is_array( $pre_connection_messages ) ) { |
|
83
|
|
|
// The incoming messages aren't an array, so just return Jetpack's messages. |
|
84
|
|
|
return $jetpack_messages; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
return array_merge( $pre_connection_messages, $jetpack_messages ); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|