Skip to content

Conversation

@xecdev
Copy link
Collaborator

@xecdev xecdev commented Mar 8, 2025

This PR fixes #36 and introduces several changes to improve the configuration experience and admin functionality of the PayButton plugin:

  • Activation Redirect: On activation, the plugin now sets a temporary flag and automatically redirects the admin to the Paywall Settings page. This ensures the admin is immediately prompted to configure the required settings.
  • Mandatory eCash Address: The eCash address field in the Paywall Settings is now marked as required so that the admin cannot leave it empty. Additionally, a persistent admin notice (non-dismissible) is displayed on every admin page if the eCash address is not set, reminding the admin to update the settings. The sticky login with Cashtab header won't appear on the front-end until admin sets a valid eCash address.
  • eCash Address Validation: Utilized the ecashaddrjs library (built and bundled withing the plugin) to automatically validate the eCash address and disable the "Save Changes" button if the address is invalid. Admins can see an address validation message beside the address input field.
  • Default Price Input Fix: Accept any value >=5.5 XEC.

Test plan:

  • Install a fresh copy of WP
  • Install the PayButton plugin
  • After the plugin installation and activation, make sure you're automatically redirected to the Paywall Settings page.
  • Make sure you see the PayButton warning message on any admin page asking the user to set their eCash address.
  • Enter an eCash address and check the validation.
  • Check if the sticky login via Cashtab header is not appearing on the front-end until a valid address is set in the Paywall settings.

@xecdev xecdev added the enhancement (UI/UX/feature) New feature or request label Mar 8, 2025
@xecdev xecdev requested a review from Klakurka March 8, 2025 01:44
@xecdev xecdev self-assigned this Mar 8, 2025
/* ------------------------------
Paywall Settings page styles
------------------------------ */
#ecashAddressValidationResult {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make the address concept generic since we do have support for other blockchains.

#addressValidationResult or #paymentAddressValidationResult would be good.

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_ecash_address' ) );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

$this->load_admin_template( 'paywall-settings', $args );
}

public function admin_notice_missing_ecash_address() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

admin_notice_missing_address or admin_notice_missing_payment_address

if (!current_user_can('manage_options')) {
return;
}
$address = get_option('paybutton_paywall_ecash_address', '');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

$address = get_option('paybutton_paywall_ecash_address', '');
if (empty($address)) {
echo '<div class="notice notice-error">';
echo '<p><strong>PayButton:</strong> Please set your eCash Address in <a href="' . esc_url(admin_url('admin.php?page=paybutton-paywall')) . '">Paywall Settings</a>. If you don\'t have an eCash Address yet, create a wallet using <a href="https://cashtab.com">Cashtab</a> or <a href="https://www.bitcoinabc.org/electrum/">Electrum ABC</a>.</p>';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

We can link to Cashtab and Electrum ABC for XEC, and Electron Cash for BCH. Wording would need some updating to make it clear that we support both.

I think in the future if we do expand to other blockchains, we'll have to improve the text layout a bit to make it more manageable as we don't want the banner at the top taking up so much room; although maybe it's fine since we want them to address the "error" anyway.

<tr>
<th scope="row"><label for="ecash_address">eCash Address</label></th>
<td><input type="text" name="ecash_address" id="ecash_address" class="regular-text" value="<?php echo esc_attr( $ecash_address ); ?>"></td>
<th scope="row"><label for="ecash_address">eCash Address (required)</label></th>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

<td><input type="text" name="ecash_address" id="ecash_address" class="regular-text" value="<?php echo esc_attr( $ecash_address ); ?>"></td>
<th scope="row"><label for="ecash_address">eCash Address (required)</label></th>
<td>
<input type="text" name="ecash_address" id="ecash_address" class="regular-text" value="<?php echo esc_attr( $ecash_address ); ?>" required>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

<td>
<input type="text" name="ecash_address" id="ecash_address" class="regular-text" value="<?php echo esc_attr( $ecash_address ); ?>" required>
<!-- This span will be populated by our bundled address validator JS -->
<span id="ecashAddressValidationResult"></span>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

// Check if the admin has set an eCash address
$admin_ecash_address = get_option('paybutton_paywall_ecash_address', '');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.


// Check if the admin has set an eCash address
$admin_ecash_address = get_option('paybutton_paywall_ecash_address', '');
if ( empty( $admin_ecash_address ) ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

@xecdev
Copy link
Collaborator Author

xecdev commented Mar 9, 2025

You can merge this PR as-is. In a subsequent PR, I will update the payment address naming across multiple files to ensure consistency and multi-chain (XEC and BCH) support.

Copy link
Member

@Klakurka Klakurka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I'll approve it this time but as a general rule, you always want to be iterating towards something and part of that means not removing/changing things that you know you will need to change very soon after.

@Klakurka Klakurka merged commit b9a3ee7 into master Mar 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement (UI/UX/feature) New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Address form improvements (Paywall Settings)

3 participants