-
Notifications
You must be signed in to change notification settings - Fork 821
Sitemaps: Fix video sitemap generation #43333
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
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! Jetpack plugin: No scheduled milestone found for this plugin. If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
Code Coverage SummaryCoverage changed in 1 file.
|
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.
Seems reasonable. Haven't tested though.
Looks like there's a test that's passing the "videos" rather than "video:video" that needs to be updated though. 😀
if ( ! empty( $array['url'] ) ) { | ||
$this->writer->startElement( 'url' ); | ||
// Return early if missing fundamental data. | ||
if ( empty( $array['url']['video:video'] ) ) { |
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.
I note this is a slight behavior change, in that if there isn't any video:video
data then it'll skip the <url>
entirely now instead of outputting it like the DOMDocument generator does.
But possibly that behavior of the DOMDocument generator is incorrect. 🤷
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.
Yeah, I consciously made this change; if there's no video data, then it doesn't make sense to map to a page with the missing data. I could even see search engines penalizing this if they wanted.
@kraftbj I've updated the test to match this, but I'm curious where you got |
@tbradsha I really struggled with the video sitemap before so I think this was a bug that I didn't understand. Thanks for fixing it. |
* Properly handle item structure * Rework some logic and return early * Add changelog * Fix test
Video sitemaps were only generating partial data due to a mismatch between what the passed array looked like and what the array was expected to look like.
It also resulted in lots of these PHP warnings:
Reported in p1745995831728999/1745855658.393169-slack-C01U2KGS2PQ; related to #42767.
Proposed changes:
Rather than the needed content being in an array of items in the
videos
key, they were directly in a single array under thevideo:video
key. I adjusted the logic to match this and also added an early return to the function.I'll note that the schema does allow for multiple
<video:video>
arrays (see example here), but I couldn't seem to reproduce any instances where actually pass an array of videos. There is a filter injetpack_sitemap_video_sitemap_item
that could modify this content, but I don't see anywhere we do. I tested with a standalone site as well as WordPress.com Atomic site, and both gave me a single video.I also updated the test, which had the errant(?) structure.
XML generated on a site using the old DOMDocument generator
XML generated on a site using the new XMLWriter generator (prior to this PR)
Array we pass to `Jetpack_Sitemap_Buffer_Video_XMLWriter::append_item()`
Array structure the code was expecting
Other information:
Jetpack product discussion
Does this pull request change what data or activity we track or use?
Testing instructions:
/wp-admin/upload.php
/wp-admin/options-reading.php
/wp-admin/admin.php?page=jetpack#/settings?term=sitemaps
wp jetpack sitemap rebuild --purge
or by running thejp_sitemap_cron_hook
cron./video-sitemap-1.xml