Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions includes/class-paybutton-activator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
75 changes: 63 additions & 12 deletions includes/class-paybutton-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ] );
Expand Down Expand Up @@ -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'] ) &&
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -266,7 +320,9 @@ public function admin_notice_missing_required_inputs() {
$public_key = get_option('paybutton_public_key', '');
if (empty($public_key)) {
echo '<div class="notice notice-error">';
echo '<p><strong>NOTICE:</strong> Please set your public key in <a href="' . esc_url(admin_url('admin.php?page=paybutton-paywall')) . '">Paywall Settings</a>.</p>';
echo '<p><strong>NOTICE:</strong> Please set your public key in
<a href="' . esc_url( admin_url('admin.php?page=paybutton-settings') ) . '">
Settings</a>.</p>';
echo '</div>';
}
}
Expand Down Expand Up @@ -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';
Expand Down
52 changes: 0 additions & 52 deletions templates/admin/paywall-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,58 +235,6 @@ class="regular-text"
<p class="description">Enter comma-separated wallet addresses to block from logging in via Cashtab.</p>
</td>
</tr>
<!--NEW Public Key input field-->
<tr>
<th scope="row">
<label for="paybutton_public_key">PayButton Public Key (required)</label>
</th>
<td>
<input type="text" name="paybutton_public_key" id="paybutton_public_key" class="regular-text" value="<?php echo esc_attr( $paybutton_public_key ); ?>" required>
<p class="description">
Enter your PayButton public key to verify Payment Trigger requests.
</p>
<!-- User-Friendly Setup Guide -->
<div class="paybutton-guide">
<p><strong>Guide to Setup your PayButton Public Key:</strong></p>
<p>
1. Create an account on
<a href="https://paybutton.org/signup" target="_blank" rel="noopener noreferrer">PayButton.org</a>
and copy your public key from the <a href="https://paybutton.org/account" target="_blank" rel="noopener noreferrer">account page</a> and paste it in the Public Key field above.
</p>
<p>
2. <a href="https://paybutton.org/buttons" target="_blank" rel="noopener noreferrer">Create a button</a>
for your paywall receiving wallet address.
</p>
<p>
3. Scroll down on the buttons page to the section <em>"When a Payment is Received..."</em>.
</p>
<p>
4. In the <em>URL</em> field, paste the following:
</p>
<pre class="pre-box"><?php echo esc_url( admin_url( 'admin-ajax.php?action=payment_trigger' ) ); ?></pre>
<p>
5. In the <em>Post Data</em> field, paste the following code as is:
</p>
<pre class="pre-box">
{
"signature": &lt;signature&gt;,
"post_id": &lt;opReturn&gt;,
"tx_hash": &lt;txId&gt;,
"tx_amount": &lt;amount&gt;,
"tx_timestamp": &lt;timestamp&gt;,
"user_address": &lt;inputAddresses&gt;,
"value": &lt;value&gt;,
"currency": &lt;currency&gt;
}</pre>
<p>
6. Save your button settings after pasting these values, and you're all set!
</p>
<p>
<strong>Note:</strong> 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.
</p>
</div>
</td>
</tr>
</table>
<p class="submit">
<button type="submit" name="paybutton_paywall_save_settings" class="button button-primary">Save Changes</button>
Expand Down
105 changes: 105 additions & 0 deletions templates/admin/settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<!-- File: templates/admin/settings.php -->
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
?>

<div class="wrap">
<div class="pb-header">
<img class="paybutton-logo" src="<?php echo esc_url( PAYBUTTON_PLUGIN_URL . 'assets/paybutton-logo.png' ); ?>" alt="PayButton Logo">
</div>
<h1>PayButton Settings</h1>
<?php if ( ! empty( $settings_saved ) ) : ?>
<div class="notice notice-success is-dismissible">
<p>Settings saved successfully.</p>
</div>
<?php endif; ?>

<form method="post">
<?php wp_nonce_field( 'paybutton_settings_save', 'paybutton_settings_nonce' ); ?>

<table class="form-table">

<!--NEW Public Key input field-->
<tr>
<th scope="row">
<label for="paybutton_public_key">PayButton Public Key (required)</label>
</th>
<td>
<input
type="text"
name="paybutton_public_key"
id="paybutton_public_key"
class="regular-text"
value="<?php echo esc_attr( $paybutton_public_key ); ?>"
required
>
<p class="description">
Enter your PayButton public key to verify Payment Trigger requests.
</p>

<!-- User-Friendly Setup Guide -->
<div class="paybutton-guide">
<p><strong>Guide to Setup your PayButton Public Key:</strong></p>
<p>
1. Create an account on
<a href="https://paybutton.org/signup" target="_blank" rel="noopener noreferrer">
PayButton.org
</a>
and copy your public key from the
<a href="https://paybutton.org/account" target="_blank" rel="noopener noreferrer">
account page
</a>
and paste it in the Public Key field above.
</p>
<p>
2.
<a href="https://paybutton.org/buttons" target="_blank" rel="noopener noreferrer">
Create a button
</a>
for your paywall receiving wallet address.
</p>
<p>
3. Scroll down on the buttons page to the section
<em>"When a Payment is Received..."</em>.
</p>
<p>
4. In the <em>URL</em> field, paste the following:
</p>
<pre class="pre-box"><?php echo esc_url( admin_url( 'admin-ajax.php?action=payment_trigger' ) ); ?></pre>
<p>
5. In the <em>Post Data</em> field, paste the following code as is:
</p>
<pre class="pre-box">
{
"signature": &lt;signature&gt;,
"post_id": &lt;opReturn&gt;,
"tx_hash": &lt;txId&gt;,
"tx_amount": &lt;amount&gt;,
"tx_timestamp": &lt;timestamp&gt;,
"user_address": &lt;inputAddresses&gt;,
"value": &lt;value&gt;,
"currency": &lt;currency&gt;
}</pre>
<p>
6. Save your button settings after pasting these values, and you're all set!
</p>
<p>
<strong>Note:</strong> 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.
</p>
</div>
</td>
</tr>

</table>

<p class="submit">
<button
type="submit"
name="paybutton_settings_save"
class="button button-primary">
Save Settings
</button>
</p>
</form>
</div>