wxr_cdata( string|null $str ): string
- Since
- 2.1.0
- Source
wp-admin/includes/export.php:245
Compatibility
- WordPress
- since 2.1.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
$strstring|null- String to wrap in XML CDATA tag. May be null.
Return value
string
Performance profile
How much work a call to wxr_cdata() 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
- Trivial
- Scaling
- Constant
- Instructions
- 13–17
- Plugin surface
- None
- Called by
- 11
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 17.
Nothing here hands control to plugin code.
11 places in core call this, so the cost is paid more often than your own code shows.
What one call costs · 2 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wxr_cdata() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
wp_is_valid_utf8() | 13 | wp_is_valid_utf8() |
!wp_is_valid_utf8() | 17 | wp_is_valid_utf8(), utf8_encode() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 17 | 13–17 | 1 | |
| 8.5 | 17 | 13–17 | 1 | |
| 8.4 | 17 | 13–17 | 1 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 20 | 16–20 | 1 | |
| 8.2 | 20 | 16–20 | 1 | |
| 8.1 | 20 | 16–20 | 1 | |
| 7.4 | 20 | 16–20 | 1 |
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.
Uses · 2
- wp_is_valid_utf8()Determines if a given byte string represents a valid UTF-8 encoding.
- utf8_encode()Converts a string from ISO-8859-1 to UTF-8.
Used by · 11
- export_wp()Generates the WXR export file for download.
- wxr_authors_list()Outputs list of authors with posts.
- wxr_cat_name()Outputs a cat_name XML tag from a given category object.
- wxr_category_description()Outputs a category_description XML tag from a given category object.
- wxr_nav_menu_terms()Outputs all navigation menu terms.
- wxr_post_taxonomy()Outputs list of taxonomy terms, in XML tag format, associated with a post.
- wxr_tag_description()Outputs a tag_description XML tag from a given tag object.
- wxr_tag_name()Outputs a tag_name XML tag from a given tag object.
- wxr_term_description()Outputs a term_description XML tag from a given term object.
- wxr_term_meta()Outputs term meta XML tags for a given term object.
- wxr_term_name()Outputs a term_name XML tag from a given term object.
Source code
function wxr_cdata( $str ) { $str = (string) $str; if ( ! wp_is_valid_utf8( $str ) ) { $str = utf8_encode( $str ); } // $str = ent2ncr(esc_html($str)); $str = '<![CDATA[' . str_replace( ']]>', ']]]]><![CDATA[>', $str ) . ']]>'; return $str; }Changelog
Introduced in 2.1.0. One change between 6.7.7 and 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
$str retyped from string to string|null.verified against sourceAbout this page
- Parsed data
- Generated from the wordpress-develop 7.0.4 tag, from
src/wp-admin/includes/export.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.