collector;
if ( ! $collector::enabled() ) {
$this->before_non_tabular_output();
echo '';
echo '';
echo '
';
printf(
/* translators: %s: Configuration file name. */
esc_html__( 'For performance reasons, this panel is not enabled by default. To enable it, add the following code to your %s file:', 'query-monitor' ),
'wp-config.php'
);
echo '
';
echo "
define( 'QM_ENABLE_CAPS_PANEL', true );
";
echo '
';
echo '';
$this->after_non_tabular_output();
return;
}
/** @var QM_Data_Caps */
$data = $this->collector->get_data();
if ( ! empty( $data->caps ) ) {
$this->before_tabular_output();
$results = array(
'true',
'false',
);
$parts = $data->parts;
$components = $data->components;
usort( $parts, 'strcasecmp' );
usort( $components, 'strcasecmp' );
echo '';
echo '';
echo '| ';
echo $this->build_filter( 'name', $parts, __( 'Capability Check', 'query-monitor' ) ); // WPCS: XSS ok;
echo ' | ';
$users = $data->users;
sort( $users );
echo '';
echo $this->build_filter( 'user', $users, __( 'User', 'query-monitor' ) ); // WPCS: XSS ok;
echo ' | ';
echo '';
echo $this->build_filter( 'result', $results, __( 'Result', 'query-monitor' ) ); // WPCS: XSS ok;
echo ' | ';
echo '' . esc_html__( 'Caller', 'query-monitor' ) . ' | ';
echo '';
echo $this->build_filter( 'component', $components, __( 'Component', 'query-monitor' ) ); // WPCS: XSS ok.
echo ' | ';
echo '
';
echo '';
echo '
';
foreach ( $data->caps as $row ) {
$component = $row['component'];
$row_attr = array();
$row_attr['data-qm-name'] = implode( ' ', $row['parts'] );
$row_attr['data-qm-user'] = $row['user'];
$row_attr['data-qm-component'] = $component->name;
$row_attr['data-qm-result'] = ( $row['result'] ) ? 'true' : 'false';
if ( 'core' !== $component->context ) {
$row_attr['data-qm-component'] .= ' non-core';
}
if ( '' === $row['name'] ) {
$row_attr['class'] = 'qm-warn';
}
$attr = '';
foreach ( $row_attr as $a => $v ) {
$attr .= ' ' . $a . '="' . esc_attr( $v ) . '"';
}
printf( // WPCS: XSS ok.
'',
$attr
);
$name = esc_html( $row['name'] );
if ( ! empty( $row['args'] ) ) {
foreach ( $row['args'] as $arg ) {
$name .= ', ' . esc_html( QM_Util::display_variable( $arg ) );
}
}
printf( // WPCS: XSS ok.
'%s | ',
$name
);
printf(
'%s | ',
esc_html( $row['user'] )
);
$result = ( $row['result'] ) ? 'true ✓' : 'false';
printf( // WPCS: XSS ok.
'%s | ',
$result
);
$stack = array();
foreach ( $row['filtered_trace'] as $frame ) {
$stack[] = self::output_filename( $frame['display'], $frame['calling_file'], $frame['calling_line'] );
}
$caller = array_shift( $stack );
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 ' | ';
printf(
'%s | ',
esc_html( $component->name )
);
echo '
';
}
echo '';
echo '';
$count = count( $data->caps );
echo '';
echo '| ';
printf(
/* translators: %s: Number of user capability checks */
esc_html( _nx( 'Total: %s', 'Total: %s', $count, 'User capability checks', 'query-monitor' ) ),
'' . esc_html( number_format_i18n( $count ) ) . ''
);
echo ' | ';
echo '
';
echo '';
$this->after_tabular_output();
} else {
$this->before_non_tabular_output();
$notice = __( 'No capability checks were recorded.', 'query-monitor' );
echo $this->build_notice( $notice ); // WPCS: XSS ok.
$this->after_non_tabular_output();
}
}
/**
* @param array $menu
* @return array
*/
public function admin_menu( array $menu ) {
$menu[ $this->collector->id() ] = $this->menu( array(
'title' => $this->name(),
) );
return $menu;
}
}
/**
* @param array $output
* @param QM_Collectors $collectors
* @return array
*/
function register_qm_output_html_caps( array $output, QM_Collectors $collectors ) {
$collector = QM_Collectors::get( 'caps' );
if ( $collector ) {
$output['caps'] = new QM_Output_Html_Caps( $collector );
}
return $output;
}
add_filter( 'qm/outputter/html', 'register_qm_output_html_caps', 105, 2 );