Skip to content

Commit

Permalink
Cherry-picked commits for WordPress 6.4 Beta 2 (#54914)
Browse files Browse the repository at this point in the history
* Fix the install of system fonts from a font collection (#54713)

* Fix set upload dir test (#54762)

* Site Editor: Prevent unintended actions on the classic theme (#54422)

* Add action and selector to track access to Patterns page

* Add a URL parameter to check if the Patterns page was accessed directly

* Revert lib changes

* Fix critical error in the Post Editor

* Explicitly add `! isBlockBasedTheme` with `isTemplatePartsMode`

* Fix critical error in the Post Editor

* Patterns: Fix back navigation after pattern creation (#54852)

* Patterns: Fix category control width in site editor (#54853)

* Patterns: Allow non-user patterns under Standard filter (#54756)

* Performance Tests: Separate page setup from test (#53808)

# Conflicts:
#	test/performance/specs/post-editor.spec.js

* Performance Tests: Support legacy selector for expanded elements (#54690)

* Paragraph: Make 'aria-label' consistent with other blocks (#54687)

* Paragraph: Make 'aria-label' consistent with other blocks

* Update tests

* Try using BC labels in performance tests

* Move lightbox render function to filter (#54670)

* syntax refactor repace strpos with str_contains (#54832)

* Font Library: avoid deprected error in test (#54802)

* fix deprecated call

* removing unwanted line

* Fix the ShortcutProvider usage (#54851)

Co-authored-by: Marin Atanasov <8436925+tyxla@users.noreply.github.com>

* Image: Ensure `false` values are preserved in memory when defined in `theme.json` (#54639)

* Modify conditional when parsing config

* Only drop the value if it's undefined.

---------

Co-authored-by: Michal Czaplinski <mmczaplinski@gmail.com>

* Use "Not synced" in place of "Standard" nomenclature for patterns (#54839)

* Standard -> Not synced

* Fix broken test

---------

Co-authored-by: Glen Davies <glen.davies@automattic.com>

* Format Library: Try to fix highlight popover jumping (#54736)

* Move mime-type collection generation to a function that can be tested… (#54844)

* Move mime-type collection generation to a function that can be tested.  Refactored to use that function.

* linting changes

* Add unit tests to mime type getter

* Fixed linting errors

* test the entire output array and replace assertTrue by assertEquals

* fixing docs

---------

Co-authored-by: Matias Benedetto <matias.benedetto@gmail.com>

* Ensure lightbox toggle is shown if block-level setting exists (#54878)

* Block Editor: Update strings in blocks 'RenameModal' component (#54887)

* Footnotes: Add aria-label to return links (#54843)

* Add aria-label to footnotes front-end links.

* Add visual output. Fix PHPCS errors.

* Remove visual changes, fix in follow-up.

* Font Library: Changed the OTF mime type expected value to be what PHP returns (#54886)

* Changed the OTF mime type expected value to be what PHP returns

* add unit test for otf file installation

---------

Co-authored-by: madhusudhand <madhusudhan.dollu@gmail.com>

* Image: Fix layout shift when lightbox is opened and closed (#53026)

* Replace overflow: hidden with JavaScript callback to prevent scrolling

* Disable scroll callback on mobile; add comments; fix scrim styles

The page jumps around when trying to override the scroll behavior
on mobile, so I disabled it altogether. I've also added comments
to clarify this and other decisions made around the scroll handling.

While testing, I realized that the scrim was completely opaque during
the zoom animation, which does not match the design, so I added a new
animation specifically for the scrim to fix that.

* Add handling for horizontally oriented pages

* Move close button so that it's further from scrollbar on desktop

* Fix call to handleScroll() and add touch callback to new render method

* Improve lightbox experience on mobile

To ensure pinch to zoom works as expected when the lightbox
is open on mobile, I added logic to disable the scroll override
when touch is detected. Without this, the scroll override kicks
in whenever one tries to pinch to zoom, and it breaks the experience.

I also revised the styles for the scrim to make it opaque, as having
content visible outside of the lightbox is distracting when
pinching to zoom on a mobile device, and I think having a consistent
lightbox across devices will make for the best user experience.

* Fix spacing

* Add touch directives to block supports

* Fix spacing in block supports

* Rename attribute for clarity

* Update comment

* Update comments

* Fix spacing

---------

Co-authored-by: Ricardo Artemio Morales <ric.morales22@gmail.com>

* Font Library: move font uploads to a new tab (#54655)

* move font uploads to a new tab in the modal

* fix invalid success message and revert the dropzone to modal

* add success notice for font uploads

* make supported file formats message dynamic based on allowed extensions

* update hint text and clear successful message with a fresh upload

* Block custom CSS: Fix incorrect CSS when multiple root selectors (#53602)

* Block custom CSS: Fix incorrect CSS when multiple root selectors

* Fix PHP lint error

* Use `scope_selector` and `append_to_selector` method and update unit test

* Use `scopeSelector` and `appendToSelector` function and update JS unit test

* Update packages/block-editor/src/components/global-styles/test/use-global-styles-output.js

Co-authored-by: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com>

* Update packages/block-editor/src/components/global-styles/test/use-global-styles-output.js

Co-authored-by: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com>

* Update packages/block-editor/src/components/global-styles/test/use-global-styles-output.js

Co-authored-by: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com>

* Update packages/block-editor/src/components/global-styles/test/use-global-styles-output.js

Co-authored-by: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com>

* Update packages/block-editor/src/components/global-styles/utils.js

Co-authored-by: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com>

* re-trigger CI

---------

Co-authored-by: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com>

* Add new e2e test for creating a pattern (#54855)

* Use list role instead of listbox for patterns (#54884)

* Popover: Fix the styles for components that use emotion within popovers (#54912)

# Conflicts:
#	packages/components/CHANGELOG.md

* Footnotes: use core’s meta revisioning if available (#52988)

# Conflicts:
#	packages/block-library/src/footnotes/index.php

* Remove base url from link control search results  (#54553)

* Expose baseURL setting on Post and Site Editors via block settings

* Strip baseURL from rendered search results

* Only fetch baseURL once in top level component

* Simplify implementation to utilise URL parse functions

* Improve comment wording to avoid referencing undefined var

* Remove superfluous conditional

* Decode URL prior to operations

* Refactor for readability

* Fix where url is not defined

* Revert change to filter util

* Ensure that filterURLForDisplay always receives a string as an arg

* Make e2e test locator less strict

* Prefer pipe

* Force remove trailing slash

* [Site Editor]: Update copy of using  the default template in a page (#54728)

* Remove overflow: hidden from the entity title h1 in the site editor sidebar (#54769)

* Site Editor: Avoid same key warnings in template parts area listings (#54863)

* TemplateAreas use template part clientId as key
* HomeTemplateDetails use template part clientId as key
* Cleanup useSelect hook

* Fix ToolSelector popover variant (#54840)

* Font Library: refactor endpoint permissions (#54829)

* break the checking of user permission and file write permissions

* return error 500 if the request to the install fonts endpoint needs write permissions and wordpress doens't have write permission on the server

* do not ask file write permission on uninstall endpoint

* Standardize the output of install and uninstall fonts endpoints

Co-authored-by: Jason Crist <146530+pbking@users.noreply.github.com>
Co-authored-by: Jeff Ong <5375500+jffng@users.noreply.github.com>

* Handle standardized output from install and uninstall endpoints in the frontend

Co-authored-by: Jason Crist <146530+pbking@users.noreply.github.com>
Co-authored-by: Jeff Ong <5375500+jffng@users.noreply.github.com>

* Update the install and unintall fonts endpoints unit tests for the new standardized output format

Co-authored-by: Jason Crist <146530+pbking@users.noreply.github.com>
Co-authored-by: Jeff Ong <5375500+jffng@users.noreply.github.com>

* fix the refersh call for the library

Co-authored-by: Jason Crist <146530+pbking@users.noreply.github.com>
Co-authored-by: Jeff Ong <5375500+jffng@users.noreply.github.com>

---------

Co-authored-by: Jason Crist <146530+pbking@users.noreply.github.com>
Co-authored-by: Jeff Ong <5375500+jffng@users.noreply.github.com>

* Don’t use TypeScript files in scripts package (#54856)

* Fix Search Block not updating in Nav block (#54823)

* Avoid setState in render

* Attempt at test coverage

* Improve tests and make them work

* Remove word-wrap property (#54866)

---------

Co-authored-by: Matias Benedetto <matias.benedetto@gmail.com>
Co-authored-by: Aki Hamano <54422211+t-hamano@users.noreply.github.com>
Co-authored-by: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com>
Co-authored-by: Bart Kalisz <bartlomiej.kalisz@gmail.com>
Co-authored-by: George Mamadashvili <georgemamadashvili@gmail.com>
Co-authored-by: Artemio Morales <artemio.morales@a8c.com>
Co-authored-by: Riad Benguella <benguella@gmail.com>
Co-authored-by: Marin Atanasov <8436925+tyxla@users.noreply.github.com>
Co-authored-by: Michal Czaplinski <mmczaplinski@gmail.com>
Co-authored-by: Rich Tabor <hi@richtabor.com>
Co-authored-by: Glen Davies <glen.davies@automattic.com>
Co-authored-by: Jason Crist <jcrist@pbking.com>
Co-authored-by: Alex Stine <alex.stine@yourtechadvisors.com>
Co-authored-by: madhusudhand <madhusudhan.dollu@gmail.com>
Co-authored-by: Carlos Bravo <37012961+c4rl0sbr4v0@users.noreply.github.com>
Co-authored-by: Ricardo Artemio Morales <ric.morales22@gmail.com>
Co-authored-by: Kai Hao <kevin830726@gmail.com>
Co-authored-by: Adam Silverstein <adamjs@google.com>
Co-authored-by: Dave Smith <getdavemail@gmail.com>
Co-authored-by: Nik Tsekouras <ntsekouras@outlook.com>
Co-authored-by: Ramon <ramonjd@users.noreply.github.com>
Co-authored-by: Jason Crist <146530+pbking@users.noreply.github.com>
Co-authored-by: Jeff Ong <5375500+jffng@users.noreply.github.com>
Co-authored-by: Pascal Birchler <pascalb@google.com>
  • Loading branch information
1 parent 5d2e3d0 commit ca2257f
Show file tree
Hide file tree
Showing 95 changed files with 2,623 additions and 1,294 deletions.
4 changes: 3 additions & 1 deletion lib/block-supports/behaviors.php
Expand Up @@ -233,7 +233,9 @@ function gutenberg_render_behaviors_support_lightbox( $block_content, $block ) {
data-wp-bind--aria-modal="context.core.image.lightboxEnabled"
data-wp-effect="effects.core.image.initLightbox"
data-wp-on--keydown="actions.core.image.handleKeydown"
data-wp-on--mousewheel="actions.core.image.hideLightbox"
data-wp-on--touchstart="actions.core.image.handleTouchStart"
data-wp-on--touchmove="actions.core.image.handleTouchMove"
data-wp-on--touchend="actions.core.image.handleTouchEnd"
data-wp-on--click="actions.core.image.hideLightbox"
>
<button type="button" aria-label="$close_button_label" style="fill: $close_button_color" class="close-button" data-wp-on--click="actions.core.image.hideLightbox">
Expand Down
20 changes: 17 additions & 3 deletions lib/class-wp-theme-json-gutenberg.php
Expand Up @@ -1145,9 +1145,23 @@ protected function process_blocks_custom_css( $css, $selector ) {
// Split CSS nested rules.
$parts = explode( '&', $css );
foreach ( $parts as $part ) {
$processed_css .= ( ! str_contains( $part, '{' ) )
? trim( $selector ) . '{' . trim( $part ) . '}' // If the part doesn't contain braces, it applies to the root level.
: trim( $selector . $part ); // Prepend the selector, which effectively replaces the "&" character.
$is_root_css = ( ! str_contains( $part, '{' ) );
if ( $is_root_css ) {
// If the part doesn't contain braces, it applies to the root level.
$processed_css .= trim( $selector ) . '{' . trim( $part ) . '}';
} else {
// If the part contains braces, it's a nested CSS rule.
$part = explode( '{', str_replace( '}', '', $part ) );
if ( count( $part ) !== 2 ) {
continue;
}
$nested_selector = $part[0];
$css_value = $part[1];
$part_selector = str_starts_with( $nested_selector, ' ' )
? static::scope_selector( $selector, $nested_selector )
: static::append_to_selector( $selector, $nested_selector );
$processed_css .= $part_selector . '{' . trim( $css_value ) . '}';
}
}
return $processed_css;
}
Expand Down
250 changes: 250 additions & 0 deletions lib/compat/plugin/footnotes.php
@@ -0,0 +1,250 @@
<?php
/**
* Compatibility shim for the footnotes bloct to enable test passing while awaiting the tested code to be merged to core.
*
* See https://github.com/WordPress/gutenberg/pull/52988.
*
* Once merged, this shim can be removed.
*
* @package gutenberg
*/

/**
* Remove footnote revision hooks when plugin is running on a version of core that already supports meta revisions.
*/
if ( function_exists( 'wp_post_revision_meta_keys' ) ) {
if ( has_action( 'rest_after_insert_post', 'wp_add_footnotes_revisions_to_post_meta' ) ) {
remove_action( 'rest_after_insert_post', 'wp_add_footnotes_revisions_to_post_meta' );
}
if ( has_action( 'rest_after_insert_page', 'wp_add_footnotes_revisions_to_post_meta' ) ) {
remove_action( 'rest_after_insert_page', 'wp_add_footnotes_revisions_to_post_meta' );
}
if ( has_action( 'wp_after_insert_post', 'wp_save_footnotes_meta' ) ) {
remove_action( 'wp_after_insert_post', 'wp_save_footnotes_meta' );
}
if ( has_action( '_wp_put_post_revision', 'wp_keep_footnotes_revision_id' ) ) {
remove_action( '_wp_put_post_revision', 'wp_keep_footnotes_revision_id' );
}
if ( has_action( 'wp_restore_post_revision', 'wp_restore_footnotes_from_revision' ) ) {
remove_action( 'wp_restore_post_revision', 'wp_restore_footnotes_from_revision' );
}
if ( has_action( 'wp_creating_autosave', '_wp_rest_api_autosave_meta' ) ) {
remove_action( 'wp_creating_autosave', '_wp_rest_api_autosave_meta' );
}
if ( has_action( '_wp_put_post_revision', '_wp_rest_api_autosave_meta' ) ) {
remove_action( '_wp_put_post_revision', '_wp_rest_api_autosave_meta' );
}
if ( has_filter( 'rest_pre_insert_post', '_wp_rest_api_force_autosave_difference' ) ) {
remove_filter( 'rest_pre_insert_post', '_wp_rest_api_force_autosave_difference' );
}
} else {
/**
* For versions of core that don't support meta revisions, use hooks to add.
*/
if ( ! function_exists( 'wp_save_footnotes_meta' ) ) {
/**
* Saves the footnotes meta value to the revision.
*
* @since 6.3.0
* @since 6.4.0 Core added post meta revisions, so this is no longer needed.
*
* @param int $revision_id The revision ID.
*/
function wp_save_footnotes_meta( $revision_id ) {
$post_id = wp_is_post_revision( $revision_id );

if ( $post_id ) {
$footnotes = get_post_meta( $post_id, 'footnotes', true );

if ( $footnotes ) {
// Can't use update_post_meta() because it doesn't allow revisions.
update_metadata( 'post', $revision_id, 'footnotes', wp_slash( $footnotes ) );
}
}
}
if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) {
add_action( 'wp_after_insert_post', 'wp_save_footnotes_meta' );
}
}

if ( ! function_exists( 'wp_keep_footnotes_revision_id' ) ) {
/**
* Keeps track of the revision ID for "rest_after_insert_{$post_type}".
*
* @since 6.3.0
* @since 6.4.0 Core added post meta revisions, so this is no longer needed.
*
* @global int $wp_temporary_footnote_revision_id The footnote revision ID.
*
* @param int $revision_id The revision ID.
*/
function wp_keep_footnotes_revision_id( $revision_id ) {
global $wp_temporary_footnote_revision_id;
$wp_temporary_footnote_revision_id = $revision_id;
}
if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) {
add_action( '_wp_put_post_revision', 'wp_keep_footnotes_revision_id' );
}
}

if ( ! function_exists( 'wp_add_footnotes_revisions_to_post_meta' ) ) {

/**
* This is a specific fix for the REST API. The REST API doesn't update
* the post and post meta in one go (through `meta_input`). While it
* does fix the `wp_after_insert_post` hook to be called correctly after
* updating meta, it does NOT fix hooks such as post_updated and
* save_post, which are normally also fired after post meta is updated
* in `wp_insert_post()`. Unfortunately, `wp_save_post_revision` is
* added to the `post_updated` action, which means the meta is not
* available at the time, so we have to add it afterwards through the
* `"rest_after_insert_{$post_type}"` action.
*
* @since 6.3.0
* @since 6.4.0 Core added post meta revisions, so this is no longer needed.
*
* @global int $wp_temporary_footnote_revision_id The footnote revision ID.
*
* @param WP_Post $post The post object.
*/
function wp_add_footnotes_revisions_to_post_meta( $post ) {
global $wp_temporary_footnote_revision_id;

if ( $wp_temporary_footnote_revision_id ) {
$revision = get_post( $wp_temporary_footnote_revision_id );

if ( ! $revision ) {
return;
}

$post_id = $revision->post_parent;

// Just making sure we're updating the right revision.
if ( $post->ID === $post_id ) {
$footnotes = get_post_meta( $post_id, 'footnotes', true );

if ( $footnotes ) {
// Can't use update_post_meta() because it doesn't allow revisions.
update_metadata( 'post', $wp_temporary_footnote_revision_id, 'footnotes', wp_slash( $footnotes ) );
}
}
}
}

if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) {
add_action( 'rest_after_insert_post', 'wp_add_footnotes_revisions_to_post_meta' );
add_action( 'rest_after_insert_page', 'wp_add_footnotes_revisions_to_post_meta' );
}
}

if ( ! function_exists( 'wp_restore_footnotes_from_revision' ) ) {

/**
* Restores the footnotes meta value from the revision.
*
* @since 6.3.0
* @since 6.4.0 Core added post meta revisions, so this is no longer needed.
*
* @param int $post_id The post ID.
* @param int $revision_id The revision ID.
*/
function wp_restore_footnotes_from_revision( $post_id, $revision_id ) {
$footnotes = get_post_meta( $revision_id, 'footnotes', true );

if ( $footnotes ) {
update_post_meta( $post_id, 'footnotes', wp_slash( $footnotes ) );
} else {
delete_post_meta( $post_id, 'footnotes' );
}
}
if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) {
add_action( 'wp_restore_post_revision', 'wp_restore_footnotes_from_revision', 10, 2 );
}
}

if ( ! function_exists( '_wp_rest_api_autosave_meta' ) ) {

/**
* The REST API autosave endpoint doesn't save meta, so we can use the
* `wp_creating_autosave` when it updates an exiting autosave, and
* `_wp_put_post_revision` when it creates a new autosave.
*
* @since 6.3.0
* @since 6.4.0 Core added post meta revisions, so this is no longer needed.
*
* @param int|array $autosave The autosave ID or array.
*/
function _wp_rest_api_autosave_meta( $autosave ) {
// Ensure it's a REST API request.
if ( ! defined( 'REST_REQUEST' ) || ! REST_REQUEST ) {
return;
}

$body = rest_get_server()->get_raw_data();
$body = json_decode( $body, true );

if ( ! isset( $body['meta']['footnotes'] ) ) {
return;
}

// `wp_creating_autosave` passes the array,
// `_wp_put_post_revision` passes the ID.
$id = is_int( $autosave ) ? $autosave : $autosave['ID'];

if ( ! $id ) {
return;
}

// Can't use update_post_meta() because it doesn't allow revisions.
update_metadata( 'post', $id, 'footnotes', wp_slash( $body['meta']['footnotes'] ) );
}

if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) {
// See https://github.com/WordPress/wordpress-develop/blob/2103cb9966e57d452c94218bbc3171579b536a40/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php#L391C1-L391C1.
add_action( 'wp_creating_autosave', '_wp_rest_api_autosave_meta' );
// See https://github.com/WordPress/wordpress-develop/blob/2103cb9966e57d452c94218bbc3171579b536a40/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php#L398.
// Then https://github.com/WordPress/wordpress-develop/blob/2103cb9966e57d452c94218bbc3171579b536a40/src/wp-includes/revision.php#L367.
add_action( '_wp_put_post_revision', '_wp_rest_api_autosave_meta' );
}
}

if ( ! function_exists( '_wp_rest_api_force_autosave_difference' ) ) {

/**
* This is a workaround for the autosave endpoint returning early if the
* revision field are equal. The problem is that "footnotes" is not real
* revision post field, so there's nothing to compare against.
*
* This trick sets the "footnotes" field (value doesn't matter), which will
* cause the autosave endpoint to always update the latest revision. That should
* be fine, it should be ok to update the revision even if nothing changed. Of
* course, this is temporary fix.
*
* @since 6.3.0
* @since 6.4.0 Core added post meta revisions, so this is no longer needed.
*
* @param WP_Post $prepared_post The prepared post object.
* @param WP_REST_Request $request The request object.
*
* See https://github.com/WordPress/wordpress-develop/blob/2103cb9966e57d452c94218bbc3171579b536a40/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php#L365-L384.
* See https://github.com/WordPress/wordpress-develop/blob/2103cb9966e57d452c94218bbc3171579b536a40/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php#L219.
*/
function _wp_rest_api_force_autosave_difference( $prepared_post, $request ) {
// We only want to be altering POST requests.
if ( $request->get_method() !== 'POST' ) {
return $prepared_post;
}

// Only alter requests for the '/autosaves' route.
if ( substr( $request->get_route(), -strlen( '/autosaves' ) ) !== '/autosaves' ) {
return $prepared_post;
}

$prepared_post->footnotes = '[]';
return $prepared_post;
}
if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) {
add_filter( 'rest_pre_insert_post', '_wp_rest_api_force_autosave_difference', 10, 2 );
}
}
}
Expand Up @@ -79,7 +79,7 @@ public function get_config() {
*/
public function get_data() {
// If the src is a URL, fetch the data from the URL.
if ( false !== strpos( $this->config['src'], 'http' ) && false !== strpos( $this->config['src'], '://' ) ) {
if ( str_contains( $this->config['src'], 'http' ) && str_contains( $this->config['src'], '://' ) ) {
if ( ! wp_http_validate_url( $this->config['src'] ) ) {
return new WP_Error( 'font_collection_read_error', __( 'Invalid URL for Font Collection data.', 'gutenberg' ) );
}
Expand Down
Expand Up @@ -85,8 +85,9 @@ public static function merge_fonts_data( $font1, $font2 ) {
* @return bool True if the file has a font MIME type, false otherwise.
*/
public static function has_font_mime_type( $filepath ) {
$filetype = wp_check_filetype( $filepath, WP_Font_Library::ALLOWED_FONT_MIME_TYPES );
$allowed_mime_types = WP_Font_Library::get_expected_font_mime_types_per_php_version();
$filetype = wp_check_filetype( $filepath, $allowed_mime_types );

return in_array( $filetype['type'], WP_Font_Library::ALLOWED_FONT_MIME_TYPES, true );
return in_array( $filetype['type'], $allowed_mime_types, true );
}
}
Expand Up @@ -182,7 +182,7 @@ private function get_upload_overrides( $filename ) {
// Seems mime type for files that are not images cannot be tested.
// See wp_check_filetype_and_ext().
'test_type' => true,
'mimes' => WP_Font_Library::ALLOWED_FONT_MIME_TYPES,
'mimes' => WP_Font_Library::get_expected_font_mime_types_per_php_version(),
'unique_filename_callback' => static function () use ( $filename ) {
// Keep the original filename.
return $filename;
Expand Down
30 changes: 22 additions & 8 deletions lib/experimental/fonts/font-library/class-wp-font-library.php
Expand Up @@ -20,14 +20,28 @@
*/
class WP_Font_Library {

const PHP_7_TTF_MIME_TYPE = PHP_VERSION_ID >= 70300 ? 'application/font-sfnt' : 'application/x-font-ttf';
/**
* 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.
*
* This is necessary until a collection of valid mime-types per-file extension can be provided to 'upload_mimes' filter.
*
* @since 6.4.0
*
* @param array $php_version_id The version of PHP to provide mime types for. The default is the current PHP version.
*
* @return Array A collection of mime types keyed by file extension.
*/
public static function get_expected_font_mime_types_per_php_version( $php_version_id = PHP_VERSION_ID ) {

const ALLOWED_FONT_MIME_TYPES = array(
'otf' => 'font/otf',
'ttf' => PHP_VERSION_ID >= 70400 ? 'font/sfnt' : self::PHP_7_TTF_MIME_TYPE,
'woff' => PHP_VERSION_ID >= 80100 ? 'font/woff' : 'application/font-woff',
'woff2' => PHP_VERSION_ID >= 80100 ? 'font/woff2' : 'application/font-woff2',
);
$php_7_ttf_mime_type = $php_version_id >= 70300 ? 'application/font-sfnt' : 'application/x-font-ttf';

return array(
'otf' => 'application/vnd.ms-opentype',
'ttf' => $php_version_id >= 70400 ? 'font/sfnt' : $php_7_ttf_mime_type,
'woff' => $php_version_id >= 80100 ? 'font/woff' : 'application/font-woff',
'woff2' => $php_version_id >= 80100 ? 'font/woff2' : 'application/font-woff2',
);
}

/**
* Font collections.
Expand Down Expand Up @@ -130,6 +144,6 @@ public static function set_upload_dir( $defaults ) {
* @return array Modified upload directory.
*/
public static function set_allowed_mime_types( $mime_types ) {
return array_merge( $mime_types, self::ALLOWED_FONT_MIME_TYPES );
return array_merge( $mime_types, self::get_expected_font_mime_types_per_php_version() );
}
}

1 comment on commit ca2257f

@github-actions
Copy link

@github-actions github-actions bot commented on ca2257f Oct 2, 2023

Choose a reason for hiding this comment

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

Flaky tests detected in ca2257f.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/6383239550
📝 Reported issues:

Please sign in to comment.