Support » Alpha/Beta/RC » Site ignoring 'after_setup_theme' hook

  • Resolved Jack Reichert

    (@jackreichert)


    I’m using WordPress 3.4-beta4-20778

    Here is the code.

    add_action('after_setup_theme', 'theme_activation');
    function theme_activation(){
    	wp_schedule_event(time(), 'twicedaily', 'hourly_uploads_cleanup');
    	flush_rewrite_rules();
    }

    I haven’t used this hook before but I understand it is supposed to only fire when the theme is activated. But each time I refresh my site I see more cron jobs added..

    (using Cron GUI)

    May 15, 2012 @ 6:59 (1337065164)	 Twice Daily	hourly_uploads_cleanup
    May 15, 2012 @ 6:59 (1337065181)	 Twice Daily	hourly_uploads_cleanup
    May 15, 2012 @ 6:59 (1337065185)	 Twice Daily	hourly_uploads_cleanup
    May 15, 2012 @ 6:59 (1337065186)	 Twice Daily	hourly_uploads_cleanup
    May 15, 2012 @ 6:59 (1337065193)	 Twice Daily	hourly_uploads_cleanup
    May 15, 2012 @ 7:02 (1337065330)	 Twice Daily	hourly_uploads_cleanup

    Is my code wrong or is this a bug?

    Thank you.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Try using switch_theme instead of after_setup_theme – the setup hook isn’t for activation, but for events that need to fire before init on any given load (most commonly post thumbnail support).

    (or better yet, put it in a plugin, where you have register_activation_hook; “hourly uploads cleanup” doesn’t sound like something that ought to be handled in a theme)

    Thread Starter Jack Reichert

    (@jackreichert)

    Thanks

    In the codex the page for after_setup_theme says:

    This hook is called during a themes initialization. Is generally used to perform basic setup, registration, and init actions for a theme.

    It sounds like it should work the way I set it up to work.

    “theme initialization” in this context refers to loading the theme’s functions during an average page display – not when the theme is first activated.

    Thread Starter Jack Reichert

    (@jackreichert)

    I checked out the action switch_theme and the “Usage” section had the usage for the function, so I fixed that in the wiki.

    Thanks for your help.

    Thread Starter Jack Reichert

    (@jackreichert)

    Thanks @esmi.

    A bit confusing but now what was happening makes sense.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Site ignoring 'after_setup_theme' hook’ is closed to new replies.