Completed
Push — update/wpcom-block-editor-shor... ( 9897fe...f43ed6 )
by Jeremy
148:26 queued 138:20
created

Jetpack_Pre_Connection_JITMs   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 78
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A get_raw_messages() 0 40 2
A generate_admin_url() 0 4 1
A add_pre_connection_jitms() 0 10 2
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
		$jetpack_setup_url = $this->generate_admin_url(
20
			array(
21
				'page'    => 'jetpack',
22
				'#/setup' => '',
23
			)
24
		);
25
26
		$messages = array(
27
			array(
28
				'id'             => 'jpsetup-upload',
29
				'message_path'   => '/wp:upload:admin_notices/',
30
				'message'        => __( 'Do you want lightning-fast images?', 'jetpack' ),
31
				'description'    => __( 'Set up Jetpack, enable Site Accelerator, and start serving your images lightning fast, for free.', 'jetpack' ),
32
				'button_link'    => $jetpack_setup_url,
33
				'button_caption' => __( 'Set up Jetpack', 'jetpack' ),
34
			),
35
			array(
36
				'id'             => 'jpsetup-widgets',
37
				'message_path'   => '/wp:widgets:admin_notices/',
38
				'message'        => __( 'Looking for even more widgets?', 'jetpack' ),
39
				'description'    => __( 'Set up Jetpack for great additional widgets that display business contact info and maps, blog stats, and top posts.', 'jetpack' ),
40
				'button_link'    => $jetpack_setup_url,
41
				'button_caption' => __( 'Set up Jetpack', 'jetpack' ),
42
			),
43
		);
44
45
		if ( wp_count_posts()->publish >= 5 ) {
46
			$messages[] = array(
47
				'id'             => 'jpsetup-posts',
48
				'message_path'   => '/wp:edit-post:admin_notices/',
49
				'message'        => __( 'Do you know which of these posts gets the most traffic?', 'jetpack' ),
50
				'description'    => __( 'Set up Jetpack to get in-depth stats about your content and visitors.', 'jetpack' ),
51
				'button_link'    => $jetpack_setup_url,
52
				'button_caption' => __( 'Set up Jetpack', 'jetpack' ),
53
			);
54
		}
55
56
		return $messages;
57
	}
58
59
	/**
60
	 * Adds the input query arguments to the admin url.
61
	 *
62
	 * @param array $args The query arguments.
63
	 *
64
	 * @return string The admin url.
65
	 */
66
	private function generate_admin_url( $args ) {
67
		$url = add_query_arg( $args, admin_url( 'admin.php' ) );
68
		return $url;
69
	}
70
71
	/**
72
	 * Add the Jetpack pre-connection JITMs to the list of pre-connection JITM messages.
73
	 *
74
	 * @param array $pre_connection_messages An array of pre-connection JITMs.
75
	 *
76
	 * @return array The array of pre-connection JITMs.
77
	 */
78
	public function add_pre_connection_jitms( $pre_connection_messages ) {
79
		$jetpack_messages = $this->get_raw_messages();
80
81
		if ( ! is_array( $pre_connection_messages ) ) {
82
			// The incoming messages aren't an array, so just return Jetpack's messages.
83
			return $jetpack_messages;
84
		}
85
86
		return array_merge( $pre_connection_messages, $jetpack_messages );
87
	}
88
}
89