Opened 7 years ago
Closed 6 years ago
#43757 closed enhancement (fixed)
`WP_REST_Attachments_Controller` includes entire admin includes for a few utility functions
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 5.0 | Priority: | normal |
Severity: | minor | Version: | 5.1 |
Component: | REST API | Keywords: | has-patch fixed-5.0 |
Focuses: | Cc: |
Description
Looks like https://core.trac.wordpress.org/browser/trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php uses only a few admin function (wp_handle_upload
, wp_generate_attachment_metadata
, wp_tempnam
, and wp_handle_sideload
) but it's requiring the entire admin.php
include.
It seems we could just require file.php
and image.php
from the admin directly instead.
Attachments (4)
Change History (23)
#1
@
7 years ago
- Keywords has-patch needs-testing added; needs-patch removed
Hey, welcome to Trac! :)
You appear to be very correct in this regard. Attached diff for leaner includes. Tests pass fine.
#2
@
7 years ago
That's exactly the patch I was going to suggest but was having internet troubles and did get around to submitting it. Looks good to me, but I'm probably much to green to be reviewing patches to core. 😅 👍🏻
#4
@
7 years ago
Some background: https://github.com/WP-API/WP-API/issues/1686
#5
@
7 years ago
- Milestone changed from Awaiting Review to 5.0
- Owner set to SergeyBiryukov
- Status changed from new to reviewing
#7
@
6 years ago
- Keywords needs-patch added; has-patch needs-testing removed
- Resolution fixed deleted
- Status changed from closed to reopened
The change is causing a fatal error by create_item()
due to the undefined function wp_read_image_metadata()
.
This happens because upload_from_data()
and upload_from_file()
are now only loading wp-admin/includes/file.php
.
#8
@
6 years ago
Good catch. These are hard to test for via unit tests since the admin.php file is always included and all these functions are defined. Required image.php in the 3rd iteration.
#9
@
6 years ago
Just stumbled upon this while working on Gutenberg. Can we get this in as soon as possible please?
This ticket was mentioned in Slack in #core-editor by afercia. View the logs.
6 years ago
#12
@
6 years ago
- Keywords needs-patch removed
- Resolution fixed deleted
- Status changed from closed to reopened
#14
@
6 years ago
- Keywords needs-patch added
- Resolution fixed deleted
- Status changed from closed to reopened
There's still a fatal error when uploading a video or an audio file due to the missing wp_read_video_metadata()
/wp_read_audio_metadata()
functions. The functions are defined in wp-admin/includes/media.php
and called by wp_generate_attachment_metadata()
in wp-admin/includes/image.php
leaner includes