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?