From 23f7e3ccb323eda592b69205f1dbd226691e3273 Mon Sep 17 00:00:00 2001 From: Osk Date: Wed, 11 Sep 2024 16:56:53 -0300 Subject: [PATCH] Sharing Service: Make sure we only check for legacy sharing buttons implementation on non-block themes (#39349) * make sure we only check for legacy sharing buttons implementation on non-block themes * changelog * Omit the function exists check --- ...-sharing-services-assets-only-on-old-themes | 4 ++++ .../modules/sharedaddy/sharing-service.php | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 projects/plugins/jetpack/changelog/update-sharing-services-assets-only-on-old-themes diff --git a/projects/plugins/jetpack/changelog/update-sharing-services-assets-only-on-old-themes b/projects/plugins/jetpack/changelog/update-sharing-services-assets-only-on-old-themes new file mode 100644 index 0000000000000..3b4740084a2ac --- /dev/null +++ b/projects/plugins/jetpack/changelog/update-sharing-services-assets-only-on-old-themes @@ -0,0 +1,4 @@ +Significance: major +Type: compat + +Improved compatibiliy with modern block themes by not checking whether we should use legacy sharing buttons mechanism diff --git a/projects/plugins/jetpack/modules/sharedaddy/sharing-service.php b/projects/plugins/jetpack/modules/sharedaddy/sharing-service.php index 2487064126881..4df18b88bb36f 100644 --- a/projects/plugins/jetpack/modules/sharedaddy/sharing-service.php +++ b/projects/plugins/jetpack/modules/sharedaddy/sharing-service.php @@ -898,6 +898,10 @@ class_exists( 'Jetpack_AMP_Support' ) * @return void */ function sharing_add_header() { + if ( ! sharing_should_load_legacy_sharing_buttons() ) { + return; + } + $sharer = new Sharing_Service(); $enabled = $sharer->get_blog_services(); @@ -912,6 +916,20 @@ function sharing_add_header() { } add_action( 'wp_head', 'sharing_add_header', 1 ); +/** + * Determine if legacy sharing buttons should be loaded. + * Do this by checking if the current theme is a block theme + * If it is, we shouldn't enqueue the sharing assets + * as the recommended way of adding sharing buttons is via the editor. + * + * @since $$next-version$$ + * + * @return bool True if legacy sharing buttons should be loaded, false otherwise. + */ +function sharing_should_load_legacy_sharing_buttons() { + return ! wp_is_block_theme(); +} + /** * Launch sharing requests on page load when a specific query string is used. *