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

Likes and Sharing Gutenberg extension: Add another hook to catch late-registered CPTs #12031

Merged
merged 1 commit into from
Apr 16, 2019

Conversation

codebykat
Copy link
Member

Eagle-eyed testers noticed that this extension (see #11709) wasn't working properly with some custom post types. This PR fixes it by running register_rest_field on both rest_api_init and restapi_theme_init.

Changes proposed in this Pull Request:

Some post types, such as testimonials and comics, are conditionally registered if the theme supports them, so instead of being hooked to rest_api_init they hook to restapi_theme_init. This runs after rest_api_init, meaning they weren't getting the necessary API fields for the extension to work.

The default action priority is 10. SO if we hook to restapi_theme_init with a priority of 20 we'll get to add this functionality to any late-registered CPTs.

In testing I found that we still need to hook to rest_api_init in order for posts to function correctly -- I haven't dug into why (is the theme_init not called for endpoint requests for posts?) but I don't believe there's any harm in calling register_rest_field twice as it will simply override the prior call.

Testing instructions:

  • Test out the Likes and Sharing sidebar extension (see below) with a custom post type. (Remember that Sharing buttons will only show up on a CPT if enabled in Settings->Sharing regardless of the checkbox setting.)
  • Also verify there are no regressions when editing normal posts and pages.

Full testing instructions from #11709:

  1. Double-check sharing button prerequisites.
  2. Make sure beta blocks are enabled with define( 'JETPACK_BETA_BLOCKS', true ); in your wp-config.php.
  3. Compile the blocks with yarn build-extensions in the checked-out branch.
  4. Enable some kind of custom post type, e.g. testimonials
  5. Load a new or existing CPT post in the block editor
  6. The Likes and Sharing checkboxes should no longer be visible in the post sidebar under Discussion.
  7. Under the Jetpack sidebar, there should be a Likes and Shares section with checkboxes to toggle these options:

screen shot 2019-01-24 at 3 44 01 pm

  1. Make sure you can set/unset them and that these settings are appropriately reflected on the front-end.

Proposed changelog entry for your changes:

  • Fix an issue that caused the Likes and Sharing sidebar extension to be broken for some custom post types.

@codebykat codebykat added [Feature] Sharing Post sharing, sharing buttons [Feature] Likes [Focus] Blocks Issues related to the block editor, aka Gutenberg, and its extensions developed in Jetpack labels Apr 12, 2019
@codebykat codebykat requested review from a team April 12, 2019 06:46
@codebykat codebykat self-assigned this Apr 12, 2019
@matticbot
Copy link
Contributor

Caution: This PR has changes that must be merged to WordPress.com
Hello codebykat! These changes need to be synced to WordPress.com - If you 're an a11n, please commandeer, review, and approve D26856-code before merging this PR. Thank you!

@codebykat codebykat added the [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. label Apr 12, 2019
@Automattic Automattic deleted a comment from jetpackbot Apr 12, 2019
@obenland
Copy link
Member

It looks good for custom post types and posts. When editing pages however, the JP sidebar doesn't show up. Is there a setting I'm missing?

obenland
obenland previously approved these changes Apr 12, 2019
Copy link
Member

@obenland obenland left a comment

Choose a reason for hiding this comment

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

Looks like this is not a regression and pages just don't seem to have the Jetpack sidebar. Shouldn't be a blocker for this PR, but we should find out the reasons behind it and what it means for sharing & likes settings there

@obenland obenland added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. labels Apr 12, 2019
@codebykat
Copy link
Member Author

codebykat commented Apr 12, 2019

Thanks @obenland! I'm checking with Gutenpack folks on whether we can enable the Jetpack sidebar on pages as well.

@codebykat
Copy link
Member Author

Convo about the Pages issue here #12045

@jeherve
Copy link
Member

jeherve commented Apr 15, 2019

I can't seem to be able to get this to work; I don't see the Jetpack sidebar at all when editing Testimonials.

@codebykat
Copy link
Member Author

@jeherve Can you re-test now that we merged #12052? I see the sidebar now for both Portfolios and Testimonials on WPCOM and Jetpack. I have had some problems getting beta blocks to show up on Jetpack local dev, so I had to move them into production in index.json for testing.

@codebykat codebykat force-pushed the fix/likes-and-sharing-extension-for-CPTs branch from 87c02d3 to 441df54 Compare April 15, 2019 21:47
@jetpackbot
Copy link
Collaborator

Thank you for the great PR description!

When this PR is ready for review, please apply the [Status] Needs Review label. If you are an a11n, please have someone from your team review the code if possible. The Jetpack team will also review this PR and merge it to be included in the next Jetpack release.

Scheduled Jetpack release: May 7, 2019.
Scheduled code freeze: April 30, 2019

Generated by 🚫 dangerJS against 441df54

@obenland
Copy link
Member

With the fix for pages in now, Testimonials work for me too.

@obenland
Copy link
Member

@Automattic/jetpack-crew Is there a chance you could give this another look and ✅?

Copy link
Member

@simison simison left a comment

Choose a reason for hiding this comment

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

Fixes for public custom post types. 🎉

Doesn't fix for private custom post types such as re-usable blocks (/wp-admin/edit.php?post_type=wp_block), though. I'd assume same problem for potential wp_template custom post type down the road.

:shipit:

@codebykat
Copy link
Member Author

Thanks @simison ! Indeed I'm noting the non-public post type issue for follow-up work. I think we should just hide the sidebar in that case.

@simison simison added [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. and removed [Status] Ready to Merge Go ahead, you can push that green button! labels Apr 16, 2019
@simison
Copy link
Member

simison commented Apr 16, 2019

Switched to "needs review" so that this will show up at Crew's lists.

Copy link
Member

@jeherve jeherve left a comment

Choose a reason for hiding this comment

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

this works well for me now. Merge when ready!

@jeherve jeherve added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. labels Apr 16, 2019
@codebykat codebykat merged commit 87a8cc4 into master Apr 16, 2019
@matticbot matticbot added [Status] Needs Changelog and removed [Status] Ready to Merge Go ahead, you can push that green button! labels Apr 16, 2019
@codebykat codebykat deleted the fix/likes-and-sharing-extension-for-CPTs branch April 16, 2019 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Likes [Feature] Sharing Post sharing, sharing buttons [Focus] Blocks Issues related to the block editor, aka Gutenberg, and its extensions developed in Jetpack Touches WP.com Files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants