wpdb::process_field_charsets()protectedWP 4.2.0

Adds field charsets to field/value/format arrays generated by wpdb::process_field_formats().

Метод класса: wpdb{}

Хуков нет.

Возвращает

Массив|false. The same array of data with additional 'charset' keys, or false if the charset for the table cannot be found.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->process_field_charsets( $data, $table );
$data(массив) (обязательный)

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

  • ...$0(массив)
    Value and format for this field.

    • value(разное)
      The value to be formatted.

    • format(строка)
      The format to be mapped to the value.
$table(строка) (обязательный)
Table name.

Список изменений

С версии 4.2.0 Введена.

Код wpdb::process_field_charsets() WP 6.5.3

protected function process_field_charsets( $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['charset'] = false;
		} else {
			$value['charset'] = $this->get_col_charset( $table, $field );
			if ( is_wp_error( $value['charset'] ) ) {
				return false;
			}
		}

		$data[ $field ] = $value;
	}

	return $data;
}