Skip to content

Commit 34fd414

Browse files
committed
Standardise the display format for closures.
1 parent f6311a1 commit 34fd414

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

output/html/hooks.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,23 @@ export const Hooks = ( { data }: PanelProps<DataTypes['hooks']> ) => {
113113
if ( ! row.callback ) {
114114
return '';
115115
}
116-
const text = row.callback.name || row.callback.display_file || '';
116+
117+
let text: string;
118+
119+
if ( 'closure' === row.callback.callback_type ) {
120+
text = sprintf(
121+
/* translators: A closure is an anonymous PHP function. 1: Line number, 2: File name */
122+
__( 'Closure on line %1$d of %2$s', 'query-monitor' ),
123+
row.callback.start_line ?? 0,
124+
row.callback.display_file ?? ''
125+
);
126+
} else if ( 'unknown_closure' === row.callback.callback_type ) {
127+
/* translators: A closure is an anonymous PHP function */
128+
text = __( 'Unknown closure', 'query-monitor' );
129+
} else {
130+
text = row.callback.name || row.callback.display_file || '';
131+
}
132+
117133
if ( ! text ) {
118134
return '';
119135
}

tests/acceptance/Callbacks.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ test.describe( 'Callback Types in Hooks & Actions', () => {
3333
test( 'Closure callback should be displayed', async ( { QueryMonitor } ) => {
3434
await QueryMonitor.amOnAPageThatTriggersCallbackType( 'closure' );
3535
await QueryMonitor.seeQMMenu();
36-
await QueryMonitor.seeInQMPanel( 'Hooks & Actions', 'Closure: ' );
36+
await QueryMonitor.seeInQMPanel( 'Hooks & Actions', 'Closure on line' );
3737
await QueryMonitor.seeInQMPanel( 'Hooks & Actions', 'acceptance.php' );
3838
await QueryMonitor.seeInQMPanel( 'Hooks & Actions', 'qm_test_hook' );
3939
} );

0 commit comments

Comments
 (0)