[wp-trac] [WordPress Trac] #49449: Wrong require_once and misleading comment

WordPress Trac noreply at wordpress.org
Mon Feb 17 03:02:01 UTC 2020


#49449: Wrong require_once and misleading comment
--------------------------+------------------------------
 Reporter:  luisrivera    |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  REST API      |     Version:  5.3
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:  rest-api
--------------------------+------------------------------

Comment (by SergeyBiryukov):

 Hi there, welcome to WordPress Trac! Thanks for the report.

 Good catch, looks like that line has some history:
 * [43589] / #43757 switched `wp-admin/includes/admin.php` to `image.php`
 to reduce the scope.
 * [43604] / #43757 added an earlier `image.php` require, resulting in two
 calls in the same method.
 * [43850] / #43757 restored `media.php` for the required audio/video
 metadata functions.
 * [44206] / #45420 removed the duplicate `image.php` require.
 * [46422] / #47987 created a new `::insert_attachment()` method and moved
 some code there.

 To summarize, `wp-admin/includes/image.php`, while being necessary for
 `wp_generate_attachment_metadata()` in `::create_item()`, is no longer
 required directly in the method. This only works because
 `::insert_attachment()` is called earlier, which does require `image.php`
 for `wp_read_image_metadata()`.

 The safest option is probably to require both `media.php` and `image.php`
 in `::create_item()`, like [43850] did.

 Technically that would revert [44206], however, since `::create_item()`
 and `::insert_attachment()` are now separate methods, the require call
 would no longer be duplicate and would prevent an error in case at some
 point `::insert_attachment()` is no longer called earlier in
 `::create_item()`.

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


More information about the wp-trac mailing list