Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.4.5 - Deprecation Notice #332

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions configuration-export.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

function onesignal_handle_export()
{
if (isset($_POST['plugin_action']) && $_POST['plugin_action'] === 'export_settings') {

if (!check_admin_referer('onesignal_export_nonce')) {
wp_die(__('Security check failed', 'onesignal-push'));
}

$settings = get_option('OneSignalWPSetting');

// name and define settings groups
$groups = [
'OneSignal App ID' => '/^app_id/',
'General Options' => '/^(chrome_auto_|persist_|default_|utm_additional_)/',
'Slide Prompt Customizations' => '/^(prompt_customize_|prompt_action_|prompt_accept_|prompt_cancel_|prompt_auto_register)/',
'Subscription Bell Customizations' => '/^notifyButton_/',
'Welcome Notification Customizations' => '/^(send_welcome_|welcome_)/',
'Plugin Settings & HTTP Setup - NO LONGER REQUIRED / DEPRECATED' => '/^(allowed_custom_|customize_http_|custom_manifest_|gcm_|is_site_|notification_on_|notification_title|onesignal_sw_|origin|prompt_auto_accept_title|prompt_example_|prompt_site_name|send_to_mobile_|showNotification|show_gcm_|how_notification_send_|subdomain|use_)/'
];

// sort settings into the defined groups
foreach ($settings as $key => $value) {
foreach ($groups as $group_name => $pattern) {
if (preg_match($pattern, $key)) {
$grouped_settings[$group_name][$key] = is_array($value) ? json_encode($value) : $value;
break;
}
}
}

// create txt file with main title, group names, and settings.
$txt_data = "OneSignal Push Configuration Export\n\n\n";

foreach ($groups as $group_name => $pattern) {
if (isset($grouped_settings[$group_name])) {
$txt_data .= "=== $group_name ===\n";

foreach ($grouped_settings[$group_name] as $key => $value) {
$txt_data .= "$key: $value\n";
}

$txt_data .= "\n\n";
}
}

header('Content-Type: text/plain');
header('Content-Disposition: attachment; filename="onesignal-configuration-export.txt"');
header('Content-Length: ' . strlen($txt_data));
header('Pragma: public');

echo $txt_data;
exit;
}
}

add_action('admin_init', 'onesignal_handle_export');
9 changes: 9 additions & 0 deletions deprecation-notice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
jQuery(document).ready(function ($) {
$('#onesignal-update-notice').on('click', '.notice-dismiss', function () {
$.post(onesignalData.ajax_url, {
action: 'dismiss_onesignal_deprecation_notice', // This action should match the PHP function's AJAX hook
nonce: onesignalData.nonce,
});
});
});

55 changes: 55 additions & 0 deletions deprecation-notice.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
// Add an admin notice for outdated plugin version
add_action('admin_notices', 'notify_plugin_update');
function notify_plugin_update() {
$dismissed_timestamp = get_option('onesignal_deprecation_notice_dismissed_time');
$time_passed = !$dismissed_timestamp || (time() - $dismissed_timestamp) > (7 * DAY_IN_SECONDS);
marclucraft marked this conversation as resolved.
Show resolved Hide resolved
$cutoff_date = strtotime('2025-12-31 23:59:59'); // Set cutoff date and time

// Show the notice only if it's before the cutoff date and the notice has not been recently dismissed
if (time() <= $cutoff_date && $time_passed) {
echo '
<div class="notice notice-warning is-dismissible" id="onesignal-update-notice">
<p>
<strong>
OneSignal Push Important Update:</strong>
We are soon releasing Version 3 of the OneSignal WordPress Plugin. Before updating, you must migrate your configuration to dashboard.onesignal.com.
<a target="_blank" href="https://documentation.onesignal.com/docs/wordpress-plugin-30">Learn More.</a>
</p>
</div>';
}
}

// Handle AJAX dismissal of the notice
add_action('wp_ajax_dismiss_onesignal_deprecation_notice', 'dismiss_onesignal_deprecation_notice');
function dismiss_onesignal_deprecation_notice() {
// Check if nonce is valid
if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'dismiss_notice_nonce')) {
// If nonce is invalid, log the error and return a JSON error response
error_log('Invalid nonce for AJAX request');
wp_send_json_error(array('message' => 'Invalid nonce'));
return;
}

// Update the option if nonce validation passes
update_option('onesignal_deprecation_notice_dismissed_time', time());
wp_send_json_success(array('message' => 'Dismissal timestamp set successfully'));
}

add_action('admin_enqueue_scripts', 'enqueue_notify_plugin_scripts');
function enqueue_notify_plugin_scripts() {
wp_enqueue_script('onesignal-admin', plugin_dir_url(__FILE__) . 'deprecation-notice.js', array('jquery'), '1.0', true);
wp_localize_script('onesignal-admin', 'onesignalData', array(
'ajax_url' => admin_url('admin-ajax.php'),
'nonce' => wp_create_nonce('dismiss_notice_nonce')
));
}

// Disable Auto-Updates
add_filter('auto_update_plugin', function ($update, $item) {
// Check for the OneSignal plugin slug
if ($item->slug === 'onesignal-free-web-push-notifications/onesignal.php') {
return false; // Disable auto-update for this plugin
}
return $update;
}, 10, 2);
4 changes: 3 additions & 1 deletion onesignal.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Plugin Name: OneSignal Push Notifications
* Plugin URI: https://onesignal.com/
* Description: Free web push notifications.
* Version: 2.4.4
* Version: 2.4.5
* Author: OneSignal
* Author URI: https://onesignal.com
* License: MIT
Expand All @@ -24,6 +24,8 @@
require_once plugin_dir_path(__FILE__).'onesignal-public.php';
require_once plugin_dir_path(__FILE__).'onesignal-settings.php';
require_once plugin_dir_path(__FILE__).'onesignal-widget.php';
include_once plugin_dir_path(__FILE__).'deprecation-notice.php';
include_once plugin_dir_path(__FILE__).'configuration-export.php';

if (file_exists(plugin_dir_path(__FILE__).'onesignal-extra.php')) {
require_once plugin_dir_path(__FILE__).'onesignal-extra.php';
Expand Down
9 changes: 7 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Contributors: OneSignal
Donate link: https://onesignal.com
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
Requires at least: 3.8
Tested up to: 6.5
Stable tag: 2.4.4
Tested up to: 6.7
Stable tag: 2.4.5
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

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

== Changelog ==

= 2.4.5 =
- Add v2 plugin deprecation warning
- Add export current configuration
- Update "Tested up to" Wordpress version to 6.7

= 2.4.4 =
- Update "Tested up to" Wordpress version to 6.5
- Update OneSignal plugin menu icon
Expand Down
Loading
Loading