I’ve got a problem on my WordPress site which I tracked down to admin_init being called twice.
I tried deactivating all the plugins and the problem goes away. I then reinstated each plugin and found which one is causing the problem.
My question is, how can I find the cause of the extra admin_init call ?
The plugin is bespoke to the site so I can’t simply replace with a different plugin and it’s one (blushes profusely) that I have muddled together myself.
Here’s what I’ve got so far after doing some research on the subject…
I’ve added
remove_filter("wp_head", "adjacent_posts_rel_link_wp_head",10);
to the functions.php file (although this may only stop the “init” hook being called twice and not the “admin_init”)?
I set up a function that sends me an email every time admin_init is called. Whilst generating the email I added the following code to it:
$backtrace = print_r(debug_backtrace(), true);
and then added $backtrace to the email text.
The first email I get has the full backtrace showing all the functions that have led up to the admin_init call originating from “admin-ajax.php”. The second admin_init call email doesn’t have any backtrace info at all ?
I also read that multiple calls to the init (and presumably admin_init hook) can be caused by images on the site (or other inclusions) returning a 404 error.
I have right-clicked and “inspected element” on the page to open the Firebug window and had a look through the tabs but I’m not 100% sure how to check for this. I didn’t see anything odd or 404’ing under any of the tabs but if someone could just clarify the procedure for checking this I’ll be able re-check for definite.
So… any other ideas as to why I’m getting this extra admin_init call and what I can check in the software to see where it’s being generated?
Thanks.
I have managed to cure this problem now.
I set the following in wp-config.php:
error_reporting(E_ALL); ini_set('display_errors', 1);
This turned on strict fault reporting.
My site was immediately peppered with Notices about problems.
I systematically went through and fixed every one of them and then my original problem disappeared as well.
I’m unsure of the exact fix but that would probably be site specfiic anyway so thought I’d post this in case it helps anyone else in the future.