/** * 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); } }
/** * Render the screen info. * * @return string */ public function screen_info_render() { /* Set parentage of current page Isn't set yet as it is set from admin_header.php which is run after the admin bar has loaded on the admin side */ if (isset($GLOBALS['current_screen']) && is_object($GLOBALS['current_screen']) && (isset($GLOBALS['parent_file']) && is_string($GLOBALS['parent_file']) && $GLOBALS['parent_file'] !== '')) { $GLOBALS['current_screen']->set_parentage($GLOBALS['parent_file']); } $screen = get_current_screen(); if (isset($screen) && is_object($screen)) { $properties = get_object_vars($screen); if (is_array($properties) && $properties !== array()) { $output = ' <h2><span>' . esc_html__('Screen:', $this->plugin_slug) . '</span>' . esc_html($screen->id) . '</h2> <h2><span>' . esc_html__('Properties:', $this->plugin_slug) . '</span>' . count($properties) . '</h2>'; uksort($properties, 'strnatcasecmp'); if (!class_exists('Debug_Bar_Pretty_Output')) { require_once plugin_dir_path(__FILE__) . 'inc/debug-bar-pretty-output/class-debug-bar-pretty-output.php'; } if (defined('Debug_Bar_Pretty_Output::VERSION')) { add_filter('db_pretty_output_table_header', array($this, 'filter_pretty_output_table_header_row')); add_filter('db_pretty_output_table_body_row', array($this, 'filter_pretty_output_table_body_row'), 10, 2); $output .= Debug_Bar_Pretty_Output::get_table($properties, __('Property', $this->plugin_slug), __('Value', $this->plugin_slug), $this->plugin_slug); remove_filter('db_pretty_output_table_header', array($this, 'filter_pretty_output_table_header_row')); remove_filter('db_pretty_output_table_body_row', array($this, 'filter_pretty_output_table_body_row'), 10, 2); } else { /* An old version of the pretty output class was loaded, the explanations will not be added to the table */ ob_start(); Debug_Bar_Pretty_Output::render_table($properties, __('Property', $this->plugin_slug), __('Value', $this->plugin_slug), $this->plugin_slug); $output .= ob_get_contents(); ob_end_clean(); } } } else { $output = '<h2>' . esc_html__('No Screen Info Found', $this->plugin_slug) . '</h2>'; } $output .= '<p>' . sprintf(esc_html__('For more information, see the %sCodex on WP_Screen', $this->plugin_slug), '<a href="http://codex.wordpress.org/Class_Reference/WP_Screen" target="_blank" title="' . esc_attr__('View the WordPress codex on WP Screen', $this->plugin_slug) . '">') . '</a></p>'; return $output; }
/** * Reset the recusion limit to it's default (unlimited). * * @since 1.4 */ public static function unset_recursion_limit() { self::$limit_recursion = false; }
/** * Create a property table for standard/custom properties. * * @since 1.2 * * @param array $properties Array of post type properties. * @param array $names Array of post type names. * @param string $table_name Translated name for this table. * @param bool $double Whether or not to repeat the row labels at the end of the table. */ protected function render_property_table($properties, $names, $table_name, $double) { /* Create header row. */ $header_row = ' <tr> <th>' . esc_html__('Property', self::DBPT_NAME) . '</th>'; foreach ($names as $name) { $header_row .= ' <th>' . esc_html($name) . '</th>'; } unset($name); if ($double === true) { $header_row .= ' <th class="' . self::DBPT_NAME . '-table-end">' . esc_html__('Property', self::DBPT_NAME) . '</th>'; } $header_row .= ' </tr>'; echo ' <h3>', esc_html($table_name), '</h3> <table class="debug-bar-table ', self::DBPT_NAME, '"> <thead> ', $header_row, ' </thead> <tfoot> ', $header_row, ' </tfoot> <tbody>'; unset($header_row); /* Sort. */ uksort($properties, 'strnatcasecmp'); /* Output. */ foreach ($properties as $key => $value) { echo ' <tr> <th>', esc_html($key), '</th>'; foreach ($names as $name) { echo ' <td>'; if (isset($value[$name])) { if (defined('Debug_Bar_Pretty_Output::VERSION')) { echo Debug_Bar_Pretty_Output::get_output($value[$name], '', true, '', true); // WPCS: XSS ok. } else { // An old version of the pretty output class was loaded. Debug_Bar_Pretty_Output::output($value[$name], '', true, '', true); } } else { echo ' '; } echo ' </td>'; } unset($name); if ($double === true) { echo ' <th class="', self::DBPT_NAME, '-table-end">', esc_html($key), '</th>'; // WPCS: XSS ok. } echo ' </tr>'; } unset($key, $value); echo ' </tbody> </table> '; }
/** * Unset recursion depth limit for the pretty output class. * * @internal Method available since DBPO v1.4. */ private function reset_debug_bar_pretty_output() { if (method_exists('Debug_Bar_Pretty_Output', 'unset_recursion_limit')) { Debug_Bar_Pretty_Output::unset_recursion_limit(); } }