Noptin_Background_Mailer::task( array $item )
Task
Description Description
Override this method to perform any actions required on each queue item. Return the modified item for further processing in the next pass through. Or, return false to remove the item from the queue.
Parameters Parameters
- $item
(array) (Required) The current item being processed.
Return Return
(mixed)
Source Source
File: includes/class-noptin-background-mailer.php
public function task( $item ) { global $wpdb; // First, prepare the campaign data. $item = $this->prepare_campaign_data( $item ); // And abort in case of an error. if ( empty( $item ) ) { return false; } $recipient_data = $item['next_recipient_data']; unset( $item['next_recipient_data'] ); // If no email is set, move on to the next recipient. if ( empty( $recipient_data['email'] ) ) { return $item; } // Ensure that this subscriber is yet to be sent this campaign. $key = '_campaign_' . $item['key']; if ( isset( $recipient_data['merge_tags'][ $key ] ) ) { return $item; } // Try sending the email. if ( noptin()->mailer->prepare_then_send( $recipient_data ) ) { if ( ! empty( $item['campaign_id'] ) ) { $sents = (int) get_post_meta( $item['campaign_id'], '_noptin_sends', true ); update_post_meta( $item['campaign_id'], '_noptin_sends', $sents + 1 ); } if ( ! empty( $recipient_data['merge_tags']['id'] ) ) { update_noptin_subscriber_meta( $recipient_data['merge_tags']['id'], $key, '1' ); } } else { if ( ! empty( $item['campaign_id'] ) ) { $fails = (int) get_post_meta( $item['campaign_id'], '_noptin_fails', true ); update_post_meta( $item['campaign_id'], '_noptin_fails', $fails + 1 ); } if ( ! empty( $recipient_data['merge_tags']['id'] ) ) { update_noptin_subscriber_meta( $recipient_data['merge_tags']['id'], $key, '0' ); } } return $item; }
Expand full source code Collapse full source code View on GitHub