From cb2549386ad03d5cc3851d80481db339b0c80726 Mon Sep 17 00:00:00 2001 From: Chi-Hsuan Huang Date: Fri, 6 Sep 2024 11:44:01 +0800 Subject: [PATCH] Only run "woocommerce_admin_shared_settings" filter on admin requests (#51161) * Only load settings if it's admin * Add changelog --- .../changelog/perf-only-load-settings-in-admin | 4 ++++ .../src/Internal/Admin/WCAdminSharedSettings.php | 8 ++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 plugins/woocommerce/changelog/perf-only-load-settings-in-admin diff --git a/plugins/woocommerce/changelog/perf-only-load-settings-in-admin b/plugins/woocommerce/changelog/perf-only-load-settings-in-admin new file mode 100644 index 00000000000..2784f25128c --- /dev/null +++ b/plugins/woocommerce/changelog/perf-only-load-settings-in-admin @@ -0,0 +1,4 @@ +Significance: patch +Type: performance + +Only run woocommerce_admin_shared_settings filter on admin requests diff --git a/plugins/woocommerce/src/Internal/Admin/WCAdminSharedSettings.php b/plugins/woocommerce/src/Internal/Admin/WCAdminSharedSettings.php index ce2b87598fb..49ead3b7509 100644 --- a/plugins/woocommerce/src/Internal/Admin/WCAdminSharedSettings.php +++ b/plugins/woocommerce/src/Internal/Admin/WCAdminSharedSettings.php @@ -54,14 +54,18 @@ class WCAdminSharedSettings { * @return void */ public function on_woocommerce_blocks_loaded() { + // Ensure we only add admin settings on the admin. + if ( ! is_admin() ) { + return; + } + if ( class_exists( '\Automattic\WooCommerce\Blocks\Assets\AssetDataRegistry' ) ) { \Automattic\WooCommerce\Blocks\Package::container()->get( \Automattic\WooCommerce\Blocks\Assets\AssetDataRegistry::class )->add( $this->settings_prefix, - function() { + function () { return apply_filters( 'woocommerce_admin_shared_settings', array() ); } ); } } } -