get_themes() as $slug => $theme ) { if ( is_object( $theme->parent() ) ) { continue; } $slugs[] = $slug; } return $slugs; } /** * Check if the given theme file path is the active theme. * * @param string $file_path The absolute file path to the theme file. * * @return bool Returns true if the given theme file path is the active theme, false otherwise. */ public function is_active_theme( $file_path ): bool { $active_theme = $this->get_theme(); $theme_dir = $this->get_path_of_themes_dir(); $abs_path = $theme_dir; $abs_path = defender_replace_line( $abs_path ); // Without the first slash. $rev_file = str_replace( $abs_path, '', $file_path ); $theme_data = explode( '/', $rev_file ); $theme_slug = $theme_data[0]; // Checking if the given theme is a child theme. if ( false !== stripos( $theme_slug, '-child' ) ) { $theme_slug = str_replace( '-child', '', $theme_slug ); } // Checking if the active theme is a parent theme. if ( is_object( $active_theme->parent() ) ) { $active_theme_slug = $active_theme->parent()->get_stylesheet(); } else { $active_theme_slug = $active_theme->get_stylesheet(); } return $theme_slug === $active_theme_slug; } }