Skip to content
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

Hide sharing buttons in Blog Posts block in the editor #25346

Merged
merged 4 commits into from
Aug 2, 2022

Conversation

wojtekn
Copy link
Contributor

@wojtekn wojtekn commented Aug 1, 2022

Fixes #25329

Changes proposed in this Pull Request:

  • Blog Posts block is rendered in the editor via REST request and still displays sharing buttons. I'm adding additional checks to remove those from the editor, to match frontend behavior.

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?

Jetpack product discussion

N/A

Does this pull request change what data or activity we track or use?

No

Testing instructions:

  1. Start a Jetpack environment
  2. Go to WP Admin
  3. Install a WordPress.com Editing Toolkit plugin
  4. Enable Sharing buttons in Jetpack -> Settings -> Sharing (works in Jetpack's offline mode)
  5. Configure sharing buttons to display them on "Front Page, Archive Pages, and Search Results", "Posts", and "Pages"
  6. Add a new page with a Blog Posts block (and not Posts Lists)
  7. Confirm sharing buttons are not displayed under each post in the list of posts in the block shown in the editor

Screen Shot 2022-08-01 at 12 42 04

Alternatively, use an Atomic site with the Jetpack Beta plugin and use this PR branch there.

@matticbot
Copy link
Contributor

Caution: This PR has changes that must be merged to WordPress.com
Hello wojtekn! These changes need to be synced to WordPress.com - If you 're an a11n, please commandeer and confirm D85150-code works as expected before merging this PR. Once this PR is merged, please commit the changes to WP.com. Thank you!
This revision will be updated with each commit to this PR

@github-actions github-actions bot added [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Status] In Progress [Feature] Sharing Post sharing, sharing buttons labels Aug 1, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Aug 1, 2022

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ All commits were linted before commit.
  • ✅ Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

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 (other than "Required review") appearing at the bottom of this PR are passing or skipped.
Then, add the "[Status] Needs Team review" label and ask someone from your team review the code.
Once you’ve done so, switch to the "[Status] Needs Review" label; someone from Jetpack Crew will then review this PR and merge it to be included in the next Jetpack release.


Jetpack plugin:

  • Next scheduled release: September 6, 2022.
  • Scheduled code freeze: August 30, 2022.

@wojtekn wojtekn requested a review from a team August 1, 2022 10:44
@wojtekn wojtekn marked this pull request as ready for review August 1, 2022 10:44
@@ -942,6 +942,11 @@ function sharing_display( $text = '', $echo = false ) {
return $text;
}

// Prevent from rendering sharing buttons in block which is fetched from REST endpoint by editor
if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@coder-karen @jeherve Just to confirm, we'd like to always remove the share buttons in REST API responses?

If we wanted to sometimes include share buttons in the REST API response, an alternative approach might be:

  1. Only include share buttons in the REST API response when share buttons are enabled for the post type.
  2. Don't ever include share buttons in the REST API response when it's a dynamic block request.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 I should think we'd not want it in the REST API response, but if we did it would be when they're enabled for the post type.

Copy link
Contributor

@samiff samiff Aug 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that the injected sharing buttons require enqueued JS to function further down in the chain, I'm not sure why anyone would want the button content to show up in REST API responses 🤔

This tested well for me, and I think it'd be safe to ship and observe for any issue requests that pop up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the editor requests this block, it appends the context GET param set to the edit value. I could include it in the condition to address @danielbachhuber concerns. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That could work, assuming the main intention is to hide the sharing buttons in the editor. That would tie in with the original linked issue.

Perhaps determining which REST API conditions to include sharing buttons in could be for a separate PR, with this one just removing them from the editor. That said I'll be releasing 11.2 in a few hours so I'm not sure if any of this should be a blocker. Given that the issue itself (share button output in the editor) has been around for quite some time it may be better that I don't try to rush this in to 11.2, then we can make sure all cases are covered.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or I can just merge as is, like @samiff suggested we can look out for any issues as is, though we could perhaps refine what we do and don't want to include in a further PR. I'll do this then unless anything comes up in the next few hours.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@coder-karen I've just added that additional check and retested it - it still works as expected.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it does. I'll merge this as is, then I think we can follow up in another PR should we need to be stricter with the REST API conditions.

@coder-karen coder-karen added this to the jetpack/11.2 milestone Aug 1, 2022
@samiff samiff added [Status] Ready to Merge Go ahead, you can push that green button! Media and removed [Status] Needs Team Review labels Aug 1, 2022
samiff
samiff previously approved these changes Aug 1, 2022
@coder-karen coder-karen merged commit 9b67937 into trunk Aug 2, 2022
@coder-karen coder-karen deleted the fix/sharing-buttons-in-editor branch August 2, 2022 11:38
@github-actions github-actions bot removed the [Status] Ready to Merge Go ahead, you can push that green button! label Aug 2, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Aug 2, 2022

Great news! One last step: head over to your WordPress.com diff, D85150-code, and deploy it.
Once you've done so, come back to this PR and add a comment with your SVN changeset ID (e.g. r12345-wpcom).

Thank you!

@wojtekn
Copy link
Contributor Author

wojtekn commented Aug 2, 2022

r249967-wpcom

@coder-karen
Copy link
Contributor

Cherry-picked to release branch in b3b1455

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Sharing Post sharing, sharing buttons Media [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ Touches WP.com Files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sharing buttons: Specific sharing configuration results in misleading page editor display
5 participants