WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 22 months ago

#15036 closed enhancement (fixed)

Add 2nd boolean parameter of wp_error to wp_update_post() to allow passthru to wp_insert_post()

Reported by: mikeschinkel Owned by: nacin
Milestone: 3.5 Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords: has-patch commit
Focuses: Cc:

Description (last modified by scribu)

Currently wp_insert_post() accepts wp_error as a second parameter; if true is passed then wp_insert_post() is allowed to return a WP_Error object, if false it can only return a zero (0) on failure.

wp_update_post() currently sets values and then delegates the work of updating to wp_insert_post(). Unfortunately wp_update_post() does not accept a second boolean parameter of wp_error meaning it cannot receive back the same failure information that wp_insert_post() can.

So this request is very simple: accept wp_error as an optional second parameter for wp_update_post() with a default of false and then to pass wp_error on through to wp_insert_post().

Attachments (2)

15036.diff (1.1 KB) - added by scribu 3 years ago.
15036.2.diff (1012 bytes) - added by scribu 22 months ago.

Download all attachments as: .zip

Change History (12)

comment:1 mikeschinkel4 years ago

  • Cc mikeschinkel@… added
  • Summary changed from Add 2nd boolean of wp_error to wp_update_post() to allow passthru to wp_insert_post() to Add 2nd boolean parameter of wp_error to wp_update_post() to allow passthru to wp_insert_post()

comment:2 follow-up: scribu4 years ago

The correct way to handle this would be for wp_insert_post() to throw an exception, which of course requires PHP 5.

comment:3 in reply to: ↑ 2 mikeschinkel4 years ago

Replying to scribu:

The correct way to handle this would be for wp_insert_post() to throw an exception, which of course requires PHP 5.

But since wp_insert_post() doesn't throw an exception, let's address this issue now for v3.1 and then add the exception logic for v3.2 or beyond. One of the principles I've seen westi quote is "Solve the problems that exist today using what we have today and then we'll worry about "the correct" way to solve it later when it's possible to do so." (at least that's how I remember it.)

Why do I need this? I'm currently writing a data import routine that reads a file that a sophisticated user creates by hand and imports the data as per that file. Unfortunately there are things that can cause the data import to fail yet on an update I can't easily report back to the user why it failed like I can on an insert, so I need to be able to get the same error result from wp_update_post() that I can get from wp_insert_post().

comment:4 scribu4 years ago

Ok, care to make a patch?

comment:5 follow-up: mikeschinkel4 years ago

Yeah, I'll get one soon.

I'm still struggling with how to keep from having to set up a new version of WordPress every time I want to start coding a new patch. I've not gotten a good answer yet:

http://wordpress.stackexchange.com/questions/990/easiest-way-to-create-a-patch-for-submission-to-wordpress-core

comment:6 in reply to: ↑ 5 hakre4 years ago

Replying to mikeschinkel:

I'm still struggling with how to keep from having to set up a new version of WordPress every time I want to start coding a new patch.

You don't need to. Just just make one install that is working out of the local SVN copy. Just don't put wp-config.php under version control. Then you can create your patch and revert afterwards. Next time you need to create a patch, you only need to update to HEAD. That's how I'm doing it for years. For outdated patches I even have another install I can switch the revision so to apply old patches, then update to head and then to refresh the patch. But that's more or less for special cases.

comment:7 nacin3 years ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to Future Release

scribu3 years ago

comment:8 scribu3 years ago

  • Description modified (diff)
  • Keywords has-patch commit added; needs-patch removed

Ran into this myself.

scribu22 months ago

comment:9 scribu22 months ago

  • Milestone changed from Future Release to 3.5

Patch refreshed.

comment:10 nacin22 months ago

  • Owner set to nacin
  • Resolution set to fixed
  • Status changed from new to closed

In [21213]:

Allow wp_update_post() to accept the same second argument as wp_insert_post(), allowing for WP_Error return values on failure. props scribu, mikeschinkel. fixes #15036.

Note: See TracTickets for help on using tickets.