Skip to content

Support offsite gateways and delayed checkout#36

Open
dwanjuki wants to merge 21 commits intostrangerstudios:devfrom
dwanjuki:offsite-gateway-fixes
Open

Support offsite gateways and delayed checkout#36
dwanjuki wants to merge 21 commits intostrangerstudios:devfrom
dwanjuki:offsite-gateway-fixes

Conversation

@dwanjuki
Copy link
Copy Markdown
Contributor

All Submissions:

Changes proposed in this Pull Request:

Storing member network site details in order meta to better support offsite gateways.

Updating pmpron_addSite() with an optional $user_id param to make site creation possible for delayed checkouts, e.g PBC, Stripe Checkout webhooks, order recheck function.

Removing PHP session based support for PayPal Express that relied on deprecated pmpro_paypalexpress_session_vars hook.

Adding details to order notes on blog creation failure.

Resolves #31

How to test the changes in this Pull Request:

  1. Complete checkout for a level that gives network sites via Pay By Check, PayPal Express, PayFast, Stripe Checkout...
  2. See that network site is created for the right user on checkout completion.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you successfully run tests with your changes locally?

Changelog entry

dwanjuki added 13 commits March 20, 2026 11:56
Update pmpron_update_site_after_checkout to consider an empty $blog_id as an error when creating network sites. The code now checks is_wp_error($blog_id) || empty($blog_id) and adds an order note on failure, preventing silent success when pmpron_addSite returns an empty/false value.
Ensure the pmpro_network_new_site action is only fired when wpmu_create_blog succeeds. The hook was previously triggered before checking for a WP_Error, which could cause the action to run on failed site creation.
Remove the unused $current_user from the global declarations in pmpron_pmpro_added_order and pmpron_update_site_after_checkout in pmpro-network.php.
Include the 'pmpro_network' text domain in the __() call for the site creation error message in pmpro-network.php so the string can be translated.
Remove early bail-out that required both sitename and blog_id. Instead, update order meta for pmpron_sitename, pmpron_sitetitle, and pmpron_blog_id only when each value is non-empty, avoiding storing empty meta values and allowing partial network site data to be saved.
@dwanjuki dwanjuki marked this pull request as ready for review March 20, 2026 15:23
@andrewlimaza andrewlimaza requested a review from Copilot March 23, 2026 12:25
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves multisite “network site” provisioning for offsite gateways and delayed checkout flows by persisting site details on the order and using those details later when checkout completes.

Changes:

  • Store sitename, sitetitle, and optional blog_id on the membership order (order meta) at order creation time.
  • Update post-checkout site creation/reactivation to read from order meta (removing prior session-based PayPal Express handling) and add more diagnostic order notes on failure.
  • Make pmpron_addSite() accept an optional $user_id so sites can be created for the correct user in delayed/offsite flows.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
pmpro-network.php Adds order-meta persistence for site details, updates post-checkout provisioning logic, and extends pmpron_addSite() to support explicit user IDs.
pages/manage-sites.php Treats empty/false pmpron_addSite() returns as an error in addition to WP_Error.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pmpro-network.php Outdated
$blog_id = intval($_REQUEST['blog_id']);

// If the order level is not set or is in the non site levels array, bail.
if ( empty( $order->membership_id ) || in_array( $order->membership_id, $pmpro_network_non_site_levels ) ) {
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

in_array( $order->membership_id, $pmpro_network_non_site_levels ) is called without guarding that $pmpro_network_non_site_levels is an array. Elsewhere in this file the code checks ! empty( $pmpro_network_non_site_levels ) before in_array; mirroring that here avoids potential PHP 8+ TypeError if the global is unset or filtered to a non-array.

Suggested change
if ( empty( $order->membership_id ) || in_array( $order->membership_id, $pmpro_network_non_site_levels ) ) {
if (
empty( $order->membership_id )
|| (
! empty( $pmpro_network_non_site_levels )
&& is_array( $pmpro_network_non_site_levels )
&& in_array( $order->membership_id, $pmpro_network_non_site_levels, true )
)
) {

Copilot uses AI. Check for mistakes.
Comment thread pmpro-network.php
Comment on lines +245 to +259
// Pull site details from order.
$sitename = get_pmpro_membership_order_meta( $order->id, 'pmpron_sitename', true );
$sitetitle = get_pmpro_membership_order_meta( $order->id, 'pmpron_sitetitle', true );
$blog_id = get_pmpro_membership_order_meta( $order->id, 'pmpron_blog_id', true );

// No network site details in the order, bail.
if ( empty( $sitename ) && empty( $blog_id ) ) {
return;
}

if ( ! empty( $blog_id ) ) {
// Reclaiming, first check that this id is associated with the user.
$all_blog_ids = pmpron_getBlogsForUser( $user_id );
if ( in_array( $blog_id, $all_blog_ids ) ) {
// Activate the blog.
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

Values pulled from order meta are used as-is. It would be safer to cast $blog_id to an int (e.g., absint) and use strict comparisons when checking membership in $all_blog_ids to avoid PHP type-juggling edge cases (e.g., numeric strings with trailing chars) leading to unintended matches.

Copilot uses AI. Check for mistakes.
Comment thread pmpro-network.php
Comment thread pmpro-network.php
Comment thread pmpro-network.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stripe Checkout Offsite Flow does not automatically create the site after checkout

3 participants