From 760b9c54cf84de1fcafb61a0dba82441a4cd01b4 Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Thu, 30 May 2024 16:09:01 +0100 Subject: [PATCH 01/13] Add post ID into custom metadata --- src/Metadata/class-metadata-builder.php | 8 ++++++++ src/Metadata/class-post-builder.php | 1 + 2 files changed, 9 insertions(+) diff --git a/src/Metadata/class-metadata-builder.php b/src/Metadata/class-metadata-builder.php index 3b842b313..a57f274dc 100644 --- a/src/Metadata/class-metadata-builder.php +++ b/src/Metadata/class-metadata-builder.php @@ -120,6 +120,14 @@ protected function build_type( WP_Post $post, string $parsely_type ): void { $this->metadata['@type'] = $type; } + protected function build_post_id( WP_Post $post ): void { + $this->metadata['custom_metadata'] = wp_json_encode( + array( + 'postID' => $post->ID, + ) + ); + } + /** * Populates the mainEntityOfPage field in the metadata object. * diff --git a/src/Metadata/class-post-builder.php b/src/Metadata/class-post-builder.php index 8f1746684..a92ecf3ee 100644 --- a/src/Metadata/class-post-builder.php +++ b/src/Metadata/class-post-builder.php @@ -60,6 +60,7 @@ public function get_metadata(): array { $this->build_publisher(); $this->build_keywords( $this->post ); $this->build_metadata_post_times( $this->post ); + $this->build_post_id( $this->post ); return $this->metadata; } From b86645c5070faf1b921a37b5d96069473c239818 Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Thu, 30 May 2024 16:19:20 +0100 Subject: [PATCH 02/13] Fix --- src/Metadata/class-metadata-builder.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Metadata/class-metadata-builder.php b/src/Metadata/class-metadata-builder.php index a57f274dc..608e70a74 100644 --- a/src/Metadata/class-metadata-builder.php +++ b/src/Metadata/class-metadata-builder.php @@ -120,6 +120,13 @@ protected function build_type( WP_Post $post, string $parsely_type ): void { $this->metadata['@type'] = $type; } + /** + * Populates all the fields related to post ID. + * + * @param WP_Post $post The post/page for which to populate the field. + * + * @since 3.0.x + */ protected function build_post_id( WP_Post $post ): void { $this->metadata['custom_metadata'] = wp_json_encode( array( From 9be78ecc580190692037430b0e1790ad5904646e Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Thu, 30 May 2024 16:23:54 +0100 Subject: [PATCH 03/13] Fix tests --- tests/Integration/Endpoints/RestMetadataTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/Integration/Endpoints/RestMetadataTest.php b/tests/Integration/Endpoints/RestMetadataTest.php index 226e1071c..75b8198c1 100644 --- a/tests/Integration/Endpoints/RestMetadataTest.php +++ b/tests/Integration/Endpoints/RestMetadataTest.php @@ -472,7 +472,8 @@ public function test_get_rendered_repeated_metas(): void { -'; + +'; self::assertSame( $expected, $meta_string ); } From a5e7c69489a1c3d155a729f169e89ff4f8971150 Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Thu, 30 May 2024 16:24:38 +0100 Subject: [PATCH 04/13] fix tests --- tests/Integration/Endpoints/RestMetadataTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Integration/Endpoints/RestMetadataTest.php b/tests/Integration/Endpoints/RestMetadataTest.php index 75b8198c1..8bd06a026 100644 --- a/tests/Integration/Endpoints/RestMetadataTest.php +++ b/tests/Integration/Endpoints/RestMetadataTest.php @@ -473,7 +473,7 @@ public function test_get_rendered_repeated_metas(): void { -'; +'; self::assertSame( $expected, $meta_string ); } From 1455961783d07262281c6ed9203efa55872e9be0 Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Wed, 5 Jun 2024 10:31:48 +0900 Subject: [PATCH 05/13] Update RestMetadataTest --- tests/Integration/Endpoints/RestMetadataTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Integration/Endpoints/RestMetadataTest.php b/tests/Integration/Endpoints/RestMetadataTest.php index 8bd06a026..8f22ef288 100644 --- a/tests/Integration/Endpoints/RestMetadataTest.php +++ b/tests/Integration/Endpoints/RestMetadataTest.php @@ -404,7 +404,7 @@ public function test_get_rendered_meta_json_ld(): void { $this->go_to( (string) $this->get_permalink( $post_id ) ); $meta_string = self::$rest->get_rendered_meta( 'json_ld' ); - $expected = ''; + $expected = ''; self::assertSame( $expected, $meta_string ); } From 1f6f753a4c420b1e00bba3e79bea2458d97054ed Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Wed, 5 Jun 2024 10:36:49 +0900 Subject: [PATCH 06/13] Another try --- tests/Integration/Endpoints/RestMetadataTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Integration/Endpoints/RestMetadataTest.php b/tests/Integration/Endpoints/RestMetadataTest.php index 8f22ef288..139bdd7d6 100644 --- a/tests/Integration/Endpoints/RestMetadataTest.php +++ b/tests/Integration/Endpoints/RestMetadataTest.php @@ -404,7 +404,7 @@ public function test_get_rendered_meta_json_ld(): void { $this->go_to( (string) $this->get_permalink( $post_id ) ); $meta_string = self::$rest->get_rendered_meta( 'json_ld' ); - $expected = ''; + $expected = ''; self::assertSame( $expected, $meta_string ); } From a290e9c1025cb1c7a4449a0a00883e14f46bb75b Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Wed, 5 Jun 2024 10:39:02 +0900 Subject: [PATCH 07/13] More of that --- tests/Integration/Endpoints/RestMetadataTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Integration/Endpoints/RestMetadataTest.php b/tests/Integration/Endpoints/RestMetadataTest.php index 139bdd7d6..1ac51b86f 100644 --- a/tests/Integration/Endpoints/RestMetadataTest.php +++ b/tests/Integration/Endpoints/RestMetadataTest.php @@ -404,7 +404,7 @@ public function test_get_rendered_meta_json_ld(): void { $this->go_to( (string) $this->get_permalink( $post_id ) ); $meta_string = self::$rest->get_rendered_meta( 'json_ld' ); - $expected = ''; + $expected = ''; self::assertSame( $expected, $meta_string ); } From ded5974d312fa6d14dc3243d914dfe1ca0a0eb2e Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Wed, 5 Jun 2024 10:40:15 +0900 Subject: [PATCH 08/13] AI correction --- tests/Integration/Endpoints/RestMetadataTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Integration/Endpoints/RestMetadataTest.php b/tests/Integration/Endpoints/RestMetadataTest.php index 1ac51b86f..efa4e4495 100644 --- a/tests/Integration/Endpoints/RestMetadataTest.php +++ b/tests/Integration/Endpoints/RestMetadataTest.php @@ -404,7 +404,7 @@ public function test_get_rendered_meta_json_ld(): void { $this->go_to( (string) $this->get_permalink( $post_id ) ); $meta_string = self::$rest->get_rendered_meta( 'json_ld' ); - $expected = ''; + $expected = ''; self::assertSame( $expected, $meta_string ); } From fb81fcf286649fe6aa0bf02227daf2945896613f Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Wed, 5 Jun 2024 10:42:17 +0900 Subject: [PATCH 09/13] Simplify --- tests/Integration/Endpoints/RestMetadataTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Integration/Endpoints/RestMetadataTest.php b/tests/Integration/Endpoints/RestMetadataTest.php index efa4e4495..2cb47dbf5 100644 --- a/tests/Integration/Endpoints/RestMetadataTest.php +++ b/tests/Integration/Endpoints/RestMetadataTest.php @@ -404,7 +404,7 @@ public function test_get_rendered_meta_json_ld(): void { $this->go_to( (string) $this->get_permalink( $post_id ) ); $meta_string = self::$rest->get_rendered_meta( 'json_ld' ); - $expected = ''; + $expected = ''; self::assertSame( $expected, $meta_string ); } From 3f3760d624974606489188ae67e5ac31ea7d46d1 Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Wed, 5 Jun 2024 10:45:28 +0900 Subject: [PATCH 10/13] missing part --- tests/Integration/Endpoints/RestMetadataTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/Integration/Endpoints/RestMetadataTest.php b/tests/Integration/Endpoints/RestMetadataTest.php index 2cb47dbf5..90af9d439 100644 --- a/tests/Integration/Endpoints/RestMetadataTest.php +++ b/tests/Integration/Endpoints/RestMetadataTest.php @@ -404,7 +404,8 @@ public function test_get_rendered_meta_json_ld(): void { $this->go_to( (string) $this->get_permalink( $post_id ) ); $meta_string = self::$rest->get_rendered_meta( 'json_ld' ); - $expected = ''; + $expected = '' . + ''; self::assertSame( $expected, $meta_string ); } From f38a201478844b57f53ffdafa89d47a1445781a6 Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Wed, 5 Jun 2024 10:52:07 +0900 Subject: [PATCH 11/13] Fix it? --- tests/Integration/Endpoints/RestMetadataTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Integration/Endpoints/RestMetadataTest.php b/tests/Integration/Endpoints/RestMetadataTest.php index 90af9d439..9e4653bdd 100644 --- a/tests/Integration/Endpoints/RestMetadataTest.php +++ b/tests/Integration/Endpoints/RestMetadataTest.php @@ -404,7 +404,7 @@ public function test_get_rendered_meta_json_ld(): void { $this->go_to( (string) $this->get_permalink( $post_id ) ); $meta_string = self::$rest->get_rendered_meta( 'json_ld' ); - $expected = '' . + $expected = '' . ''; self::assertSame( $expected, $meta_string ); } From 9806e347111aa179fe9f483928b51b823484d7c4 Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Thu, 6 Jun 2024 10:25:19 +0900 Subject: [PATCH 12/13] s:postID:wpParselyPostID:g --- src/Metadata/class-metadata-builder.php | 2 +- tests/Integration/Endpoints/RestMetadataTest.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Metadata/class-metadata-builder.php b/src/Metadata/class-metadata-builder.php index 608e70a74..2f00ccaa7 100644 --- a/src/Metadata/class-metadata-builder.php +++ b/src/Metadata/class-metadata-builder.php @@ -130,7 +130,7 @@ protected function build_type( WP_Post $post, string $parsely_type ): void { protected function build_post_id( WP_Post $post ): void { $this->metadata['custom_metadata'] = wp_json_encode( array( - 'postID' => $post->ID, + 'wpParselyPostID' => $post->ID, ) ); } diff --git a/tests/Integration/Endpoints/RestMetadataTest.php b/tests/Integration/Endpoints/RestMetadataTest.php index 9e4653bdd..d623981b5 100644 --- a/tests/Integration/Endpoints/RestMetadataTest.php +++ b/tests/Integration/Endpoints/RestMetadataTest.php @@ -404,8 +404,8 @@ public function test_get_rendered_meta_json_ld(): void { $this->go_to( (string) $this->get_permalink( $post_id ) ); $meta_string = self::$rest->get_rendered_meta( 'json_ld' ); - $expected = '' . - ''; + $expected = '' . + ''; self::assertSame( $expected, $meta_string ); } @@ -474,7 +474,7 @@ public function test_get_rendered_repeated_metas(): void { -'; +'; self::assertSame( $expected, $meta_string ); } From 0ae8fcbf81c88f030f034563d8365e73d35574f6 Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Thu, 6 Jun 2024 10:27:09 +0900 Subject: [PATCH 13/13] Update src/Metadata/class-metadata-builder.php Co-authored-by: Alex Cicovic <23142906+acicovic@users.noreply.github.com> --- src/Metadata/class-metadata-builder.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Metadata/class-metadata-builder.php b/src/Metadata/class-metadata-builder.php index 2f00ccaa7..f19d785da 100644 --- a/src/Metadata/class-metadata-builder.php +++ b/src/Metadata/class-metadata-builder.php @@ -121,11 +121,11 @@ protected function build_type( WP_Post $post, string $parsely_type ): void { } /** - * Populates all the fields related to post ID. + * Populates the custom metadata field with the current post's/page's ID. * - * @param WP_Post $post The post/page for which to populate the field. + * @since 3.16.0 * - * @since 3.0.x + * @param WP_Post $post The post/page for which to populate the field. */ protected function build_post_id( WP_Post $post ): void { $this->metadata['custom_metadata'] = wp_json_encode(