wpdb::process_field_lengths()protectedWP 4.2.1

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

Method of the class: wpdb{}

No Hooks.

Return

Array|false. The same array of data with additional 'length' keys, or false if information for the table cannot be found.

Usage

// protected - for code of main (parent) or child class
$result = $this->process_field_lengths( $data, $table );
$data(array) (required)

Array of values, formats, and charsets keyed by their field names, as it comes from the wpdb::process_field_charsets() method.

  • ...$0(array)
    Value, format, and charset for this field.

    • value(mixed)
      The value to be formatted.

    • format(string)
      The format to be mapped to the value.

    • charset(string|false)
      The charset to be used for the value.
$table(string) (required)
Table name.

Changelog

Since 4.2.1 Introduced.

wpdb::process_field_lengths() code WP 6.5.2

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;
}