What ?
Font with the same name but different type as existing custom font (e.g. guillon_normal_400.ttf and guillon_normal_400.woff2) is added as a separate variant.
Originally reported by @ironprogrammer in #53884 (comment)
Expected:
- There should not be 2 variants if you are uploading the same family weight and style.
- The old file should be removed or overwritten.
Current behavior
Currently, we compare the incoming variant with the existing one in the backend. We use a string-based approach around the entire font face data, so if something of the font face data is different (the file name in this case), it will be treated as a new variant.
|
$font_faces_1 = isset( $font1['fontFace'] ) ? $font1['fontFace'] : array(); |
|
$font_faces_2 = isset( $font2['fontFace'] ) ? $font2['fontFace'] : array(); |
|
$merged_font_faces = array_merge( $font_faces_1, $font_faces_2 ); |
|
|
|
$serialized_faces = array_map( 'serialize', $merged_font_faces ); |
|
$unique_serialized_faces = array_unique( $serialized_faces ); |
|
$unique_faces = array_map( 'unserialize', $unique_serialized_faces ); |
|
|
|
$merged_font = array_merge( $font1, $font2 ); |
What needs to be changed
- Consider the variants by their font style and weight to know if they are repeated.
- If we update the file asset, the old should be removed or overwritten.
What ?
Originally reported by @ironprogrammer in #53884 (comment)
Expected:
Current behavior
Currently, we compare the incoming variant with the existing one in the backend. We use a string-based approach around the entire font face data, so if something of the font face data is different (the file name in this case), it will be treated as a new variant.
gutenberg/lib/experimental/fonts/font-library/class-wp-font-family-utils.php
Lines 65 to 73 in e7b7c83
What needs to be changed