Skip to content

Commit 9728f01

Browse files
author
Rodrigo Gomez Palacio
authored
Merge pull request #340 from OneSignal/3.0.5
3.0.5 Release
2 parents 7483da9 + 8c79ad1 commit 9728f01

File tree

9 files changed

+78
-27
lines changed

9 files changed

+78
-27
lines changed

onesignal.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Plugin Name: OneSignal Push Notifications
77
* Plugin URI: https://onesignal.com/
88
* Description: Free web push notifications.
9-
* Version: 3.0.4
9+
* Version: 3.0.5
1010
* Author: OneSignal
1111
* Author URI: https://onesignal.com
1212
* License: MIT

readme.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Donate link: https://onesignal.com
44
Tags: push notification, push notifications, desktop notifications, mobile notifications, chrome push, android, android notification, android notifications, android push, desktop notification, firefox, firefox push, mobile, mobile notification, notification, notifications, notify, onesignal, push, push messages, safari, safari push, web push, chrome
55
Requires at least: 3.8
66
Tested up to: 6.7
7-
Stable tag: 3.0.4
7+
Stable tag: 3.0.5
88
License: GPLv2 or later
99
License URI: http://www.gnu.org/licenses/gpl-2.0.html
1010

@@ -64,6 +64,11 @@ OneSignal is trusted by over 1.8M+ developers and marketing strategists. We powe
6464

6565
== Changelog ==
6666

67+
= 3.0.5 =
68+
- Change push title and content to match 2.X version
69+
- Bugfix: handle missing UTM parameters
70+
- Update documentation links
71+
6772
= 3.0.4 =
6873
- Added features: auto-send on publish, UTM tags
6974
- Bug fixes: validation issues on settings form
@@ -79,7 +84,7 @@ WARNING: this update contains changes that may break specific setups, as detaile
7984

8085
If you have made any code modifications to your Wordpress installation to directly interact with the OneSignal SDK, this version will break your implementation. Please revert your code modifications prior to upgrading and use our improved dashboard functionality to configure your OneSignal integration instead.
8186

82-
Learn more: https://documentation.onesignal.com/docs/wordpress-plugin-30
87+
Learn more: https://documentation.onesignal.com/docs/wordpress
8388

8489
- Support migration to new configuration flow.
8590
- Simpler configuration interface.

v2/views/config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
<span style="padding:0 20px 15px; color:#3A3DB2; font-weight:700;">
4242
Migrate Settings to OneSignal.com<br><br>
4343
<p style="font-size:1.15rem;font-weight:500">All OneSignal prompt configurations on this page are moving to OneSignal.com.</p>
44-
<button type="button" class="ui medium teal button" onclick="window.open('https://documentation.onesignal.com/docs/wordpress-plugin-30','_blank');">Learn More</button>
44+
<button type="button" class="ui medium teal button" onclick="window.open('https://documentation.onesignal.com/docs/wordpress','_blank');">Learn More</button>
4545
<form method="post" action="" style="margin-bottom: 20px; margin-top: 20px;">
4646
<p style="font-size:1.15rem;">Save your current settings to a txt file</p>
4747
<?php wp_nonce_field('onesignal_export_nonce'); ?>

