Noptin_Background_Mailer::fetch_subscriber_from_query( $item )
Fetches a subscriber from a subscribers query.
Parameters Parameters
(array) (Required) item The item to fetch a subscriber for.
Source Source
File: includes/class-noptin-background-mailer.php
public function fetch_subscriber_from_query( $item ) { // Ensure that the query is an array... $subscriber_query = ( ! is_array( $item['subscribers_query'] ) ) ? array() : $item['subscribers_query']; // ... and it has a meta query too. if ( empty( $subscriber_query['meta_query'] ) ) { $subscriber_query['meta_query'] = array(); } $subscriber_query['meta_query']['relation'] = 'AND'; // Avoid sending the same campaign twice. $subscriber_query['meta_query'][] = array( 'key' => '_campaign_' . $item['key'], 'compare' => 'NOT EXISTS', ); // Retrieve the id... $subscriber_query['fields'] = array( 'id' ); // ... of the next subscriber... $subscriber_query['number'] = 1; // who is active. $subscriber_query['subscriber_status'] = 'active'; // We do not need to count the total number of subscribers. $subscriber_query['count_total'] = false; // Filters the query used to find the next recipient of a mass mail. $query = apply_filters( 'noptin_background_mailer_subscriber_query', $subscriber_query, $item ); // Run the query... $subscriber = new Noptin_Subscriber_Query( $query ); $result = $subscriber->get_results(); // ... and return the result. return empty( $result ) ? null : $result[0]; }
Expand full source code Collapse full source code View on GitHub