[wp-trac] [WordPress Trac] #8899: has_action no reporting existing action hook

WordPress Trac wp-trac at lists.automattic.com
Tue Jan 20 15:00:07 GMT 2009


#8899: has_action no reporting existing action hook
--------------------------+-------------------------------------------------
 Reporter:  firebird75    |       Owner:     
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  2.8
Component:  Plugins       |     Version:  2.7
 Severity:  normal        |    Keywords:     
--------------------------+-------------------------------------------------
 I am trying to write a plugin which uses the has_action function.
 Unfortunately, it doesn't seem to be working under specific circunstances.
 It reports that the action isn't existing while it is thus allowing the
 action scheduling to be duplicated...

 So he is what I am doing :
 1/ First, I am registering and deregistering the plugin :
 register_activation_hook(__FILE__, 'myplugin_activation');
 register_deactivation_hook(__FILE__, 'myplugin_deactivation');

 2/ Then we have both activation and deactivation functions :
 function myplugin_activation()
 {
         if
 (!has_action('myplugin_monthly_cron_hook','myplugin_monthly_cron'))
         {
 add_action('myplugin_monthly_cron_hook','myplugin_monthly_cron');
            wp_schedule_event(time(), 'hourly',
 'myplugin_monthly_cron_hook');
         }
 }

 function myplugin_deactivation()
 {
         wp_clear_scheduled_hook('myplugin_monthly_cron_hook');
 remove_action('myplugin_monthly_cron_hook','myplugin_monthly_cron');
 }

 So in the activation function, I am registering a hook for a cron task and
 then I am scheduling it and in the deactivation function, I am removing
 it.

 Here is the scenario of the problem :
 1/ Activate the plugin => the action hook is created and the associated
 cron action as well;
 2/ Modify the plugin file (either by uploading a new one or by modifying
 it within the inline editor) without deactivating the plugin;
 3/ This triggers the register_activation_hook function again (as the
 plugin file has been modified);
 4/ Wordpress goes through myplugin_activation() and the
 (!has_action('myplugin_monthly_cron_hook','myplugin_monthly_cron')) test
 is entered while the action hasn't been removed (since the plugin wasn't
 deactivated manually). This is where the bug is, I cannot figure out why
 the has_action is returning false here while the action is indeed there...

 I understand that this scenario will happen only when people updates the
 files without deactivating the plugin first. This isn't the right way to
 upgrade plugins but this can happen and so cause duplicate scheduling
 action registrations...

-- 
Ticket URL: <http://trac.wordpress.org/ticket/8899>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list