admin管理员组

文章数量:1279188

Is there any other good way to initiate an hourly cron job other than using register_activation_hook within a plugin?

As looks like it will not be useful for websites that have already installed and activated that plugin.

Thanks

Is there any other good way to initiate an hourly cron job other than using register_activation_hook within a plugin?

As looks like it will not be useful for websites that have already installed and activated that plugin.

Thanks

Share Improve this question asked Oct 5, 2021 at 16:46 SaqibSaqib 631 silver badge4 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Simply check if the event is scheduled, and if not, schedule it:

add_action(
    'init',
    function () {
        if ( ! wp_next_scheduled( 'my_scheduled_event' ) ) {
            wp_schedule_event( time(), 'hourly', 'my_scheduled_event' );
        }
    }
);

本文标签: plugin developmentLooking for a better way to initiate cron job