Skip to content

Instantly share code, notes, and snippets.

@girafffee
Last active January 31, 2022 17:27
Show Gist options
  • Save girafffee/8f319e3f550bce945321447b4d928ff3 to your computer and use it in GitHub Desktop.
Save girafffee/8f319e3f550bce945321447b4d928ff3 to your computer and use it in GitHub Desktop.
Using data from the form, insert post id, notification settings
<?php
$on_insert_port = function ( $settings, $notification ) {
if ( 'post' !== $settings['post_type'] ) {
return;
}
/**
* To get/set the entered data from the form use $notification->data
*/
$post_id = (int) $notification->data['inserted_post_id'];
$meta_key = '_is_adult';
$is_adult = absint( $notification->data['age'] ) < 18;
if ( $is_adult ) {
$notification->data['first_name'] .= ' (adult)';
}
/**
* See more here
* https://developer.wordpress.org/reference/functions/update_post_meta/
*/
update_post_meta( $post_id, $meta_key, $is_adult );
};
/**
* on update post use this action:
* jet-engine/forms/notifications/after-post-update
*/
add_action( 'jet-engine/forms/notifications/after-post-insert', $on_insert_port, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment