From ba09957fc12a74642fad0199c6aaa1963e145d18 Mon Sep 17 00:00:00 2001 From: ndeet Date: Tue, 9 Apr 2024 00:14:19 +0200 Subject: [PATCH] Fix disabling notification button (#49) --- btcpay-greenfield-for-woocommerce.php | 15 ++++---- .../btcpay-greenfield-for-woocommerce.pot | 36 +++++++++---------- readme.txt | 11 +++--- resources/js/backend/notifications.js | 14 ++++---- 4 files changed, 42 insertions(+), 34 deletions(-) diff --git a/btcpay-greenfield-for-woocommerce.php b/btcpay-greenfield-for-woocommerce.php index 34f5ea6..e819e21 100644 --- a/btcpay-greenfield-for-woocommerce.php +++ b/btcpay-greenfield-for-woocommerce.php @@ -7,12 +7,12 @@ * Author URI: https://btcpayserver.org * Text Domain: btcpay-greenfield-for-woocommerce * Domain Path: /languages - * Version: 2.6.1 + * Version: 2.6.2 * Requires PHP: 8.0 - * Tested up to: 6.4 + * Tested up to: 6.5 * Requires at least: 5.9 * WC requires at least: 6.0 - * WC tested up to: 8.6 + * WC tested up to: 8.7 */ use BTCPayServer\WC\Admin\Notice; @@ -26,7 +26,7 @@ defined( 'ABSPATH' ) || exit(); -define( 'BTCPAYSERVER_VERSION', '2.6.1' ); +define( 'BTCPAYSERVER_VERSION', '2.6.2' ); define( 'BTCPAYSERVER_VERSION_KEY', 'btcpay_gf_version' ); define( 'BTCPAYSERVER_PLUGIN_FILE_PATH', plugin_dir_path( __FILE__ ) ); define( 'BTCPAYSERVER_PLUGIN_URL', plugin_dir_url(__FILE__ ) ); @@ -99,7 +99,8 @@ public function includes(): void { * Add scripts to admin pages. */ public function enqueueAdminScripts(): void { - wp_enqueue_script('btcpaygf-notifications', plugin_dir_url(__FILE__) . 'assets/js/backend/notifications.js', ['jquery'], null, true); + wp_register_script('btcpaygf-notifications', plugin_dir_url(__FILE__) . 'assets/js/backend/notifications.js', ['jquery'], BTCPAYSERVER_VERSION); + wp_enqueue_script('btcpaygf-notifications'); wp_localize_script('btcpaygf-notifications', 'BTCPayNotifications', [ 'ajax_url' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('btcpaygf-notifications-nonce') @@ -324,7 +325,9 @@ public function processAjaxModalBlocksCheckout() { * Handles the AJAX callback to dismiss review notification. */ public function processAjaxNotification() { - check_ajax_referer('btcpaygf-notifications-nonce', 'nonce'); + if ( ! check_ajax_referer( 'btcpaygf-notifications-nonce', 'nonce' ) ) { + wp_die( 'Unauthorized!', '', [ 'response' => 401 ] ); + } $dismissForever = filter_var($_POST['dismiss_forever'], FILTER_VALIDATE_BOOL); diff --git a/languages/btcpay-greenfield-for-woocommerce.pot b/languages/btcpay-greenfield-for-woocommerce.pot index 095f568..15f814b 100644 --- a/languages/btcpay-greenfield-for-woocommerce.pot +++ b/languages/btcpay-greenfield-for-woocommerce.pot @@ -2,14 +2,14 @@ # This file is distributed under the same license as the BTCPay For Woocommerce V2 plugin. msgid "" msgstr "" -"Project-Id-Version: BTCPay For Woocommerce V2 2.6.0\n" +"Project-Id-Version: BTCPay For Woocommerce V2 2.6.2\n" "Report-Msgid-Bugs-To: https://woocommerce.com/my-account/create-a-ticket/\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"POT-Creation-Date: 2024-04-04T15:31:42+00:00\n" +"POT-Creation-Date: 2024-04-08T22:04:43+00:00\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "X-Generator: WP-CLI 2.9.0\n" "language-team: LANGUAGE \n" @@ -35,69 +35,69 @@ msgstr "" msgid "https://btcpayserver.org" msgstr "" -#: btcpay-greenfield-for-woocommerce.php:137 +#: btcpay-greenfield-for-woocommerce.php:138 msgid "Plugin not configured yet, please %1$sconfigure the plugin here%2$s" msgstr "" -#: btcpay-greenfield-for-woocommerce.php:155 +#: btcpay-greenfield-for-woocommerce.php:156 msgid "Your PHP version is %s but BTCPay Greenfield Payment plugin requires version 8.0+." msgstr "" -#: btcpay-greenfield-for-woocommerce.php:161 +#: btcpay-greenfield-for-woocommerce.php:162 msgid "WooCommerce seems to be not installed. Make sure you do before you activate BTCPayServer Payment Gateway." msgstr "" -#: btcpay-greenfield-for-woocommerce.php:167 +#: btcpay-greenfield-for-woocommerce.php:168 msgid "The PHP cURL extension is not installed. Make sure it is available otherwise this plugin will not work." msgstr "" -#: btcpay-greenfield-for-woocommerce.php:177 +#: btcpay-greenfield-for-woocommerce.php:178 msgid "Seems you have the old BTCPay for WooCommerce plugin installed. While it should work it is strongly recommended to not run both versions but rely on the maintained version (BTCPay Greenfield for WooCommerce)." msgstr "" -#: btcpay-greenfield-for-woocommerce.php:188 +#: btcpay-greenfield-for-woocommerce.php:189 msgid "Thank you for using BTCPay for WooCommerce! If you like the plugin, we would love if you %1$sleave us a review%2$s. %3$sRemind me later%4$s %5$sStop reminding me forever!%6$s" msgstr "" -#: btcpay-greenfield-for-woocommerce.php:443 +#: btcpay-greenfield-for-woocommerce.php:446 msgid "Settings" msgstr "" -#: btcpay-greenfield-for-woocommerce.php:445 +#: btcpay-greenfield-for-woocommerce.php:448 msgid "Debug log" msgstr "" -#: btcpay-greenfield-for-woocommerce.php:447 +#: btcpay-greenfield-for-woocommerce.php:450 msgid "Docs" msgstr "" -#: btcpay-greenfield-for-woocommerce.php:449 +#: btcpay-greenfield-for-woocommerce.php:452 msgid "Support Chat" msgstr "" -#: btcpay-greenfield-for-woocommerce.php:489 +#: btcpay-greenfield-for-woocommerce.php:492 msgid "Error on verifiying redirected API wey with stored BTCPay Server url. Aborting API wizard. Please try again or do a manual setup." msgstr "" -#: btcpay-greenfield-for-woocommerce.php:511 +#: btcpay-greenfield-for-woocommerce.php:514 msgid "Successfully received api key and store id from BTCPay Server API. Please finish setup by saving this settings form." msgstr "" -#: btcpay-greenfield-for-woocommerce.php:515 +#: btcpay-greenfield-for-woocommerce.php:518 #: src/Admin/GlobalSettings.php:374 msgid "Successfully registered a new webhook on BTCPay Server." msgstr "" -#: btcpay-greenfield-for-woocommerce.php:519 +#: btcpay-greenfield-for-woocommerce.php:522 #: src/Admin/GlobalSettings.php:378 msgid "Could not register a new webhook on the store." msgstr "" -#: btcpay-greenfield-for-woocommerce.php:528 +#: btcpay-greenfield-for-woocommerce.php:531 msgid "Please make sure you only select one store on the BTCPay API authorization page." msgstr "" -#: btcpay-greenfield-for-woocommerce.php:533 +#: btcpay-greenfield-for-woocommerce.php:536 msgid "Error processing the data from BTCPay. Please try again." msgstr "" diff --git a/readme.txt b/readme.txt index f3940b8..dba5315 100644 --- a/readme.txt +++ b/readme.txt @@ -3,9 +3,9 @@ Contributors: ndeet, kukks, nicolasdorier Donate link: https://btcpayserver.org/donate/ Tags: Bitcoin, Lightning Network, BTCPay Server, WooCommerce, payment gateway Requires at least: 5.2 -Tested up to: 6.4 +Tested up to: 6.5 Requires PHP: 8.0 -Stable tag: 2.6.1 +Stable tag: 2.6.2 License: MIT License URI: https://github.com/btcpayserver/woocommerce-greenfield-plugin/blob/master/license.txt @@ -111,10 +111,13 @@ You'll find extensive documentation and answers to many of your questions on [BT 6. On BTCPay Server you have extensive reporting and accounting features. == Upgrade Notice == -= 2.6.1 = -* Minor changes, just update. += 2.6.2 = +* Notifications fix, buttons should now work. == Changelog == += 2.6.2 :: 2024-04-09 = +* Fix: Dismissing the review notification forever, finally. + = 2.6.1 :: 2024-04-04 = * Fix: Error when processing full amount refunds. * Fix: Show warning when bcmath extension is missing. diff --git a/resources/js/backend/notifications.js b/resources/js/backend/notifications.js index 453fb1d..6a7940a 100644 --- a/resources/js/backend/notifications.js +++ b/resources/js/backend/notifications.js @@ -1,5 +1,6 @@ jQuery(document).ready(function($) { - jQuery(document).on('click', '.btcpay-review-notice button.btcpay-review-dismiss', function() { + jQuery(document).on('click', '.btcpay-review-notice button.btcpay-review-dismiss', function(e) { + e.preventDefault(); $.ajax({ url: BTCPayNotifications.ajax_url, type: 'post', @@ -7,12 +8,13 @@ jQuery(document).ready(function($) { action: 'btcpaygf_notifications', nonce: BTCPayNotifications.nonce }, - success : function(data) { - window.location.reload(true); + success: function(data) { + jQuery('.btcpay-review-notice').remove(); } }); }); - jQuery(document).on('click', '.btcpay-review-notice button.btcpay-review-dismiss-forever', function() { + jQuery(document).on('click', '.btcpay-review-notice button.btcpay-review-dismiss-forever', function(e) { + e.preventDefault(); $.ajax({ url: BTCPayNotifications.ajax_url, type: 'post', @@ -21,8 +23,8 @@ jQuery(document).ready(function($) { nonce: BTCPayNotifications.nonce, dismiss_forever: true }, - success : function(data) { - window.location.reload(true); + success: function(data) { + jQuery('.btcpay-review-notice').remove(); } }); });