Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timing functions for hooks #78

Merged
merged 4 commits into from
Jul 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions qmx-time-hooks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

defined( 'WPINC' ) || die();

function qmx_time_hooks( string $start_lap_stop ) : void {
if ( ! doing_action() ) {
return;
}

if ( ! in_array( $start_lap_stop, array( 'start', 'lap', 'stop' ) ) ) {
return;
}

global $wp_filter;

$label = current_action();
$action = sprintf( 'qm/%s', $start_lap_stop );
$priority = '';

if ( 'lap' === $start_lap_stop ) {
$priority = $wp_filter[ current_action() ]->current_priority();
}

do_action( $action, $label, $priority );
}

/**
* @return void
*/
function qmx_start() : void {
qmx_time_hooks( 'start' );
}

/**
* @return void
*/
function qmx_lap() : void {
qmx_time_hooks( 'lap' );
}

/**
* @return void
*/
function qmx_stop() : void {
qmx_time_hooks( 'stop' );
}

/**
* @return void
*/
function qmx_auto() : void {
if ( ! doing_action() ) {
return;
}

qmx_time_hooks( 'start' );
add_action( current_action(), 'qmx_stop', PHP_INT_MAX );
}
3 changes: 3 additions & 0 deletions query-monitor-extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,8 @@
}
}

# Include hook timing feature.
include_once $dir . 'qmx-time-hooks.php';

# Include additional conditionals.
include_once $dir . 'qmx-conditionals.php';
Loading