Skip to content

REST API: Register Likes/Sharing fields for all post types#11516

Merged
codebykat merged 4 commits intomasterfrom
fix/enable-likes-and-sharing-api-for-all-post-types
Mar 7, 2019
Merged

REST API: Register Likes/Sharing fields for all post types#11516
codebykat merged 4 commits intomasterfrom
fix/enable-likes-and-sharing-api-for-all-post-types

Conversation

@codebykat
Copy link
Copy Markdown
Contributor

Changes proposed in this Pull Request:

In #11298, metadata to check whether sharing and Like buttons are enabled was added to post endpoints. I thought at the time that hooking it to the "post" type meant "posts and pages", but it turns out it does not.

This PR follows the pre-existing pattern of enabling this functionality for all public post types (this is the same logic used to add the metaboxes to the admin screen).

Testing instructions:

  • Go through the following testing instructions for multiple post types: pages, another CPT that supports likes or sharing, and posts.
  • 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 (or page) endpoint via the REST API. Verify that jetpack_likes_enabled and jetpack_sharing_enabled show under the meta keys:

screen shot 2019-02-07 at 12 48 47 am

  • Experiment with different combinations of sitewide like and sharing settings and post settings, and ensure the values returned by the API reflect reality

Proposed changelog entry for your changes:

  • REST API: Enable Likes and Sharing meta field for all post types

@codebykat codebykat added [Feature] Sharing Post sharing, sharing buttons [Feature] Likes [Status] Needs Review This PR is ready for review. [Feature] WP REST API labels Mar 7, 2019
@codebykat codebykat self-assigned this Mar 7, 2019
@codebykat codebykat requested review from a team March 7, 2019 05:21
@matticbot
Copy link
Copy Markdown
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 D25225-code before merging this PR. Thank you!

@jetpackbot
Copy link
Copy Markdown
Collaborator

jetpackbot commented Mar 7, 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: April 2, 2019.
Scheduled code freeze: March 26, 2019

Generated by 🚫 dangerJS against b6cccf1

@jeherve jeherve added this to the 7.2 milestone Mar 7, 2019
jeherve
jeherve previously requested changes Mar 7, 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.

Hey, it's me, nit-picking again. We're working on adding linting to our pre-commit hook (see #11515 for more info), but until then I'm afraid you'll need to fix those manually. I would do it myself but I don't want to overwrite your wpcom changes with Fusion by mistake.

Here is what I think should be changed to please the linter:

diff --git a/modules/likes.php b/modules/likes.php
index 0594c469e..b2e5de545 100644
--- a/modules/likes.php
+++ b/modules/likes.php
@@ -622,15 +622,16 @@ function jetpack_post_likes_update_value( $enable_post_likes, $post_object ) {
  */
 function jetpack_post_likes_register_rest_field() {
 	$post_types = get_post_types( array( 'public' => true ) );
-	foreach( $post_types as $post_type ) {
+	foreach ( $post_types as $post_type ) {
 		register_rest_field(
-			$post_type, 'jetpack_likes_enabled',
+			$post_type,
+			'jetpack_likes_enabled',
 			array(
-				'get_callback' => 'jetpack_post_likes_get_value',
+				'get_callback'    => 'jetpack_post_likes_get_value',
 				'update_callback' => 'jetpack_post_likes_update_value',
-				'schema' => array(
-					'description' => __( 'Are Likes enabled?' ),
-					'type'        => 'boolean'
+				'schema'          => array(
+					'description' => __( 'Are Likes enabled?', 'jetpack' ),
+					'type'        => 'boolean',
 				),
 			)
 		);
diff --git a/modules/sharedaddy/sharing.php b/modules/sharedaddy/sharing.php
index 33de9d3d9..b2d4872cc 100644
--- a/modules/sharedaddy/sharing.php
+++ b/modules/sharedaddy/sharing.php
@@ -591,15 +591,16 @@ function jetpack_post_sharing_update_value( $enable_sharing, $post_object ) {
  */
 function jetpack_post_sharing_register_rest_field() {
 	$post_types = get_post_types( array( 'public' => true ) );
-	foreach( $post_types as $post_type ) {
+	foreach ( $post_types as $post_type ) {
 		register_rest_field(
-			$post_type, 'jetpack_sharing_enabled',
+			$post_type,
+			'jetpack_sharing_enabled',
 			array(
-				'get_callback' => 'jetpack_post_sharing_get_value',
+				'get_callback'    => 'jetpack_post_sharing_get_value',
 				'update_callback' => 'jetpack_post_sharing_update_value',
-				'schema' => array(
-					'description' => __( 'Are sharing buttons enabled?' ),
-					'type'        => 'boolean'
+				'schema'          => array(
+					'description' => __( 'Are sharing buttons enabled?', 'jetpack' ),
+					'type'        => 'boolean',
 				),
 			)
 		);

Other than that, it works well and is a good addition. It should be good to go.

Comment thread modules/likes.php Outdated
Comment thread modules/sharedaddy/sharing.php Outdated
@jeherve jeherve added [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. and removed [Status] Needs Review This PR is ready for review. labels Mar 7, 2019
Add Jetpack textdomain to translation string

Co-Authored-By: codebykat <kat@codebykat.com>
@matticbot
Copy link
Copy Markdown
Contributor

codebykat, Your synced wpcom patch D25225-code has been updated.

Add Jetpack textdomain to translation string

Co-Authored-By: codebykat <kat@codebykat.com>
@matticbot
Copy link
Copy Markdown
Contributor

codebykat, Your synced wpcom patch D25225-code has been updated.

@matticbot
Copy link
Copy Markdown
Contributor

codebykat, Your synced wpcom patch D25225-code has been updated.

@codebykat
Copy link
Copy Markdown
Contributor Author

Nits fixed! Thanks @jeherve !

@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 Mar 7, 2019
@codebykat codebykat requested a review from jeherve March 7, 2019 15:44
@codebykat codebykat dismissed jeherve’s stale review March 7, 2019 15:52

changes addressed

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.

This should now be good to merge.

@jeherve jeherve added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] Needs Review This PR is ready for review. labels Mar 7, 2019
@codebykat codebykat merged commit 530fda1 into master Mar 7, 2019
@codebykat codebykat deleted the fix/enable-likes-and-sharing-api-for-all-post-types branch March 7, 2019 15:56
@ghost ghost removed the [Status] Ready to Merge Go ahead, you can push that green button! label Mar 7, 2019
kraftbj added a commit that referenced this pull request Mar 26, 2019
kraftbj added a commit that referenced this pull request Mar 27, 2019
* 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
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.

5 participants