There’s an action hook, pre_post_update
that gets executed just before updating a post.
add_action('pre_post_update', function($post_id, $data)){
if(!isset($_POST['date_start']){
wp_safe_redirect("post.php?post={$post_id}");
die();
}
}
I didn’t find any action that gets executed right before creating a post, however, I did find a filter that does and will work to validate data / abort with a redirect just like the function above.
* @param array $data An array of slashed post data.
* @param array $postarr An array of sanitized, but otherwise unmodified post data.
add_filter('wp_insert_post_data', $data, $postarr, function(){})