PluginProbe
Property Hive / trunk
Property Hive vtrunk
2.3.1 2.3.0 2.2.6 2.2.5 2.2.4 2.2.3 2.2.2 1.4.46 1.4.47 1.4.48 1.4.49 1.4.5 1.4.50 1.4.51 1.4.52 1.4.53 1.4.54 1.4.55 1.4.56 1.4.57 1.4.58 1.4.59 1.4.6 1.4.60 1.4.61 All 261 releases
← All changes | includes/class-ph-emails.php +34 -0 2.3.0trunk View file →
@@ -229,8 +229,41 @@
229 229 foreach ( $emails_to_send as $email_to_send )
230 230 {
231 231 $email_id = $email_to_send->email_id;
232 232
233 + $contact_id = (int)$email_to_send->contact_id;
234 +
235 + // Ensure client is still publised, hasn't unsubscribed from emails and that send matching properties is yes
236 + // To combat being added to the queue but then the queue only getting processed at a later date
237 + $forbidden_contact_methods = get_post_meta( $contact_id, '_forbidden_contact_methods', true );
238 +
239 + $email_forbidden = is_array( $forbidden_contact_methods ) && in_array( 'email', $forbidden_contact_methods, true );
240 +
241 + $applicant_profile = get_post_meta( $contact_id, '_applicant_profile_' . (int)$email_to_send->applicant_profile_id, true );
242 +
243 + $matching_enabled = is_array( $applicant_profile )
244 + && isset( $applicant_profile['send_matching_properties'] )
245 + && 'yes' === $applicant_profile['send_matching_properties'];
246 +
247 + if (
248 + 'publish' !== get_post_status( $contact_id )
249 + || $email_forbidden
250 + || !$matching_enabled
251 + ) {
252 + $wpdb->update(
253 + $wpdb->prefix . 'ph_email_log',
254 + array(
255 + 'status' => 'fail2',
256 + 'lock_id' => '',
257 + ),
258 + array( 'email_id' => (int)$email_id ),
259 + array( '%s', '%s' ),
260 + array( '%d' )
261 + );
262 +
263 + continue;
264 + }
265 +
233 266 $headers = array();
234 267 $headers[] = 'From: ' . html_entity_decode($email_to_send->from_name) . ' <' . $email_to_send->from_email_address . '>';
235 268 if ( $email_to_send->cc_email_address != '' )
236 269 {
@@ -419,8 +452,9 @@
419 452
420 453 // Get all contacts that have a type of applicant
421 454 $args = array(
422 455 'post_type' => 'contact',
456 + 'post_status' => 'publish',
423 457 'nopaging' => true,
424 458 // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Matching mail must include all eligible applicant profiles; membership and opt-in eligibility are stored in contact metadata.
425 459 'meta_query' => $meta_query,
426 460 'fields' => 'ids'