Wordpress:创建计划

时间:2013-06-20 09:58:51

标签: wordpress events clear schedule

我正在尝试创建显示AD的计划。更具体地说,我想在上午12:00到上午06:00之间展示一个广告。之后再添加一个。我是第一次为它编写插件(甚至不知道插件是否可能)。

到目前为止,我开发的是这段代码:

function create_schedule()
{
    add_action('init','register_schedule');
}
register_activation_hook(__FILE__, 'create_schedule');

function destroy_schedule()
{
    remove_action('init','register_schedule');
}
register_deactivation_hook(__FILE__,'destroy_schedule');


function register_schedule()
{
    date_default_timezone_set('Asia/Tokyo');
    $month = date("n");
    $date = date("j");
    $year = date("Y");

    $hour = date("G");
    $minute = date("i");
    $second = date("s");

    if($hour >6 && $hour <= 23)
    {
        wp_schedule_single_event( mktime( 0,0,0,$month,$date+1,$year ), 'my_night_time_event');
    }
    if{
        wp_schedule_single_event( mktime( 0,0,0,$month,$date,$year ), 'my_day_time_event');
    }

}

function display_nightly_add()
{
}
add_action('my_night_time_event','display_nightly_add');


function display_daytime_add()
{
}
add_action('my_day_time_event','display_daytime_add');


function clear_schedules()
{
    $timestamp = wp_next_scheduled( 'my_night_time_event' );
    wp_unschedule_event($timestamp, 'my_night_time_event' );

    $timestamp = wp_next_scheduled( 'my_day_time_event' );
    wp_unschedule_event($timestamp, 'my_day_time_event' );
}
add_action('wp_logout','clear_schedules');

问题是当一个用户登录,创建计划并且用户注销时,正在清除计划。我想仅为此用户清除计划,而不是其他登录用户。我该如何实现呢?

有人可以对此有所了解吗?

提前谢谢

1 个答案:

答案 0 :(得分:0)

在您的函数中添加is_admin()条件...

希望它有效......