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
33 changes: 33 additions & 0 deletions DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,36 @@ screen. Explain token permissions, legacy-key migration, SSL contact email,
resource IDs, extra domains and wildcard limitations beside the relevant form.
Reuse the existing stacked, wrapping layout on desktop and mobile; no new styles
or wizard steps are needed. Keep the access token in a password field.

## Frontend customer accounts

Keep account-wide membership, billing and invoices separate from site-specific
summary and limits. Account Summary must offer a sign-in link when logged out,
an owner-scoped site chooser before site selection, and a neutral no-sites state
instead of silently rendering nothing. Do not silently select the first site:
customers may own several. Once a site is selected, omit self-referential
"See More" links and show remaining trial days from the actual membership date.
Use the existing stacked widget styles on desktop and mobile, with native links
and wrapping site names; do not add fixed-width panels or a second design system.
Frontend account pages belong on the main site; customer-site admin Account
screens remain an alternative interface to the same membership.

On combined pages, Manage must visibly land on the selected site's controls,
using a keyboard-focusable native fragment target (Account Summary is the
fallback). Your Sites clears selected-site context and returns to the page
permalink. Successful frontend deletion returns to the account landing page,
unless an explicit destination is configured; never retain a deleted-site URL.
Sites without a template initialize the selector to numeric zero so their first
selection exposes the same destructive-action confirmation as template changes.

Payment-method changes must return from Stripe Billing Portal to the originating
account page, using a validated local destination. Show the subscription's card
override when present; otherwise show the customer's default payment method,
including after the portal clears an override while replacing the default card.

Native account blocks share shortcode renderers, settings and ownership checks.
Load widget preview styles inside the block editor canvas, including iframe
editors. Numeric controls save integers and toggle defaults use booleans. Group
and Columns layouts must preserve nested element attributes during early setup,
especially the Checkout form slug. Editor previews use sample data; verify real
customer actions on the published page rather than treating a preview as proof.
49 changes: 45 additions & 4 deletions inc/admin-pages/class-payment-edit-admin-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -1186,10 +1186,11 @@ public function register_widgets(): void {
'confirm_membership' => [
'type' => 'toggle',
'title' => __('Activate Membership?', 'ultimate-multisite'),
'desc' => __('This payment belongs to a pending membership. If you toggle this option, this change in status will also apply to the membership. If any sites are pending, they are also going to be published automatically.', 'ultimate-multisite'),
'desc' => __('This payment belongs to a membership that is not active yet. Enable this option to activate, renew or reactivate it when confirming the payment. Any pending sites will also be published automatically.', 'ultimate-multisite'),
'value' => 0,
'wrapper_html_attr' => [
'v-if' => 'status !== original_status && status === "completed" && membership_status === "pending"',
// Mirrors handle_save(): only a pending payment being completed can confirm a membership.
'v-if' => 'original_status === "pending" && status === "completed" && membership_status !== "active" && membership_status !== "trialing"',
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
'v-cloak' => '1',
],
],
Expand Down Expand Up @@ -1480,13 +1481,35 @@ public function handle_save(): bool {
if ($should_confirm_membership && $membership) {
$is_initial_payment = Membership_Status::PENDING === $membership->get_status()
&& 0 === $membership->get_times_billed();
$is_addon_payment = $this->is_addon_payment($payment);

// The initial payment counts as a bill, but checkout already set its period.
$membership->add_to_times_billed(1);
if ( ! $is_addon_payment) {
// The initial payment counts as a bill, but checkout already set its period.
$membership->add_to_times_billed(1);
}

if ($is_initial_payment) {
$membership->set_status(Membership_Status::ACTIVE);
$membership_saved = $membership->save();
} elseif ($is_addon_payment) {
/*
* Add-ons are extras on the plan, not one of its billing cycles: lift
* the hold without moving the plan's period or its bill count.
*/
$membership->set_status(Membership_Status::ACTIVE);
$membership_saved = $membership->save();
} elseif (in_array($membership->get_status(), [Membership_Status::CANCELLED, Membership_Status::EXPIRED], true)) {
/*
* A paid reactivation. Like the Stripe and PayPal gateways, use
* reactivate() so the cancellation date clears and the reactivation
* hooks fire. Cancelling clears the gateway: record how this
* membership was paid so the account page shows it.
*/
if ( ! $membership->get_gateway() && $payment->get_gateway()) {
$membership->set_gateway($payment->get_gateway());
}

$membership_saved = $membership->reactivate(false);
} else {
$membership_saved = $membership->renew(false, Membership_Status::ACTIVE);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}
Expand Down Expand Up @@ -1529,4 +1552,22 @@ public function handle_save(): bool {

return $saved;
}

/**
* Checks whether a payment came from an add-on checkout.
*
* An add-on cart holds only the extras to add to a membership. Paying for it
* is not a billing cycle of the membership's plan.
*
* @since n.e.x.t
*
* @param \WP_Ultimo\Models\Payment $payment The payment.
* @return bool
*/
private function is_addon_payment($payment): bool {

$cart = $payment->get_meta(Payment::META_ORIGINAL_CART);

return $cart instanceof \WP_Ultimo\Checkout\Cart && 'addon' === $cart->get_cart_type();
}
}
20 changes: 19 additions & 1 deletion inc/builders/block-editor/assets/js/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,25 @@

const obj = {};

obj[ field_slug ] = value;
if (field.type === 'number') {

// NumberControl emits strings, and '' while cleared; the block schema requires integers.
const number = parseInt(value, 10);

// Keep the last valid number rather than saving an invalid one mid-edit.
if (Number.isNaN(number)) {

return;

}

obj[ field_slug ] = number;

} else {

obj[ field_slug ] = value;

}

props.setAttributes(obj);

Expand Down
2 changes: 1 addition & 1 deletion inc/builders/block-editor/assets/js/blocks.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion inc/builders/block-editor/class-block-editor-widget-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public function register_block($element): void {
[
'attributes' => $attributes,
'editor_script' => 'wu-blocks',
'editor_style' => 'wu-admin',
'render_callback' => \Closure::fromCallable([$element, 'get_content']),
]
);
Expand Down Expand Up @@ -236,9 +237,21 @@ public function get_attributes_from_fields($element) {
}

$default_value = wu_get_isset($defaults, $field_id, '');
$value = wu_get_isset($field, 'value', $default_value);

// Block defaults must have the same types as their REST schema.
if ( ! is_callable($value)) {
if ('boolean' === $type) {
$value = (bool) $value;
} elseif ('integer' === $type) {
$value = (int) $value;
} else {
$value = (string) $value;
}
}

$_fields[ $field_id ] = [
'default' => wu_get_isset($field, 'value', $default_value),
'default' => $value,
'type' => $type,
];
}
Expand Down
Loading
Loading