#37813 closed enhancement (fixed)
Missing $wp_error parameter for wp_insert_attachment
Reported by: | grapplerulrich | Owned by: | johnbillion |
---|---|---|---|
Milestone: | 4.7 | Priority: | normal |
Severity: | normal | Version: | 2.0 |
Component: | Media | Keywords: | has-patch has-unit-tests |
Focuses: | Cc: |
Description
wp_insert_attachment()
uses wp_insert_post()
which has a parameter whether to allow return of WP_Error on failure.
It is not possible to do the same for wp_insert_attachment()
.
This would be my suggested patch.
<?php function wp_insert_attachment( $args, $file = false, $parent = 0, $wp_error = false ) { $defaults = array( 'file' => $file, 'post_parent' => 0 ); $data = wp_parse_args( $args, $defaults ); if ( ! empty( $parent ) ) { $data['post_parent'] = $parent; } $data['post_type'] = 'attachment'; return wp_insert_post( $data, $wp_error ); }
Related: #32318
Attachments (4)
Change History (18)
#1
@
8 years ago
- Focuses administration removed
- Keywords needs-patch added
- Milestone changed from Awaiting Review to 4.7
- Type changed from defect (bug) to enhancement
#5
@
8 years ago
- Keywords needs-testing added
Oh, looks like I forgot to upload and when I did, there was already a patch. Anywho, I added the docs as well. Looks, like @grapplerulrich your patch has some issue as well. It's removing what you intend to add. Test my patch to see what I am talking about.
#6
follow-up:
↓ 7
@
8 years ago
I have updated my patch. I followed the docs in https://make.wordpress.org/core/handbook/contribute/git/
Could there be a mistake there in step 4?
#7
in reply to:
↑ 6
@
8 years ago
Replying to grapplerulrich:
I have updated my patch. I followed the docs in https://make.wordpress.org/core/handbook/contribute/git/
Could there be a mistake there in step 4?
I am using SVN diff at the moment. Will check that later.
@since 4.7.0 Add fourth paramater `$wp_error` to allow return of WP_Error on failure.
@since is used to depict when was this function introduced. It's not a changelog. So, the line above should not be there. Take a look at my patch https://core.trac.wordpress.org/attachment/ticket/37813/37813.diff and see if there is anything wrong with it. You can use Grunt WP patch https://github.com/aaronjorbin/grunt-patch-wordpress to apply the patch.
Let me know.
#8
follow-up:
↓ 9
@
8 years ago
I have been asked in the past to add @since
to be used as a changelog. e.g. https://core.trac.wordpress.org/ticket/37076#comment:4
#9
in reply to:
↑ 8
@
8 years ago
- Status changed from assigned to closed
Replying to grapplerulrich:
I have been asked in the past to add
@since
to be used as a changelog. e.g. https://core.trac.wordpress.org/ticket/37076#comment:4
You are right. I was not aware of this. I think it is a new change. https://make.wordpress.org/core/handbook/best-practices/inline-documentation-standards/php/#since-section-changelogs
#10
follow-up:
↓ 14
@
8 years ago
- Status changed from closed to reopened
@mrahmadawais Tickets remain open until they've been committed to core. Thanks!
#11
@
8 years ago
- Keywords needs-testing removed
- Owner changed from grapplerulrich to johnbillion
- Status changed from reopened to reviewing
#12
@
8 years ago
- Keywords has-unit-tests added; good-first-bug removed
37813.2.patch improves the phrasing and adds a unit test.
#14
in reply to:
↑ 10
@
8 years ago
Replying to johnbillion:
@mrahmadawais Tickets remain open until they've been committed to core. Thanks!
Sorry about that. I just wrote the comment and pressed submit. Must have mistakenly clicked at the closed option. My bad! Thanks for the props!
Assigning to mark the
good-first-bug
as "claimed".