[wp-trac] [WordPress Trac] #48477: Add a hook before creating image sub-sizes
WordPress Trac
noreply at wordpress.org
Sun Feb 1 12:39:10 UTC 2026
#48477: Add a hook before creating image sub-sizes
-------------------------------------------------+-------------------------
Reporter: GregLone | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Future
| Release
Component: Upload | Version: 5.3
Severity: normal | Resolution:
Keywords: has-patch 2nd-opinion needs-dev- | Focuses:
note |
-------------------------------------------------+-------------------------
Changes (by ozgursar):
* keywords: has-patch needs-testing 2nd-opinion needs-dev-note => has-
patch 2nd-opinion needs-dev-note
Comment:
== Patch Testing Report
Patch Tested: https://github.com/WordPress/wordpress-develop/pull/9453
=== Environment
- WordPress: 7.0-alpha-61215-src
- PHP: 8.2.29
- Server: nginx/1.29.4
- Database: mysqli (Server: 8.4.7 / Client: mysqlnd 8.2.29)
- Browser: Chrome 144.0.0.0
- OS: macOS
- Theme: Twenty Twenty-One 2.7
- MU Plugins: None activated
- Plugins:
* Code Snippets 3.9.4
* Test Reports 1.2.1
=== Steps taken
1. Add the following snippet to `functions.php` or via Code Snippets
plugin
{{{
add_action('wp_before_make_subsizes', function($new_sizes, $file,
$image_meta, $attachment_id) {
error_log("=== wp_before_make_subsizes HOOK FIRED ===");
error_log("Attachment ID: " . $attachment_id);
error_log("File: " . $file);
error_log("Sizes to create: " . implode(', ',
array_keys($new_sizes)));
error_log("==========================================");
}, 10, 4);
}}}
2. Add an image to Media
3. Ensure `WP_DEBUG` and `WP_DEBUG_LOG` are enabled in `wp-config.php`
4. Check `/wp-content/debug.log` to confirm the hook is running as
expected
5. When I uploaded a random image, the following lines are logged:
{{{
[01-Feb-2026 12:30:30 UTC] === wp_before_make_subsizes HOOK FIRED ===
[01-Feb-2026 12:30:30 UTC] Attachment ID: 98
[01-Feb-2026 12:30:30 UTC] File: /var/www/src/wp-
content/uploads/2026/02/images.jpg
[01-Feb-2026 12:30:30 UTC] Sizes to create: medium, large, thumbnail,
medium_large, 1536x1536, 2048x2048, post-thumbnail
[01-Feb-2026 12:30:30 UTC] ==========================================
}}}
6. ✅ Patch is solving the problem
=== Expected result
- We are expecting `wp_before_make_subsizes` hook to run before creating
image sub-sizes when an image is uploaded.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/48477#comment:16>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list