diff --git a/lib/compat/wordpress-6.5/fonts/class-wp-rest-font-faces-controller.php b/lib/compat/wordpress-6.5/fonts/class-wp-rest-font-faces-controller.php index 8a4040e3397e0..1a38aa4de18e0 100644 --- a/lib/compat/wordpress-6.5/fonts/class-wp-rest-font-faces-controller.php +++ b/lib/compat/wordpress-6.5/fonts/class-wp-rest-font-faces-controller.php @@ -326,6 +326,14 @@ public function create_item( $request ) { $settings = $request->get_param( 'font_face_settings' ); $file_params = $request->get_file_params(); + if ( ! empty( $file_params ) && ! $this->can_upload_fonts() ) { + return new WP_Error( + 'rest_cannot_upload_fonts', + __( 'You are not allowed to upload font files.', 'gutenberg' ), + array( 'status' => 403 ) + ); + } + // Check that the necessary font face properties are unique. $query = new WP_Query( array( @@ -903,6 +911,18 @@ public function handle_font_file_upload_error( $file, $message ) { return new WP_Error( $code, $message, array( 'status' => $status ) ); } + /** + * Checks if fonts can be uploaded to the site. + * + * @since 6.5.0 + * + * @return bool Whether font assets can be upload. + */ + protected function can_upload_fonts() { + $fonts_dir = wp_get_font_dir()['path']; + return wp_is_file_mod_allowed( 'can_upload_fonts' ) && wp_is_writable( $fonts_dir ); + } + /** * Returns relative path to an uploaded font file. * diff --git a/packages/edit-site/src/components/global-styles/font-library-modal/font-collection.js b/packages/edit-site/src/components/global-styles/font-library-modal/font-collection.js index 6236ea8fe3f24..c0ef746e79e31 100644 --- a/packages/edit-site/src/components/global-styles/font-library-modal/font-collection.js +++ b/packages/edit-site/src/components/global-styles/font-library-modal/font-collection.js @@ -23,6 +23,8 @@ import { import { debounce } from '@wordpress/compose'; import { sprintf, __, _x } from '@wordpress/i18n'; import { search, closeSmall } from '@wordpress/icons'; +import { store as editorStore } from '@wordpress/editor'; +import { useSelect } from '@wordpress/data'; /** * Internal dependencies @@ -161,13 +163,13 @@ function FontCollection( { slug } ) { setFontsToInstall( [] ); }; - const handleInstall = async () => { + const handleInstall = async ( shouldUpload = true ) => { setNotice( null ); const fontFamily = fontsToInstall[ 0 ]; try { - if ( fontFamily?.fontFace ) { + if ( fontFamily?.fontFace && shouldUpload ) { await Promise.all( fontFamily.fontFace.map( async ( fontFace ) => { if ( fontFace.src ) { @@ -398,12 +400,17 @@ function PaginationFooter( { page, totalPages, setPage } ) { function InstallFooter( { handleInstall, isDisabled } ) { const { isInstalling } = useContext( FontLibraryContext ); + const fontUploadEnabled = useSelect( + ( select ) => + select( editorStore ).getEditorSettings().fontUploadEnabled, + [] + ); return (