-
Notifications
You must be signed in to change notification settings - Fork 33
Allow full metadata in homepages #3571
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
Conversation
📝 WalkthroughWalkthroughFront_Page_Builder now accepts a WP_Post via a new constructor and stores it; get_metadata() conditionally builds full post-related metadata (type, main entity, images, section, author, publisher, keywords, post times) when the full_metadata_in_non_posts option is enabled, and callers now pass the current post when instantiating front-page builders. Changes
Sequence Diagram(s)sequenceDiagram
participant Caller as construct_metadata()
participant Front as Front_Page_Builder
Note over Caller,Front: instantiate Front_Page_Builder(parsely, post)
Caller->>Front: get_metadata()
Front->>Front: build_basic(), build_url(), build_headline()
alt full_metadata_in_non_posts == true
Front->>Front: build_type(post_type)
Front->>Front: build_main_entity(post)
Front->>Front: build_thumbnail_url(post)
Front->>Front: build_image(post)
Front->>Front: build_article_section(post)
Front->>Front: build_author(post)
Front->>Front: build_publisher()
Front->>Front: build_keywords(post)
Front->>Front: build_metadata_post_times(post)
end
Front-->>Caller: metadata array
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Assessment against linked issues
Out-of-scope changes
Suggested reviewers
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 PHPStan (2.1.17)Invalid configuration: ✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/Metadata/class-front-page-builder.php (1)
27-27: Update the version number in the documentation.The comment indicates this needs to be updated for the actual release version instead of the placeholder "3.20.7".
- * @since 3.20.7 - this needs to be updated as per version in which this will be released. + * @since 3.21.0
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/Metadata/class-front-page-builder.php(2 hunks)src/class-metadata.php(1 hunks)tests/Integration/Metadata/GetCurrentUrlTest.php(3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{html,php}
⚙️ CodeRabbit Configuration File
**/*.{html,php}: "Perform a detailed review of the provided code with following key aspects in mind:
- Review the HTML and PHP code to ensure it is well-structured and adheres to best practices.
- Ensure the code follows WordPress coding standards and is well-documented.
- Confirm the code is secure and free from vulnerabilities.
- Optimize the code for performance, removing any unnecessary elements.
- Validate comments for accuracy, currency, and adherence to WordPress coding standards.
- Ensure each line comment concludes with a period.
- Verify code compatibility with the latest version of WordPress, avoiding deprecated functions or features."
Files:
src/class-metadata.phptests/Integration/Metadata/GetCurrentUrlTest.phpsrc/Metadata/class-front-page-builder.php
🧬 Code Graph Analysis (3)
src/class-metadata.php (2)
src/Metadata/class-front-page-builder.php (1)
Front_Page_Builder(22-89)src/Utils/class-utils.php (2)
Utils(35-501)get_page_on_front(98-105)
tests/Integration/Metadata/GetCurrentUrlTest.php (2)
src/Metadata/class-front-page-builder.php (1)
Front_Page_Builder(22-89)tests/Integration/TestCase.php (1)
get_post(249-264)
src/Metadata/class-front-page-builder.php (2)
src/class-parsely.php (2)
Parsely(75-1192)get_options(550-610)src/Metadata/class-metadata-builder.php (10)
Metadata_Builder(29-690)build_type(91-120)build_main_entity(131-136)build_thumbnail_url(263-269)build_image(279-288)build_article_section(210-212)build_author(146-158)build_publisher(166-172)build_keywords(222-253)build_metadata_post_times(183-200)
🔇 Additional comments (10)
src/class-metadata.php (3)
94-94: LGTM: Constructor updated correctly for non-paged front page.The addition of the
$postparameter aligns with the updatedFront_Page_Builderconstructor signature and enables richer metadata generation for static front pages.
96-96: LGTM: Constructor updated correctly for paginated front page.The
Paginated_Front_Page_Builderconstructor call is correctly updated to include the$postparameter, maintaining consistency with the parent class changes.
99-99: LGTM: Constructor updated correctly for static page as front page.This change ensures that when a static page is set as the front page but no specific page is assigned, the metadata builder receives the post context needed for enhanced metadata generation.
tests/Integration/Metadata/GetCurrentUrlTest.php (3)
135-135: LGTM: Test constructor updated correctly for homepage URL testing.The addition of
$this->get_post( 0 )parameter correctly adapts the test to the updatedFront_Page_Builderconstructor while maintaining the test's focus on URL generation functionality.
152-152: LGTM: Test constructor updated correctly for specific post URL testing.The use of
$this->get_post( $post_id )appropriately provides the post context needed by the updated constructor while preserving the test's URL validation logic.
169-169: LGTM: Test constructor updated correctly for random URL testing.The addition of
$this->get_post( 0 )maintains consistency with other test methods and properly adapts to the new constructor signature.src/Metadata/class-front-page-builder.php (4)
13-14: LGTM: Clean import statements added.The use statements for
ParselyandWP_Postare properly added to support the enhanced functionality.
24-31: LGTM: Well-documented post property added.The private
$postproperty is properly typed withWP_Postand includes appropriate documentation following WordPress coding standards.
33-42: LGTM: Constructor properly implemented.The constructor correctly accepts both required parameters, calls the parent constructor, and stores the post object. The documentation follows WordPress standards with proper
@paramtags.
57-67: LGTM: Enhanced metadata generation addresses the PR objective.The conditional metadata building when
full_metadata_in_non_postsis enabled correctly uses the stored post object to generate rich metadata fields. This directly addresses the issue of missing metadata from static pages set as homepage by providing author, publication dates, and other important fields that were previously missing.The implementation properly leverages existing
build_*methods from the parentMetadata_Builderclass and maintains consistency with the plugin's architecture.
acicovic
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi and thank you for your work, we appreciate every contribution that makes the product better.
I've allowed the workflows to run, and some of our tests are failing. These should be fixed before we can merge this. I've also left a commit suggestion, since if this is ready we can ship it in v3.21.
|
Thanks for the review, @acicovic. I will look into the test case issue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/Metadata/class-front-page-builder.php (1)
24-32: Normalize @SInCE version; consider property typing (if PHP ≥ 7.4).
- Use full semantic version to match project style (e.g., 3.4.0 elsewhere).
- Optional: add a typed property if plugin’s minimum PHP is 7.4+.
Apply:
- * @since 3.21 + * @since 3.21.0If PHP ≥ 7.4:
- private $post; + private WP_Post $post;
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
src/Metadata/class-front-page-builder.php(2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{html,php}
⚙️ CodeRabbit configuration file
**/*.{html,php}: "Perform a detailed review of the provided code with following key aspects in mind:
- Review the HTML and PHP code to ensure it is well-structured and adheres to best practices.
- Ensure the code follows WordPress coding standards and is well-documented.
- Confirm the code is secure and free from vulnerabilities.
- Optimize the code for performance, removing any unnecessary elements.
- Validate comments for accuracy, currency, and adherence to WordPress coding standards.
- Ensure each line comment concludes with a period.
- Verify code compatibility with the latest version of WordPress, avoiding deprecated functions or features."
Files:
src/Metadata/class-front-page-builder.php
🧬 Code graph analysis (1)
src/Metadata/class-front-page-builder.php (3)
src/class-parsely.php (2)
Parsely(75-1192)get_options(550-610)src/Metadata/class-metadata-builder.php (9)
build_type(91-120)build_main_entity(131-136)build_thumbnail_url(263-269)build_image(279-288)build_article_section(210-212)build_author(146-158)build_publisher(166-172)build_keywords(222-253)build_metadata_post_times(183-200)src/class-metadata.php (1)
__construct(78-80)
🔇 Additional comments (2)
src/Metadata/class-front-page-builder.php (2)
13-15: LGTM: imports are correct and scoped.
Parsely\ParselyandWP_Postare properly imported and used.
57-67: Ensure mainEntityOfPage '@id' resolves to the home URL for static front pages.
Passing$this->post->post_typetobuild_main_entity()may set@idto the page permalink (e.g.,/sample-page/) instead of the canonical home (/). AlignmainEntityOfPage.@idwithurlto avoid duplicate/incorrect attribution.Option A (if
get_current_url('front')returnshome_url()):- $this->build_main_entity( $this->post->post_type ); + $this->build_main_entity( 'front' );Option B (force alignment after building):
$this->build_thumbnail_url( $this->post ); $this->build_image( $this->post ); $this->build_article_section( $this->post ); $this->build_author( $this->post ); $this->build_publisher(); $this->build_keywords( $this->post ); $this->build_metadata_post_times( $this->post ); + $this->metadata['mainEntityOfPage']['@id'] = home_url();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
tests/Integration/TestCase.php (3)
263-274: Prefer factory->post->create_and_get() and drop unreachable WP_Error check.Simplifies the fallback and avoids an extra get_post() call. The factory create() doesn’t return WP_Error for posts.
- if ( ! $post_obj instanceof WP_Post ) { - // Need to return post object, so if it's not WP_Post then create one. - $new_post_id = self::factory()->post->create(); - if ( is_wp_error( $new_post_id ) ) { - throw new UnexpectedValueException( 'Failed to create a new post.' ); - } - $post_obj = get_post( $new_post_id ); - if ( ! $post_obj instanceof WP_Post ) { - throw new UnexpectedValueException( 'Failed to get the newly created post.' ); - } - } + if ( ! $post_obj instanceof WP_Post ) { + // Ensure a WP_Post is returned in tests; create one when absent. + $post_obj = self::factory()->post->create_and_get(); + if ( ! $post_obj instanceof WP_Post ) { + throw new UnexpectedValueException( 'Failed to create and retrieve a WP_Post.' ); + } + }
263-274: Docblock should include null in $post_id type.Method accepts null (Line 249) but the @param omits it. Add |null to reflect reality.
/** * @param int|WP_Error|null $post_id Optional. Defaults to global $post. */
263-274: Explicitly create posts in tests instead of relying on fallback.Fallback in
get_post()silently creates a new post when none is provided, which can mask misconfigured test inputs. Update these call sites to use an explicit factory call:
- tests/Integration/Metadata/TermArchiveTest.php:64 – replace
$this->get_post()with$post_id = self::factory()->post->create(); $post_obj = get_post( $post_id );- tests/Integration/Metadata/CustomPostTypeArchiveTest.php:81 – same replacement
- tests/Integration/Metadata/AuthorArchiveTest.php:67 – same replacement
- tests/Integration/Metadata/GetCurrentUrlTest.php:135,169 – replace
$this->get_post( 0 )with an explicit post creation and use that ID
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
tests/Integration/TestCase.php(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{html,php}
⚙️ CodeRabbit configuration file
**/*.{html,php}: "Perform a detailed review of the provided code with following key aspects in mind:
- Review the HTML and PHP code to ensure it is well-structured and adheres to best practices.
- Ensure the code follows WordPress coding standards and is well-documented.
- Confirm the code is secure and free from vulnerabilities.
- Optimize the code for performance, removing any unnecessary elements.
- Validate comments for accuracy, currency, and adherence to WordPress coding standards.
- Ensure each line comment concludes with a period.
- Verify code compatibility with the latest version of WordPress, avoiding deprecated functions or features."
Files:
tests/Integration/TestCase.php
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
tests/Integration/Metadata/GetCurrentUrlTest.php (3)
133-137: Add period to end of inline comment (WP coding standards).Ensure each line comment ends with a period.
- // Using Category_Builder since we can't instantiate abstract + // Using Category_Builder since we can't instantiate abstract.
150-155: Fail fast: assert WP_Post before constructing Front_Page_Builder.Improves test clarity if post creation ever fails.
- $builder = new Front_Page_Builder( new Parsely(), $this->get_post( $post_id ) ); + $post = $this->get_post( $post_id ); + self::assertInstanceOf( \WP_Post::class, $post ); + $builder = new Front_Page_Builder( new Parsely(), $post );
167-171: Add period to end of inline comment (WP coding standards).Same nit as above.
- // Using Category_Builder since we can't instantiate abstract + // Using Category_Builder since we can't instantiate abstract.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
tests/Integration/Metadata/GetCurrentUrlTest.php(4 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{html,php}
⚙️ CodeRabbit configuration file
**/*.{html,php}: "Perform a detailed review of the provided code with following key aspects in mind:
- Review the HTML and PHP code to ensure it is well-structured and adheres to best practices.
- Ensure the code follows WordPress coding standards and is well-documented.
- Confirm the code is secure and free from vulnerabilities.
- Optimize the code for performance, removing any unnecessary elements.
- Validate comments for accuracy, currency, and adherence to WordPress coding standards.
- Ensure each line comment concludes with a period.
- Verify code compatibility with the latest version of WordPress, avoiding deprecated functions or features."
Files:
tests/Integration/Metadata/GetCurrentUrlTest.php
🧬 Code graph analysis (1)
tests/Integration/Metadata/GetCurrentUrlTest.php (5)
src/class-metadata.php (1)
Metadata(65-144)src/Metadata/class-front-page-builder.php (1)
Front_Page_Builder(22-89)src/Metadata/class-metadata-builder.php (1)
get_current_url(321-349)tests/Traits/TestsReflection.php (1)
get_method(27-32)tests/Integration/TestCase.php (1)
get_post(249-264)
🔇 Additional comments (1)
tests/Integration/Metadata/GetCurrentUrlTest.php (1)
12-12: LGTM: imports updated to reflect builder usage.The grouped use statement correctly brings in Category_Builder and Front_Page_Builder used below.
acicovic
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few comments. By the way, our E2E tests are currently failing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
tests/Integration/Metadata/GetCurrentUrlTest.php (3)
133-137: Fix inline comment style; end with a period and avoid broken sentence.Unify the two-line comment into one sentence and terminate with a period to match project/WP standards.
- // Using Category_Builder since we can't instantiate abstract - // Metadata_Builder. + // Using Category_Builder since we can't instantiate the abstract Metadata_Builder.
150-154: Apply the same comment cleanup here.Keep the comment to a single, punctuated line.
- // Using Category_Builder since we can't instantiate abstract - // Metadata_Builder. + // Using Category_Builder since we can't instantiate the abstract Metadata_Builder.
167-171: Repeat the comment style fix for consistency.- // Using Category_Builder since we can't instantiate abstract - // Metadata_Builder. + // Using Category_Builder since we can't instantiate the abstract Metadata_Builder.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
src/Metadata/class-front-page-builder.php(2 hunks)tests/Integration/Metadata/GetCurrentUrlTest.php(4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- src/Metadata/class-front-page-builder.php
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{html,php}
⚙️ CodeRabbit configuration file
**/*.{html,php}: "Perform a detailed review of the provided code with following key aspects in mind:
- Review the HTML and PHP code to ensure it is well-structured and adheres to best practices.
- Ensure the code follows WordPress coding standards and is well-documented.
- Confirm the code is secure and free from vulnerabilities.
- Optimize the code for performance, removing any unnecessary elements.
- Validate comments for accuracy, currency, and adherence to WordPress coding standards.
- Ensure each line comment concludes with a period.
- Verify code compatibility with the latest version of WordPress, avoiding deprecated functions or features."
Files:
tests/Integration/Metadata/GetCurrentUrlTest.php
🧬 Code graph analysis (1)
tests/Integration/Metadata/GetCurrentUrlTest.php (3)
src/class-metadata.php (1)
Metadata(65-144)src/Metadata/class-metadata-builder.php (1)
get_current_url(321-349)tests/Traits/TestsReflection.php (1)
get_method(27-32)
🔇 Additional comments (1)
tests/Integration/Metadata/GetCurrentUrlTest.php (1)
12-12: Switch to Category_Builder in tests looks good.Using Category_Builder to exercise Metadata_Builder::get_current_url via inheritance is appropriate and aligns with the broader refactor away from Front_Page_Builder imports.
Hey @acicovic, are there different configurations needed to run the e2e tests? I ran |
|
Hi @up1512001, I don't know why you're getting this. ICYMI, we have some instructions about E2E tests here. Different configuration isn't needed, and I'd try running Let me know if the issue persists. In this case, we'll find another solution. |
|
Hey @up1512001, just wanted to let you know that we're pivoting to releasing a fix release early next week with whatever fixes we've got available, and I'll be happy to include this given we manage to push it forward. |
|
Thanks @acicovic, I just pushed the fix for the e2e test case. Let's see if that works or not. By the way, for me, |
|
I see that you pushed a commit. I've allowed the workflows, and I'll be taking a look into it tomorrow. |
Strange. Are you using your own custom devenv, or have you followed the contributing instructions? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
♻️ Duplicate comments (1)
src/Metadata/class-front-page-builder.php (1)
23-31: Docblock tweaks: version format and stray blank line.Use 3-part version to match existing @SInCE usage and remove the blank line flagged previously.
Apply:
/** * Post object to generate the metadata for. * - * @since 3.21 - * + * @since 3.21.0 * @var WP_Post */ private $post;
🧹 Nitpick comments (5)
tests/e2e/specs/front-end-metadata.spec.ts (4)
56-62: Parse JSON-LD instead of brittle string contains.Use DOM selection + JSON parse to assert structure; this is more robust across host/port/scheme changes.
Apply:
- expect( content ).toContain( '<script type="application/ld+json" class="wp-parsely-metadata">' ); - expect( content ).toContain( '"@context":"https:\\/\\/schema.org"' ); - expect( content ).toContain( '"@type":"WebPage"' ); - expect( content ).toContain( '"headline":"wp-parsely"' ); - expect( content ).toContain( '"url":"http:\\/\\/localhost:8889"' ); - expect( content ).not.toContain( '<meta name="parsely-title"' ); + const json = await page.locator( 'script.wp-parsely-metadata' ).textContent(); + expect( json ).not.toBeNull(); + const data = JSON.parse( json! ); + expect( data['@context'] ).toBe( 'https://schema.org' ); + expect( data['@type'] ).toBe( 'WebPage' ); + expect( data.headline ).toBe( 'wp-parsely' ); + expect( new URL( data.url ).origin ).toBe( new URL( page.url() ).origin ); + expect( content ).not.toContain( '<meta name="parsely-title"' );
111-114: Tighten ISO8601 assertion for pub-date.Anchor to strict Zulu timestamp to avoid accidental matches.
Apply:
- expect( content ).toMatch( /<meta name="parsely-pub-date" content=".*Z">/ ); + expect( content ).toMatch( /<meta name="parsely-pub-date" content="\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z">/ );
190-194: Use visitAdminPage params instead of embedding query into path.Improves readability and consistency with @wordpress/e2e-test-utils-playwright conventions.
Apply:
- await this.admin.visitAdminPage( '/admin.php?page=parsely-settings&e2e_parsely_skip_api_validate=y' ); + await this.admin.visitAdminPage( 'admin.php', 'page=parsely-settings&e2e_parsely_skip_api_validate=y' );
38-41: Centralize settings-page URL with skip flag
Multiple e2e specs (front-end-metadata.spec.ts, plugin-action-link.spec.ts, browse-logo-button.spec.ts, activation-flow.spec.ts, settings-track-post-types-as.spec.ts) hardcode the/wp-admin/admin.php?page=parsely-settingsURL and the&e2e_parsely_skip_api_validate=yflag. Extract a sharedSETTINGS_URLconstant (for example, intests/e2e/utils.ts) and import it in each spec for bothpage.goto(…)andadmin.visitAdminPage(…)calls to ensure consistency and DRYness.src/Metadata/class-front-page-builder.php (1)
32-41: Add @SInCE tag to constructor docblock.Keeps API docs consistent.
Apply:
/** * Constructor. * + * @since 3.21.0 + * * @param Parsely $parsely Instance of Parsely class. * @param WP_Post $post Post object to generate the metadata for. */
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
src/Metadata/class-front-page-builder.php(2 hunks)tests/e2e/specs/front-end-metadata.spec.ts(4 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{js,ts,tsx,jsx}
⚙️ CodeRabbit configuration file
**/*.{js,ts,tsx,jsx}: "Perform a detailed review of the provided code with following key aspects in mind:
- Review the code to ensure it is well-structured and adheres to best practices.
- Verify compliance with WordPress coding standards.
- Ensure the code is well-documented.
- Check for security vulnerabilities and confirm the code is secure.
- Optimize the code for performance, removing any unnecessary elements.
- Validate JSDoc comments for accuracy, currency, and adherence to WordPress coding standards.
- Ensure each line comment concludes with a period.
- Confirm every JSDoc comment includes a @SInCE tag indicating the next version of the plugin to include the code.
- Guarantee compatibility with the latest version of WordPress, avoiding deprecated functions or features."
Files:
tests/e2e/specs/front-end-metadata.spec.ts
**/*.{html,php}
⚙️ CodeRabbit configuration file
**/*.{html,php}: "Perform a detailed review of the provided code with following key aspects in mind:
- Review the HTML and PHP code to ensure it is well-structured and adheres to best practices.
- Ensure the code follows WordPress coding standards and is well-documented.
- Confirm the code is secure and free from vulnerabilities.
- Optimize the code for performance, removing any unnecessary elements.
- Validate comments for accuracy, currency, and adherence to WordPress coding standards.
- Ensure each line comment concludes with a period.
- Verify code compatibility with the latest version of WordPress, avoiding deprecated functions or features."
Files:
src/Metadata/class-front-page-builder.php
🧬 Code graph analysis (1)
src/Metadata/class-front-page-builder.php (2)
src/class-parsely.php (2)
Parsely(75-1192)get_options(550-610)src/Metadata/class-metadata-builder.php (10)
Metadata_Builder(29-690)build_type(91-120)build_main_entity(131-136)build_thumbnail_url(263-269)build_image(279-288)build_article_section(210-212)build_author(146-158)build_publisher(166-172)build_keywords(222-253)build_metadata_post_times(183-200)
🔇 Additional comments (3)
src/Metadata/class-front-page-builder.php (3)
13-15: Imports look correct and scoped.
54-55: Reordering to build URL before headline is fine.
56-66: Consider passing explicit'non-post'for non-post metadata
Replace$this->post->post_typewith the literal'non-post'whenfull_metadata_in_non_postsis enabled:- if ( true === $this->parsely->get_options()['full_metadata_in_non_posts'] ) { - $this->build_type( $this->post, $this->post->post_type ); - $this->build_main_entity( $this->post->post_type ); + if ( true === $this->parsely->get_options()['full_metadata_in_non_posts'] ) { + $this->build_type( $this->post, 'non-post' ); + $this->build_main_entity( 'non-post' );
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
♻️ Duplicate comments (1)
tests/e2e/specs/front-end-metadata.spec.ts (1)
190-190: Remove the e2e_parsely_skip_api_validate flag; tests should pass without it.This bypass reduces fidelity and was already flagged in review.
- await this.admin.visitAdminPage( '/admin.php?page=parsely-settings&e2e_parsely_skip_api_validate=y' ); + await this.admin.visitAdminPage( '/admin.php?page=parsely-settings' );Run to confirm no stray uses:
#!/bin/bash rg -n "e2e_parsely_skip_api_validate"
🧹 Nitpick comments (2)
tests/e2e/specs/front-end-metadata.spec.ts (2)
56-61: Make homepage JSON-LD assertions resilient (parse DOM JSON instead of substring).String contains checks are brittle (escaping/order). Parse the script content and assert structure with locators.
- expect( content ).toContain( '<script type="application/ld+json" class="wp-parsely-metadata">' ); - expect( content ).toContain( '"@context":"https:\\/\\/schema.org"' ); - expect( content ).toContain( '"@type":"WebPage"' ); - expect( content ).toContain( '"headline":"wp-parsely"' ); - expect( content ).toContain( '"url":"http:\\/\\/localhost:8889"' ); - expect( content ).not.toContain( '<meta name="parsely-title"' ); + await expect( page.locator( 'script.wp-parsely-metadata' ) ).toHaveCount( 1 ); + const raw = await page.locator( 'script.wp-parsely-metadata' ).first().textContent(); + const data = JSON.parse( String( raw ) ); + const nodes = Array.isArray( data ) ? data : [ data ]; + const webPage = nodes.find( ( n ) => n['@type'] === 'WebPage' ) || nodes[0]; + expect( webPage['@context'] ).toBe( 'https://schema.org' ); + expect( webPage['@type'] ).toBe( 'WebPage' ); + expect( webPage.headline ).toBeTruthy(); + expect( webPage.url ).toMatch( /^http:\/\/localhost:8889/ ); + expect( content ).not.toContain( '<meta name="parsely-title"' );
111-113: Reduce flakiness in homepage metas (assert existence, not env-specific values).Values like “Uncategorized” and “admin” vary by locale/fixtures; assert presence and basic format instead.
- expect( content ).toMatch( /<meta name="parsely-pub-date" content=".*Z">/ ); - expect( content ).toContain( '<meta name="parsely-section" content="Uncategorized">' ); - expect( content ).toContain( '<meta name="parsely-author" content="admin">' ); + await expect( page.locator( 'meta[name="parsely-pub-date"]' ) ).toHaveCount( 1 ); + const pubDate = await page.locator( 'meta[name="parsely-pub-date"]' ).first().getAttribute( 'content' ); + expect( pubDate ).toMatch( /Z$/ ); + await expect( page.locator( 'meta[name="parsely-section"]' ) ).toHaveCount( 1 ); + await expect( page.locator( 'meta[name="parsely-author"]' ) ).toHaveCount( 1 );
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
src/Metadata/class-front-page-builder.php(2 hunks)tests/e2e/specs/front-end-metadata.spec.ts(3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- src/Metadata/class-front-page-builder.php
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{js,ts,tsx,jsx}
⚙️ CodeRabbit configuration file
**/*.{js,ts,tsx,jsx}: "Perform a detailed review of the provided code with following key aspects in mind:
- Review the code to ensure it is well-structured and adheres to best practices.
- Verify compliance with WordPress coding standards.
- Ensure the code is well-documented.
- Check for security vulnerabilities and confirm the code is secure.
- Optimize the code for performance, removing any unnecessary elements.
- Validate JSDoc comments for accuracy, currency, and adherence to WordPress coding standards.
- Ensure each line comment concludes with a period.
- Confirm every JSDoc comment includes a @SInCE tag indicating the next version of the plugin to include the code.
- Guarantee compatibility with the latest version of WordPress, avoiding deprecated functions or features."
Files:
tests/e2e/specs/front-end-metadata.spec.ts
acicovic
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@acicovic for now in Front_Page_Builder I am passing this to make sure it will always have WebPage, let me know if there's better approach.
I'd most probably just remove the call to build_type(). Notice that most builder classes do not call build_type(), because they call build_basic() which auto-assigns the WebPage type. This should be what we want in our case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
♻️ Duplicate comments (1)
src/Metadata/class-front-page-builder.php (1)
23-31: Type the property and normalize the DocBlock.Add a typed property for stronger contracts and align the
@sinceformat; also remove the extra blank line between tags.Apply:
/** * Post object to generate the metadata for. * - * @since 3.21 - * - * @var WP_Post + * @since 3.21.0 + * @var WP_Post */ - private $post; + private WP_Post $post;
🧹 Nitpick comments (1)
src/Metadata/class-front-page-builder.php (1)
84-86: Optional: canonical trailing slash.If the rest of the codebase expects a trailing slash on homepage URLs, consider
home_url( '/' )for consistency.- $this->metadata['url'] = home_url(); + $this->metadata['url'] = home_url( '/' );
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
src/Metadata/class-front-page-builder.php(2 hunks)tests/e2e/specs/front-end-metadata.spec.ts(2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- tests/e2e/specs/front-end-metadata.spec.ts
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{html,php}
⚙️ CodeRabbit configuration file
**/*.{html,php}: "Perform a detailed review of the provided code with following key aspects in mind:
- Review the HTML and PHP code to ensure it is well-structured and adheres to best practices.
- Ensure the code follows WordPress coding standards and is well-documented.
- Confirm the code is secure and free from vulnerabilities.
- Optimize the code for performance, removing any unnecessary elements.
- Validate comments for accuracy, currency, and adherence to WordPress coding standards.
- Ensure each line comment concludes with a period.
- Verify code compatibility with the latest version of WordPress, avoiding deprecated functions or features."
Files:
src/Metadata/class-front-page-builder.php
🔇 Additional comments (3)
src/Metadata/class-front-page-builder.php (3)
13-15: Imports and strict types look good.
use Parsely\Parsely;anduse WP_Post;are correct within theParsely\Metadatanamespace.
54-55: Reordering is fine.Calling
build_url()beforebuild_headline()is harmless and keeps behavior intact.
56-65: Drop undefined-index and strict-bool concerns—get_options()always returns a booleanfull_metadata_in_non_posts; caching$optionsis optional. Verifybuild_main_entity()leaves the homepage@typeasWebPage/indexand thatbuild_keywords()/build_author()handle non-post types without notices.
|
Hey @up1512001, FYI I'll be taking a last look and approving this on Monday. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
♻️ Duplicate comments (1)
src/Metadata/class-front-page-builder.php (1)
23-31: Align @SInCE version and property nullability.DocBlocks say @SInCE 3.20.7, but PR discussion mentions the next release. Please confirm and update to the correct target version for both the property and constructor to avoid future churn. If you later decide to make
$postoptional for BC, update@vartoWP_Post|null.Suggested diff (if release is 3.21.0):
- * @since 3.20.7 + * @since 3.21.0
🧹 Nitpick comments (1)
src/Metadata/class-front-page-builder.php (1)
32-43: Document BC break and consider optional$postfallback. Only two internal instantiations were found (src/class-metadata.php lines 94, 99), so internal usage is safe. Add a note in the changelog about making$posta required constructor parameter. Optionally, for smoother third-party migrations, revert to?WP_Post $post = nullwith a fallback to the queried object or front page post.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/Metadata/class-front-page-builder.php(2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{html,php}
⚙️ CodeRabbit configuration file
**/*.{html,php}: "Perform a detailed review of the provided code with following key aspects in mind:
- Review the HTML and PHP code to ensure it is well-structured and adheres to best practices.
- Ensure the code follows WordPress coding standards and is well-documented.
- Confirm the code is secure and free from vulnerabilities.
- Optimize the code for performance, removing any unnecessary elements.
- Validate comments for accuracy, currency, and adherence to WordPress coding standards.
- Ensure each line comment concludes with a period.
- Verify code compatibility with the latest version of WordPress, avoiding deprecated functions or features."
Files:
src/Metadata/class-front-page-builder.php
🧬 Code graph analysis (1)
src/Metadata/class-front-page-builder.php (3)
src/class-parsely.php (2)
Parsely(75-1192)get_options(550-610)src/Metadata/class-metadata-builder.php (9)
Metadata_Builder(29-690)build_main_entity(131-136)build_thumbnail_url(263-269)build_image(279-288)build_article_section(210-212)build_author(146-158)build_publisher(166-172)build_keywords(222-253)build_metadata_post_times(183-200)src/class-metadata.php (1)
__construct(78-80)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: E2E against WordPress latest
🔇 Additional comments (1)
src/Metadata/class-front-page-builder.php (1)
13-15: LGTM on namespace imports.Using fully qualified imports for Parsely and WP_Post is correct and improves clarity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
♻️ Duplicate comments (4)
src/Metadata/class-front-page-builder.php (4)
23-31: Property DocBlock added — good. Please verify @SInCE version.The DocBlock is clear. Confirm that “3.20.7” matches the release this change will ship in.
23-31: Nit: remove the blank line between tags in the property DocBlock.Drop the empty line between @SInCE and @var for consistency with prior feedback.
/** * Post object to generate the metadata for. * * @since 3.20.7 - * * @var WP_Post */
32-43: Constructor signature change — verify external usages and BC.Ensure all instantiations pass the WP_Post argument and that no third-party code constructs this without the new param.
#!/bin/bash # Find all constructor call sites. rg -nP -C2 '\bnew\s+Front_Page_Builder\s*\('
32-43: Nit: tighten constructor DocBlock formatting.Remove the blank line between @SInCE and @param tags.
/** * Constructor. * * @since 3.20.7 - * * @param Parsely $parsely Instance of Parsely class. * @param WP_Post $post Post object to generate the metadata for. */
🧹 Nitpick comments (1)
src/Metadata/class-front-page-builder.php (1)
58-67: Anchor mainEntityOfPage to the canonical homepage URL and avoid empty JSON-LD fields.Using get_current_url('non-post') may diverge from build_url() (trailing slash or query string), leading to url/@id mismatch. Also, emitting empty image fields degrades schema quality.
if ( true === $this->parsely->get_options()['full_metadata_in_non_posts'] ) { - $this->build_main_entity( 'non-post' ); + $this->build_main_entity( 'non-post' ); + // Ensure @id matches the canonical homepage URL used in build_url(). + $this->metadata['mainEntityOfPage']['@id'] = $this->metadata['url']; $this->build_thumbnail_url( $this->post ); $this->build_image( $this->post ); $this->build_article_section( $this->post ); $this->build_author( $this->post ); $this->build_publisher(); $this->build_keywords( $this->post ); $this->build_metadata_post_times( $this->post ); + // Prune empty fields to keep JSON-LD clean. + if ( isset( $this->metadata['thumbnailUrl'] ) && '' === $this->metadata['thumbnailUrl'] ) { + unset( $this->metadata['thumbnailUrl'] ); + } + if ( isset( $this->metadata['image']['url'] ) && '' === $this->metadata['image']['url'] ) { + unset( $this->metadata['image'] ); + } + if ( isset( $this->metadata['articleSection'] ) && '' === $this->metadata['articleSection'] ) { + unset( $this->metadata['articleSection'] ); + } }
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/Metadata/class-front-page-builder.php(2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{html,php}
⚙️ CodeRabbit configuration file
**/*.{html,php}: "Perform a detailed review of the provided code with following key aspects in mind:
- Review the HTML and PHP code to ensure it is well-structured and adheres to best practices.
- Ensure the code follows WordPress coding standards and is well-documented.
- Confirm the code is secure and free from vulnerabilities.
- Optimize the code for performance, removing any unnecessary elements.
- Validate comments for accuracy, currency, and adherence to WordPress coding standards.
- Ensure each line comment concludes with a period.
- Verify code compatibility with the latest version of WordPress, avoiding deprecated functions or features."
Files:
src/Metadata/class-front-page-builder.php
🧬 Code graph analysis (1)
src/Metadata/class-front-page-builder.php (3)
src/class-parsely.php (2)
Parsely(75-1192)get_options(550-610)src/Metadata/class-metadata-builder.php (9)
Metadata_Builder(29-690)build_main_entity(131-136)build_thumbnail_url(263-269)build_image(279-288)build_article_section(210-212)build_author(146-158)build_publisher(166-172)build_keywords(222-253)build_metadata_post_times(183-200)src/class-metadata.php (1)
__construct(78-80)
🔇 Additional comments (2)
src/Metadata/class-front-page-builder.php (2)
13-15: Imports and typing look correct.Namespaces, strict_types, and WP_Post import are appropriate here.
58-67: Confirm homepage “type” remains index/WebPage for both front-page modes.Please re-check that meta parsely-type is index and JSON-LD @type is WebPage for:
- Settings → Reading → “Your latest posts”.
- “A static page”.
acicovic
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for working on this! LGTM! 🙂
At least for me, it turned out to have much more back and forth than I anticipated. Still, I hope that you feel happy with the result and that you don't regret your decision to open this PR.
This will be in the next patch release, scheduled for tomorrow. Feel free to merge this. Else I'll do it at my EOD or early tomorrow.
|
@acicovic Absolutely loved it! I am planning to open another PR over the weekend. Thanks for being helpful throughout the entire process. 🙇
I can not merge as I am not part of Parsely repo 😄 May I know till when this will be reflected in VIP mu-plugins? |
|
OK, I'll merge it now. I'm glad you're motivated and I'm always happy to help with PRs. This should become available in tomorrow's VIP mu-plugins release. |
Closes #3570
Description
When a static page is used as the Homepage, it only outputs 3 meta tags, which causes issues in analytics because the page is listed under the
Staffauthor, which is incorrect and causes confusion.How has this been tested?
Settings -> Readingand changeYour homepage displaystoA static page (select below)and select any of your pages.Screenshots (if appropriate)
Summary by CodeRabbit
New Features
Improvements
Tests