WordPress.org

Make WordPress Core

#22335 closed enhancement (fixed)

XML-RPC: wp.editPost changes post_status from 'inherit' to 'draft'

Reported by: DaEnno Owned by: ryan
Milestone: 3.5 Priority: normal
Severity: normal Version: 3.4
Component: XML-RPC Keywords: commit
Focuses: Cc:

Description

To send a blogpost via XML-RPC interface I take the following steps:

  1. Upload all images via wp.uploadFile.
  2. Receive the IDs and URLs of the uploaded images and insert image markup into the blogpost.
  3. Create the actual blogpost via wp.newPost.

The Problem: the uploaded images will show up in the blogpost but can't be found in the media library.

This seems to appear due to a bug in the function "attach_uploads" in the file class-wp-xmlrpc-server.php. The function sets the post_parent of all images to the ID of the actual blogpost. But it does not update the image's "post_status" from "draft" to "inherit".

The images are included when displaying the image count in the media library but they are not listed there.

Attachments (1)

22335.fix-wp-methods.diff (553 bytes) - added by markoheijnen 18 months ago.
Check if post status exists before overwriting it

Download all attachments as: .zip

Change History (13)

comment:1 markoheijnen18 months ago

That doesn't make sense to me. Tried to look into the code but it should always be inherit. There is no post_status change anywhere

comment:2 DaEnno18 months ago

You can't upload an image with the post status inherit. Of course, the parent will be created after the image is uploaded.
That's why the initial post_status of an image is draft.

This is the point where the attach_uploads function should be doing it's job properly by setting the image's post_status to inherit.

When I first recognized this I thought I could get around it by setting the image's post status afterwards via wp.editPost. Unfortunately this doesn't work either. This is due to some switch-statement where inherit is not included for the post_status, so it defaults to draft.
You can see this in the function mw_editPost, starting with

switch( $content_struct["{$post_type}_status"] ) {
Last edited 18 months ago by DaEnno (previous) (diff)

comment:3 markoheijnen18 months ago

The default "post_status" isn't draft but inherit. It seems you edit the image through wp.editPost and that this can be the reason of post status change.

Also attach_uploads shouldn't really care about post_status and what it is.

comment:4 DaEnno18 months ago

The default "post_status" isn't draft but inherit.

Ok, sorry for mistaking. But does that make sense? It inherits from... what?

It seems you edit the image through wp.editPost and that this can be the reason of post status change.

Yes, I do. I have to set post_excerpt and post_content manually since I can't send all the data needed when executing wp.uploadFile. Nevertheless don't you think it's weird this makes the image draft instead of inherit?

Also attach_uploads shouldn't really care about post_status and what it is.

I thought attach_uploads is responsible for making images children of a post. That's why an post_status of inherit makes sense to me.

comment:5 markoheijnen18 months ago

The status of an image is always inherit. It makes more sense then others.

So the real issue is the change of post status and I can see why that can happen. I will look in what the best solution can be for that.
The best is to create a way to change the media through the API but that isn't something that can be done for 3.5.

comment:6 DaEnno18 months ago

Ok.

I thought the only thing to do is to add...

case 'inherit':

... to...

switch( $content_struct["{$post_type}_status"] ) {
	case 'draft':
	case 'pending':
	case 'private':
	case 'publish':
		$post_status = $content_struct["{$post_type}_status"];
		break;

comment:7 markoheijnen18 months ago

  • Milestone changed from Awaiting Review to 3.5
  • Type changed from defect (bug) to enhancement
  • Version set to 3.4

I do something like that for the wp method. Older methods will stay untouched unless there is a bug and this is an enhancement to make more possible through the existing methods

markoheijnen18 months ago

Check if post status exists before overwriting it

comment:8 markoheijnen18 months ago

I just uploaded a patch for the wp.* methods. That should fix the case

comment:9 DaEnno18 months ago

Thanks very much!

comment:10 markoheijnen18 months ago

  • Keywords commit added

comment:11 markoheijnen18 months ago

  • Summary changed from XML-RPC: attach_uploads does not set post_status 'inherit' to XML-RPC: wp.editPost changes post_status from 'inherit' to 'draft'

comment:12 ryan18 months ago

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

In 22368:

In wp_xmlrpc_server::_insert_post(), preservea valid post status instead of overwriting it with 'draft'. This preserves the 'inherit' status of attachments. Props markoheijnen. fixes #22335

Note: See TracTickets for help on using tickets.