我正在尝试创建一个小时间测试程序,在get\\u header hook加载,使用该值在wp\\u footer中执行某些操作。。。
我尝试使用全局$var,我尝试将全局var放入函数中,我尝试将其附加到wp\\u头,而不是get\\u头
Here is a simplefied ver of the the code:
// LOAD TIME CHECKER
function start_timer() {
global $time_start;
$time_start = microtime(true);
}
add_action(\'wp_head\', \'start_timer\', 1);
if(is_user_logged_in()) {
function end_time() {
echo \'
<div class="clearfix"></div>
<div id="queryTime" style="position: fixed; bottom: 30px; left: 30px;">
<ul class="li"><span class="label label-success fs13">Start Time: \'.$time_start.\'</span></ul>
<ul class="li"><span class="label label-success fs13">Query Took: \'.number_format( microtime(true) - $time_start, 10).\'</span></ul>
</div>
\';
}
add_action(\'wp_footer\', \'end_time\', 100);
}
有人能提供一个有点解释的指针吗?试图理解我做错了什么。
最合适的回答,由SO网友:Parth Kumar 整理而成
您需要在end\\u time()中重新声明变量,而且不需要用户登录。。你可以试试下面的答案。
// LOAD TIME CHECKER
function start_timer() {
global $time_start;
$time_start = microtime(true);
}
add_action(\'wp_head\', \'start_timer\', 1);
function end_time() {
//try redeclaring the var
global $time_start;
echo \'
<div class="clearfix"></div>
<div id="queryTime" style="position: fixed; bottom: 30px; left: 30px;">
<ul class="li"><span class="label label-success fs13">Start Time: \'.$time_start.\'</span></ul>
<ul class="li"><span class="label label-success fs13">Query Took: \'.number_format( microtime(true) - $time_start, 10).\'</span></ul>
</div>
\';
}
add_action(\'wp_footer\', \'end_time\', 100);