wpdb::strip_invalid_text( array $data ): array|WP_Error
- Since
- 4.2.0
- Source
wp-includes/class-wpdb.php:3624
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
$dataarray- Array of value arrays. Each value array has the keys 'value', 'charset', and 'length'.
An optional 'ascii' key can be set to false to avoid redundant ASCII checks.
Return value
array|WP_Error- The $data parameter, with invalid characters removed from each value.
This works as a passthrough: any additional keys such as 'field' are retained in each value array. If we cannot remove invalid characters, a WP_Error object is returned.
Performance profile
How much work a call to wpdb::strip_invalid_text() 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
- Heavy
- Scaling
- Scales with input
- Instructions
- 7–34
- Plugin surface
- None
- Called by
- 3
Reaches the database via ->get_row().
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 214.
Nothing here hands control to plugin code.
3 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- sqldatabase query
->get_row()called directly
Further down the call graph this can also reach option, hook, cache, serialize, query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 3 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wpdb::strip_invalid_text() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 7–8 | none |
| always | 29–33 | ->get_row(), array_keys() |
| always | 31–34 | ->get_row(), __() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 220 | 7–34 | 35 | 6 more instructions than PHP 8.5 |
| 8.5 | 214 | 7–34 | 34 | |
| 8.4 | 214 | 7–34 | 34 | 9 fewer instructions than PHP 8.3 |
| 8.3 | 223 | 7–37 | 34 | |
| 8.2 | 223 | 7–37 | 34 | |
| 8.1 | 223 | 7–37 | 34 | |
| 7.4 | 223 | 7–37 | 34 |
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 · 9
- mbstring_binary_safe_encoding()Sets the mbstring internal encoding to a binary safe encoding when func_overload is enabled.
- reset_mbstring_encoding()Resets the mbstring internal encoding to a users previously set encoding.
- mb_strlen()Compat function to mimic mb_strlen().
- mb_substr()Compat function to mimic mb_substr().
- __()Retrieves the translation of $text.
- wpdb::check_ascii()Checks if a string is ASCII.
- wpdb::prepare()Prepares a SQL query for safe execution.
- wpdb::get_row()Retrieves one row from the database.
- WP_Error::__construct()Initializes the error.
Used by · 3
- wpdb::process_fields()Processes arrays of field/value pairs and field formats.
- wpdb::strip_invalid_text_for_column()Strips any invalid characters from the string for a given table and column.
- wpdb::strip_invalid_text_from_query()Strips any invalid characters from the query.
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 7.1.0 tag, from
src/wp-includes/class-wpdb.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.