From be106ef49a38cbc126ad5c7dca515f4315fef865 Mon Sep 17 00:00:00 2001 From: xecdev Date: Mon, 2 Feb 2026 12:35:54 +0430 Subject: [PATCH 1/3] Move Public Key to the new Settings tab --- includes/class-paybutton-activator.php | 2 - includes/class-paybutton-admin.php | 69 +++++++++++++--- templates/admin/paywall-settings.php | 52 ------------ templates/admin/settings.php | 105 +++++++++++++++++++++++++ 4 files changed, 162 insertions(+), 66 deletions(-) create mode 100644 templates/admin/settings.php diff --git a/includes/class-paybutton-activator.php b/includes/class-paybutton-activator.php index f2ef3e2..a962628 100644 --- a/includes/class-paybutton-activator.php +++ b/includes/class-paybutton-activator.php @@ -17,8 +17,6 @@ class PayButton_Activator { public static function activate() { self::create_tables(); self::create_profile_page(); - // Set a flag to redirect the admin to the Paywall Settings page after activation - update_option('paybutton_activation_redirect', true); //self::migrate_old_option(); } diff --git a/includes/class-paybutton-admin.php b/includes/class-paybutton-admin.php index 6a62628..3b87c97 100644 --- a/includes/class-paybutton-admin.php +++ b/includes/class-paybutton-admin.php @@ -15,8 +15,8 @@ public function __construct() { add_action( 'admin_menu', array( $this, 'add_admin_menus' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) ); add_action( 'admin_notices', array( $this, 'admin_notice_missing_required_inputs' ) ); - // Process form submissions early - add_action( 'admin_init', array( $this, 'handle_save_settings' ) ); + // Handle settings save + add_action( 'admin_init', array( $this, 'process_settings_forms' ) ); // New: Posts page PayButton Unlocks column add_filter( 'manage_edit-post_columns', [ $this, 'register_paybutton_unlocks_column' ] ); @@ -74,9 +74,26 @@ public function add_admin_menus() { 'paybutton-paywall-content', array( $this, 'content_page' ) ); + + add_submenu_page( + 'paybutton', + 'Settings', + 'Settings', + 'manage_options', + 'paybutton-settings', + array( $this, 'settings_page' ) + ); } - public function handle_save_settings() { + /** + * Process all settings form submissions. + * Routes to appropriate handler based on which form was submitted. + */ + public function process_settings_forms() { + if ( empty( $_POST ) ) { + return; + } + // Handle Paywall Settings save if ( isset( $_POST['paybutton_paywall_save_settings'] ) && isset( $_POST['paybutton_settings_nonce'] ) && @@ -88,7 +105,27 @@ public function handle_save_settings() { wp_safe_redirect( admin_url( 'admin.php?page=paybutton-paywall&settings-updated=true' ) ); exit; } - } + + // Handle Settings (public key) save + if ( + isset( $_POST['paybutton_settings_save'] ) && + isset( $_POST['paybutton_settings_nonce'] ) && + wp_verify_nonce( + sanitize_text_field( wp_unslash( $_POST['paybutton_settings_nonce'] ) ), + 'paybutton_settings_save' + ) && + current_user_can( 'manage_options' ) + ) { + $public_key = sanitize_text_field( + wp_unslash( $_POST['paybutton_public_key'] ) + ); + update_option( 'paybutton_public_key', $public_key ); + wp_safe_redirect( + admin_url( 'admin.php?page=paybutton-settings&settings-updated=true' ) + ); + exit; + } + } /** * This function is hooked into the admin_enqueue_scripts action. It receives a @@ -240,14 +277,25 @@ public function paywall_settings_page() { 'logout_button_text_color' => get_option( 'paybutton_logout_button_text_color', '#FFFFFF' ), // blacklist 'blacklist' => get_option( 'paybutton_blacklist', array() ), - //Public key - 'paybutton_public_key' => get_option( 'paybutton_public_key', '' ), // Login & content unlock cookie expiry (days) 'paybutton_cookie_ttl_days' => get_option( 'paybutton_cookie_ttl_days', 0 ), ); $this->load_admin_template( 'paywall-settings', $args ); } + public function settings_page() { + if ( ! current_user_can( 'manage_options' ) ) { + return; + } + + $args = array( + 'paybutton_public_key' => get_option( 'paybutton_public_key', '' ), + 'settings_saved' => isset( $_GET['settings-updated'] ), + ); + + $this->load_admin_template( 'settings', $args ); + } + public function admin_notice_missing_required_inputs() { if (isset($_GET['settings-updated']) && $_GET['settings-updated'] === 'true') { return; @@ -266,7 +314,9 @@ public function admin_notice_missing_required_inputs() { $public_key = get_option('paybutton_public_key', ''); if (empty($public_key)) { echo '
'; - echo '

NOTICE: Please set your public key in Paywall Settings.

'; + echo '

NOTICE: Please set your public key in + + Settings.

'; echo '
'; } } @@ -334,11 +384,6 @@ private function save_settings() { $blacklist = array_map( 'trim', explode( ',', $raw_blacklist ) ); update_option( 'paybutton_blacklist', $blacklist ); } - //Adding the new public key option - if ( isset( $_POST['paybutton_public_key'] ) ) { - $public_key = sanitize_text_field( $_POST['paybutton_public_key'] ); - update_option( 'paybutton_public_key', $public_key ); - } //Front‐end unlock count toggle $enable_frontend_unlock_count = isset( $_POST['paybutton_enable_frontend_unlock_count'] ) ? '1' : '0'; diff --git a/templates/admin/paywall-settings.php b/templates/admin/paywall-settings.php index 8d3ee52..dbbb9c6 100644 --- a/templates/admin/paywall-settings.php +++ b/templates/admin/paywall-settings.php @@ -235,58 +235,6 @@ class="regular-text"

Enter comma-separated wallet addresses to block from logging in via Cashtab.

- - - - - - - -

- Enter your PayButton public key to verify Payment Trigger requests. -

- -
-

Guide to Setup your PayButton Public Key:

-

- 1. Create an account on - PayButton.org - and copy your public key from the account page and paste it in the Public Key field above. -

-

- 2. Create a button - for your paywall receiving wallet address. -

-

- 3. Scroll down on the buttons page to the section "When a Payment is Received...". -

-

- 4. In the URL field, paste the following: -

-
-

- 5. In the Post Data field, paste the following code as is: -

-
-{
-"signature": <signature>,
-"post_id": <opReturn>,
-"tx_hash": <txId>,
-"tx_amount": <amount>,
-"tx_timestamp": <timestamp>,
-"user_address": <inputAddresses>,
-"value": <value>,
-"currency": <currency>
-}
-

- 6. Save your button settings after pasting these values, and you're all set! -

-

- Note: Enabling this feature is required as it improves payment reliability, leveraging secure server-to-server messaging to record paywall and login transactions to your database. -

-
- -

diff --git a/templates/admin/settings.php b/templates/admin/settings.php new file mode 100644 index 0000000..d12f880 --- /dev/null +++ b/templates/admin/settings.php @@ -0,0 +1,105 @@ + + + +

+
+ +
+

PayButton Settings

+ +
+

Settings saved successfully.

+
+ + +
+ + + + + + + + + + +
+ + + +

+ Enter your PayButton public key to verify Payment Trigger requests. +

+ + +
+

Guide to Setup your PayButton Public Key:

+

+ 1. Create an account on + + PayButton.org + + and copy your public key from the + + account page + + and paste it in the Public Key field above. +

+

+ 2. + + Create a button + + for your paywall receiving wallet address. +

+

+ 3. Scroll down on the buttons page to the section + "When a Payment is Received...". +

+

+ 4. In the URL field, paste the following: +

+
+

+ 5. In the Post Data field, paste the following code as is: +

+
+{
+"signature": <signature>,
+"post_id": <opReturn>,
+"tx_hash": <txId>,
+"tx_amount": <amount>,
+"tx_timestamp": <timestamp>,
+"user_address": <inputAddresses>,
+"value": <value>,
+"currency": <currency>
+}
+

+ 6. Save your button settings after pasting these values, and you're all set! +

+

+ Note: Enabling this feature is required as it improves payment reliability, + leveraging secure server-to-server messaging to record paywall and login transactions to your database. +

+
+
+ +

+ +

+
+
\ No newline at end of file From 26505a3a3f7a2a82a3abe2806e590a50f5953de6 Mon Sep 17 00:00:00 2001 From: xecdev Date: Mon, 2 Feb 2026 12:49:20 +0430 Subject: [PATCH 2/3] Guard against missing/empty paybutton_public_key before save --- includes/class-paybutton-admin.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/includes/class-paybutton-admin.php b/includes/class-paybutton-admin.php index 3b87c97..9e4361a 100644 --- a/includes/class-paybutton-admin.php +++ b/includes/class-paybutton-admin.php @@ -116,6 +116,12 @@ public function process_settings_forms() { ) && current_user_can( 'manage_options' ) ) { + if ( empty( $_POST['paybutton_public_key'] ) ) { + wp_safe_redirect( + admin_url( 'admin.php?page=paybutton-settings&settings-updated=false' ) + ); + exit; + } $public_key = sanitize_text_field( wp_unslash( $_POST['paybutton_public_key'] ) ); From 7e757c57c122d03810275baa1062f30842668089 Mon Sep 17 00:00:00 2001 From: xecdev Date: Mon, 2 Feb 2026 12:54:17 +0430 Subject: [PATCH 3/3] Fix settings_saved success message --- includes/class-paybutton-admin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-paybutton-admin.php b/includes/class-paybutton-admin.php index 9e4361a..f931842 100644 --- a/includes/class-paybutton-admin.php +++ b/includes/class-paybutton-admin.php @@ -296,7 +296,7 @@ public function settings_page() { $args = array( 'paybutton_public_key' => get_option( 'paybutton_public_key', '' ), - 'settings_saved' => isset( $_GET['settings-updated'] ), + 'settings_saved' => isset( $_GET['settings-updated'] ) && $_GET['settings-updated'] === 'true', ); $this->load_admin_template( 'settings', $args );