Skip to content

Commit

Permalink
Fix custom fonts assets path (#601)
Browse files Browse the repository at this point in the history
* fix custom fonts assets path
* improve syntax
* Update admin/create-theme/theme-zip.php

Co-authored-by: Vicente Canales <1157901+vcanales@users.noreply.github.com>
  • Loading branch information
matiasbenedetto and vcanales authored Apr 30, 2024
1 parent 6aa9391 commit 058c6fe
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions admin/create-theme/theme-zip.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static function add_activated_fonts_to_zip( $zip, $theme_json_string ) {
$theme_json = json_decode( $theme_json_string, true );

$font_families_to_copy = Theme_Fonts::get_user_activated_fonts();
$theme_font_asset_location = '/assets/fonts/';
$theme_font_asset_location = 'assets/fonts';
$font_slugs_to_remove = array();

if ( ! $font_families_to_copy ) {
Expand All @@ -47,14 +47,15 @@ public static function add_activated_fonts_to_zip( $zip, $theme_json_string ) {
}
$font_slugs_to_remove[] = $font_family['slug'];
foreach ( $font_family['fontFace'] as &$font_face ) {
$font_filename = basename( $font_face['src'] );
$font_dir = wp_get_font_dir();
$font_filename = basename( $font_face['src'] );
$font_dir = wp_get_font_dir();
$font_face_path = path_join( $theme_font_asset_location, $font_filename );
if ( str_contains( $font_face['src'], $font_dir['url'] ) ) {
$zip->addFileToTheme( $font_dir['path'] . '/' . $font_filename, $theme_font_asset_location . '/' . $font_filename );
$zip->addFileToTheme( path_join( $font_dir['path'], $font_filename ), $font_face_path );
} else {
// otherwise download it from wherever it is hosted
$tmp_file = download_url( $font_face['src'] );
$zip->addFileToTheme( $tmp_file, $theme_font_asset_location . '/' . $font_filename );
$zip->addFileToTheme( $tmp_file, $font_face_path );
unlink( $tmp_file );
}

Expand Down

0 comments on commit 058c6fe

Please sign in to comment.