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..f931842 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,33 @@ 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' ) + ) { + 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'] ) + ); + 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 +283,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'] ) && $_GET['settings-updated'] === 'true', + ); + + $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 +320,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 +390,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