Wordpress:为什么多次调用 init 钩子? [英] Wordpress: why is the init hook invoked multiple times?

查看:31
本文介绍了Wordpress:为什么多次调用 init 钩子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这个问题上真的很茫然.我刚刚创建了一个插件,为了记录插件中的操作(因为我看不到处理的输出),我添加了一个钩子到 init 像这样:

I am at a real loss at this problem. I just created a plug-in, and to log the actions in the plug-in (as I can't see the output of the processing), I added a hook to init like so:

add_action('init', 'test_hook');

function test_hook()
{

   global $wpdb;
   $message = "Some informational message here";
   $wpdb->insert("pq_logs", array("message"=>$message), array("%s"));

}

让我接受的是,不是每次加载页面获取一行条目,而是获得相同日志的 1 到 8 行条目,带有不同的时间戳.输入的条目数量不一致,似乎完全随机(有时我认为这取决于当前的天气状况或证券交易所指数).

What's bringing me into submission is that instead of getting one line of entry per page load, I get from 1 to 8 row entries of the same log, with different time stamps. The number of entries that is entered is inconsistent and seems to be totally in random (sometimes I'm thinking it depends on the current weather conditions or the stock exchange index).

我做了标准检查,关闭了所有其他插件,但无济于事.我搜索了任何可以执行 do_action('init') 的代码,但我只被指出了在 wp-settings.php 上的一个调用.

I did the standard checks, turned off all other plug-ins, but to no avail. I searched for the code for anything that does do_action('init'), but I was only pointed out to one call at wp-settings.php.

你也遇到过吗?你做了什么?

Have you also encountered? What did you do?

推荐答案

您在站点中是否有任何 404 链接(图像、脚本、样式表等)?如果是这样,默认 404 页面将在默认站点主题中显示您正在寻找不在这里的东西"页面,因此您最终会为初始页面请求调用一次 init 钩子,并为每个请求调用一次链接错误.

Do you have any links in the site (images, scripts, stylesheets, etc) that are 404'ing? If so, the default 404 page will display a "You are looking for something that is not here" page in the default site theme, so you'll end up getting the init hook called once for the initial page request, plus once for each bad link.

用 Firebug 仔细检查一下,看看是否有什么东西被错误地调用了.

Doublecheck with Firebug and see if anything is being called incorrectly.

这篇关于Wordpress:为什么多次调用 init 钩子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