Skip to content

Use wp_update_image_subsizes() for --only-missing on WP 5.3+#236

Merged
swissspidy merged 3 commits intomainfrom
copilot/update-process-regeneration-function
Mar 17, 2026
Merged

Use wp_update_image_subsizes() for --only-missing on WP 5.3+#236
swissspidy merged 3 commits intomainfrom
copilot/update-process-regeneration-function

Conversation

Copy link
Contributor

Copilot AI commented Mar 17, 2026

  • Investigate wp_update_image_subsizes() and wp_get_missing_image_subsizes() WP 5.3 API
  • Update process_regeneration() to use wp_update_image_subsizes() on WP 5.3+ for the --only-missing case
  • Handle WP_Error return from wp_update_image_subsizes() — emit warning, log failure, increment $errors
  • Keep the legacy wp_generate_attachment_metadata() path as fallback
  • Add a @require-wp-5.3 Behat test scenario verifying the new code path
  • Run static analysis and code style checks (lint, phpcs, phpstan — all pass)
Original prompt

This section details on the original issue you should resolve

<issue_title>Perhaps update process_regeneration() to reflect changes in WP 5.3</issue_title>
<issue_description>Just an FYI that from WP 5.3 there are couple of functions to find and generate missing image sub-sizes, and the image meta is saved after each sub-size is generated.

For back-compat wp_generate_attachment_metadata() still returns the whole image meta array after all sub-sizes have been created (if the server doesn't run out of resources), but is not the best way to generate only missing image sub-sizes. See https://core.trac.wordpress.org/ticket/40439 and https://core.trac.wordpress.org/changeset/45538 (testing and suggestions welcome). </issue_description>

Comments on the Issue (you are @copilot in this section)

@schlessera Thanks for the heads-up, @azaozz !

Yes, that looks like it would make everything a bit more streamlined. However, it also means maintaining two separate execution paths for solving the same issue, which might have different results...

I'll have to spend some time looking into this to see how best to support this new functionality.</comment_new>


💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.

@github-actions github-actions bot added command:media-regenerate Related to 'media regenerate' command scope:testing Related to testing labels Mar 17, 2026
@codecov
Copy link

codecov bot commented Mar 17, 2026

Codecov Report

❌ Patch coverage is 71.42857% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/Media_Command.php 71.42% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

… 5.3+

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Perhaps update process_regeneration() to reflect changes in WP 5.3 Use wp_update_image_subsizes() for --only-missing on WP 5.3+ Mar 17, 2026
Copilot AI requested a review from swissspidy March 17, 2026 14:59
@swissspidy swissspidy requested a review from Copilot March 17, 2026 15:27

This comment was marked as resolved.

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
@swissspidy swissspidy marked this pull request as ready for review March 17, 2026 16:29
@swissspidy swissspidy requested a review from a team as a code owner March 17, 2026 16:29
@swissspidy
Copy link
Member

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a valuable optimization for regenerating media thumbnails on WordPress 5.3 and newer. By leveraging the more efficient wp_update_image_subsizes() function for the --only-missing flag, it avoids unnecessary work and improves reliability through incremental metadata saving. The implementation is solid and is well-supported by a new Behat test case. My feedback includes a minor suggestion to enhance code consistency.

@swissspidy swissspidy merged commit d2edbef into main Mar 17, 2026
59 of 60 checks passed
@swissspidy swissspidy added this to the 2.2.6 milestone Mar 17, 2026
@swissspidy swissspidy deleted the copilot/update-process-regeneration-function branch March 17, 2026 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

command:media-regenerate Related to 'media regenerate' command scope:testing Related to testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Perhaps update process_regeneration() to reflect changes in WP 5.3

3 participants