Opened 5 years ago
Closed 5 years ago
#49449 closed defect (bug) (fixed)
Wrong require_once and misleading comment
Reported by: | luisrivera | Owned by: | SergeyBiryukov |
---|---|---|---|
Milestone: | 5.4 | Priority: | normal |
Severity: | normal | Version: | 5.3 |
Component: | REST API | Keywords: | |
Focuses: | rest-api | Cc: |
Description
Location: class-wp-rest-attachments-controller.php, lines 167 - 168
https://core.trac.wordpress.org/browser/tags/5.3/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php#L167
<?php // Include admin function to get access to wp_generate_attachment_metadata(). require_once ABSPATH . 'wp-admin/includes/media.php';
wp_generate_attachment_metadata() is actually located in 'wp-admin/includes/image.php'
https://core.trac.wordpress.org/browser/tags/5.3/src/wp-admin/includes/image.php#L458
This isn't breaking because the correct file is being required_once before by ('insert_attachment') another method in the same class but this should be corrected.
Change History (4)
Note: See
TracTickets for help on using
tickets.
Hi there, welcome to WordPress Trac! Thanks for the report.
Good catch, looks like that line has some history:
wp-admin/includes/admin.php
toimage.php
to reduce the scope.image.php
require, resulting in two calls in the same method.media.php
for the required audio/video metadata functions.image.php
require.::insert_attachment()
method and moved some code there.To summarize,
wp-admin/includes/image.php
, while being necessary forwp_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 requireimage.php
forwp_read_image_metadata()
.The safest option is probably to require both
media.php
andimage.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()
.