WordPress/wp-includes/rest-api/endpoints
Pascal Birchler 47687d8799 Editor: Prevent font folder naive filtering causing infinite loops.
This modifies the font directory API to more closely reflect the upload directory API to help account for naive filtering when uploading fonts.

This moves the protection of infinite loops to the new function `_wp_filter_font_directory()` to allow developers extending and maintaining the font library to apply the filter without the need for a closure.

These changes also ensure both the `upload_dir` and `font_dir` filter are applied consistently when both creating and deleting fonts faces. Prior to this commit the `upload_dir` filter was only fired when creating fonts faces via the REST API.

Applying the font directory filter to the `upload_dir` filter is now done by adding the `_wp_filter_font_directory` function rather than `wp_get_font_dir()`. Developers who have previously modified the font upload directory using the `font_dir` filter will NOT need to upload their code.

Extenders wishing to upload files to the font directory can do so via the code:

{{{#!php
<?php
add_filter( 'upload_dir', '_wp_filter_font_directory' );
// Your code to upload or sideload a font file.
remove_filter( 'upload_dir', '_wp_filter_font_directory' );
}}}

Introduces:

* `wp_font_dir()`: Attempt to create and retrieve the font upload directory. The equivalent to `wp_upload_dir()`.
* `_wp_filter_font_directory()`: To run on the `upload_dir` filter, this sets the default destination of the fonts directory and fires the `font_dir` filter. 

`wp_get_font_dir()` has been modified to be a lightweight getter for the font directory. It returns the location without attempting to create it. The equivalent to `wp_get_upload_dir()`.

Follow up to [57740].

Reviewed by swissspidy.
Merges [57868] to the 6.5 branch.

Props peterwilsoncc, mukesh27, mikachan, costdev, mmaattiiaass, swissspidy, youknowriad, dd32, grantmkin.
Fixes #60652.
Built from https://develop.svn.wordpress.org/branches/6.5@57879


