wpdb::process_field_formats( array $data, string[]|string $format ): array

In this article

Prepares arrays of value/format pairs as passed to wpdb CRUD methods.

Parameters

$dataarrayrequired
Array of values keyed by their field names.
$formatstring[]|stringrequired
Formats or format to be mapped to the values in the data.

Return

array Array of values and formats keyed by their field names.
  • value mixed
    The value to be formatted.
  • format string
    The format to be mapped to the value.

Source

protected function process_field_formats( $data, $format ) {
	$formats          = (array) $format;
	$original_formats = $formats;

	foreach ( $data as $field => $value ) {
		$value = array(
			'value'  => $value,
			'format' => '%s',
		);

		if ( ! empty( $format ) ) {
			$value['format'] = array_shift( $formats );
			if ( ! $value['format'] ) {
				$value['format'] = reset( $original_formats );
			}
		} elseif ( isset( $this->field_types[ $field ] ) ) {
			$value['format'] = $this->field_types[ $field ];
		}

		$data[ $field ] = $value;
	}

	return $data;
}

Changelog

VersionDescription
4.2.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.