From a5c8362773a69efb809549cfc2991e536b8099e2 Mon Sep 17 00:00:00 2001 From: sergeymitr Date: Mon, 11 Nov 2024 16:06:39 +0000 Subject: [PATCH] Jetpack: optimize the Sharing module hook (#40128) Make the Sharing module run the `template_redirect` action callback only when necessary. Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/11781856359 Upstream-Ref: Automattic/jetpack@11ca6bdbef73903dd1b11c439fb39a8d2eaef6e7 --- CHANGELOG.md | 1 + extensions/blocks/sharing-button/sharing-button.php | 6 +++++- modules/sharedaddy/sharing-service.php | 6 +++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 128ca118ee..20305081c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ This is an alpha version! The changes listed here are not final. - Fix Slideshow block width when used inside a Row block - Jetpack AI: fix image generation modals jumpiness by fitting boththe image sizes and the placeholder/empty image - Opengraph: minor bug fixing. +- Optimize the Sharing module hook callback. - Remove old widget migration code. - Search: add ability to customize order of results - Sync: Added test for Full Sync sending modules in the order config is set diff --git a/extensions/blocks/sharing-button/sharing-button.php b/extensions/blocks/sharing-button/sharing-button.php index 5c9e6dd8ca..7c11321fdf 100644 --- a/extensions/blocks/sharing-button/sharing-button.php +++ b/extensions/blocks/sharing-button/sharing-button.php @@ -202,7 +202,11 @@ function sharing_process_requests() { } } } -add_action( 'template_redirect', __NAMESPACE__ . '\sharing_process_requests', 9 ); + +// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Only checking for the data being present. +if ( isset( $_GET['share'] ) ) { + add_action( 'template_redirect', __NAMESPACE__ . '\sharing_process_requests', 9 ); +} /** * Automatically add the Sharing Buttons block to the end of the Single Posts template. diff --git a/modules/sharedaddy/sharing-service.php b/modules/sharedaddy/sharing-service.php index 2487064126..db9a37dac1 100644 --- a/modules/sharedaddy/sharing-service.php +++ b/modules/sharedaddy/sharing-service.php @@ -930,7 +930,11 @@ function sharing_process_requests() { } } } -add_action( 'template_redirect', 'sharing_process_requests', 9 ); + +// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Only checking for the data being present. +if ( isset( $_GET['share'] ) ) { + add_action( 'template_redirect', 'sharing_process_requests', 9 ); +} /** * Gets the url to customise the sharing buttons in Calypso.