Last active
June 22, 2024 21:22
-
-
Save moxet/adfe7b74ec65d39026019b488f1f4370 to your computer and use it in GitHub Desktop.
Send Notification via JetForm Builder / JetEngine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 <[email protected]>'); | |
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