v3/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
OneSignal WordPress Plugin - v3.0.0
22
====================================
3-
[OneSignal WordPress Plugin 3.0 – Documentation](https://documentation.onesignal.com/docs/wordpress-plugin-30)
3+
[OneSignal WordPress Plugin 3.0 – Documentation](https://documentation.onesignal.com/docs/wordpress)
44

55
## Overview
66

v3/onesignal-admin/onesignal-admin.css

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,9 @@
143143
border-radius: 0.25rem;
144144
border: 1px solid rgb(185, 194, 202);
145145
padding: 1rem 2rem;
146-
background-color: #fff;
146+
background-color: #eee;
147+
margin-bottom: 20px;
148+
margin-top: 20px;
147149
}
148150

149151
.os-content input[type="submit"] {

v3/onesignal-admin/onesignal-admin.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
window.addEventListener("DOMContentLoaded", () => {
2-
const helpIcon = document.querySelector(".help");
3-
const infoDiv = document.querySelector(".information");
2+
const sendToMobileHelpIcon = document.querySelector(".mobile-app .help");
3+
const sendToMobileInfoDiv = document.querySelector(".mobile-app .information");
4+
const utmParamsHelpIcon = document.querySelector(".utm-params .help");
5+
const utmParamsInfoDiv = document.querySelector(".utm-params .information");
46

5-
if (helpIcon && infoDiv) {
6-
helpIcon.addEventListener("click", () => {
7-
infoDiv.style.display =
8-
infoDiv.style.display === "none" ? "inherit" : "none";
9-
});
10-
}
7+
const setupToggleAction = (helpIcon, infoDiv) => {
8+
if (helpIcon && infoDiv) {
9+
helpIcon.addEventListener("click", () => {
10+
infoDiv.style.display =
11+
infoDiv.style.display === "none" ? "inherit" : "none";
12+
});
13+
}
14+
};
15+
16+
setupToggleAction(sendToMobileHelpIcon, sendToMobileInfoDiv);
17+
setupToggleAction(utmParamsHelpIcon, utmParamsInfoDiv);
1118
});
1219

1320
window.addEventListener("DOMContentLoaded", () => {

v3/onesignal-admin/onesignal-admin.php

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function onesignal_admin_page()
6262
?>
6363
<div style="margin-bottom: 20px;">
6464
<span style="margin-bottom:35px;color:#E54B4D; font-weight:700;">
65-
<a href="https://documentation.onesignal.com/docs/wordpress-plugin-30" target="_blank">Getting Started → </a>
65+
<a href="https://documentation.onesignal.com/docs/wordpress" target="_blank">Getting Started → </a>
6666
</span>
6767
</div>
6868
<?php
@@ -122,14 +122,33 @@ function onesignal_admin_page()
122122

123123
<h3>Advanced Settings</h3>
124124
<div class="ui borderless shadowless segment">
125-
<div class="field">
126-
<label>Additional Notification URL Parameters<i class="tiny circular help icon link" role="popup" data-html="Adds the specified string as extra URL parameters to your notification URL so that they can be tracked as an event by your analytics system. <em>Please escape your parameter values</em>; your input will be added as-is to the end of your notification URL. Example:</p>If you want:<em><li><code>utm_medium</code> to be <code>ppc</code></li><li><code>utm_source</code> to be <code>adwords</code></li><li><code>utm_campaign</code> to be <code>snow boots</code></li><li><code>utm_content</code> to be <code>durable snow boots</code></li></em><p><p>Then use the following string:</p><p><code style='word-break: break-all;'>utm_medium=ppc&utm_source=adwords&utm_campaign=snow%20boots&utm_content=durable%20%snow%boots</code></p>" data-variation="wide"></i></label>
127-
<input id="utm-params" type="text" placeholder="utm_medium=ppc&utm_source=adwords&utm_campaign=snow%20boots&utm_content=durable%20%snow%boots" name="utm_additional_url_params" value="<?php echo esc_attr(get_option('OneSignalWPSetting')['utm_additional_url_params']); ?>">
125+
<?php
126+
$oneSignalSettings = get_option('OneSignalWPSetting');
127+
$utmParams = ''; // Default empty value
128+
129+
// Check if the settings are an array and if the key exists
130+
if (is_array($oneSignalSettings) && isset($oneSignalSettings['utm_additional_url_params'])) {
131+
$utmParams = esc_attr($oneSignalSettings['utm_additional_url_params']);
132+
}
133+
?>
134+
<div class="field utm-params">
135+
<label>Additional Notification URL Parameters</label>
136+
<div class="help" aria-label="More information">
137+
<svg viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg" fill="currentColor">
138+
<g fill="currentColor">
139+
<path d="M8 0a8 8 0 108 8 8.009 8.009 0 00-8-8zm0 12.667a1 1 0 110-2 1 1 0 010 2zm1.067-4.054a.667.667 0 00-.4.612.667.667 0 01-1.334 0 2 2 0 011.2-1.834A1.333 1.333 0 106.667 6.17a.667.667 0 01-1.334 0 2.667 2.667 0 113.734 2.444z"></path>
140+
</g>
141+
</svg>
142+
</div>
143+
<div class="information" style="display: none;">
144+
<p>Adds the specified string as extra URL parameters to your notification URL so that they can be tracked as an event by your analytics system. <em>Please escape your parameter values</em>; your input will be added as-is to the end of your notification URL. Example:</p>If you want:<em><li><code>utm_medium</code> to be <code>ppc</code></li><li><code>utm_source</code> to be <code>adwords</code></li><li><code>utm_campaign</code> to be <code>snow boots</code></li><li><code>utm_content</code> to be <code>durable snow boots</code></li></em><p><p>Then use the following string:</p><p><code style='word-break: break-all;'>utm_medium=ppc&utm_source=adwords&utm_campaign=snow%20boots&utm_content=durable%20%snow%boots</code></p>
145+
</div>
146+
<input id="utm-params" type="text" placeholder="utm_medium=ppc&utm_source=adwords&utm_campaign=snow%20boots&utm_content=durable%20%snow%boots" name="utm_additional_url_params" value="<?php echo $utmParams; ?>">
128147
</div>
129148
</div>
130149

131150
<!-- Auto Send Checkbox -->
132-
<div class="checkbox-wrapper">
151+
<div class="checkbox-wrapper auto-send">
133152
<label for="auto-send">
134153
<input id="auto-send" type="checkbox" name="onesignal_auto_send"
135154
<?php echo (get_option('OneSignalWPSetting')['notification_on_post'] ?? 0) == 1 ? 'checked' : ''; ?>>
@@ -139,7 +158,7 @@ function onesignal_admin_page()
139158
</div>
140159

141160
<!-- Mobile App Checkbox -->
142-
<div class="checkbox-wrapper">
161+
<div class="checkbox-wrapper mobile-app">
143162
<label for="send-to-mobile">
144163
<input id="send-to-mobile" type="checkbox" name="onesignal_send_to_mobile"
145164
<?php echo (get_option('OneSignalWPSetting')['send_to_mobile_platforms'] ?? 0) == 1 ? 'checked' : ''; ?>>

v3/onesignal-helpers.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,20 @@ function onesignal_get_api_key_type()
1717

1818
return (strpos($apiKey, 'os_v') === 0) ? "Rich" : "Legacy";
1919
}
20+
21+
/* If >= PHP 5.4, ENT_HTML401 | ENT_QUOTES will correctly decode most entities including both double and single quotes.
22+
In PHP 5.3, ENT_HTML401 does not exist, so we have to use `str_replace("&apos;","'", $value)` before feeding it to html_entity_decode(). */
23+
function decode_entities($string) {
24+
$HTML_ENTITY_DECODE_FLAGS = ENT_QUOTES;
25+
if (defined('ENT_HTML401')) {
26+
$HTML_ENTITY_DECODE_FLAGS = ENT_HTML401 | $HTML_ENTITY_DECODE_FLAGS;
27+
}
28+
return html_entity_decode(str_replace(['&apos;', '&#x27;', '&#39;', '&quot;'], '\'', $string), $HTML_ENTITY_DECODE_FLAGS, 'UTF-8');
29+
}
30+
31+
function sanitize_content_for_excerpt($content) {
32+
$decoded = wp_specialchars_decode($content);
33+
$stripped_slashes = stripslashes_deep($decoded);
34+
$cleaned_content = wp_strip_all_tags(strip_shortcodes($stripped_slashes));
35+
return $cleaned_content;
36+
}

v3/onesignal-notification.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,17 @@ function onesignal_schedule_notification($new_status, $old_status, $post)
2121
}
2222

2323
// set api params
24-
$title = !empty($_POST['os_title']) ? $_POST['os_title'] : $post->post_title;
25-
$content = !empty($_POST['os_content']) ? $_POST['os_content'] : $post->post_content;
26-
$excerpt = $excerpt = substr($content, 0, 120);
24+
$title = !empty($_POST['os_title']) ? sanitize_text_field($_POST['os_title']) : decode_entities(get_bloginfo('name'));
25+
$content = !empty($_POST['os_content']) ? sanitize_text_field($_POST['os_content']) : $post->post_title;
26+
$excerpt = sanitize_content_for_excerpt($content);
2727
$segment = $_POST['os_segment'] ?? 'All';
2828
$config_utm_additional_url_params = $onesignal_wp_settings['utm_additional_url_params'] ?? '';
29-
$url = get_permalink($post->ID);
3029

31-
// Append UTM parameters to the URL
30+
$url = get_permalink($post->ID);
3231
if (!empty($config_utm_additional_url_params)) {
33-
$url = $url . (strpos($url, '?') === false ? '?' : '&') . $config_utm_additional_url_params;
32+
// validate and encode the URL parameters
33+
$params = urlencode($config_utm_additional_url_params);
34+
$url = $url . (strpos($url, '?') === false ? '?' : '&') . $params;
3435
}
3536

3637
$apiKeyType = onesignal_get_api_key_type();
@@ -47,7 +48,7 @@ function onesignal_schedule_notification($new_status, $old_status, $post)
4748
'body' => json_encode(array(
4849
'app_id' => get_option('OneSignalWPSetting')['app_id'],
4950
'headings' => array('en' => $title),
50-
'contents' => array('en' => wp_strip_all_tags($excerpt)),
51+
'contents' => array('en' => $excerpt),
5152
'included_segments' => array($segment),
5253
'web_push_topic' => str_replace(' ', '-', strtolower($segment)),
5354
'isAnyWeb' => true,

0 commit comments

Comments
 (0)