public static get_table ( array $array, string $col1, string $col2, string | array $class = null ) : string | ||
$array | array | Array to be shown in the table. |
$col1 | string | Label for the first table column. |
$col2 | string | Label for the second table column. |
$class | string | array | One or more CSS classes to add to the table. |
리턴 | string |
public static function get_table($array, $col1, $col2, $class = null)
{
$classes = 'debug-bar-table ' . sanitize_html_class(self::NAME);
if (isset($class)) {
if (is_string($class) && '' !== $class) {
$classes .= ' ' . sanitize_html_class($class);
} else {
if (!empty($class) && is_array($class)) {
$class = array_map($class, 'sanitize_html_class');
$classes = $classes . ' ' . implode(' ', $class);
}
}
}
$col1 = is_string($col1) ? $col1 : __('Key', 'db-pretty-output');
$col2 = is_string($col2) ? $col2 : __('Value', 'db-pretty-output');
$double_it = false;
if (count($array) > self::TBODY_MAX) {
$double_it = true;
}
$return = self::get_table_start($col1, $col2, $classes, $double_it);
$return .= self::get_table_rows($array);
$return .= self::get_table_end();
return $return;
}
/** * Helper method to render the output in a table * * @param array $array Array to be shown in the table * @param string $col1 Label for the first table column * @param string $col2 Label for the second table column * @param string|array $class One or more CSS classes to add to the table */ public function dbc_render_table($array, $col1 = null, $col2 = null, $class = null) { $classes = self::DBC_NAME; if (isset($class)) { if (is_string($class) && $class !== '') { $classes .= ' ' . $class; } else { if (is_array($class) && $class !== array()) { $classes = $classes . ' ' . implode(' ', $class); } } } $col1 = isset($col1) ? $col1 : __('Name', self::DBC_NAME); $col2 = isset($col2) ? $col2 : __('Value', self::DBC_NAME); uksort($array, 'strnatcasecmp'); if (defined('Debug_Bar_Pretty_Output::VERSION')) { echo Debug_Bar_Pretty_Output::get_table($array, $col1, $col2, $classes); // xss: ok } else { // An old version of the pretty output class was loaded Debug_Bar_Pretty_Output::render_table($array, $col1, $col2, $classes); } }