SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    Team ********* Louis Simoneau's Avatar
    Join Date
    Sep 2009
    Location
    Melbourne, Australia
    Posts
    228
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Scheduling Tasks in WordPress: a Plugin Developer's Guide

    Notice: This is a discussion thread for comments about the SitePoint article, Scheduling Tasks in WordPress: a Plugin Developer's Guide.
    __________

    What experience have you had using WordPress's scheduling API? Any tips you'd add?

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,044
    Mentioned
    187 Post(s)
    Tagged
    2 Thread(s)
    I recently added an "auto delete old log files" feature to one of my plugins. It took a little while to get my head around the API, but it wasn't that bad for me.

    In my "activate" I added
    PHP Code:
    wp_schedule_event(time(), 'daily''er_cron_del_hook'
    In my "deactivate"
    PHP Code:
    wp_clear_scheduled_hook('er_cron_del_hook');
    remove_action('er_cron_del_hook''mitt_er_cron_delete_logs'); 
    add an action
    PHP Code:
    add_action('er_cron_del_hook''mitt_er_cron_delete_logs'); 
    and write the function
    PHP Code:
    function mitt_er_cron_delete_logs()
    {
        
    $cron_del_limiter get_option('er_do_cron_del');

        if ( (
    $cron_del_limiter == 'month') || ($cron_del_limiter == 'week') )
        {
            
    $curr_time time();
            
    $cron_file_age 31536000// default 1 year should be way more than enough

            
    if ($cron_del_limiter == 'month'$cron_file_age 2678400;
            if (
    $cron_del_limiter == 'week'$cron_file_age 604800;
    .......
    // do file delete stuff if conditional tests pass 

  3. #3
    SitePoint Guru marcel's Avatar
    Join Date
    Nov 2000
    Posts
    920
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could also hack php and use a GET post via Cpanel CRON

  4. #4
    SitePoint Enthusiast techiekaran's Avatar
    Join Date
    Dec 2008
    Posts
    50
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @Mittineague: Cool hack. Will save my server resources a lot!

  5. #5
    SitePoint Enthusiast
    Join Date
    Jul 2008
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great tutorial - Thankyou.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •