Skip to content

Instantly share code, notes, and snippets.

@moxet
Last active June 22, 2024 21:22
Show Gist options
  • Save moxet/adfe7b74ec65d39026019b488f1f4370 to your computer and use it in GitHub Desktop.
Save moxet/adfe7b74ec65d39026019b488f1f4370 to your computer and use it in GitHub Desktop.
Send Notification via JetForm Builder / JetEngine
add_action( 'jet-form-builder/custom-action/send_notification', function( $request, $action_handler ) {
$cct_id = $request['inserted_cct_notifications'];
$email_notify = $request['email_notify'];
$notification_details = $request['notification_details'];
$users = get_users();
foreach ($users as $user) {
$user_id = $user->ID;
$user_email = $user->user_email;
$meta_value = get_user_meta($user_id, 'notifications', true);
$new_value = "";
if(empty($meta_value))
{
$new_value = $cct_id;
}
else
{
$new_value = $meta_value.",".$cct_id;
}
if(!empty($email_notify))
{
$txt = "Hello, there is a new notification in the system with following content.<br/><br/>".$notification_details;
$headers = array('Content-Type: text/html; charset=UTF-8','From: your-name <admin@softemblems.com>');
wp_mail( $user_email , "System Notification", $txt, $headers);
}
update_user_meta($user_id, 'notifications', $new_value);
}
}, 10, 2 );
function get_data() {
if (isset($_POST['new_meta_value'])) {
$user_id = get_current_user_id();
$new_meta_value = $_POST['new_meta_value'];
$old_meta_value = explode(",", get_user_meta($user_id, 'notifications', true));
$remove_notification_id = array_diff($old_meta_value, array($new_meta_value));
$result = implode(",", $remove_notification_id);
update_user_meta($user_id, 'notifications', $result);
return true;
wp_die();
}
}
add_action( 'wp_ajax_nopriv_get_data', 'get_data' );
add_action( 'wp_ajax_get_data', 'get_data' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment