Add tags to a “pending” post before publishing

The @PieterGoosen’s answer saved my life:

add_action( 'transition_post_status', function ( $new_status, $old_status, $post ) {
   if( 'publish' == $new_status && 'advert_tmp' == $old_status && $post->post_type == 'advert' ) {
      $tags = get_post_meta( $post->ID, 'advert_tags_field', true );
      $tags = explode( ',', $tags );
      if( !empty( $tags ) ) {
         wp_set_object_terms( $post->ID, $tags, 'advert_tag' );
         delete_post_meta( $post->ID, 'advert_tags_field' );
      }
    }
}, 10, 3 );

tech