[wp-trac] [WordPress Trac] #44801: `image_constrain_size_for_editor()` forcing the `$content_width` messes up dimensions

WordPress Trac noreply at wordpress.org
Wed Aug 15 09:53:47 UTC 2018


#44801: `image_constrain_size_for_editor()` forcing the `$content_width` messes up
dimensions
----------------------------------------+------------------------------
 Reporter:  flixos90                    |       Owner:  (none)
     Type:  defect (bug)                |      Status:  new
 Priority:  normal                      |   Milestone:  Awaiting Review
Component:  Media                       |     Version:
 Severity:  normal                      |  Resolution:
 Keywords:  needs-unit-tests has-patch  |     Focuses:
----------------------------------------+------------------------------
Changes (by flixos90):

 * keywords:  needs-patch needs-unit-tests => needs-unit-tests has-patch


Comment:

 [attachment:"44801.diff"] addresses the problem as follows:

 * Introduce a filter function
 `wp_constrain_editor_max_image_size_to_content_width()` for
 `editor_max_image_size`.
 * Outsource all `$content_width`-related bits from
 `image_constrain_size_for_editor()` to that filter function.
 * Hook the filter in with priority 0 in `default-filters.php`.
 * Clean up the `image_constrain_size_for_editor()` function's tons of if-
 clauses a bit to use strict comparisons and less repetitive code for the
 same thing.

 Functionality-wise, this doesn't change anything, I preserved the exact
 same behavior as is in place currently. However, by having that part being
 a filter, it can be unhooked to skip it. As a nice side-effect, the very
 specific `$content_width` global is no longer used as part of
 `image_constrain_size_for_editor()`.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/44801#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list