wp_staticize_emoji_for_email( array $mail ): array
- Since
- 4.2.0
- Source
wp-includes/formatting.php:6096
Compatibility
- WordPress
- since 4.2.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$mailarray- The email data array.
Return value
array- The email data array, with emoji in the message staticized.
Performance profile
How much work a call to wp_staticize_emoji_for_email() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Light
- Scaling
- Scales with input
- Instructions
- 4–72
- Plugin surface
- 1 hook
- Called by
- 0
Touches nothing outside its own arguments.
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 77.
Third-party callbacks on 'wp_mail_content_type' run inside this call, and their cost is not bounded by anything here.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
apply_filters()called directly
What one call costs · 13 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_staticize_emoji_for_email() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!isset($mail) | 4 | none |
isset($mail) && $content_type !== "text/html" | 18–26 | apply_filters() |
isset($mail) && $content_type === "text/html" | 25–33 | apply_filters(), wp_staticize_emoji() |
isset($mail) && $content_type !== "text/html" | 29–31 | explode(), apply_filters() |
isset($mail) && $content_type === "text/html" | 36–38 | explode(), apply_filters(), wp_staticize_emoji() |
isset($mail) && !$headers && $header && !$content && $content_type !== "text/html" | 44–51 | explode(), strtolower(), apply_filters() |
isset($mail) && !$headers && $header && !$content && $content_type === "text/html" | 51–58 | explode(), strtolower(), apply_filters(), wp_staticize_emoji() |
isset($mail) && !$headers && $header && $content && $content_type !== "text/html" | 53–60 | explode(), strtolower(), explode(), apply_filters() |
isset($mail) && !$headers && $header && !$content && $content_type !== "text/html" | 55–56 | explode(), explode(), strtolower(), apply_filters() |
isset($mail) && !$headers && $header && $content && $content_type === "text/html" | 60–67 | explode(), strtolower(), explode(), apply_filters(), wp_staticize_emoji() |
isset($mail) && !$headers && $header && !$content && $content_type === "text/html" | 62–63 | explode(), explode(), strtolower(), apply_filters(), wp_staticize_emoji() |
isset($mail) && !$headers && $header && $content && $content_type !== "text/html" | 64–65 | explode(), explode(), strtolower(), explode(), apply_filters() |
1 further outcome, up to 72 instructions
isset($mail) && !$headers && $header && $content && $content_type === "text/html" | 71–72 | explode(), explode(), strtolower(), explode(), apply_filters(), wp_staticize_emoji() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 77 | 4–72 | 10 | |
| 8.5 | 77 | 4–72 | 10 | |
| 8.4 | 77 | 4–72 | 10 | 21 fewer instructions than PHP 8.3 |
| 8.3 | 98 | 4–90 | 10 | |
| 8.2 | 98 | 4–90 | 10 | |
| 8.1 | 98 | 4–90 | 10 | |
| 7.4 | 98 | 4–90 | 10 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Hooks and filters fired · 1
One hook fires while wp_staticize_emoji_for_email() runs, in this order:
- apply_filters( wp_mail_content_type )filterline 6146 (+50 into the body)
Filters the wp_mail() content type.
Uses · 3
- str_contains()Polyfill for `str_contains()` function added in PHP 8.0.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- wp_staticize_emoji()Converts emoji to a static img element.
Source code
function wp_staticize_emoji_for_email( $mail ) { if ( ! isset( $mail['message'] ) ) { return $mail; } /* * We can only transform the emoji into images if it's a `text/html` email. * To do that, here's a cut down version of the same process that happens * in wp_mail() - get the `Content-Type` from the headers, if there is one, * then pass it through the {@see 'wp_mail_content_type'} filter, in case * a plugin is handling changing the `Content-Type`. */ $headers = array(); if ( isset( $mail['headers'] ) ) { if ( is_array( $mail['headers'] ) ) { $headers = $mail['headers']; } else { $headers = explode( "\n", str_replace( "\r\n", "\n", $mail['headers'] ) ); } } foreach ( $headers as $header ) { if ( ! str_contains( $header, ':' ) ) { continue; } // Explode them out. list( $name, $content ) = explode( ':', trim( $header ), 2 ); // Cleanup crew. $name = trim( $name ); $content = trim( $content ); if ( 'content-type' === strtolower( $name ) ) { if ( str_contains( $content, ';' ) ) { list( $type, $charset ) = explode( ';', $content ); $content_type = trim( $type ); } else { $content_type = trim( $content ); } break; } } // Set Content-Type if we don't have a content-type from the input headers. if ( ! isset( $content_type ) ) { $content_type = 'text/plain'; } /** This filter is documented in wp-includes/pluggable.php */ $content_type = apply_filters( 'wp_mail_content_type', $content_type ); if ( 'text/html' === $content_type ) { $mail['message'] = wp_staticize_emoji( $mail['message'] ); } return $mail;}Changelog
Introduced in 4.2.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.8.8 tag, from
src/wp-includes/formatting.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.