Skip to content
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

Adds fallback to main url when the indexable is not available. #21393

Conversation

thijsoo
Copy link
Contributor

@thijsoo thijsoo commented May 17, 2024

Context

  • We want to fix a bug where we throw a PHP notice when the canonical URL of the parent page wasn't found.

Summary

This PR can be summarized in the following changelog entry:

  • Fixes a bug where a PHP notice would be thrown on RSS feeds when a canonical URL can not be created for its parent page.

Relevant technical choices:

Test instructions

Test instructions for the acceptance test before the PR gets merged

This PR can be acceptance tested by following these steps:

(in all cases, there should be no PHP notices thrown once you load the feeds)

Author case.

  • Make sure you don't have Remove post authors feeds enabled in de crawl optimizations. And make sure you do have author archives enabled.
  • Make sure you have 1 author with a post and an indexable.
  • Create a fresh author without any posts or indexables.
  • Much like the production version: go to http://basic.wordpress.test/author/{authorname}/feed/ where {authorname} is your author with a post. You should see <link>http://basic.wordpress.test/author/{authorname}/</link> In the network tab make sure you see a header in the request for the page with a link to <http://basic.wordpress.test/author/{authorname}/>; rel="canonical"

image

Term case

  • Go to the archive page of a category and add /feed/. Much like the production version: make sure the link points to that category page and the Link header does the same.
  • Remove the indexable for this category (or clean all indexables) and add the following filter:
add_filter( 'wpseo_indexable_excluded_taxonomies', 'exclude_category' );
function exclude_category ( ) {
	return ['category'];
}
  • Refresh and make sure the link now goes to the homepage. Also make sure there is no canonical header.

Post case

  • Go to a page and add at the end of its URL the /feed/. Much like the production version: make sure the link points to that specific page.
  • Remove the indexable for this page (or clean all indexables) and add the following filter:
add_filter( 'wpseo_indexable_excluded_post_types', 'exclude_page' );
function exclude_page( ) {
	return ['page'];
}
  • Refresh and make sure the link now goes to the homepage. Also make sure there is no canonical header.

CPT archive case

  • Go to the archive page of a CPT and add /feed/. Much like the production version: make sure the link points to that specific page. For example http://basic.wordpress.test/yoast-test-movies/feed
  • Remove the indexable for this page (or clean all indexables) and add the following filter:
add_filter( 'wpseo_indexable_excluded_post_types', 'exclude_page' );
function exclude_page( ) {
	return ['movie'];
}
  • Refresh and make sure the link now goes to the homepage. Also make sure there is no canonical header.

Relevant test scenarios

  • Changes should be tested with the browser console open
  • Changes should be tested on different posts/pages/taxonomies/custom post types/custom taxonomies
  • Changes should be tested on different editors (Default Block/Gutenberg/Classic/Elementor/other)
  • Changes should be tested on different browsers
  • Changes should be tested on multisite

Test instructions for QA when the code is in the RC

  • QA should use the same steps as above.

QA can test this PR by following these steps:

Impact check

This PR affects the following parts of the plugin, which may require extra testing:

  • Smoke test the RSS feed for the homepage
    • Go to the homepage and add /feed/. Much like the production version: make sure the link tag and the Link header point to the homepage. For example http://basic.wordpress.test/

UI changes

  • This PR changes the UI in the plugin. I have added the 'UI change' label to this PR.

Other environments

  • This PR also affects Shopify. I have added a changelog entry starting with [shopify-seo], added test instructions for Shopify and attached the Shopify label to this PR.

Documentation

  • I have written documentation for this change. For example, comments in the Relevant technical choices, comments in the code, documentation on Confluence / shared Google Drive / Yoast developer portal, or other.

Quality assurance

  • I have tested this code to the best of my abilities.
  • During testing, I had activated all plugins that Yoast SEO provides integrations for.
  • I have added unit tests to verify the code works as intended.
  • If any part of the code is behind a feature flag, my test instructions also cover cases where the feature flag is switched off.
  • I have written this PR in accordance with my team's definition of done.
  • I have checked that the base branch is correctly set.

Innovation

  • No innovation project is applicable for this PR.
  • This PR falls under an innovation project. I have attached the innovation label.
  • I have added my hours to the WBSO document.

Fixes #
#20436

@thijsoo thijsoo added the changelog: bugfix Needs to be included in the 'Bugfixes' category in the changelog label May 17, 2024
@coveralls
Copy link

coveralls commented May 17, 2024

Pull Request Test Coverage Report for Build 050032edf51f3e0ae7d3f66c4d62b5acf64fb364

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 11 (0.0%) changed or added relevant lines in 1 file are covered.
  • 6 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.03%) to 52.661%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/integrations/front-end/feed-improvements.php 0 11 0.0%
Files with Coverage Reduction New Missed Lines %
src/integrations/front-end/feed-improvements.php 1 0.0%
inc/class-rewrite.php 5 67.95%
Totals Coverage Status
Change from base Build 5c69bf7f9e9b2722313b5f23207ead0be6f1bba7: 0.03%
Covered Lines: 28318
Relevant Lines: 54387

💛 - Coveralls

@thijsoo thijsoo linked an issue May 17, 2024 that may be closed by this pull request
2 tasks
Copy link
Contributor

@leonidasmi leonidasmi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_url_for_queried_object() is used for two things:

  • For populating the <link>> element
  • For creating the canonical header

While, we correctly fallback to the homepage for the former, I don't think we should do the same for the latter. I think it would be better to not output a canonical header at all, in those cases. At least, that was the final summary of our decisions here, so if we do something different we have to get a new approval.

Also, it would be very nice if we had test instructions for all changes here, not only for the author archives - that would help us also understand when those cases happen for the other feeds, for future reference.

Copy link
Contributor

@leonidasmi leonidasmi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per a convo with @thijsoo I pushed a commit about code duplication here.

With that, CR is ✅:

  • @thijsoo can you review my last commit, just for safety?

AT is ❌:

  • We no longer have a Link header for the homepage feed.

Copy link
Contributor

@leonidasmi leonidasmi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CR + AT is 👍

@leonidasmi leonidasmi added this to the feature/plugin-fixes milestone May 28, 2024
@leonidasmi leonidasmi merged commit facad09 into feature/plugin-fixes May 28, 2024
23 checks passed
@leonidasmi leonidasmi deleted the 20436-throwing-php-notice-trying-to-get-property-canonical-of-non-object branch May 28, 2024 10:35
@hardikgohil7988
Copy link

hardikgohil7988 commented Jun 6, 2024

@tatasha2004 @oksanayoast
I've tested fallback URL & header by:

  • Verifying feed data for the author with/without post
  • Veirfying feed data for Taxonomies
  • Verifying feed data for Post/Page
  • Verifying feed data for CPT
  • Verifying feed data with/without author archive enable

There is an issue reported for the case of Author without post.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: bugfix Needs to be included in the 'Bugfixes' category in the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Throwing PHP Notice "Trying to get property 'canonical' of non-object"
5 participants