How can I save a Custom Post Title and Slug with a Custom Field?

I found some code that allows both Post Title and Slug to be generated from custom field data:

function recipe_update_title( $value, $post_id, $field ) {

$new_title = get_field( 'recipe_name', $post_id) . ' ' . $value;
$new_slug = sanitize_title( $new_title );

// update post
$recipe_postdata = array(
    'ID'          => $post_id,
    'post_title'  => $new_title,
    'post_name'   => $new_slug,
);  

if ( ! wp_is_post_revision( $post_id ) ){

    // unhook this function so it doesn't loop infinitely
    remove_action('save_post', 'recipe_update_title');

    // update the post, which calls save_post again
    wp_update_post( $recipe_postdata );

    // re-hook this function
    add_action('save_post', 'recipe_update_title');
}   

return $value;
}

add_filter('acf/update_value/name=recipe_featured_image', 'recipe_update_title', 10, 3);