[wp-trac] [WordPress Trac] #17115: Publishing an empty post results in success

WordPress Trac noreply at wordpress.org
Tue Apr 5 13:41:02 UTC 2016


#17115: Publishing an empty post results in success
------------------------------------+------------------------------
 Reporter:  kawauso                 |       Owner:
     Type:  defect (bug)            |      Status:  new
 Priority:  normal                  |   Milestone:  Awaiting Review
Component:  Posts, Post Types       |     Version:  3.1
 Severity:  normal                  |  Resolution:
 Keywords:  has-patch dev-feedback  |     Focuses:  administration
------------------------------------+------------------------------

Comment (by GhostToast):

 Patch 17115.5 considers whether a given post supports a particular field
 before determining if it's presence matters. This will actually cause
 ''more'' things to be considered empty instead of just post types that
 have all 3 of these supports. It fixes the too-much-logic in one line that
 was happening when defining `$maybe_empty`.

 In my own project, I ended up utilizing the filter to prevent my post type
 from being flagged as empty. This is important because much data could be
 saved in post_meta or taxonomical connections, before a title, content or
 excerpt could be drafted. Looks a bit like this:

 {{{#!php
 <?php
 /**
  * Allow empty Review to be saved, even though it supports `excerpt`.
  * @param $maybe_empty
  * @param $postarr
  *
  * @return bool
  */
 function slc_review_maybe_empty( $maybe_empty, $postarr ) {
         if (
                 'slc_review' === $postarr['post_type']
                 && empty( $postarr['post_title'] )
                 && empty( $postarr['post_content'] )
                 && empty( $postarr['post_excerpt'] )
         ) {
                 return false;
         }
         return $maybe_empty;
 }
 add_filter( 'wp_insert_post_empty_content', 'slc_review_maybe_empty', 10,
 2 );
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/17115#comment:29>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list