posts – Admin notice on wp_insert_post
Question
I am trying to display some error messages in case some conditions are not met when using wp_insert_post. However, it the admin_notice doesn’t seem to trigger.
Here’s the example I have:
add_action( 'wp_insert_post', 'automate_intercom', 10, 3);
function automate_intercom($post_id, $post, $update) {
if($post->post_status == 'publish' && $post->post_type == 'help-center') {
$someCondition = '';
if($someCondition!== '') {
}else{
add_action( 'admin_notices', 'show_example_error' );
}
}
}
function show_example_error() {
$class="notice notice-info";
$message = __( 'Example error', 'admin_notice' );
error_log("In admin notice ");
printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), $message);
}
Any ideas why it doesn’t trigger the admin_notices?
0
3 weeks
2023-01-13T00:34:15-05:00
2023-01-13T00:34:15-05:00 0 Answers
0 views
0
Leave an answer