Skip to:
Content
Pages
Categories
Search
Top
Bottom

Cron Tasks with BuddyPress

  • Avatar of techguy
    techguy
    Participant

    @crashutah

    Does anyone have experience having simple cron jobs run on your BP install?

    For example, I’m looking to send a PM to users 3 days after a certain type of user has joined. I know how to get the list of user-id’s that I want to send the message to. I’m just not sure the best way to schedule it to do so automatically. Can someone point me in the right direction or let me know of any plugins that do this type of cron job like processing on a BP install?

    I’d prefer to do it in BP so that I can use all the BP calls to send the PMs and link to certain locations.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Avatar of Travel-Junkie
    Boris
    Participant

    @travel-junkie

    Have a look at this function:
    `wp_schedule_single_event`

    You can find it in wp-includes/cron.php. There’s a bunch of other cron related functions in there, but the one I mentioned above is probably your best bet. Then schedule an event by attaching it to a hook, when a user signs up

    Avatar of techguy
    techguy
    Participant

    @crashutah

    Thanks Travel-Junkie. That looks like it will work well hooked to a specific function (ie. user creation). I’ll look into it for some cases.

    How about something that runs nightly and sends an email to a group of users based on a BP query of the users? Is there a way to schedule this in BP?

    Avatar of Travel-Junkie
    Boris
    Participant

    @travel-junkie

    No worries. There’s a recurring scheduling function as well in that file.

    Avatar of techguy
    techguy
    Participant

    @crashutah

    Do you know of any plugins that implement these types of cron? I learn better looking at other example code and building it from there.

    something like: (what i use for sitemap generator for a daily function call)

    `
    //on plugin activation register cron
    function myplugin_activation() {
    wp_schedule_event( time(), ‘daily’, ‘myplugin_wp_cron_call’ );
    }
    register_activation_hook(__FILE__, ‘myplugin_activation’);

    //on plugin deactivation remove cron
    function myplugin_deactivation() {
    wp_clear_scheduled_hook( ‘myplugin_wp_cron_call’ );
    }
    register_deactivation_hook(__FILE__, ‘myplugin_deactivation’);

    //hook the action to call from wp_cron
    add_action( ‘myplugin_wp_cron_call’, ‘myplugin_some_function_to_hook_for_wp_cron’ );
    `

    Avatar of Boone Gorges
    Boone Gorges
    Keymaster

    @boonebgorges

    Here’s a pretty good guide that covers what Rich has shown here, plus how to designate custom intervals: http://themocracy.com/2010/02/wp-cron-automating-scheduling/

Viewing 6 replies - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.