On this page
wpdb::strip_invalid_text_from_query( string $query ): string|WP_Error
Strips any invalid characters from the query.
Parameters
$querystring Required-
Query to convert.
Return
string|WP_Error The converted query, or a WP_Error object if the conversion fails.
Source
File: wp-includes/class-wpdb.php. View all references
protected function strip_invalid_text_from_query( $query ) {
// We don't need to check the collation for queries that don't read data.
$trimmed_query = ltrim( $query, "\r\n\t (" );
if ( preg_match( '/^(?:SHOW|DESCRIBE|DESC|EXPLAIN|CREATE)\s/i', $trimmed_query ) ) {
return $query;
}
$table = $this->get_table_from_query( $query );
if ( $table ) {
$charset = $this->get_table_charset( $table );
if ( is_wp_error( $charset ) ) {
return $charset;
}
// We can't reliably strip text from tables containing binary/blob columns.
if ( 'binary' === $charset ) {
return $query;
}
} else {
$charset = $this->charset;
}
$data = array(
'value' => $query,
'charset' => $charset,
'ascii' => false,
'length' => false,
);
$data = $this->strip_invalid_text( array( $data ) );
if ( is_wp_error( $data ) ) {
return $data;
}
return $data[0]['value'];
}
Related
Uses
| Uses | Description |
|---|---|
| wpdb::get_table_from_query() wp-includes/class-wpdb.php | Finds the first table name referenced in a query. |
| wpdb::get_table_charset() wp-includes/class-wpdb.php | Retrieves the character set for the given table. |
| wpdb::strip_invalid_text() wp-includes/class-wpdb.php | Strips any invalid characters based on value/charset pairs. |
| is_wp_error() wp-includes/load.php | Checks whether the given variable is a WordPress Error. |
Used By
| Used By | Description |
|---|---|
| wpdb::query() wp-includes/class-wpdb.php | Performs a database query, using current database connection. |
Changelog
| Version | Description |
|---|---|
| 4.2.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wpdb/strip_invalid_text_from_query