/** * Actions on person save. * * When a person is saved, we get the positions that they are assigned to, * and add their email to each position list, if it is not already in the * specified list. * * @since 1.0.0 * @param int $post_id The post ID. * @param post $post The post object. * @param bool $updated Whether this is an existing post being updated or not. */ public function person_save_action($post_id, $post, $updated) { $slug = 'oaldr_person'; if ($slug !== $post->post_type) { return; } $fname = get_field('first_name', $post_id); $lname = get_field('last_name', $post_id); $person_email = get_field('person_email', $post_id); $parent_email = get_field('parent_email', $post_id); $title = get_the_title(); if ($person_email) { $options = array('post_type' => 'oaldr_position', 'posts_per_page' => 50, 'meta_query' => array(array('key' => 'person', 'value' => $post_id, 'compare' => 'LIKE'))); $query = new WP_Query($options); if ($query->has_posts()) { $slack_invite = $this->slack->invite_member($post_id, $fname, $lname, $person_email); $addresses = []; foreach ($query->posts as $post) { $position_email = get_field('position_email', $post->id); // $this->mailgun->add_list_member( $position_email, $person_email, $fname.' '.$lname ); $addresses[] = ['address' => $person_email, 'name' => $fname . ' ' . $lname]; } $addresses = json_encode($addresses); $this->mailgun->add_array_list_members($position_email, $addresses); } } }