Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Trying to find an issue with my theme that is not related with this question, I've started the debugger and enabled a breakpoint to the first line of a function hooked to after_setup_theme.

Here I've realized that the function is called three times, before the page is rendered.

Is that normal? Isn't this action supposed to be called only one time?

Here's an excerpt of the functions.php (after_setup_theme is the only hook in functions.php):

function get_theme_text_domain()
{
    $theme = wp_get_theme();
    return $theme->get('TextDomain');
}

//This is the function that is called 3 times when opening any page of the site
function tamtando_theme_setup()
{
    load_textdomain(get_theme_text_domain(), get_template_directory() . '/languages');
    //[...]
}

add_action('after_setup_theme', 'tamtando_theme_setup');

To clarify, checking the value of $wp_filter['after_setup_theme'], I've found 2 hooks: one is from my theme, the other, from the "Event Organiser" plugin, calling a different function (I wonder why the developer is using this hook, but this doesn't relate to this issue).

share|improve this question
    
Post your code please. –  s_ha_dum Jun 21 '13 at 18:09
    
Do you have any wp-cron jobs queued for processing? WordPress can make calls back to itself to process things, and this can cause the whole page to load again, including the hooks. –  Otto Jun 21 '13 at 18:46
    
No, the wp-cron is disabled in the wp-config. –  Andrea Sciamanna Jun 21 '13 at 18:56
2  
@AndreaSciamanna - EO uses that hook to define a constant pointing to the plug-in's directory. It uses after_setup_theme - because someone complained that their theme set up symlinks and they weren't able to over-ride the value assigned to the constant from their theme. I maintain that theme's shouldn't be doing that (a plug-ins job) but anyhow - that's what that function is doing :). –  Stephen Harris Jun 22 '13 at 11:31
    
Good to know @Stephen :) –  Andrea Sciamanna Jun 22 '13 at 15:10
add comment

2 Answers 2

Hooks and filters can have several Actions attached. Hence the $priority argument. In short: It's just a big multi dimensional array where the key is the hook/filter name and the values are the attached callbacks plus their priority.

share|improve this answer
    
Yes, I know that, but this is the "after_setup_theme" and as far as I can see, in my theme, this actions is hooked only once. Unless some plugin hooks to my function (but how it could know the function name, considering that it has a very unique name?), to me it seems that WP itself is executing this action 3 times and, again, I wonder if this is normal. –  Andrea Sciamanna Jun 21 '13 at 17:37
    
Do a var_dump( $GLOBALS['wp_filter']['after_setup_theme'] ); for more info. –  kaiser Jun 21 '13 at 19:29
    
See my last edit (the last sentences). –  Andrea Sciamanna Jun 21 '13 at 19:55
add comment

after_setup_theme action should be called only once. It's called on line 294 of wp-settings.php file directly (not inside any function). So I don't see how/why it could be called 3 times.

The only reason I can think of to this situation (debugger stopping on this function) is that wp_cron is processing some scheduled events. I'm not sure if it will call this action then, but it definitely will include wp-settings.php file and I don't see any if statements that will disable this action when it's wp_cron, so it's possible.

Remember that WordPress has some events scheduled even when you don't schedule them manually.

You should also check What happens when you add echo 'bla'; in your after_setup_theme callback? Will it be echoed 3 times? Maybe it's only some debugger issue?

share|improve this answer
    
I've already stated the wp-cron is disabled. By the way, even supposing that is enabled, after_setup_theme is called ALWAYS 3 times, when loading a page. If wp-cron would be the issue, the function would be called continuously (the debugger is always enabled), instead, the 3 times it's a constant. –  Andrea Sciamanna Jun 21 '13 at 19:55
1  
Sorry, didn't see info about wp-cron is disabled. What happens when you add echo 'bla'; in your after_setup_theme callback? Will it be echoed 3 times? Maybe it's only some debugger issue? –  Krzysiek Dróżdż Jun 21 '13 at 19:58
    
Oh, well... it appears you're right. I see only one echo. –  Andrea Sciamanna Jun 21 '13 at 20:12
    
OK. I would also check it with some logging into file solution. Maybe there are some redirects or output is buffered and cleaned, so you see it only once. –  Krzysiek Dróżdż Jun 21 '13 at 20:17
    
I really think it's a debugger issue. If you post your comment as answer, I'll mark it as answered. –  Andrea Sciamanna Jun 22 '13 at 15:11
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.