Post Media: Add Images class (copy of Jetpack_PostImages)#47208
Post Media: Add Images class (copy of Jetpack_PostImages)#47208
Conversation
Copy Jetpack_PostImages class into the post-media package as Images (Automattic\Jetpack\Post_Media\Images), bringing all static methods for extracting images from WordPress posts. Includes tests adapted from the Jetpack plugin test suite for the WorDBless test environment. Also adds automattic/jetpack-image-cdn as a dependency.
|
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: The Jetpack plugin has different release cadences depending on the platform:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. Social 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 Summary1 file is newly checked for coverage.
|
There was a problem hiding this comment.
Pull request overview
This PR copies the Jetpack_PostImages class from the Jetpack plugin into the jetpack-post-media package as a new Images class (Automattic\Jetpack\Post_Media\Images). This is part of a larger effort to modularize Jetpack functionality into standalone packages, as referenced in the linked PR #47169 which moves the Twitter_Cards class and depends on this new Images class.
Changes:
- Adds new
Imagesclass with all static methods for extracting images from WordPress posts - Adds comprehensive test suite adapted from
Jetpack_PostImages_Testfor WorDBless environment - Adds
automattic/jetpack-image-cdndependency to support Image CDN functionality
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
projects/packages/post-media/src/class-images.php |
New Images class - faithful copy of Jetpack_PostImages with namespace updates and properly escaped global class references |
projects/packages/post-media/tests/php/ImagesTest.php |
Comprehensive test suite with 40+ tests covering all image extraction methods |
projects/packages/post-media/tests/php/bootstrap.php |
Adds Test_Environment initialization for package tests |
projects/packages/post-media/composer.json |
Adds jetpack-image-cdn dependency |
projects/packages/post-media/tests/files/large-featured-image.png |
Test fixture for featured image tests |
projects/packages/post-media/changelog/jeherve-post-media-images-class |
Changelog entry documenting the new Images class |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This makes Block_Scanner available at runtime, enabling the from_blocks() method and removing the need to skip block-related tests.
- Use null coalescing operator instead of isset ternary - Cast string IDs from explode/regex to int for type safety - Suppress Phan errors for runtime-checked classes/functions (blavatar_*, wpcom_get_avatar_url, Jetpack::is_module_active, Jetpack_Slideshow_Shortcode) - Fix from_gravatar() param type to string|false - Return array() instead of '' from get_post_html() for consistency with declared return type - Remove unreachable code after markTestSkipped()
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 6 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Fix swapped sprintf arguments in gallery block test helper (src/data-id were reversed) - Fix sprintf argument order in story block test helper (url/width/height were in wrong positions) - Fix indentation of fallback return in determine_thumbnail_size_for_photon - Guard get_alt_text() call when $thumb may be falsy in WP.com meta thumbnail fallback path
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Copied from PR #47183 (Post Images: add image exclusion via CSS class and filter). Adds `jetpack-ignore-thumbnail` CSS class support and `jetpack_postimages_exclude_image` filter to exclude specific images from post image discovery in both `from_blocks()` and `from_html()` methods.
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 10 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (2)
projects/packages/post-media/tests/php/ImagesTest.php:631
- There is a spelling error in the docblock comment: "Colunms" should be "Columns".
* Test if the array extracted from Colunms blocks include the image URL and alt text.
projects/packages/post-media/tests/php/ImagesTest.php:647
- There is a spelling error in the docblock comment: "Colunms" should be "Columns".
* Test if a Colunms block with an externally hosted image is not extracted by Post Images.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Migrate all references to Jetpack_PostImages across the codebase to use the new Automattic\Jetpack\Post_Media\Images class introduced in #47208. This includes: - Adding `use Automattic\Jetpack\Post_Media\Images` imports - Replacing all Jetpack_PostImages:: static method calls with Images:: - Removing class_exists('Jetpack_PostImages') guards (the new class is autoloaded via Composer) - Removing related phan suppression comments - Adding automattic/jetpack-post-media dependency to classic-theme-helper Fixes CM-547
* Replace Jetpack_PostImages usage with the new Post_Media Images class Migrate all references to Jetpack_PostImages across the codebase to use the new Automattic\Jetpack\Post_Media\Images class introduced in #47208. This includes: - Adding `use Automattic\Jetpack\Post_Media\Images` imports - Replacing all Jetpack_PostImages:: static method calls with Images:: - Removing class_exists('Jetpack_PostImages') guards (the new class is autoloaded via Composer) - Removing related phan suppression comments - Adding automattic/jetpack-post-media dependency to classic-theme-helper Fixes CM-547 * Update lock files * Update Phan config Not related to changes in branch, but throws up an error.
All methods in the Jetpack_PostImages class are now thin wrappers that emit a deprecation notice and delegate to the equivalent method in Automattic\Jetpack\Post_Media\Images, following the same pattern used for Jetpack_Twitter_Cards in #47208. The old test file is removed since the post-media package already has equivalent coverage in ImagesTest.php.
Fixes CM-71
Proposed changes:
Jetpack_PostImagesclass from the Jetpack plugin into thepost-mediapackage as a newImagesclass (Automattic\Jetpack\Post_Media\Images).Jetpack_PostImages_Test, adjusted for the WorDBless test environment used by packages.automattic/jetpack-image-cdnas a dependency of the post-media package.@since x.x.xversion tags to@since jetpack-x.x.xformat in both class and tests.Other information:
Jetpack product discussion
The new class is not used anywhere yet. Once #47169 is merged, we can update to start using the new
Imagesclass inside thepost-mediapackage.Does this pull request change what data or activity we track or use?
No.
Testing instructions:
Block_Scannernot being available and WorDBless limitations).src/class-images.phpand confirm it is a faithful copy ofclass.jetpack-post-images.phpfrom the Jetpack plugin, with namespace/class name updates.