Wordpress - Custom Body Classes

Add custom classes to the <body> tag in Wordpress.  Classes added:

-Not front page
-Post type
-Post slug
-Post slug ancestors
-User logged in
-User is admin
-ACF block class depending on block type

/**
 * Custom body classes.
 */
function example_body_class($classes) {
  global $post;
  // homepage or not
  if (is_front_page() == FALSE) {
    $classes[] = 'not-home';
  }
  // post type
  $classes[] = sprintf('post-type-%s', $post->post_type);
  // page slug
  $post_slug = $post->post_name;
  $classes[] = sprintf('page-%s', $post_slug);
  // permalink classes
  $permalink = str_replace(home_url(), '', get_permalink());
  $permalink_parts = explode('/', $permalink);
  foreach($permalink_parts as $part) {
    if (!empty($part)) {
      $classes[] = sprintf('page-%s', $part);
    }
  }
  // user logged in status
  if (is_user_logged_in()) {
    $classes[] = 'logged-in';
  }
  // user role
  $current_user = wp_get_current_user();
  if ($current_user && in_array('administrator', $current_user->roles)) {
    $classes[] = 'is-admin';
  }
  $blocks = parse_blocks( $post->post_content );
  foreach ($blocks as $block) {
    if ($block['blockName'] == 'acf/hero-image-title') {
      $classes[] = 'has-hero-image-title';
      break;
    }
  }
  return $classes;
}
add_filter('body_class', 'example_body_class');