[wp-trac] [WordPress Trac] #36462: Updating or publishing a (custom) post that hasn't loaded completely closes comments

WordPress Trac noreply at wordpress.org
Sun Apr 10 14:44:30 UTC 2016


#36462: Updating or publishing a (custom) post that hasn't loaded completely closes
comments
-------------------------------+-----------------------------
 Reporter:  SeBsZ              |      Owner:
     Type:  defect (bug)       |     Status:  new
 Priority:  normal             |  Milestone:  Awaiting Review
Component:  Posts, Post Types  |    Version:  4.4.2
 Severity:  normal             |   Keywords:
  Focuses:                     |
-------------------------------+-----------------------------
 I am using a custom post type, but I assume this happens to the default
 post type as well. On the edit post screen (post.php?post=1&action=edit) I
 have several custom meta boxes. Some of these have content that is quite
 slow to load. You can reproduce this behavior by adding a sleep(5)
 statement somewhere in the code that loads the content for a custom meta
 box. Now in the document's DOM, the sidebar is loaded before the custom
 meta boxes. This introduces a situation where it is possible to update or
 publish a post before all the meta boxes have completely loaded. In most
 cases this isn't a huge problem - I myself check to see if the $_POST
 fields are there and if they are not then I don't act upon them.

 Unfortunately this does not happen for the included "Discussion" meta box.
 This box has a checkbox named "Allow Comments" which gets switched off
 when you update the post before this meta box has loaded into the DOM.

 The culprit is the code in wp-admin/includes/post.php on line 133 in the
 _wp_translate_postdata() function:

 {{{#!php
 if (!isset( $post_data['comment_status'] ))
   $post_data['comment_status'] = 'closed';
 }}}
 Since the comment_status field is not in the post data, it is
 automatically assumed it needs to be closed.

 Of course there are two "workarounds" I can think of that would improve my
 current situation. One is for me to optimize the meta boxes so the page
 loads quicker, the other is to move the Discussion metabox to the top of
 the page, so it loads first.

 Is this expected behavior? I would much rather see the current
 comment_status be preserved - don't touch it if I didn't intend to modify
 it. Of course there might be a reason for this implementation that I don't
 know about.

 This post data is then finally presented to wp_insert_post in wp-
 includes/post.php which actually updates the post's comment_status to
 become closed, which finally answers my boss' question why comments kept
 getting disabled automatically.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/36462>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list