Skip to content

Commit

Permalink
Jetpack: optimize the Sharing module hook (#40128)
Browse files Browse the repository at this point in the history
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@11ca6bd
  • Loading branch information
sergeymitr authored and matticbot committed Nov 11, 2024
1 parent 8eeec1a commit a5c8362
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion extensions/blocks/sharing-button/sharing-button.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 5 additions & 1 deletion modules/sharedaddy/sharing-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit a5c8362

Please sign in to comment.