-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Allow to use associative arrays beside indexed arrays in wp_mail $headers #9971
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Changes from all commits
9c84dc6
657f092
1b29a91
811ff70
2c982bb
a08a6ce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6171,13 +6171,21 @@ function wp_staticize_emoji_for_email( $mail ) { | |
| } | ||
| } | ||
|
|
||
| foreach ( $headers as $header ) { | ||
| if ( ! str_contains( $header, ':' ) ) { | ||
| foreach ( $headers as $key => $header ) { | ||
| if ( is_string( $header ) && | ||
| strpos( $header, ':' ) === false && | ||
| is_numeric( $key ) | ||
| ) { | ||
| continue; | ||
| } | ||
|
|
||
| // Explode them out. | ||
| list( $name, $content ) = explode( ':', trim( $header ), 2 ); | ||
| list( $name, $content ) = ( is_numeric( $key ) ) ? explode( ':', trim( $header ), 2 ) : array( $key, $header ); | ||
|
|
||
| // Skip because Content-Type must be an string. | ||
| if ( ! is_string( $name ) || ! is_string( $content ) ) { | ||
|
Comment on lines
+6185
to
+6186
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if someone
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you show me an example of how you can make this array possible?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Per the Trac ticket description: https://core.trac.wordpress.org/ticket/30128 $headers = [
'From' => 'Me Myself <me@example.net>',
'Cc' => [
'John Q Codex <jqc@wordpress.org>',
'iluvwp@wordpress.org',
],
];What if someone provided: $headers = [
'Content-Type' => [
'text/html',
],
'Cc' => [
'John Q Codex <jqc@wordpress.org>',
'iluvwp@wordpress.org',
],
];Where arrays are used for every value for consistency. Relatedly, there's some interesting behaviors when you try to send multiple
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True, I did not consider adding this to the mix, but technically it is plausible. I will give this a second thought. |
||
| continue; | ||
| } | ||
|
|
||
| // Cleanup crew. | ||
| $name = trim( $name ); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why switch to
strpos()fromstr_contains()?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having this option, why using a PHP 8.0 function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WordPress includes a polyfill for
str_contains()wordpress-develop/src/wp-includes/compat.php
Lines 402 to 422 in 6b006e9
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, I knew that it used a polyfill that triggers that exact function. This is why it makes no sense to me to use
str_containsin this context.Also, now I remember that the original patch using strpos was made like one decade ago, and I felt that most of the logic was very appropriate, so I preferred to preserve it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you reluctant to use it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not reluctant. Simply in the original logic in
pluggable.php, it was using strpos, so I respected, and wanted to match both scenarios. Since its basically identical, I don't really care one or another.