*/
public function get_type_labels() {
return array(
/* translators: %s: Total number of Doing it Wrong occurrences */
'total' => _x( 'Total: %s', 'Doing it Wrong', 'query-monitor' ),
'plural' => __( 'Doing it Wrong occurrences', 'query-monitor' ),
/* translators: %s: Total number of Doing it Wrong occurrences */
'count' => _x( 'Doing it Wrong (%s)', 'Doing it Wrong', 'query-monitor' ),
);
}
/**
* @return void
*/
public function output() {
/** @var QM_Data_Doing_It_Wrong $data */
$data = $this->collector->get_data();
if ( empty( $data->actions ) ) {
$this->before_non_tabular_output();
$notice = __( 'No occurrences.', 'query-monitor' );
echo $this->build_notice( $notice ); // WPCS: XSS ok.
$this->after_non_tabular_output();
return;
}
$this->before_tabular_output();
echo '';
echo '';
echo '| ' . esc_html__( 'Message', 'query-monitor' ) . ' | ';
echo '' . esc_html__( 'Caller', 'query-monitor' ) . ' | ';
echo '' . esc_html__( 'Component', 'query-monitor' ) . ' | ';
echo '
';
echo '';
echo '
';
foreach ( $data->actions as $row ) {
$stack = array();
foreach ( $row->get_trace()->get_filtered_trace() as $frame ) {
$stack[] = self::output_filename( $frame['display'], $frame['calling_file'], $frame['calling_line'] );
}
$caller = array_shift( $stack );
echo '';
printf( '| %s | ', esc_html( wp_strip_all_tags( $row->get_message() ) ) );
echo '';
if ( ! empty( $stack ) ) {
echo self::build_toggler(); // WPCS: XSS ok;
}
echo '';
echo "- {$caller}
"; // WPCS: XSS ok.
if ( ! empty( $stack ) ) {
echo '- ' . implode( '
- ', $stack ) . '
'; // WPCS: XSS ok.
}
echo ' | ';
echo '' . esc_html( $row->get_trace()->get_component()->get_name() ) . ' | ';
echo '
';
}
echo '';
echo '';
printf(
'| %s |
',
sprintf(
/* translators: %s: Total number of Doing it Wrong occurrences */
esc_html_x( 'Total: %s', 'Total Doing it Wrong occurrences', 'query-monitor' ),
'' . esc_html( number_format_i18n( count( $data->actions ) ) ) . ''
)
);
echo '';
$this->after_tabular_output();
}
/**
* @param array $class
* @return array
*/
public function admin_class( array $class ) {
/** @var QM_Data_Doing_It_Wrong */
$data = $this->collector->get_data();
if ( ! empty( $data->actions ) ) {
$class[] = 'qm-notice';
}
return $class;
}
/**
* @param array $menu
* @return array
*/
public function admin_menu( array $menu ) {
/** @var QM_Data_Doing_It_Wrong */
$data = $this->collector->get_data();
if ( empty( $data->actions ) ) {
return $menu;
}
$type_label = $this->get_type_labels();
$label = sprintf(
$type_label['count'],
number_format_i18n( count( $data->actions ) )
);
$args = array(
'title' => esc_html( $label ),
'id' => esc_attr( "query-monitor-{$this->collector->id}" ),
'href' => esc_attr( '#' . $this->collector->id() ),
);
if ( ! empty( $data->actions ) ) {
$args['meta']['classname'] = 'qm-notice';
}
$id = $this->collector->id();
$menu[ $id ] = $this->menu( $args );
return $menu;
}
}
/**
* @param array $output
* @param QM_Collectors $collectors
* @return array
*/
function register_qm_output_html_doing_it_wrong( array $output, QM_Collectors $collectors ) {
$collector = QM_Collectors::get( 'doing_it_wrong' );
if ( $collector ) {
$output['doing_it_wrong'] = new QM_Output_Html_Doing_It_Wrong( $collector );
}
return $output;
}
add_filter( 'qm/outputter/html', 'register_qm_output_html_doing_it_wrong', 110, 2 );