git-svn-id: http://core.svn.wordpress.org/branches/6.5@57380 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-03-26 09:24:11 +00:00
..
class-wp-rest-application-passwords-controller.php
class-wp-rest-attachments-controller.php REST API: Add featured_media field to attachments endpoint. 2024-02-12 22:17:11 +00:00
class-wp-rest-autosaves-controller.php REST API: Fix issue with Template and Template Part Revision/Autosave REST API controllers. 2023-10-10 14:05:21 +00:00
class-wp-rest-block-directory-controller.php
class-wp-rest-block-pattern-categories-controller.php REST API: Cache schema in block pattern and menu item endpoints. 2023-06-28 15:53:26 +00:00
class-wp-rest-block-patterns-controller.php REST API: Cache schema in block pattern and menu item endpoints. 2023-06-28 15:53:26 +00:00
class-wp-rest-block-renderer-controller.php
class-wp-rest-block-types-controller.php Coding standards: Apply some changes after composer format. 2024-03-05 06:55:08 +00:00
class-wp-rest-blocks-controller.php Coding Standards: Remove extra space in a comment in WP_REST_Blocks_Controller. 2023-10-31 14:23:21 +00:00
class-wp-rest-comments-controller.php General: Consistently cast return value to int in functions that use ceil(). 2024-02-17 15:24:08 +00:00
class-wp-rest-controller.php Coding Standards: Include one space after function keyword for closures. 2023-09-12 15:23:18 +00:00
class-wp-rest-edit-site-export-controller.php
class-wp-rest-font-collections-controller.php Editor: Ensure font collection metadata can be properly localized. 2024-02-21 19:27:14 +00:00
class-wp-rest-font-faces-controller.php Editor: Prevent font folder naive filtering causing infinite loops. 2024-03-26 09:24:11 +00:00
class-wp-rest-font-families-controller.php REST API: Introduce the necessary endpoints for the font library. 2024-02-07 09:20:08 +00:00
class-wp-rest-global-styles-controller.php REST API: Revert the refactor of global styles endpoints in REST API in [57624]. 2024-02-13 15:13:17 +00:00
class-wp-rest-global-styles-revisions-controller.php General: Consistently cast return value to int in functions that use ceil(). 2024-02-17 15:24:08 +00:00
class-wp-rest-menu-items-controller.php REST API: Correct the docblocks for various permission related methods. 2023-08-18 17:46:18 +00:00
class-wp-rest-menu-locations-controller.php Coding Standards: Restore more descriptive variable names in a few class methods. 2023-09-14 12:46:20 +00:00
class-wp-rest-menus-controller.php REST API: Correct the docblocks for various permission related methods. 2023-08-18 17:46:18 +00:00
class-wp-rest-navigation-fallback-controller.php General: Remove discouraged @return void annotations. 2023-10-16 15:17:23 +00:00
class-wp-rest-pattern-directory-controller.php Coding Standards: Remove redundant ignore annotations, take 5. 2023-10-02 11:27:24 +00:00
class-wp-rest-plugins-controller.php Coding Standards: Include one space after function keyword for closures. 2023-09-12 15:23:18 +00:00
class-wp-rest-post-statuses-controller.php Coding Standards: Restore more descriptive variable names in a few class methods. 2023-09-14 12:46:20 +00:00
class-wp-rest-post-types-controller.php Coding Standards: Restore more descriptive variable names in a few class methods. 2023-09-14 12:46:20 +00:00
class-wp-rest-posts-controller.php General: Consistently cast return value to int in functions that use ceil(). 2024-02-17 15:24:08 +00:00
class-wp-rest-revisions-controller.php General: Consistently cast return value to int in functions that use ceil(). 2024-02-17 15:24:08 +00:00
class-wp-rest-search-controller.php General: Consistently cast return value to int in functions that use ceil(). 2024-02-17 15:24:08 +00:00
class-wp-rest-settings-controller.php Coding Standards: Remove superfluous blank lines at the end of various functions. 2023-09-08 10:03:21 +00:00
class-wp-rest-sidebars-controller.php Coding Standards: Restore more descriptive variable names in a few class methods. 2023-09-14 12:46:20 +00:00
class-wp-rest-site-health-controller.php Coding Standards: Include one space after function keyword for closures. 2023-09-12 15:23:18 +00:00
class-wp-rest-taxonomies-controller.php Coding Standards: Restore more descriptive variable names in a few class methods. 2023-09-14 12:46:20 +00:00
class-wp-rest-template-autosaves-controller.php REST API: Fix issue with Template and Template Part Revision/Autosave REST API controllers. 2023-10-10 14:05:21 +00:00
class-wp-rest-template-revisions-controller.php REST API: Fix issue with Template and Template Part Revision/Autosave REST API controllers. 2023-10-10 14:05:21 +00:00
class-wp-rest-templates-controller.php Block Hooks: Use new Templates Controller filter instead of action. 2024-03-11 14:15:33 +00:00
class-wp-rest-terms-controller.php General: Consistently cast return value to int in functions that use ceil(). 2024-02-17 15:24:08 +00:00
class-wp-rest-themes-controller.php Coding Standards: Restore more descriptive variable names in a few class methods. 2023-09-14 12:46:20 +00:00
class-wp-rest-url-details-controller.php Bootstrap/Load: Introduce functions to check whether WordPress is serving a REST API request. 2024-01-19 17:40:09 +00:00
class-wp-rest-users-controller.php General: Consistently cast return value to int in functions that use ceil(). 2024-02-17 15:24:08 +00:00
class-wp-rest-widget-types-controller.php Coding Standards: Restore more descriptive variable names in a few class methods. 2023-09-14 12:46:20 +00:00
class-wp-rest-widgets-controller.php Coding Standards: Include one space after function keyword for closures. 2023-09-12 15:23:18 +00:00