#40861 closed defect (bug) (fixed)
REST API saves attachments with absolute path for `_wp_attached_file` on Windows platforms
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 4.9.8 | Priority: | normal |
Severity: | normal | Version: | 4.6 |
Component: | REST API | Keywords: | has-patch needs-unit-tests |
Focuses: | Cc: |
Description
On windows, create media with rest api insert the meta "_wp_attached_file" not correctly.
It save the absolute path and not the relative path.
the function "wp_slash" add backslash in windows file path.
file: class-rest-attachements-controller.php
line: 150
<?php $id = wp_insert_post( wp_slash( (array) $attachment ), true );
Attachments (2)
Change History (16)
This ticket was mentioned in Slack in #core by bobbingwide. View the logs.
7 years ago
#4
@
7 years ago
- Keywords needs-patch added
- Summary changed from Rest Api create media to REST API saves attachments with absolute path for `_wp_attached_file` on Windows platforms
- Version changed from 4.7.5 to 4.6
Looks like _wp_relative_upload_path()
is missing here.
#5
@
7 years ago
- Keywords has-patch needs-unit-tests added; needs-patch removed
Attached 40861.patch and 40861.2.patch.
Since wp_insert_post()
expects slashed data we should unslash the file argument as well, done in 40861.patch.
In 40861.2.patch I switched to wp_insert_attachment()
so the file argument doesn't get slashed in the first place.
#6
follow-up:
↓ 7
@
7 years ago
The second patch makes it a lot more obvious that it's difficult to use the REST API to create an attachment which is actually attached to something! Is that one of the reasons for the 'rest_insert_attachment' action hook?
#7
in reply to:
↑ 6
@
7 years ago
Replying to bobbingwide:
The second patch makes it a lot more obvious that it's difficult to use the REST API to create an attachment which is actually attached to something!
Not sure I'm following. wp_insert_attachment()
is a simple wrapper for wp_insert_post()
without any additional filters. What's the issue you're seeing here?
#8
@
7 years ago
- Milestone changed from 5.0 to 4.9.7
Let's land this in 4.9.7 so we can see this sooner rather than later.
#9
@
7 years ago
- Milestone changed from 4.9.7 to 4.9.8
4.9.7 has been released, moving to next milestone.
This bug causes a problem with Gutenberg. See https://github.com/WordPress/gutenberg/issues/5332