2013-06-20 89 views
1

我想創建一個時間表來顯示廣告。更具體地說,我想在上午12:00到上午06:00之間顯示一個廣告,之後再添加一個廣告。我正在爲它寫一個插件(即使不知道插件是否可能),這是第一次。WordPress的:創建時間表

到目前爲止,我已經開發了此代碼:

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'); 

當一個用戶登錄時,計劃創建,並在用戶註銷時,時間表正在清理的問題。我只想爲該用戶清除日程安排,而不是其他登錄用戶。我如何實現它?

任何人都可以對此有所瞭解嗎?

先感謝

回答

0

把你的功能is_admin()條件...

希望工程......