[wp-trac] [WordPress Trac] #58141: `wp_insert_post` considers `"0"` as empty content.

WordPress Trac noreply at wordpress.org
Thu Apr 20 10:51:24 UTC 2023


#58141: `wp_insert_post` considers `"0"` as empty content.
-------------------------------+---------------------
 Reporter:  peterwilsoncc      |       Owner:  (none)
     Type:  defect (bug)       |      Status:  new
 Priority:  normal             |   Milestone:  6.3
Component:  Posts, Post Types  |     Version:  3.3
 Severity:  normal             |  Resolution:
 Keywords:  needs-patch        |     Focuses:
-------------------------------+---------------------

Comment (by davidmusnik):

 Hello people,

 I have been investigating this issue during the contributing day organized
 by WPFR in Paris on April 20th, 2023.  First, it seems the problem pops up
 only when the title is equal to « 0 ».  For some reason when both the
 title AND the content are equal to « 0 », the post seems inserted without
 error, unlike what is stated in the ticket description.

 In any event, after having reviewed this part of the code, I have checked
 the following PHP statement in wp-include/post.php :


 {{{#!php
 <?php
 $maybe_empty = 'attachment' !== $post_type
         && ! $post_content && ! $post_title && ! $post_excerpt
         && post_type_supports( $post_type, 'editor' )
         && post_type_supports( $post_type, 'title' )
         && post_type_supports( $post_type, 'excerpt' );

 }}}

 This test is somehow dubious as I have written a quick and dirty program
 in PHP which tests that basic IF feature :

 {{{#!php
 <?php
 date_default_timezone_set("Europe/Paris");
 $title = "0";
 print ("title=$title\n");
 if ($title) {
         print ("PHP returned TRUE\n");
 } else {
         print ("PHP returned FALSE\n");
 }

 }}}



 In my understanding of PHP, I thought that the program should return true
 ($title variable contains a correct string, but in fact it unexpectedly
 does return false (NB : both in PHP7.4’ and PHP 8.2).

 Back to the issue at hand and beyond the overall PHP behavior, I suggest
 that the above statement should be modified the following way :


 {{{#!php
 <?php
         $maybe_empty = 'attachment' !== $post_type
                 && ( $post_content === '' )
                 && ( $post_title === '' )
                 && ( $post_excerpt === '' )
                 && post_type_supports( $post_type, 'editor' )
                 && post_type_supports( $post_type, 'title' )
                 && post_type_supports( $post_type, 'excerpt' );

 }}}

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


More information about the wp-trac mailing list