Hooks cannot be added directly inside functions. Using do_action, you can invoke a custom hook.
In your case try out the below solution:
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 {
show_example_error();
}
}
}
function show_example_error() {
$screen = get_current_screen();
if ( $screen->post_type == 'help-center' ) {
$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 );
}
}
add_action( 'admin_notices', 'show_example_error' );