Expired Ads Email Bug - explained (plus a fix)
It would seem that this bug has been present since 2011.
ClassiPress does not send out an email for expired ads when the cron job purges expired ads.
The process:
1. File: classipress\includes\cron.php - function cp_check_expired_cron()
This is a cron job which runs periodically.
This checks the expiry of the Ad and if over the expiry date it changes the Ad post status from "publish" to "draft".
This function does not send the email out. This is done in step 2
2. File: classipress\includes\emails.php - function cp_notify_ad_owner_email()
This is the function that is meant to email the Ad owner on expiry.
It hooks into the "transition_post_status" filter which detects the change in a posts status using this conditional:
PHP Code:
elseif ( $old_status == 'publish' && $new_status == 'draft' && $current_user->ID != $ad_author_id && $send_expired_email ) { email code blah blah }
This works well if you are logged into WordPress and manually change the post status of an expired Ad from "publish" to "draft". The email will be sent.
HOWEVER - the bug is this.
When the post status is changed from the cron job, it is the system which is changing the post status - not a logged in user.
Hence when the filter is triggered from the cron job, there is no $current_user object. This is causing an error and failing the logic of the elseif clause. Hence expired emails during cron purge will never work using this logic.
A temp fix
If you really need this functionality then you can remove the following from the elseif statement:
PHP Code:
&& $current_user->ID != $ad_author_id
so the line reads:
PHP Code:
elseif ( $old_status == 'publish' && $new_status == 'draft' && $send_expired_email ) {
Of course this is only a patch as the fix will get overwritten when ClassiPress is next updated and if AppThemes don't include a fix by then.
This should help those in these threads:
http://forums.appthemes.com/report-c...problem-28959/
http://forums.appthemes.com/report-c...-14035/page-2/
http://forums.appthemes.com/report-c...sending-29043/
http://forums.appthemes.com/report-c...ication-28827/