Passed
Push — master ( 6f0a6d...90a9ca )
by
unknown
09:41
created

MonsterInsights_Notification_Visitors   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
dl 0
loc 39
rs 10
c 1
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A prepare_notification_data() 0 20 4
1
<?php
2
3
/**
4
 * Add visitors notification
5
 * Recurrence: 30 Days
6
 *
7
 * @since 7.12.3
8
 */
9
final class MonsterInsights_Notification_Visitors extends MonsterInsights_Notification_Event {
10
11
	public $notification_id             = 'monsterinsights_notification_visitors';
12
	public $notification_interval       = 30; // in days
13
	public $notification_type           = array( 'basic', 'lite', 'master', 'plus', 'pro' );
14
	public $notification_icon           = '<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">
15
<circle cx="16" cy="16" r="16" fill="#E1DAF1"/>
16
<path d="M20.0331 13.2857C20.2831 13.2857 20.4706 13.3929 20.5956 13.6071C20.7206 13.8214 20.7206 14.0357 20.5956 14.25L15.8813 22.3929C15.7563 22.6071 15.5688 22.7143 15.3188 22.7143C15.1045 22.7143 14.9349 22.6339 14.8099 22.4732C14.6849 22.3125 14.6492 22.125 14.7027 21.9107L15.9349 16.7143H12.7474C12.6224 16.7143 12.5063 16.6786 12.3992 16.6071C12.292 16.5357 12.2117 16.4464 12.1581 16.3393C12.1045 16.2321 12.0867 16.1161 12.1045 15.9911L12.9617 9.5625C12.9795 9.45536 13.0152 9.35714 13.0688 9.26786C13.1402 9.17857 13.2206 9.11607 13.3099 9.08036C13.3992 9.02679 13.4974 9 13.6045 9H17.4617C17.6759 9 17.8456 9.08929 17.9706 9.26786C18.0956 9.42857 18.1313 9.60714 18.0777 9.80357L16.9527 13.2857H20.0331Z" fill="#6F4BBB"/>
17
</svg>';
18
19
	/**
20
	 * Build Notification
21
	 *
22
	 * @param array $report Overview report
23
	 *
24
	 * @return array $notification notification is ready to add
25
	 *
26
	 * @since 7.12.3
27
	 */
28
	public function prepare_notification_data( $notification ) {
29
		$report = $this->get_report();
30
31
		if ( ! is_array( $report ) || empty( $report ) ) {
0 ignored issues
show
introduced by
The condition is_array($report) is always true.
Loading history...
32
			return false;
33
		}
34
35
		$total_visitors          = isset( $report['data']['infobox']['sessions']['value'] ) ? $report['data']['infobox']['sessions']['value'] : 0;
36
		// Translators: visitors notification title
37
		$notification['title']   = sprintf( __( 'See how %s visitors found your site!', 'google-analytics-for-wordpress' ), $total_visitors );
38
		// Translators: visitors notification content
39
		$notification['content'] = sprintf( __( 'Your website has been visited by %s visitors in the past 30 days. Click the button below to view the full analytics report.', 'google-analytics-for-wordpress' ), $total_visitors );
40
		$notification['btns']    = array(
41
			"view_report" => array(
42
				'url'  => $this->get_view_url(),
43
				'text' => __( 'View Report', 'google-analytics-for-wordpress' )
44
			),
45
		);
46
47
		return $notification;
48
	}
49
50
}
51
52
// initialize the class
53
new MonsterInsights_Notification_Visitors();
54