wpdb::process_field_lengths() WordPress Method

The wpdb::process_field_lengths() method is used to process the lengths of fields returned from a database table. This is used to ensure that the fields are the correct length for the data being stored in them.

wpdb::process_field_lengths( array $data, string $table ) #

For string fields, records the maximum string length that field can safely save.


Parameters

$data

(array)(Required)As it comes from the wpdb::process_field_charsets() method.

$table

(string)(Required)Table name.


Top ↑

Return

(array|false) The same array as $data with additional 'length' keys, or false if any of the values were too long for their corresponding field.


Top ↑

Source

File: wp-includes/wp-db.php

	protected function process_field_lengths( $data, $table ) {
		foreach ( $data as $field => $value ) {
			if ( '%d' === $value['format'] || '%f' === $value['format'] ) {
				/*
				 * We can skip this field if we know it isn't a string.
				 * This checks %d/%f versus ! %s because its sprintf() could take more.
				 */
				$value['length'] = false;
			} else {
				$value['length'] = $this->get_col_length( $table, $field );
				if ( is_wp_error( $value['length'] ) ) {
					return false;
				}
			}

			$data[ $field ] = $value;
		}

		return $data;
	}


Top ↑

Changelog

Changelog
VersionDescription
4.2.1Introduced.

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.