Skip to content

Post Media: Add Images class (copy of Jetpack_PostImages)#47208

Merged
jeherve merged 9 commits intotrunkfrom
jeherve/post-media-images-class
Feb 20, 2026
Merged

Post Media: Add Images class (copy of Jetpack_PostImages)#47208
jeherve merged 9 commits intotrunkfrom
jeherve/post-media-images-class

Conversation

@jeherve
Copy link
Member

@jeherve jeherve commented Feb 18, 2026

Fixes CM-71

Proposed changes:

  • Copy the Jetpack_PostImages class from the Jetpack plugin into the post-media package as a new Images class (Automattic\Jetpack\Post_Media\Images).
  • All static methods for extracting images from WordPress posts are preserved with identical behavior.
  • Bring along tests adapted from Jetpack_PostImages_Test, adjusted for the WorDBless test environment used by packages.
  • Add automattic/jetpack-image-cdn as a dependency of the post-media package.
  • Update @since x.x.x version tags to @since jetpack-x.x.x format in both class and tests.

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

The new class is not used anywhere yet. Once #47169 is merged, we can update to start using the new Images class inside the post-media package.

Does this pull request change what data or activity we track or use?

No.

Testing instructions:

  • Verify that all tests pass (some tests will be skipped due to Block_Scanner not being available and WorDBless limitations).
  • Review src/class-images.php and confirm it is a faithful copy of class.jetpack-post-images.php from the Jetpack plugin, with namespace/class name updates.

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.
Copilot AI review requested due to automatic review settings February 18, 2026 18:55
@jeherve jeherve added the [Status] Needs Review This PR is ready for review. label Feb 18, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Feb 18, 2026

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

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:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

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:

  • WordPress.com Simple releases happen as soon as you deploy your changes after merging this PR (PCYsg-Jjm-p2).
  • WoA releases happen weekly.
  • Releases to self-hosted sites happen monthly:
    • Scheduled release: March 3, 2026
    • Code freeze: March 3, 2026

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.

@jeherve jeherve added [Status] In Progress [Pri] Normal and removed [Status] Needs Review This PR is ready for review. labels Feb 18, 2026
@jp-launch-control
Copy link

jp-launch-control bot commented Feb 18, 2026

Code Coverage Summary

1 file is newly checked for coverage.

File Coverage
projects/packages/post-media/src/class-images.php 246/549 (44.81%) ❤️‍🩹

Full summary · PHP report · JS report

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 Images class with all static methods for extracting images from WordPress posts
  • Adds comprehensive test suite adapted from Jetpack_PostImages_Test for WorDBless environment
  • Adds automattic/jetpack-image-cdn dependency 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()
Copilot AI review requested due to automatic review settings February 18, 2026 19:24
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

@jeherve jeherve self-assigned this Feb 18, 2026
- 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
Copilot AI review requested due to automatic review settings February 18, 2026 20:55
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

@jeherve jeherve added [Status] Needs Review This PR is ready for review. and removed [Status] In Progress labels Feb 18, 2026
@jeherve jeherve requested a review from a team February 18, 2026 21:02
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.
@github-actions
Copy link
Contributor

github-actions bot commented Feb 19, 2026

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack), and enable the jeherve/post-media-images-class branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack jeherve/post-media-images-class

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

Copilot AI review requested due to automatic review settings February 19, 2026 18:47
@github-actions github-actions bot added [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Plugin] Social Issues about the Jetpack Social plugin labels Feb 19, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

@jeherve jeherve merged commit 29fd948 into trunk Feb 20, 2026
91 of 92 checks passed
@jeherve jeherve deleted the jeherve/post-media-images-class branch February 20, 2026 09:38
@github-actions github-actions bot removed the [Status] Needs Review This PR is ready for review. label Feb 20, 2026
jeherve added a commit that referenced this pull request Feb 20, 2026
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
jeherve added a commit that referenced this pull request Feb 24, 2026
* 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.
jeherve added a commit that referenced this pull request Feb 27, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Post Media [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Plugin] Social Issues about the Jetpack Social plugin [Pri] Normal [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants