Skip to content
This repository was archived by the owner on May 21, 2025. It is now read-only.

Commit 1f59901

Browse files
authored
Only fetch subscription object on subscription admin pages (#776)
* Only fetch subscription object on subscription admin pages * Add changelog entry * Avoid unnecessary wcs_is_subscription() call * Return if the subscription result is no a subscription * Refine logic for fetching subscription ID from global post ID
1 parent baa08e3 commit 1f59901

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Fix - Correctly load product names with HTML on the cart and checkout shipping rates.
77
* Fix - Improve our admin notice handling to ensure notices are displayed to the intended admin user.
88
* Fix - Improve protections around the pending renewal order-creation process, to prevent uncaught exceptions and other errors from breaking the subscription editor.
9+
* Fix - Prevent unnecessary subscription object lookups on non-subscription admin pages when global $post is set.
910
* Fix - After enabling the Customer Notification feature or changing the reminder timer setting, ensure notification emails are scheduled for subscriptions with pending cancellation status.
1011
* Update - Include subscription items table in all customer notification emails.
1112
* Update - Subscription notes for unsent customer notification emails now only occurs if WCS_DEBUG is enabled.

includes/admin/class-wcs-admin-meta-boxes.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,21 +136,29 @@ public function remove_meta_box_save( $order_id, $order ) {
136136
public function enqueue_styles_scripts() {
137137
global $theorder;
138138

139-
// If $theorder is empty, fallback to using the global post object.
140-
if ( empty( $theorder ) && ! empty( $GLOBALS['post']->ID ) ) {
141-
$theorder = wcs_get_subscription( $GLOBALS['post']->ID );
142-
}
143-
144139
// Get admin screen ID.
145140
$screen = get_current_screen();
146141
$screen_id = isset( $screen->id ) ? $screen->id : '';
147142

148143
// Get the script version.
149144
$ver = WC_Subscriptions_Core_Plugin::instance()->get_library_version();
150145

151-
if ( wcs_get_page_screen_id( 'shop_subscription' ) === $screen_id && wcs_is_subscription( $theorder ) ) {
152-
// Declare a subscription variable for clearer use. The $theorder global on edit subscription screens is a subscription.
153-
$subscription = $theorder;
146+
if ( wcs_get_page_screen_id( 'shop_subscription' ) === $screen_id ) {
147+
// If global $theorder is empty, fallback to using the global post object.
148+
if ( empty( $theorder ) && ! empty( $GLOBALS['post']->ID ) ) {
149+
$subscription = wcs_get_subscription( $GLOBALS['post']->ID );
150+
151+
// If we have a subscription, set it as the global $theorder.
152+
if ( $subscription ) {
153+
$theorder = $subscription;
154+
}
155+
} else {
156+
$subscription = $theorder;
157+
}
158+
159+
if ( ! wcs_is_subscription( $subscription ) ) {
160+
return;
161+
}
154162

155163
wp_register_script( 'jstz', WC_Subscriptions_Core_Plugin::instance()->get_subscriptions_core_directory_url( 'assets/js/admin/jstz.min.js' ), [], $ver, false );
156164
wp_register_script( 'momentjs', WC_Subscriptions_Core_Plugin::instance()->get_subscriptions_core_directory_url( 'assets/js/admin/moment.min.js' ), [], $ver, false );

0 commit comments

Comments
 (0)