Skip to content

Commit

Permalink
Add configuration export
Browse files Browse the repository at this point in the history
Update tweaked deprecation message
Update tested to 6.7
  • Loading branch information
marclucraft committed Nov 14, 2024
1 parent bca87ca commit e2d651b
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 237 deletions.
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');
2 changes: 1 addition & 1 deletion deprecation-notice.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function notify_plugin_update() {
<p>
<strong>
OneSignal Push Important Update:</strong>
Before updating to Version 3 of the OneSignal WordPress plugin you must migrate your configuration to dashboard.onesignal.com.
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>';
Expand Down
1 change: 1 addition & 0 deletions onesignal.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
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
7 changes: 4 additions & 3 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 @@ -66,7 +66,8 @@ OneSignal is trusted by over 1.8M+ developers and marketing strategists. We powe

= 2.4.5 =
- Add v2 plugin deprecation warning
- Update "Tested up to" Wordpress version to 6.6
- 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
Expand Down
Loading

0 comments on commit e2d651b

Please sign in to comment.