Support offsite gateways and delayed checkout#36
Support offsite gateways and delayed checkout#36dwanjuki wants to merge 21 commits intostrangerstudios:devfrom
Conversation
Saving in order meta now
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.
There was a problem hiding this comment.
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 optionalblog_idon 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_idso 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.
| $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 ) ) { |
There was a problem hiding this comment.
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.
| 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 ) | |
| ) | |
| ) { |
| // 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. |
There was a problem hiding this comment.
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.
Values in $all_blog_ids are strings
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_idparam 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_varshook.Adding details to order notes on blog creation failure.
Resolves #31
How to test the changes in this Pull Request:
Other information:
Changelog entry