Skip to content

API: Add likes and sharing settings to the REST API Post response#11196

Merged
jeherve merged 3 commits intomasterfrom
add/enable-likes-and-sharing-postmeta-in-api
Jan 28, 2019
Merged

API: Add likes and sharing settings to the REST API Post response#11196
jeherve merged 3 commits intomasterfrom
add/enable-likes-and-sharing-postmeta-in-api

Conversation

@codebykat
Copy link
Copy Markdown
Contributor

@codebykat codebykat commented Jan 24, 2019

This is necessary groundwork to support migrating the Likes and Sharing metabox to Gutenberg. See Automattic/wp-calypso#29744 for context.

Changes proposed in this Pull Request:

  • Calls register_meta with show_in_rest=>true for switch_like_status and sharing_disabled.

Testing instructions:

  • In both Gutenberg and the Classic Editor, verify that the old (backwards-compatible) Likes and Sharing metabox still displays, and works as intended.
  • In Jetpack Sharing settings, enable the toggles to show Likes and Sharing Buttons.
  • Request the post endpoint via the REST API. Verify that switch_like_status and sharing_disabled show under the meta keys:

screen shot 2019-01-24 at 1 56 13 pm

Note: These meta are confusingly named. A post with Likes disabled will have switch_like_status set to FALSE (assuming Likes are enabled on posts by default). A post with Sharing Buttons enabled will have sharing_disabled set to FALSE.

For the purposes of this PR, if these keys show up in the API, the values don't matter that much, as this simply exposes the meta saved on the post.

Proposed changelog entry for your changes:

  • Add likes and sharing settings to the REST API Post response

@codebykat codebykat requested a review from a team January 24, 2019 18:58
@matticbot
Copy link
Copy Markdown
Contributor

D23504-code. (newly created revision)

@codebykat codebykat self-assigned this Jan 24, 2019
@codebykat codebykat added the [Status] Needs Review This PR is ready for review. label Jan 24, 2019
@Automattic Automattic deleted a comment from jetpackbot Jan 24, 2019
@codebykat codebykat requested a review from a team January 24, 2019 19:13
@kwight
Copy link
Copy Markdown
Contributor

kwight commented Jan 24, 2019

Looks great, works for me! 👍

@gwwar
Copy link
Copy Markdown
Contributor

gwwar commented Jan 24, 2019

@kwight @codebykat which endpoints are we testing against? relative to the site, or public.api?

Any other testing instructions?

For example, I used Jetpack Beta to test this but see:

screen shot 2019-01-24 at 3 02 27 pm

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

@codebykat
Copy link
Copy Markdown
Contributor Author

codebykat commented Jan 25, 2019

Hmm. I tried it on jurassic.ninja and the new post_meta keys showed up right away when I switched to this branch. 🤔

@gwwar Maybe you need to have the Likes module activated?

screen shot 2019-01-24 at 11 28 12 pm

screen shot 2019-01-24 at 11 27 05 pm

@codebykat
Copy link
Copy Markdown
Contributor Author

Ahh okay confirmed you have to have Likes enabled in the Jetpack Settings or it won't load the module (which makes sense):

screen shot 2019-01-24 at 11 33 25 pm

So. Now there's some weirdness, because it doesn't load if you toggle Sharing Buttons and not likes. But on the WPCOM side, both of these are handled in the Likes plugin; on the Jetpack side, the sharing stuff is overridden when Sharedaddy loads.

Let me think about how best to handle this.

@jetpackbot
Copy link
Copy Markdown
Collaborator

jetpackbot commented Jan 25, 2019

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: February 5, 2019.
Scheduled code freeze: January 29, 2019

Generated by 🚫 dangerJS against 2f7385f

@codebykat
Copy link
Copy Markdown
Contributor Author

codebykat commented Jan 25, 2019

Okay - Updated to register the meta within the appropriate module. This works correctly on WPCOM as well because sharing.php is in Fusion.

Now when you test on the v2 API, you should see the post_meta enabled with whichever feature you have enabled under Settings:

screen shot 2019-01-25 at 12 16 45 am

With Likes enabled, switch_like_status should be in the meta:

screen shot 2019-01-25 at 12 11 34 am

With sharing buttons toggled on, sharing_disabled will be added:

screen shot 2019-01-25 at 12 10 49 am

And when they're both enabled, you should see both:

screen shot 2019-01-25 at 12 11 46 am

Also worth noting These meta are confusingly named. A post with Likes disabled will have switch_like_status set to FALSE (assuming Likes are enabled on posts by default). A post with Sharing Buttons enabled will have sharing_disabled set to FALSE.

Copy link
Copy Markdown
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.

Just a few minor remarks.

@jeherve jeherve added [Feature] Sharing Post sharing, sharing buttons [Feature] Likes [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. [Feature] WP REST API and removed [Status] Needs Review This PR is ready for review. labels Jan 25, 2019
@codebykat
Copy link
Copy Markdown
Contributor Author

Updated! Thanks @jeherve 😄

@codebykat
Copy link
Copy Markdown
Contributor Author

@gwwar Just want to double-check that you're able to verify functionality with the modules enabled?

@gwwar
Copy link
Copy Markdown
Contributor

gwwar commented Jan 25, 2019

For testing purposes we can use this link: https://jurassic.ninja/create/?jetpack-beta&branch=add/enable-likes-and-sharing-postmeta-in-api&wp-debug-log

I can see the prop, but do we map this to another name on the Jetpack side @jeherve ? I can't get the endpoint to properly reflect values.

cc @codebykat if you find weird behavior like

Also worth noting These meta are confusingly named. A post with Likes disabled will have switch_like_status set to FALSE (assuming Likes are enabled on posts by default). A post with Sharing Buttons enabled will have sharing_disabled set to FALSE.

#11196 (comment) please update the top summary with new testing instructions.

I think the behavior is okay here, I'd prefer if we could write up the expected permutations so folks can manually verify.

@codebykat codebykat added [Status] Needs Review This PR is ready for review. and removed [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. labels Jan 25, 2019
@codebykat
Copy link
Copy Markdown
Contributor Author

Updated the summary and toggled back to Needs Review. I think we just need sign-off from someone on the Jetpack side.

@jeherve jeherve added this to the 7.0 milestone Jan 28, 2019
@jeherve jeherve removed the [Status] Needs Review This PR is ready for review. label Jan 28, 2019
Copy link
Copy Markdown
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.

Everything looks good now. Merging.

@jeherve jeherve merged commit ca7c26b into master Jan 28, 2019
@jeherve jeherve deleted the add/enable-likes-and-sharing-postmeta-in-api branch January 28, 2019 10:30
jeherve added a commit that referenced this pull request Jan 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants