Skip to content

Commit

Permalink
fix: only run form submit logic when saving admin settings
Browse files Browse the repository at this point in the history
Addresses an issue where checkbox toggles on the admin page revert back to `unchecked`. Although users would check these inputs and then save their settings, the value would revert back after a while, or when logging out of the site and back in.

This was due to the form submission code executing even though the admin "Save Settings" button was not pressed. It seems that WordPress will submit page forms for different reasons, which can incorrectly trigger our "Save Settings" logic and inadvertently overwrite values.

This commit adds a more strict check so that submission logic is only run when the value is explicitly set to `Save Settings`. In other words, only when the user presses the "Save Settings" button on the page.

Follow up to [#346](#346)
  • Loading branch information
sherwinski committed Feb 19, 2025
1 parent dfc1b1c commit 8daba2d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion v3/onesignal-admin/onesignal-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function admin_files()
}

if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST["submit"])) {
if (isset($_POST["submit"]) && $_POST["submit"] === "Save Settings") {
// Get existing settings with default values
$onesignal_settings = get_option('OneSignalWPSetting', onesignal_get_default_settings());

Expand Down

0 comments on commit 8daba2d

Please sign in to comment.