[wp-trac] [WordPress Trac] #49853: Sending post via email results in “(no title)” for the post title
WordPress Trac
noreply at wordpress.org
Thu Apr 9 06:03:38 UTC 2020
#49853: Sending post via email results in “(no title)” for the post title
----------------------------+---------------------
Reporter: SergeyBiryukov | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: 5.4.1
Component: Mail | Version:
Severity: normal | Resolution:
Keywords: | Focuses:
----------------------------+---------------------
Comment (by Otto42):
Somebody pointed out (and I apologize, I don't know where I saw this,
which is why I prefer to keep these types of discussions in ticket, for
the records), that the use of `if ( empty($post_title) ) {` or similar
would preclude the use of the string '0' for a post title. The number zero
is empty according to PHP. Ah, the fun we have with loose typing.
https://www.php.net/manual/en/function.empty.php
{{{
The following values are considered to be empty:
"" (an empty string)
0 (0 as an integer)
0.0 (0 as a float)
"0" (0 as a string)
NULL
FALSE
array() (an empty array)
}}}
So, my suggestion is to basically use trim (do your own yoda conditioning,
I refuse):
`if ( trim( $post_title ) == '' )`
Test it with identity and equality comparisons to see if that provides the
needed results.
Reason I suggest this is because trim() returns an empty string for a
null/false/unset value. So, should give what we want over empty, which
doesn't.
If we find that too has issues, then it looks like we should manually
check for things that shouldn't be, because simply casting to whatever
isn't going to work.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/49853#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list