WordPress: why is the init hook invoked multiple times?

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"));

}

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).

Read More

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?

Related posts

Leave a Reply

2 comments

  1. 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.

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