Prepares arrays of value/format pairs as passed to wpdb CRUD methods.
Parameters
$data
arrayrequired- Array of values keyed by their field names.
$format
string[]|stringrequired- Formats or format to be mapped to the values in the data.
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
Version | Description |
---|---|
4.2.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.