diff --git a/projects/plugins/jetpack/changelog/update-optimize-sharing-hook b/projects/plugins/jetpack/changelog/update-optimize-sharing-hook new file mode 100644 index 0000000000000..45ec4fd0d5c43 --- /dev/null +++ b/projects/plugins/jetpack/changelog/update-optimize-sharing-hook @@ -0,0 +1,4 @@ +Significance: patch +Type: other + +Optimize the Sharing module hook callback. diff --git a/projects/plugins/jetpack/extensions/blocks/sharing-button/sharing-button.php b/projects/plugins/jetpack/extensions/blocks/sharing-button/sharing-button.php index 5c9e6dd8cad0c..7c11321fdfd59 100644 --- a/projects/plugins/jetpack/extensions/blocks/sharing-button/sharing-button.php +++ b/projects/plugins/jetpack/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/projects/plugins/jetpack/modules/sharedaddy/sharing-service.php b/projects/plugins/jetpack/modules/sharedaddy/sharing-service.php index 2487064126881..db9a37dac1216 100644 --- a/projects/plugins/jetpack/modules/sharedaddy/sharing-service.php +++ b/projects/plugins/jetpack/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.