WP_Debug_Data::format()public staticWP 5.2.0

Formats the information gathered for debugging, in a manner suitable for copying to a forum or support ticket.

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

Хуков нет.

Возвращает

Строку. The formatted data.

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

$result = WP_Debug_Data::format( $info_array, $data_type );
$info_array(массив) (обязательный)
Information gathered from the WP_Debug_Data::debug_data() function.
$data_type(строка) (обязательный)
The data type to return, either 'info' or 'debug'.

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

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

Код WP_Debug_Data::format() WP 6.4.3

public static function format( $info_array, $data_type ) {
	$return = "`\n";

	foreach ( $info_array as $section => $details ) {
		// Skip this section if there are no fields, or the section has been declared as private.
		if ( empty( $details['fields'] ) || ( isset( $details['private'] ) && $details['private'] ) ) {
			continue;
		}

		$section_label = 'debug' === $data_type ? $section : $details['label'];

		$return .= sprintf(
			"### %s%s ###\n\n",
			$section_label,
			( isset( $details['show_count'] ) && $details['show_count'] ? sprintf( ' (%d)', count( $details['fields'] ) ) : '' )
		);

		foreach ( $details['fields'] as $field_name => $field ) {
			if ( isset( $field['private'] ) && true === $field['private'] ) {
				continue;
			}

			if ( 'debug' === $data_type && isset( $field['debug'] ) ) {
				$debug_data = $field['debug'];
			} else {
				$debug_data = $field['value'];
			}

			// Can be array, one level deep only.
			if ( is_array( $debug_data ) ) {
				$value = '';

				foreach ( $debug_data as $sub_field_name => $sub_field_value ) {
					$value .= sprintf( "\n\t%s: %s", $sub_field_name, $sub_field_value );
				}
			} elseif ( is_bool( $debug_data ) ) {
				$value = $debug_data ? 'true' : 'false';
			} elseif ( empty( $debug_data ) && '0' !== $debug_data ) {
				$value = 'undefined';
			} else {
				$value = $debug_data;
			}

			if ( 'debug' === $data_type ) {
				$label = $field_name;
			} else {
				$label = $field['label'];
			}

			$return .= sprintf( "%s: %s\n", $label, $value );
		}

		$return .= "\n";
	}

	$return .= '`';

	return $return;
}