wpdb::strip_invalid_text_for_column() WordPress Method

The wpdb::strip_invalid_text_for_column() method is used to remove invalid characters from a string for a given database column. This is useful when you want to ensure that the data you are going to insert into the database is valid for the column type.

wpdb::strip_invalid_text_for_column( string $table, string $column, string $value ) #

Strips any invalid characters from the string for a given table and column.


Parameters

$table

(string)(Required)Table name.

$column

(string)(Required)Column name.

$value

(string)(Required)The text to check.


Top ↑

Return

(string|WP_Error) The converted string, or a WP_Error object if the conversion fails.


Top ↑

Source

File: wp-includes/wp-db.php

	public function strip_invalid_text_for_column( $table, $column, $value ) {
		if ( ! is_string( $value ) ) {
			return $value;
		}

		$charset = $this->get_col_charset( $table, $column );
		if ( ! $charset ) {
			// Not a string column.
			return $value;
		} elseif ( is_wp_error( $charset ) ) {
			// Bail on real errors.
			return $charset;
		}

		$data = array(
			$column => array(
				'value'   => $value,
				'charset' => $charset,
				'length'  => $this->get_col_length( $table, $column ),
			),
		);

		$data = $this->strip_invalid_text( $data );
		if ( is_wp_error( $data ) ) {
			return $data;
		}

		return $data[ $column ]['value'];
	}


Top ↑

Changelog

Changelog
VersionDescription
4.2.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.