Skip to content

Fix display of Smart Crop thumbnails on WordPress UI#971

Merged
dkotter merged 2 commits intodevelopfrom
fix/768
Sep 9, 2025
Merged

Fix display of Smart Crop thumbnails on WordPress UI#971
dkotter merged 2 commits intodevelopfrom
fix/768

Conversation

@mendezcode
Copy link
Contributor

@mendezcode mendezcode commented Aug 12, 2025

Description of the Change

Introduces a filter on wp_prepare_attachment_for_js and replaces the medium thumbnail size (150x300) with the thumbnail thumbnail size (150x150), which effectively displays the cropped image thumbnail on the WordPress Media Library.

💡 Since the wp_prepare_attachment_for_js filter works within wp-ajax.php, there is no way to access the $pagenow global, to possibly filter the current page to the WordPress Media Library and potentially make the thumbnail override on that page only, and not globally (within the JavaScript data, that is).

This change replaces the medium thumbnail with the thumbnail size only for the JavaScript data used with the frontend Backbone models. It is a global change, but only within JavaScript.
 
Screenshot 2025-08-12 at 4 52 15 PM

Closes #768

How to test the Change

  1. Ensure ClassifAI is active and the Smart Crop feature
  2. Upload an image to the Media Library
  3. View the image and its thumbnail in the uploads directory, see properly smart-cropped image
  4. Confirm within the WP UI that the cropped image is shown instead of the default center-crop one

Changelog Entry

Fixed - Smart crop thumbnails not showing in WordPress UI

Credits

Props @kmgalanakis , @dkotter

Checklist:

@github-actions github-actions bot added this to the Future Release milestone Aug 12, 2025
@mendezcode mendezcode marked this pull request as ready for review August 14, 2025 21:22
@mendezcode mendezcode requested review from a team, dkotter and jeffpaul as code owners August 14, 2025 21:22
@github-actions github-actions bot added the needs:code-review This requires code review. label Aug 14, 2025
@jeffpaul jeffpaul modified the milestones: Future Release, 3.6.0 Aug 14, 2025
@jeffpaul jeffpaul requested a review from iamdharmesh August 18, 2025 17:16
iamdharmesh
iamdharmesh previously approved these changes Aug 19, 2025
Copy link
Member

@iamdharmesh iamdharmesh left a comment

Choose a reason for hiding this comment

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

Thanks a lot for the PR @mendezcode. LGTM.

@dkotter, since we are updating the medium size with the thumbnail one, I’m tagging you here to check if you have any concerns with it. I did a quick check on this and couldn’t find a better solution.

Copy link
Collaborator

@dkotter dkotter left a comment

Choose a reason for hiding this comment

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

So in testing this out, I'm not seeing this working. I get the exact same images used both on this branch and on develop, unless there's something I'm missing here?

@dkotter dkotter modified the milestones: 3.6.0, 3.7.0 Aug 19, 2025
@iamdharmesh
Copy link
Member

I'm not seeing this working. I get the exact same images used both on this branch and on develop, unless there's something I'm missing here?

Here is how it looks to me. Maybe you should try with regenerate thumbnails?

on develop on this branch
Screenshot 2025-08-20 at 4 11 48 PM Screenshot 2025-08-20 at 4 22 19 PM

@dkotter
Copy link
Collaborator

dkotter commented Aug 20, 2025

Here is how it looks to me. Maybe you should try with regenerate thumbnails?

Working now, I thought I had the Feature enabled but did not, so the code wasn't loading 😅

This is working though I left a few comments. I don't necessarily love that this is a global change, does make me a bit worried this could impact other areas unintentionally but not seeing anything doing a quick review of the admin

@dkotter dkotter merged commit 6dd02f2 into develop Sep 9, 2025
18 checks passed
@dkotter dkotter deleted the fix/768 branch September 9, 2025 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs:code-review This requires code review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Smart crop thumbnails not showing in WordPress UI

4 participants