#49853 closed defect (bug) (fixed)
Sending post via email results in “(no title)” for the post title
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 5.4.1 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Keywords: | has-patch | |
Focuses: | Cc: |
Description
Reported by @markrh in 5.4: Sending Post via Email Results in “(no title)” for the post title on the forums:
Once a week I send an email to my blog to go into a category I have set for them. Anyway, starting with 5.4, the post titles were all “(no title)”. I did a comparison between wp-mail.php in 5.4 and 5.3. At line 216 changed:
if ( '' === $post_title ) { $post_title = $subject; }To:
if ( '' == $post_title ) { $post_title = $subject; }Now, the posts get the title from the email’s subject once again. Not sure if this is a bug or emails need to be structured differently now.
Attachments (2)
Change History (14)
#2
@
5 years ago
There really isn't a need to use true === empty( $post_title )
when empty( $post_title )
evaluates to true if it is empty. A second evaluation isn't necessary.
#4
@
5 years ago
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.
#5
@
5 years ago
@Otto42
I think it was me that highlighted to post title of 'zero' issue, following from conversation about this with JoyR.
In my testing if ( trim( $post_title ) === '' )
works as expected and maintains the strict comparison:
<?php $tests = array( 0, NULL, 'foo', '', '0' ); foreach ( $tests as $test ) { if ( '' === trim( $test ) ) { var_dump( $test ); echo ' is empty!'; } }
Using the suggestion here: https://wordpress.org/support/topic/5-4-sending-post-via-email-results-in-no-title-for-the-post-title/#post-12646149 this also works in getting the post title from the email subject.