Skip to content

Instantly share code, notes, and snippets.

@gajayana
Last active October 14, 2017 17:01
Show Gist options
  • Save gajayana/2d0b37b52526a5aa7781c5ddce6ae958 to your computer and use it in GitHub Desktop.
Save gajayana/2d0b37b52526a5aa7781c5ddce6ae958 to your computer and use it in GitHub Desktop.
CMV #2
<?php
add_action( 'wp_ajax_add_notifier_email', 'add_notifier_email');
function add_notifier_email() {
$post_id = (int)$_POST['company_id'];
$email = sanitize_email($_POST['email']);
if (is_numeric($post_id) && $email) {
$emails = get_field('email_notifiers', $post_id);
$emails[] = array(
'email' => $email,
);
update_field('email_notifiers', $emails, $post_id);
$res = array(
'status' => 'ok',
'message' => 'e-mail has been saved',
);
} else {
$res = array(
'status' => 'error',
'message' => 'Check company id and/or email',
);
}
echo json_encode($res);
wp_die();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment