-
Notifications
You must be signed in to change notification settings - Fork 813
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sharing Block: automatically add block to templates in block themes #35542
Conversation
Under a few specific conditions, we want to automatically add a sharing buttons block (and 3 inner blocks, Facebook, X, and Mastodon) to the bottom of the post content. Site owners can then go to Appearance > Editor if they want to remove or customize that block. For now, we're trying to automatically add the block right after the post content block, in post and page templates (that includes templates like `page-wide`, `page-no-sidebar`, etc). Here are the conditions: - The site must be using a block theme. - An option (`jetpack_sharing_buttons_auto_add`) must be set. Later on we can add UI to set that option under Jetpack > Settings > Social. - The sharing module must be deactivated. We wouldn't want to automatically add sharing buttons to the post content twice. - On WordPress.com Simple, the module is always active. There, we check if sharing posts are enabled on single posts and / or pages, since that matches the template where we'd like to automatically add the block. Resources: - https://make.wordpress.org/core/2023/10/15/introducing-block-hooks-for-dynamic-blocks/ - https://github.com/ockham/like-button - https://core.trac.wordpress.org/ticket/59572 - https://core.trac.wordpress.org/ticket/60126 Internal references: - p1707216098587689-slack-C065QF2R1B6
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available. Once your PR is ready for review, check one last time that all required checks appearing at the bottom of this PR are passing or skipped. Jetpack plugin: The Jetpack plugin has different release cadences depending on the platform:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
projects/plugins/jetpack/extensions/blocks/sharing-button/sharing-button.php
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this. This is a great POC and works as described.
I understand that it's not a ready solution yet, just wanted to point out what we also should consider in the future.
- We probably need to consider if Sharing Buttons already integrated as a part of Post template and not insert it if it is.
- We also won't need to add these if we add the block manually to the page.
- It would be great to see these buttons in editor as well, so they could be adjusted if needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I just got it completely wrong. We actually do change the template of the Post. I it's a great way to do this. 👍
I think this is ready to go now. It won't appear for anyone since it relies on the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that it's safe to move forward as it won't actually show unless option is set tu true
.
Let's merge it so we would be able to iterate on this.
Follow-up to #35542 Core recently changed the definition of the filter we're using to automatically add the sharing block to post templates. As a result, our code is not compatible with WordPress 6.4 anymore: ``` PHP Fatal error: Uncaught ArgumentCountError: Too few arguments to function Automattic\Jetpack\Extensions\Sharing_Button_Block\add_default_services_to_block(), 4 passed in /var/www/html/wp-includes/class-wp-hook.php on line 324 and exactly 5 expected in /usr/local/src/jetpack-monorepo/projects/plugins/jetpack/extensions/blocks/sharing-button/sharing-button.php:254 ``` Let's gate that functionality to WordPress 6.5+ to avoid that error.
Follow-up to #35542 Core recently changed the definition of the filter we're using to automatically add the sharing block to post templates. As a result, our code is not compatible with WordPress 6.4 anymore: ``` PHP Fatal error: Uncaught ArgumentCountError: Too few arguments to function Automattic\Jetpack\Extensions\Sharing_Button_Block\add_default_services_to_block(), 4 passed in /var/www/html/wp-includes/class-wp-hook.php on line 324 and exactly 5 expected in /usr/local/src/jetpack-monorepo/projects/plugins/jetpack/extensions/blocks/sharing-button/sharing-button.php:254 ``` Let's gate that functionality to WordPress 6.5+ to avoid that error.
Important
This is an experiment to play with the Block Hooks API. It can only work with recent changes made to WP Core, and scheduled to ship in WordPress 6.5 next month.
Proposed changes:
Under a few specific conditions, we want to automatically add a sharing buttons block (and 3 inner blocks, Facebook, X, and Mastodon) to the bottom of the post content.
Site owners can then go to Appearance > Editor if they want to remove or customize that block.
For now, we're trying to automatically add the block right after the post content block, in post and page templates (that includes templates like
page-wide
,page-no-sidebar
, etc).Here are the conditions:
jetpack_sharing_buttons_auto_add
) must be set. Later on we can add UI to set that option under Jetpack > Settings > Social.To do
Resources:
Other information:
Jetpack product discussion
Does this pull request change what data or activity we track or use?
Testing instructions:
jetpack_sharing_buttons_auto_add
option:wp option add jetpack_sharing_buttons_auto_add true