REST API: Change likes and sharing post meta to REST fields#11298
REST API: Change likes and sharing post meta to REST fields#11298
Conversation
|
Caution: This PR has changes that must be merged to WordPress.com |
|
Thank you for the great PR description! When this PR is ready for review, please apply the Scheduled Jetpack release: March 5, 2019. |
|
codebykat, Your synced wpcom patch D24043-code has been updated. |
jeherve
left a comment
There was a problem hiding this comment.
Just some minor comments. I also wanted to point out that since #10600, we also have WPCOM_REST_API_V2_Field_Controller as a wrapper for register_rest_field. Here is how it's used today:
https://github.com/Automattic/jetpack/tree/5323005738d3c4a5a672f1d30be6875f4fab483b/_inc/lib/core-api/wpcom-fields
|
Code looks good to me, nice work @codebykat! However, I get an incorrect value for the
When I request the post data via the API, Note that I have D24043-code applied with the API sandboxed and I run Jetpack locally (with docker + ngrok). |
Yup, just pointing it out for reference, and for our future selves, as it may be more convenient in some scenarios. :) |
|
I've tested by applying this branch to my local Docker+ngrok setup, and then queried using the developer console (seemed to work well!) to get a single test post ( Changing the global settings result in the fields being present or not (eg. the setting being off meant the field would not be in the API result, as opposed to being present and |
|
Ah sounds like there might be a bug with Likes -- I wonder if the filter is wrong on Jetpack? Investigating. |
|
codebykat, Your synced wpcom patch D24043-code has been updated. |
|
And yes on Jetpack disabling the global setting will not load the module, so the API key won't be present. We'd only expect to see a value of |
|
This is really close @codebykat! I think I'm seeing the same behavior while testing that @mmtr saw in #11298 (comment). Basically sharing appears to be reflected properly, but when toggling the likes property on a post it's never false for me, unless I modify the likes setting under sharing buttons in Calypso: |
|
codebykat, Your synced wpcom patch D24043-code has been updated. |
|
I FOUND IT and it's REALLY AWFUL. On Jetpack the This is actually somewhat great in that it solves the problem of what happens when the global site setting gets changed. On Jetpack, an unset value means "No overrides -- follow the global setting." Whereas a set value allows us to determine what the user originally intended to happen, and proceed accordingly. On the front-end, the check to display like buttons utilizes On WPCOM, where we simply set the meta to However, it is of course terrible that this boolean currently means different things on different platforms. I updated this PR with a POC solution that does different logic depending on whether this is a Jetpack or WPCOM environment, but tomorrow I plan to see if I can easily bring the WPCOM behavior in line with the Jetpack behavior and thus be able to simplify things again. |
|
After thinking about this a little, here's the issue on WPCOM that we'll need to either solve or accept that it will break for some users: Current status on WPCOM:likes enabled globally,
likes disabled globally,
THEN: we change the behavior on WPCOM to follow Jetpack. So now:likes enabled globally,
likes disabled globally,
I also need to test more and verify whether this is different on wp-admin and Calypso; I suspect it's an API bug (as the metabox code is shared) and thus may be Calypso-only. |
mmtr
left a comment
There was a problem hiding this comment.
This is working well now. It wasn't trivial to figure out the differences between WP.com and Jetpack, good job @codebykat!
I plan to see if I can easily bring the WPCOM behavior in line with the Jetpack behavior and thus be able to simplify things again.
That's great! But I don't consider that a blocker, so I'd say it is ok to simplify the behavior on a follow-up PR.
gwwar
left a comment
There was a problem hiding this comment.
Awesome work @codebykat ! Great investigation on the different behaviors between wpcom and Jetpack. What a journey! The API response is now very clear to read too 💖
I tested this with a variety of combinations of setting post options, global settings, and everything aligned on the published view and api response. 💯
|
Also noting this patch doesn't apply cleanly on WPCOM because I accidentally reverted the |
Thanks @codebykat! However I still see the weird behavior with the Actually, I'm starting to think that it might be a core issue caused by making a
I think you can go ahead and manually update the diff so the changes are synced. |
|
@mmtr Hmm. I tested this from the API console, and my fixes from last night did make the correct values show up from both POST and GET requests. Can you share the specific reproduction steps and whether you have Like buttons enabled or disabled globally? Also, are you seeing this with the sharing value or just likes? |
Yeah, I did that, but it's showing up in the "Some checks were not successful" box because it couldn't sync it over. I don't know whether or not that blocks merging. |
I get the results while testing on a Jetpack site and updating a post from the UI as you can see on the GIF I shared above:
|
|
Hm, what actually updates the values in the db? I can't tell; in fact, I can't get the code in
@kat what is the API call you're making to see the correct results? Is it the same as the |
|
On a sandboxed WPCOM site, Does this happen for y'all on WPCOM sites or just on Jetpack? The logic should be the same 🤔 I think you're right @kwight that the update does call |
|
Also can you duplicate the issue with the sharing setting, or is it just Likes? |
|
Ah OK, I think we've been testing two different ways. @mmtr and I have been changing values in the UI, then hitting Update; this fires the @kat you've been making a direct API call with the fields themselves directly in the body of the TL;DR, this PR is good to go, as far as I'm concerned :)
I've just been testing this PR against a local ngrokked JP site, so I haven't had the API or anything sandboxed. From what I can tell, these calls hit the site directly, and don't have anything to do with As far as the outdated values in the Update API call, I don't consider them a blocker/problem here; if anything, we'd want to follow up with a separate PR that might involve hooks somewhere other than the API. |
mmtr
left a comment
There was a problem hiding this comment.
Thanks for the analysis @kwight ! All looking good then :)
Awesome work @codebykat!
|
@jeherve Anything else we need to merge this, beyond one of you to approve? We've forced the |
|
With everyone else approving, let me give it a quick last look. |
kraftbj
left a comment
There was a problem hiding this comment.
I tried various combinations of status changes using Classic Editor and the Jetpack console. Meta via the REST endpoint looked as expected per testing call.
|
@codebykat @kwight Please merge this at will when y'all are ready. |
|
Excellent shepherding and bugfixing @codebykat ! 🎉 💖 from the great code reviews here too! |
* Initial Changelog for 7.2 * Testing list: add mention of IE11 testing * Initial Changelog for 7.2 * Testing list: add mention of IE11 testing * Add CL for #11224 * Add CL for #11426 * Add CL for #11442 * Add testing instructions for #11224 * Add CL for #11451 * Reclassify CL item * Add testing instructions for #11451 * Add CL for #11486 * Add CL for #11418 * Add CL for #11524 * Add CL and testing instructions for #11449 * Add CL for #11460 * Add CL for #11520 and #11582 * Add CL for #11531 * Add CL #11644 * Add testing instructions for #11644 * Add testing instructions for #11644 * Add CL for #11618 * Uniform changelog lines * CL #11679 * CL #11661 * CL #11654 * CL #11645 * CL #11643 * CL #11636 * CL #11635 and for other PHPCS commits * CL #11627 * CL #11626 * CL #11598 * CL #11596 * Remove nested items for shortcopy. I don't believe the detailed list is helpful * CL #11570 * CL #11569 * CL #11560 * CL #11558 * CL #11555 * CL #6704 * CL #11298 * CL #11324 * CL #11443 * CL #11484 * CL #11516 * CL #11529 * Expand Ads block enhancement CL item






This is an update to #11196, further groundwork to support migrating the Likes and Sharing metabox to Gutenberg. After working to implement this logic within Calypso, it became obvious that we should offload the complexity to the API instead.
See Automattic/wp-calypso#29744 for the front-end block code and D23763-code for prior discussion on the WPCOM side.
Changes proposed in this Pull Request:
register_meta, we need to useregister_rest_fieldso that we can add a response with custom callbacks for get and updatepost_metafields, this PR coerces them into booleans that make senseTesting instructions:
jetpack_likes_enabledandjetpack_sharing_enabledshow under the meta keys:Proposed changelog entry for your changes: