WordPress安排任务更新插件选项

时间:2017-08-08 15:25:10

标签: wordpress task hook schedule

我正在使用wordpress的插件,我需要使用单一事件调度程序更新数据库选项,但它似乎没有触发。 我的代码:

function task_to_perform()
{
    update_option( "number_of_cubes", 50);
    wp_unschedule_event('lalala_hook');
}

add_action( 'lalala_hook','task_to_perform' );

function some_other_function()
{
    if ( !wp_next_scheduled( 'lalala_hook' ) )
        wp_schedule_single_event( time() + 10, 'lalala_hook' );
}

所以当我打电话给some_other_function();时,我希望wordpress从现在起设置一个10秒的计划时间来更新选项" number_of_cubes"。

此选项在插件中定义如下:

register_setting("stars_settings", "number_of_cubes");

if (!get_option( "number_of_cubes"))
    update_option( "number_of_cubes", 0);

0 个答案:

没有答案