-
Notifications
You must be signed in to change notification settings - Fork 21
/
class-perfecty-push-lib-payload.php
51 lines (44 loc) · 1.53 KB
/
class-perfecty-push-lib-payload.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
/***
* Paylod builder
*/
class Perfecty_Push_Lib_Payload {
/**
* Build the payload to be send as a notification
*
* @param string $body Notification content
* @param string $title Title
* @param string $image Image to show
* @param string $url_to_open Url to open
* @return array payload
*/
public static function build( $body, $title = '', $image = '', $url_to_open = '' ) {
$options = get_option( 'perfecty_push', array() );
$icon_url = isset( $options['notifications_default_icon'] ) && ! empty( $options['notifications_default_icon'] ) ? wp_get_attachment_url( $options['notifications_default_icon'] ) : '';
$require_interaction = isset( $options['notifications_interaction_required'] ) && $options['notifications_interaction_required'] == 1;
if ( ! $title ) {
$title = get_bloginfo( 'name' );
}
if ( ! $url_to_open ) {
$url_to_open = get_site_url();
}
if ( ! $image ) {
$image = '';
}
$utm = isset( $options['segmentation_tracking_utm'] ) ? $options['segmentation_tracking_utm'] : '';
if ( '' !== $utm ) {
$prefix = strpos( $url_to_open, '?' ) === false ? '?' : '&';
$url_to_open = $url_to_open . $prefix . $utm;
}
return array(
'title' => substr( stripslashes( $title ), 0, 250 ),
'body' => substr( stripslashes( $body ), 0, 1750 ),
'icon' => $icon_url,
'image' => $image,
'require_interaction' => $require_interaction,
'extra' => array(
'url_to_open' => $url_to_open,
),
);
}
}