How do I hook into Pro Site's cron job

I’m trying to hook into psts_process_stats to send my own expiration emails. I have a function that send emails at different periods of their trial depending on what day they are at. Here’s what I’m trying to do:

add_action( ‘psts_process_stats’, array(&$this, ‘sendExpirationEmails’:wink: );

I made a plugin for this. Can you tell me why this doesn’t work? Thanks.

  • traviscf
    • Site Builder, Child of Zeus

    Ok this is the code in my plugin. I simplified the functions to make it easier on the eyes. I used to have this in /pro-sites/pro-sites.php right at the end of process_stats() function but I’d rather have it in a plugin so I can keep updating Pro Sites without having to add this back in. It worked fine when it was in pro-sites.php.

    This is what I had at the end of the process_stats() function before the closing bracket: $this->sendExpirationEmails();

    Here is the start of the plugin code:

    add_action( 'psts_process_stats', array(&$this, 'sendExpirationEmails') );

    function wrapemail($message){

    My function to wrap email messages in html

    }

    function sendExpirationEmails(){
    global $wpdb;

    $expiring = $wpdb->get_results( $wpdb->prepare("SELECT blog_ID,expire FROM {$wpdb->base_prefix}pro_sites WHERE expire > " . time() . " AND expire < ".strtotime('+16 days')." AND gateway = 'Trial'") );
    foreach ($expiring as $site) {

    $days = round( ( $site->expire - time() ) / 86400 ); //calculate days left rounded
    if($days==15) {
    $this->sendExpirationEmail($site->blog_ID,15);
    }
    if($days==7) {
    $this->sendExpirationEmail($site->blog_ID,7);
    }
    if($days==1) {
    $this->sendExpirationEmail($site->blog_ID,1);

    }

    }

    $expired = $wpdb->get_results( $wpdb->prepare("SELECT blog_ID,expire FROM {$wpdb->base_prefix}pro_sites WHERE expire < " . time() . " AND expire < ".strtotime('+8 days')." AND gateway = 'Trial'") );
    foreach ($expired as $site) {
    $days = round( ( time() - $site->expire ) / 86400 ); //calculate days left rounded
    if($days==3) {
    $this->sendExpiredEmail($site->blog_ID,3);
    }
    if($days==7) {
    $this->sendExpiredEmail($site->blog_ID,7);
    }
    }
    }

    function sendExpiredEmail($site,$days){

    My function to send expired emails

    }

    function sendExpirationEmail($site,$days){

    My function to send expiration emails

    }

  • Aaron
    • CTO

    It looks like you are calling &$this not in an object context. Since it appears you have no wrapper class, it would be:

    add_action( 'psts_process_stats', 'sendExpirationEmails' );

    Note that this hook is only called once daily, and only on a live site with traffic.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.