Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Font Library Address Outstanding Feedback from WP 6.4 review #58675

Merged
merged 8 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/compat/wordpress-6.5/fonts/class-wp-font-collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ final class WP_Font_Collection {
*
* @since 6.5.0
*
* @param string $slug Font collection slug.
* @param array|string $data_or_file Font collection data array or a path/URL to a JSON file
* containing the font collection.
* See {@see wp_register_font_collection()} for the supported fields.
* @param string $slug Font collection slug.
* @param array|string $data_or_file Font collection data array or a path/URL to a JSON file
* containing the font collection.
* See {@see wp_register_font_collection()} for the supported fields.
*/
public function __construct( $slug, $data_or_file ) {
$this->slug = sanitize_title( $slug );
Expand Down Expand Up @@ -194,7 +194,7 @@ private function sanitize_and_validate_data( $data ) {
if ( empty( $data[ $property ] ) ) {
$message = sprintf(
// translators: 1: Font collection slug, 2: Missing property name.
__( 'Font collection "%1$s" has missing or empty property: "%2$s."', 'gutenberg' ),
__( 'Font collection "%1$s" has missing or empty property: "%2$s".', 'gutenberg' ),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$this->slug,
$property
);
Expand Down
2 changes: 1 addition & 1 deletion lib/compat/wordpress-6.5/fonts/class-wp-font-library.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function get_font_collection( $slug ) {
if ( array_key_exists( $slug, $this->collections ) ) {
return $this->collections[ $slug ];
}
return new WP_Error( 'font_collection_not_found', 'Font collection not found.' );
return new WP_Error( 'font_collection_not_found', __( 'Font collection not found.', 'gutenberg' ) );
}

/**
Expand Down
12 changes: 8 additions & 4 deletions lib/compat/wordpress-6.5/fonts/class-wp-font-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static function sanitize_font_family( $font_family ) {
$wrapped_font_families = array_map(
function ( $family ) {
$trimmed = trim( $family );
if ( ! empty( $trimmed ) && false !== strpos( $trimmed, ' ' ) && false === strpos( $trimmed, "'" ) && false === strpos( $trimmed, '"' ) ) {
if ( ! empty( $trimmed ) && str_contains( $trimmed, ' ' ) && ! str_contains( $trimmed, "'" ) && ! str_contains( $trimmed, '"' ) ) {
return '"' . $trimmed . '"';
}
return $trimmed;
Expand Down Expand Up @@ -215,13 +215,17 @@ private static function apply_sanitizer( $value, $sanitizer ) {
}

/**
* Provide the expected mime-type value for font files per-PHP release. Due to differences in the values returned these values differ between PHP versions.
* Returns the expected mime-type values for font files, depending on PHP version.
*
* This is necessary until a collection of valid mime-types per-file extension can be provided to 'upload_mimes' filter.
* This is needed because font mime types vary by PHP version, so checking the PHP version
* is necessary until a list of valid mime-types for each file extension can be provided to
* the 'upload_mimes' filter.
*
* @since 6.5.0
*
* @return Array A collection of mime types keyed by file extension.
* @access private
getdave marked this conversation as resolved.
Show resolved Hide resolved
*
* @return array A collection of mime types keyed by file extension.
*/
public static function get_allowed_font_mime_types() {
$php_7_ttf_mime_type = PHP_VERSION_ID >= 70300 ? 'application/font-sfnt' : 'application/x-font-ttf';
Expand Down
Loading