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: font family and font uploads capability checks #59294

Closed
wants to merge 20 commits into from

Conversation

creativecoder
Copy link
Contributor

@creativecoder creativecoder commented Feb 22, 2024

What?

Fixes #55280

  • Adds a meta capability for uploading fonts
  • Adds an editor setting that enables/disables font uploads
  • Adds capability checks in the Font Library UI for creating/installing fonts, uploading font files, and deleting fonts

Combines approaches from #58957 and #59104

Note that in the future, it should be possible to create/install fonts from a collection without uploading a font file to the site, as font-faces support using an existing url as the src. The font could be loaded from a CDN provided by the collection. Or a plugin could provide bundled fonts that don't need the font files to be uploaded to the site because they're included with the plugin. See #58229.

For this reason, font upload and font creation capabilities are separate, so that it's possible to install a font without the ability to upload font files.

Why?

  • Ensures that customizing capabilities for font post types is reflected in the UI
  • Respects the DISALLOW_FILE_MODS constant to prevent font uploads for sites that don't allow file modification

How?

  • Adds an upload_fonts meta capability that's tied to DISALLOW_FILE_MODS/wp_is_file_mod_allowed
  • Checks the upload_fonts capability before allowing font file uploads on the font-faces endpoint
  • Adds a fontUploadsEnabled setting the site editor that checks the upload_fonts capability
  • Hides font uploads and font collections tabs in the font library when the user does not have the capability to upload or create fonts
  • Hides the delete button when the user does not have the capability to delete fonts

Testing Instructions

IMPORTANT: Test with WP 6.4 to ensure you are running the Gutenberg code from this PR

Test with DISALLOW_FILE_MODS

  • Add define( 'DISALLOW_FILE_MODS', true ); in wp-config.php
  • In the font library, you should not see the "Upload" or "Install Fonts" tabs
  • If you create a font that includes a font file, it will error (POST wp/v2/font-families/<id>/font-faces)

Test with custom permissions

Add the following to your site

add_filter( 'register_post_type_args', function( $args, $post_type ) {
	if ( $post_type === 'wp_font_family' ) {
		$args['capabilities']['create_posts'] = 'do_not_allow';
		$args['capabilities']['delete_published_posts'] = 'do_not_allow';
	}
	return $args;
}, 10, 2 );
  • In the font library, you should not see the "Upload" or "Install Fonts" tabs
  • For fonts that are already installed, you should not see a "Delete" button

Copy link

github-actions bot commented Feb 22, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: creativecoder <grantmkin@git.wordpress.org>
Co-authored-by: matiasbenedetto <mmaattiiaass@git.wordpress.org>
Co-authored-by: anton-vlasenko <antonvlasenko@git.wordpress.org>
Co-authored-by: peterwilsoncc <peterwilsoncc@git.wordpress.org>
Co-authored-by: swissspidy <swissspidy@git.wordpress.org>
Co-authored-by: mikachan <mikachan@git.wordpress.org>
Co-authored-by: felixarntz <flixos90@git.wordpress.org>
Co-authored-by: azaozz <azaozz@git.wordpress.org>
Co-authored-by: jasmussen <joen@git.wordpress.org>
Co-authored-by: hellofromtonya <hellofromtonya@git.wordpress.org>
Co-authored-by: jffng <jffng@git.wordpress.org>
Co-authored-by: getdave <get_dave@git.wordpress.org>
Co-authored-by: joemcgill <joemcgill@git.wordpress.org>
Co-authored-by: mtias <matveb@git.wordpress.org>
Co-authored-by: aaronjorbin <jorbin@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@creativecoder creativecoder added [Type] Bug An existing feature does not function as intended [Feature] Font Library REST API Interaction Related to REST API labels Feb 22, 2024
Copy link

github-actions bot commented Feb 22, 2024

This pull request has changed or added PHP files. Please confirm whether these changes need to be synced to WordPress Core, and therefore featured in the next release of WordPress.

If so, it is recommended to create a new Trac ticket and submit a pull request to the WordPress Core Github repository soon after this pull request is merged.

If you're unsure, you can always ask for help in the #core-editor channel in WordPress Slack.

Thank you! ❤️

View changed files
❔ phpunit/tests/fonts/font-library/deleteFontPostMetaCaps.php
❔ phpunit/tests/fonts/font-library/maybeGrantUploadFontCap.php
❔ lib/compat/wordpress-6.5/fonts/class-wp-rest-font-faces-controller.php
❔ lib/compat/wordpress-6.5/fonts/fonts.php

Copy link

github-actions bot commented Feb 22, 2024

Size Change: +383 B (0%)

Total Size: 1.71 MB

Filename Size Change
build/block-editor/content-rtl.css 4.36 kB +6 B (0%)
build/block-editor/content.css 4.36 kB +6 B (0%)
build/block-editor/index.min.js 250 kB +137 B (0%)
build/block-editor/style-rtl.css 15.5 kB +33 B (0%)
build/block-editor/style.css 15.5 kB +33 B (0%)
build/data/index.min.js 8.95 kB +12 B (0%)
build/edit-site/index.min.js 214 kB +149 B (0%)
build/edit-site/style-rtl.css 15.3 kB +1 B (0%)
build/edit-site/style.css 15.3 kB +1 B (0%)
build/editor/index.min.js 63.9 kB +5 B (0%)
ℹ️ View Unchanged
Filename Size
build/a11y/index.min.js 955 B
build/annotations/index.min.js 2.69 kB
build/api-fetch/index.min.js 2.32 kB
build/autop/index.min.js 2.1 kB
build/blob/index.min.js 578 B
build/block-directory/index.min.js 7.22 kB
build/block-directory/style-rtl.css 1.02 kB
build/block-directory/style.css 1.02 kB
build/block-editor/default-editor-styles-rtl.css 381 B
build/block-editor/default-editor-styles.css 381 B
build/block-library/blocks/archives/editor-rtl.css 61 B
build/block-library/blocks/archives/editor.css 60 B
build/block-library/blocks/archives/style-rtl.css 90 B
build/block-library/blocks/archives/style.css 90 B
build/block-library/blocks/audio/editor-rtl.css 150 B
build/block-library/blocks/audio/editor.css 150 B
build/block-library/blocks/audio/style-rtl.css 122 B
build/block-library/blocks/audio/style.css 122 B
build/block-library/blocks/audio/theme-rtl.css 126 B
build/block-library/blocks/audio/theme.css 126 B
build/block-library/blocks/avatar/editor-rtl.css 116 B
build/block-library/blocks/avatar/editor.css 116 B
build/block-library/blocks/avatar/style-rtl.css 104 B
build/block-library/blocks/avatar/style.css 104 B
build/block-library/blocks/block/editor-rtl.css 305 B
build/block-library/blocks/block/editor.css 305 B
build/block-library/blocks/button/editor-rtl.css 415 B
build/block-library/blocks/button/editor.css 414 B
build/block-library/blocks/button/style-rtl.css 627 B
build/block-library/blocks/button/style.css 626 B
build/block-library/blocks/buttons/editor-rtl.css 337 B
build/block-library/blocks/buttons/editor.css 337 B
build/block-library/blocks/buttons/style-rtl.css 332 B
build/block-library/blocks/buttons/style.css 332 B
build/block-library/blocks/calendar/style-rtl.css 239 B
build/block-library/blocks/calendar/style.css 239 B
build/block-library/blocks/categories/editor-rtl.css 113 B
build/block-library/blocks/categories/editor.css 112 B
build/block-library/blocks/categories/style-rtl.css 124 B
build/block-library/blocks/categories/style.css 124 B
build/block-library/blocks/code/editor-rtl.css 53 B
build/block-library/blocks/code/editor.css 53 B
build/block-library/blocks/code/style-rtl.css 121 B
build/block-library/blocks/code/style.css 121 B
build/block-library/blocks/code/theme-rtl.css 124 B
build/block-library/blocks/code/theme.css 124 B
build/block-library/blocks/columns/editor-rtl.css 108 B
build/block-library/blocks/columns/editor.css 108 B
build/block-library/blocks/columns/style-rtl.css 421 B
build/block-library/blocks/columns/style.css 421 B
build/block-library/blocks/comment-author-avatar/editor-rtl.css 125 B
build/block-library/blocks/comment-author-avatar/editor.css 125 B
build/block-library/blocks/comment-content/style-rtl.css 92 B
build/block-library/blocks/comment-content/style.css 92 B
build/block-library/blocks/comment-template/style-rtl.css 199 B
build/block-library/blocks/comment-template/style.css 198 B
build/block-library/blocks/comments-pagination-numbers/editor-rtl.css 123 B
build/block-library/blocks/comments-pagination-numbers/editor.css 121 B
build/block-library/blocks/comments-pagination/editor-rtl.css 222 B
build/block-library/blocks/comments-pagination/editor.css 209 B
build/block-library/blocks/comments-pagination/style-rtl.css 235 B
build/block-library/blocks/comments-pagination/style.css 231 B
build/block-library/blocks/comments-title/editor-rtl.css 75 B
build/block-library/blocks/comments-title/editor.css 75 B
build/block-library/blocks/comments/editor-rtl.css 840 B
build/block-library/blocks/comments/editor.css 839 B
build/block-library/blocks/comments/style-rtl.css 637 B
build/block-library/blocks/comments/style.css 636 B
build/block-library/blocks/cover/editor-rtl.css 647 B
build/block-library/blocks/cover/editor.css 650 B
build/block-library/blocks/cover/style-rtl.css 1.69 kB
build/block-library/blocks/cover/style.css 1.68 kB
build/block-library/blocks/details/editor-rtl.css 65 B
build/block-library/blocks/details/editor.css 65 B
build/block-library/blocks/details/style-rtl.css 98 B
build/block-library/blocks/details/style.css 98 B
build/block-library/blocks/embed/editor-rtl.css 322 B
build/block-library/blocks/embed/editor.css 322 B
build/block-library/blocks/embed/style-rtl.css 410 B
build/block-library/blocks/embed/style.css 410 B
build/block-library/blocks/embed/theme-rtl.css 126 B
build/block-library/blocks/embed/theme.css 126 B
build/block-library/blocks/file/editor-rtl.css 316 B
build/block-library/blocks/file/editor.css 316 B
build/block-library/blocks/file/style-rtl.css 280 B
build/block-library/blocks/file/style.css 281 B
build/block-library/blocks/file/view.min.js 324 B
build/block-library/blocks/footnotes/style-rtl.css 201 B
build/block-library/blocks/footnotes/style.css 199 B
build/block-library/blocks/form-input/editor-rtl.css 227 B
build/block-library/blocks/form-input/editor.css 227 B
build/block-library/blocks/form-input/style-rtl.css 343 B
build/block-library/blocks/form-input/style.css 343 B
build/block-library/blocks/form-submission-notification/editor-rtl.css 340 B
build/block-library/blocks/form-submission-notification/editor.css 340 B
build/block-library/blocks/form-submit-button/style-rtl.css 69 B
build/block-library/blocks/form-submit-button/style.css 69 B
build/block-library/blocks/form/view.min.js 471 B
build/block-library/blocks/freeform/editor-rtl.css 2.61 kB
build/block-library/blocks/freeform/editor.css 2.61 kB
build/block-library/blocks/gallery/editor-rtl.css 947 B
build/block-library/blocks/gallery/editor.css 952 B
build/block-library/blocks/gallery/style-rtl.css 1.72 kB
build/block-library/blocks/gallery/style.css 1.72 kB
build/block-library/blocks/gallery/theme-rtl.css 108 B
build/block-library/blocks/gallery/theme.css 108 B
build/block-library/blocks/group/editor-rtl.css 647 B
build/block-library/blocks/group/editor.css 647 B
build/block-library/blocks/group/style-rtl.css 57 B
build/block-library/blocks/group/style.css 57 B
build/block-library/blocks/group/theme-rtl.css 78 B
build/block-library/blocks/group/theme.css 78 B
build/block-library/blocks/heading/style-rtl.css 189 B
build/block-library/blocks/heading/style.css 189 B
build/block-library/blocks/html/editor-rtl.css 336 B
build/block-library/blocks/html/editor.css 337 B
build/block-library/blocks/image/editor-rtl.css 894 B
build/block-library/blocks/image/editor.css 893 B
build/block-library/blocks/image/style-rtl.css 1.6 kB
build/block-library/blocks/image/style.css 1.59 kB
build/block-library/blocks/image/theme-rtl.css 126 B
build/block-library/blocks/image/theme.css 126 B
build/block-library/blocks/image/view.min.js 1.54 kB
build/block-library/blocks/latest-comments/style-rtl.css 357 B
build/block-library/blocks/latest-comments/style.css 357 B
build/block-library/blocks/latest-posts/editor-rtl.css 213 B
build/block-library/blocks/latest-posts/editor.css 212 B
build/block-library/blocks/latest-posts/style-rtl.css 478 B
build/block-library/blocks/latest-posts/style.css 478 B
build/block-library/blocks/list/style-rtl.css 88 B
build/block-library/blocks/list/style.css 88 B
build/block-library/blocks/media-text/editor-rtl.css 266 B
build/block-library/blocks/media-text/editor.css 263 B
build/block-library/blocks/media-text/style-rtl.css 505 B
build/block-library/blocks/media-text/style.css 503 B
build/block-library/blocks/more/editor-rtl.css 431 B
build/block-library/blocks/more/editor.css 431 B
build/block-library/blocks/navigation-link/editor-rtl.css 668 B
build/block-library/blocks/navigation-link/editor.css 669 B
build/block-library/blocks/navigation-link/style-rtl.css 259 B
build/block-library/blocks/navigation-link/style.css 257 B
build/block-library/blocks/navigation-submenu/editor-rtl.css 296 B
build/block-library/blocks/navigation-submenu/editor.css 295 B
build/block-library/blocks/navigation/editor-rtl.css 2.26 kB
build/block-library/blocks/navigation/editor.css 2.26 kB
build/block-library/blocks/navigation/style-rtl.css 2.26 kB
build/block-library/blocks/navigation/style.css 2.25 kB
build/block-library/blocks/navigation/view.min.js 1.02 kB
build/block-library/blocks/nextpage/editor-rtl.css 395 B
build/block-library/blocks/nextpage/editor.css 395 B
build/block-library/blocks/page-list/editor-rtl.css 377 B
build/block-library/blocks/page-list/editor.css 377 B
build/block-library/blocks/page-list/style-rtl.css 175 B
build/block-library/blocks/page-list/style.css 175 B
build/block-library/blocks/paragraph/editor-rtl.css 235 B
build/block-library/blocks/paragraph/editor.css 235 B
build/block-library/blocks/paragraph/style-rtl.css 335 B
build/block-library/blocks/paragraph/style.css 335 B
build/block-library/blocks/post-author/style-rtl.css 175 B
build/block-library/blocks/post-author/style.css 176 B
build/block-library/blocks/post-comments-form/editor-rtl.css 96 B
build/block-library/blocks/post-comments-form/editor.css 96 B
build/block-library/blocks/post-comments-form/style-rtl.css 508 B
build/block-library/blocks/post-comments-form/style.css 508 B
build/block-library/blocks/post-content/editor-rtl.css 74 B
build/block-library/blocks/post-content/editor.css 74 B
build/block-library/blocks/post-date/style-rtl.css 61 B
build/block-library/blocks/post-date/style.css 61 B
build/block-library/blocks/post-excerpt/editor-rtl.css 71 B
build/block-library/blocks/post-excerpt/editor.css 71 B
build/block-library/blocks/post-excerpt/style-rtl.css 141 B
build/block-library/blocks/post-excerpt/style.css 141 B
build/block-library/blocks/post-featured-image/editor-rtl.css 666 B
build/block-library/blocks/post-featured-image/editor.css 662 B
build/block-library/blocks/post-featured-image/style-rtl.css 342 B
build/block-library/blocks/post-featured-image/style.css 342 B
build/block-library/blocks/post-navigation-link/style-rtl.css 215 B
build/block-library/blocks/post-navigation-link/style.css 214 B
build/block-library/blocks/post-template/editor-rtl.css 99 B
build/block-library/blocks/post-template/editor.css 98 B
build/block-library/blocks/post-template/style-rtl.css 409 B
build/block-library/blocks/post-template/style.css 408 B
build/block-library/blocks/post-terms/style-rtl.css 96 B
build/block-library/blocks/post-terms/style.css 96 B
build/block-library/blocks/post-time-to-read/style-rtl.css 69 B
build/block-library/blocks/post-time-to-read/style.css 69 B
build/block-library/blocks/post-title/style-rtl.css 100 B
build/block-library/blocks/post-title/style.css 100 B
build/block-library/blocks/preformatted/style-rtl.css 125 B
build/block-library/blocks/preformatted/style.css 125 B
build/block-library/blocks/pullquote/editor-rtl.css 135 B
build/block-library/blocks/pullquote/editor.css 135 B
build/block-library/blocks/pullquote/style-rtl.css 354 B
build/block-library/blocks/pullquote/style.css 354 B
build/block-library/blocks/pullquote/theme-rtl.css 168 B
build/block-library/blocks/pullquote/theme.css 168 B
build/block-library/blocks/query-pagination-numbers/editor-rtl.css 122 B
build/block-library/blocks/query-pagination-numbers/editor.css 121 B
build/block-library/blocks/query-pagination/editor-rtl.css 221 B
build/block-library/blocks/query-pagination/editor.css 211 B
build/block-library/blocks/query-pagination/style-rtl.css 288 B
build/block-library/blocks/query-pagination/style.css 284 B
build/block-library/blocks/query-title/style-rtl.css 63 B
build/block-library/blocks/query-title/style.css 63 B
build/block-library/blocks/query/editor-rtl.css 486 B
build/block-library/blocks/query/editor.css 486 B
build/block-library/blocks/query/view.min.js 958 B
build/block-library/blocks/quote/style-rtl.css 237 B
build/block-library/blocks/quote/style.css 237 B
build/block-library/blocks/quote/theme-rtl.css 223 B
build/block-library/blocks/quote/theme.css 226 B
build/block-library/blocks/read-more/style-rtl.css 140 B
build/block-library/blocks/read-more/style.css 140 B
build/block-library/blocks/rss/editor-rtl.css 149 B
build/block-library/blocks/rss/editor.css 149 B
build/block-library/blocks/rss/style-rtl.css 289 B
build/block-library/blocks/rss/style.css 288 B
build/block-library/blocks/search/editor-rtl.css 184 B
build/block-library/blocks/search/editor.css 184 B
build/block-library/blocks/search/style-rtl.css 629 B
build/block-library/blocks/search/style.css 628 B
build/block-library/blocks/search/theme-rtl.css 114 B
build/block-library/blocks/search/theme.css 114 B
build/block-library/blocks/search/view.min.js 478 B
build/block-library/blocks/separator/editor-rtl.css 146 B
build/block-library/blocks/separator/editor.css 146 B
build/block-library/blocks/separator/style-rtl.css 229 B
build/block-library/blocks/separator/style.css 229 B
build/block-library/blocks/separator/theme-rtl.css 194 B
build/block-library/blocks/separator/theme.css 194 B
build/block-library/blocks/shortcode/editor-rtl.css 323 B
build/block-library/blocks/shortcode/editor.css 323 B
build/block-library/blocks/site-logo/editor-rtl.css 754 B
build/block-library/blocks/site-logo/editor.css 754 B
build/block-library/blocks/site-logo/style-rtl.css 204 B
build/block-library/blocks/site-logo/style.css 204 B
build/block-library/blocks/site-tagline/editor-rtl.css 86 B
build/block-library/blocks/site-tagline/editor.css 86 B
build/block-library/blocks/site-title/editor-rtl.css 116 B
build/block-library/blocks/site-title/editor.css 116 B
build/block-library/blocks/site-title/style-rtl.css 57 B
build/block-library/blocks/site-title/style.css 57 B
build/block-library/blocks/social-link/editor-rtl.css 184 B
build/block-library/blocks/social-link/editor.css 184 B
build/block-library/blocks/social-links/editor-rtl.css 682 B
build/block-library/blocks/social-links/editor.css 681 B
build/block-library/blocks/social-links/style-rtl.css 1.49 kB
build/block-library/blocks/social-links/style.css 1.48 kB
build/block-library/blocks/spacer/editor-rtl.css 350 B
build/block-library/blocks/spacer/editor.css 350 B
build/block-library/blocks/spacer/style-rtl.css 48 B
build/block-library/blocks/spacer/style.css 48 B
build/block-library/blocks/table/editor-rtl.css 395 B
build/block-library/blocks/table/editor.css 395 B
build/block-library/blocks/table/style-rtl.css 639 B
build/block-library/blocks/table/style.css 639 B
build/block-library/blocks/table/theme-rtl.css 146 B
build/block-library/blocks/table/theme.css 146 B
build/block-library/blocks/tag-cloud/style-rtl.css 251 B
build/block-library/blocks/tag-cloud/style.css 253 B
build/block-library/blocks/template-part/editor-rtl.css 403 B
build/block-library/blocks/template-part/editor.css 403 B
build/block-library/blocks/template-part/theme-rtl.css 101 B
build/block-library/blocks/template-part/theme.css 101 B
build/block-library/blocks/term-description/style-rtl.css 111 B
build/block-library/blocks/term-description/style.css 111 B
build/block-library/blocks/text-columns/editor-rtl.css 95 B
build/block-library/blocks/text-columns/editor.css 95 B
build/block-library/blocks/text-columns/style-rtl.css 166 B
build/block-library/blocks/text-columns/style.css 166 B
build/block-library/blocks/verse/style-rtl.css 99 B
build/block-library/blocks/verse/style.css 99 B
build/block-library/blocks/video/editor-rtl.css 552 B
build/block-library/blocks/video/editor.css 555 B
build/block-library/blocks/video/style-rtl.css 185 B
build/block-library/blocks/video/style.css 185 B
build/block-library/blocks/video/theme-rtl.css 126 B
build/block-library/blocks/video/theme.css 126 B
build/block-library/classic-rtl.css 179 B
build/block-library/classic.css 179 B
build/block-library/common-rtl.css 1.1 kB
build/block-library/common.css 1.1 kB
build/block-library/editor-elements-rtl.css 75 B
build/block-library/editor-elements.css 75 B
build/block-library/editor-rtl.css 12.4 kB
build/block-library/editor.css 12.3 kB
build/block-library/elements-rtl.css 54 B
build/block-library/elements.css 54 B
build/block-library/index.min.js 216 kB
build/block-library/reset-rtl.css 472 B
build/block-library/reset.css 472 B
build/block-library/style-rtl.css 14.8 kB
build/block-library/style.css 14.8 kB
build/block-library/theme-rtl.css 688 B
build/block-library/theme.css 693 B
build/block-serialization-default-parser/index.min.js 1.12 kB
build/block-serialization-spec-parser/index.min.js 2.87 kB
build/blocks/index.min.js 51.8 kB
build/commands/index.min.js 15.6 kB
build/commands/style-rtl.css 921 B
build/commands/style.css 918 B
build/components/index.min.js 223 kB
build/components/style-rtl.css 11.8 kB
build/components/style.css 11.9 kB
build/compose/index.min.js 12.6 kB
build/core-commands/index.min.js 2.77 kB
build/core-data/index.min.js 72.8 kB
build/customize-widgets/index.min.js 12.1 kB
build/customize-widgets/style-rtl.css 1.32 kB
build/customize-widgets/style.css 1.32 kB
build/data-controls/index.min.js 640 B
build/date/index.min.js 17.9 kB
build/deprecated/index.min.js 451 B
build/dom-ready/index.min.js 324 B
build/dom/index.min.js 4.65 kB
build/edit-post/classic-rtl.css 544 B
build/edit-post/classic.css 545 B
build/edit-post/index.min.js 23.8 kB
build/edit-post/style-rtl.css 5.64 kB
build/edit-post/style.css 5.63 kB
build/edit-widgets/index.min.js 17.3 kB
build/edit-widgets/style-rtl.css 4.22 kB
build/edit-widgets/style.css 4.22 kB
build/editor/style-rtl.css 5.32 kB
build/editor/style.css 5.32 kB
build/element/index.min.js 4.83 kB
build/escape-html/index.min.js 537 B
build/format-library/index.min.js 7.89 kB
build/format-library/style-rtl.css 478 B
build/format-library/style.css 477 B
build/hooks/index.min.js 1.55 kB
build/html-entities/index.min.js 448 B
build/i18n/index.min.js 3.58 kB
build/interactivity/file.min.js 447 B
build/interactivity/image.min.js 1.67 kB
build/interactivity/index.min.js 12.8 kB
build/interactivity/navigation.min.js 1.15 kB
build/interactivity/query.min.js 740 B
build/interactivity/router.min.js 1.29 kB
build/interactivity/search.min.js 618 B
build/is-shallow-equal/index.min.js 527 B
build/keyboard-shortcuts/index.min.js 1.74 kB
build/keycodes/index.min.js 1.46 kB
build/list-reusable-blocks/index.min.js 2.11 kB
build/list-reusable-blocks/style-rtl.css 836 B
build/list-reusable-blocks/style.css 836 B
build/media-utils/index.min.js 2.9 kB
build/modules/importmap-polyfill.min.js 12.2 kB
build/notices/index.min.js 948 B
build/nux/index.min.js 2 kB
build/nux/style-rtl.css 735 B
build/nux/style.css 732 B
build/patterns/index.min.js 5.78 kB
build/patterns/style-rtl.css 540 B
build/patterns/style.css 539 B
build/plugins/index.min.js 1.8 kB
build/preferences-persistence/index.min.js 2.05 kB
build/preferences/index.min.js 2.82 kB
build/preferences/style-rtl.css 698 B
build/preferences/style.css 700 B
build/primitives/index.min.js 975 B
build/priority-queue/index.min.js 1.52 kB
build/private-apis/index.min.js 1 kB
build/react-i18n/index.min.js 623 B
build/react-refresh-entry/index.min.js 9.47 kB
build/react-refresh-runtime/index.min.js 6.78 kB
build/redux-routine/index.min.js 2.7 kB
build/reusable-blocks/index.min.js 2.72 kB
build/reusable-blocks/style-rtl.css 243 B
build/reusable-blocks/style.css 243 B
build/rich-text/index.min.js 10.4 kB
build/router/index.min.js 1.79 kB
build/server-side-render/index.min.js 1.95 kB
build/shortcode/index.min.js 1.39 kB
build/style-engine/index.min.js 2.08 kB
build/token-list/index.min.js 582 B
build/url/index.min.js 3.72 kB
build/vendors/inert-polyfill.min.js 2.48 kB
build/vendors/react-dom.min.js 41.8 kB
build/vendors/react.min.js 4.02 kB
build/viewport/index.min.js 957 B
build/warning/index.min.js 249 B
build/widgets/index.min.js 7.21 kB
build/widgets/style-rtl.css 1.15 kB
build/widgets/style.css 1.16 kB
build/wordcount/index.min.js 1.02 kB

compressed-size-action

Copy link

Flaky tests detected in efa01ec.
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/8012036634
📝 Reported issues:

@creativecoder creativecoder added the Backport to WP 6.7 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Feb 22, 2024
Copy link
Contributor

@peterwilsoncc peterwilsoncc left a comment

Choose a reason for hiding this comment

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

I've added a few notes inline.

Some form of snowflake code for the post types meta cap will be needed but it would be good to avoid the recursive checking on the font-family post.

It might be possible to use pre_delete_post for font-families and if the font-faces can't be deleted then handle the use case with an early return.

Feel free to push back on anything, I'm playing catch up and you're much more familiar with the code than I am.

I appreciate your help working on these roles and caps issues. They're certainly a Thing.

lib/compat/wordpress-6.5/fonts/fonts.php Outdated Show resolved Hide resolved
@@ -84,6 +84,35 @@ function gutenberg_create_initial_post_types() {
);
}

/**
Copy link
Contributor

Choose a reason for hiding this comment

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

The delete_post meta capability will need to account for deleting fonts with files attached. This is to account for the file deletion hooks in wp_delete_post().

I'm not in love with the performance aspect of this code when checking the font family post type but can't think of more performant approach.

Suggested change
/**
/**
* Modify the `delete_post` meta capability for font post types.
*
* For font families and font faces containing attached font files, file
* system access is required by the user in order to delete posts.
*
* @param string[] $caps The primitive capabilities required for the given capability.
* @param string $cap The capability being checked.
* @param int $user_id The user ID.
* @param array $args Context for the capability check.
* @return string[] The modified primitive capabilities required for the given capability.
*/
function gutenberg_delete_font_post_meta_caps( $caps, $cap, $user_id, $args ) {
if ( in_array( 'do_not_allow', $caps, true ) ) {
// It's already known that the user is not allowed to perform the requested capability.
return $caps;
}
if ( 'delete_post' !== $cap ) {
// This filter is only concerned with the 'delete_post' meta capability.
return $caps;
}
$post = get_post( $args[0] );
if ( ! $post ) {
$caps[] = 'do_not_allow';
return $caps;
}
$post_type = get_post_type( $post );
if ( 'wp_font_face' === $post_type ) {
// Are there any font files associated with this font face?
$font_files = get_post_meta( $post->ID, '_wp_font_face_file', false );
if ( empty( $font_files ) ) {
/*
* No font files.
*
* The user can delete the post based on the 'delete_post' meta capability.
*/
return $caps;
}
// The user can only delete the post if they can modify the file system.
$caps[] = 'upload_fonts';
return $caps;
}
if ( 'wp_font_family' === $post_type ) {
// Are there any font faces associated with this font family?
$font_faces = get_children(
array(
'post_parent' => $post->ID,
'post_type' => 'wp_font_face',
)
);
if ( empty( $font_faces ) ) {
/*
* No font faces.
*
* The user can delete the post based on the 'delete_post' meta capability.
*/
return $caps;
}
// If any of the font faces contain files, the user needs to be able to modify the file system.
foreach ( $font_faces as $font_face ) {
$font_files = get_post_meta( $font_face->ID, '_wp_font_face_file', false );
if ( ! empty( $font_files ) ) {
$caps[] = 'upload_fonts';
// File system caps are required, so no need to check further.
break;
}
}
return $caps;
}
// Return existing caps if the post type is not a font family or font face.
return $caps;
}
/**

if (
wp_is_file_mod_allowed( 'can_upload_fonts' ) &&
wp_is_writable( $fonts_dir ) &&
! empty( $allcaps['edit_theme_options'] )
Copy link
Contributor

Choose a reason for hiding this comment

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

Developers can modify the cap required for editing the font face/families (similar to the example in #59104 (comment) ) so I am not sure this is required.

canUser( 'create' ... ) should catch this.

However, I'm not entirely sure it is not required, either, so will require a logic check on this.

@@ -28,6 +29,7 @@ export const EDITOR_SETTINGS_DEFAULTS = {
richEditingEnabled: true,
codeEditingEnabled: true,
fontLibraryEnabled: true,
fontUploadsEnabled: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

It's probably safer to assume false as the default if the filter is removed. That will avoid the UI showing only to display an error if the caps check fails.

@peterwilsoncc
Copy link
Contributor

For props, the following list will need to be combined with the bot's list as they contributed to earlier iterations of this PR.

Co-authored-by: youknowriad <youknowriad@git.wordpress.org>
Co-authored-by: swissspidy <swissspidy@git.wordpress.org>
Co-authored-by: getdave <get_dave@git.wordpress.org>
Co-authored-by: matiasbenedetto <mmaattiiaass@git.wordpress.org>

@peterwilsoncc peterwilsoncc added the props-bot Adding this label triggers the Props Bot workflow for a PR. label Feb 23, 2024
@github-actions github-actions bot removed the props-bot Adding this label triggers the Props Bot workflow for a PR. label Feb 23, 2024
@creativecoder
Copy link
Contributor Author

Note that I've copied over the UI permissions checks into a separate PR, as they are useful whether we add a new capability or not, so I want to consider them separately.

#59332

@peterwilsoncc
Copy link
Contributor

Regarding the use of DISALLOW_FILE_MODS to prevent uploading of font files: I'm still not convinced this is "logical" as font files are just another type of media files that can be used on a website. True, font files are stored outside of wp-content/uploads however I don't think DISALLOW_FILE_MODS was meant to prevent uploading and using of (relatively safe) media files. It was meant to prevent modifying (and updating) of theme, plugin, and core files, and to prevent editing these highly exploitable (PHP and JS) files.

@azaozz DISALLOW_FILE_MODS is mainly used to indicate an immutable file system (such as used by WP VIP, Pantheon, Altis DXP, and no doubt elsewhere). As the font files aren't stored in the uploads folder, the files can't physically be uploaded in this circumstance.

There are filters in place to allow the font path to be modified to use the uploads folder and the file_mod_allowed filter will be able to used in conjunction with that to indicate files can be uploaded in the can_upload_fonts context.

Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

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

This PR looks on the right track to me if we think the 2nd option in #55280 (comment) is the way to go.

It seems this is still being discussed on the issue though, so I think we need to wait for a decision before finalizing and merging this.

Comment on lines +182 to +199
function gutenberg_maybe_grant_upload_font_cap( $allcaps, $caps ) {
if ( ! in_array( 'upload_fonts', $caps, true ) ) {
return $allcaps;
}

$fonts_dir = wp_get_font_dir()['path'];
$post_type = get_post_type_object( 'wp_font_face' );
if (
wp_is_file_mod_allowed( 'can_upload_fonts' ) &&
wp_is_writable( $fonts_dir ) &&
current_user_can( $post_type->cap->create_posts )
) {
$allcaps['upload_fonts'] = true;
}

return $allcaps;
}
add_filter( 'user_has_cap', 'gutenberg_maybe_grant_upload_font_cap', 10, 2 );
Copy link
Member

Choose a reason for hiding this comment

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

Technically speaking, the user_has_cap filter's recommended use is to grant capabilities generally, based on other capabilities.

For specific checks like wp_is_file_mod_allowed() and wp_is_writable(), it is recommended to use the map_meta_cap filter instead.

In other words, I'd suggest:

  • Simplify this function to only focus on granting upload_fonts to any user that can $post_type->cap->create_posts.
  • In a separate map_meta_cap filter callback, include do_not_allow as a required capability if the relevant file mods aren't allowed or if the directory is not writable. This way it will effectively not be granted to anyone, but the actual capability grant logic is still tied to purely the other capabilities on the relevant user.

Copy link
Contributor

@azaozz azaozz Feb 26, 2024

Choose a reason for hiding this comment

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

focus on granting upload_fonts to any user that can $post_type->cap->create_posts

Hmm, afaik "contributors" can create posts (that they cannot publish), but cannot upload files. Not sure if they should be able to upload (and install) fonts, seems inconsistent?

Also don't think "authors" should be able to upload and install fonts. The reason is: how are they going to be able to use a font after it has been uploaded? May be missing something but afaik "authors" cannot make CSS changes, neither "global" nor "local". So what's the point in uploading a file you cannot use?

(Also there seems to be some more considerations about who should be able to "install" fonts. Afaik adding another font to a site is more of a "theme option" rather than "post author choice". Using a lot of fonts in a post would make the site slower, especially if these fonts are "one-use-only", i.e. uploaded and installed by a post author. Seems that if post authors would like to use a font they should ask an editor (or admin) to provide/install it. This is also important for the decision whether the font should be local (uploaded) vs. used from a CDN, etc.)

There are the reasons why I'm thinking a new upload_fonts capability looks mostly redundant. It should match exactly edit_theme_options as far as I understand it, and should not be used separately. I can see a need for it to simplify capability checks if DISALLOW_FILE_MODS would affect font files, but this use would be somewhat inconsistent. I mean, users that have upload_fonts will also have be able to use these newly uploaded fonts or the UI and UX will be a total mess :)

Copy link
Member

Choose a reason for hiding this comment

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

I think your response fits much better on the discussion in the issue rather than my feedback here. My comment here was specifically about the code and is not related to the larger conversation we're having.
Could you put this on the issue as well please so we can discuss in a single place?

@azaozz
Copy link
Contributor

azaozz commented Feb 26, 2024

DISALLOW_FILE_MODS is mainly used to indicate an immutable file system

Right. I agree that from a "software developer" point of view respecting that constant is the right choice. My main concerns are that this results in a somewhat diminished/subpar user experience as having DISALLOW_FILE_MODS means some of the UI will have to be disabled.

As far as I see this boils down to: have a better UX and "inconvenience" some hosting companies as they will have to make a minor change to their servers settings and treat wp-content/fonts the same way as wp-content/uploads, vs. have a worse UX for all WP users whose sites are hosted by one of these hosting companies. Frankly I am a +1 for the users and -1 for the hosting companies however this is just my opinion. Happy to change it if there's something I'm missing or misunderstanding :)

@peterwilsoncc
Copy link
Contributor

As far as I see this boils down to: have a better UX and "inconvenience" some hosting companies as they will have to make a minor change to their servers settings and treat wp-content/fonts the same way as wp-content/uploads, vs. have a worse UX for all WP users whose sites are hosted by one of these hosting companies. Frankly I am a +1 for the users and -1 for the hosting companies however this is just my opinion. Happy to change it if there's something I'm missing or misunderstanding :)

This is what I am trying to convey, it's not a choice that can be made now. It was decided when the decision was made to store fonts outside of the uploads folder.

For systems in which the file system is immutable, the files simply won't upload so we need to hide the UI to avoid making false promises. On systems such as WP VIP it's not simply a case of mkdir fonts; chmod ... as the files are stored on a different server.

Depending on how these servers are deployed, even if the fonts folder is writable, it may be destroyed between deploys as we've put it in an area in which the we've promised the constant applies. This could be as simple as a git clean or as complex as building a new server and swapping out the old.

Hosts will need to update their file systems, end users will need to update S3 and similar plugins. Meta data/URLs will need to be filtered, security headers modified.

@felixarntz
Copy link
Member

FWIW even if we decide to go for the disruptive change of requiring hosts to change their setups and users to reconfigure their CDNs etc., this would be a major undertaking that would take time. As such, some sites would not be configured correctly when this feature launches.

In other words: We would need a graceful fallback no matter what, for the scenario that the folders aren't writable. If it's technically impossible to upload fonts, it's a better UX to not show the UI to upload fonts, rather than showing it but then it fails.

@hellofromtonya
Copy link
Contributor

hellofromtonya commented Feb 26, 2024

I agree with @peterwilsoncc and @felixarntz assessments. They've shared the impact and disruption to hosts, extenders, and users including:

Hosts will need to update their file systems

requiring hosts to change their setups

end users will need to update S3 and similar plugins.

Meta data/URLs will need to be filtered, security headers modified.

users to reconfigure their CDNs etc.

As @felixarntz noted, it will take time for these changes to happen and will go beyond 6.5 shipping.

So what will happen if they are required to make these changes?

If the changes are not made for those impacted, then either:

  • the feature will be turned off (users won't have access to it).
  • font uploads will fail (bad user experience).

I think @felixarntz summed it well:

If it's technically impossible to upload fonts, it's a better UX to not show the UI to upload fonts, rather than showing it but then it fails.

Given the major hosts @peterwilsoncc listed, IMO DISALLOW_FILE_MODS should be respected.

@azaozz
Copy link
Contributor

azaozz commented Feb 26, 2024

It was decided when the decision was made to store fonts outside of the uploads folder

Yea it would have been ideal if this discussion has happened when the location of the fonts dir was being decided...

If it's technically impossible to upload fonts, it's a better UX to not show the UI to upload fonts, rather than showing it but then it fails.

Right. Actually seems the code here should probably ignore DISALLOW_FILE_MODS and relay more on is_writable(). This would probably prevent/fix another edge case here: when somebody is using DISALLOW_FILE_MODS but has made the fonts dir writable (or should there be another way to set this?). Don't think WP should "forbid" this usage as it seems it makes the most sense.

@azaozz
Copy link
Contributor

azaozz commented Feb 26, 2024

Given the major hosts @peterwilsoncc listed, IMO DISALLOW_FILE_MODS should be respected.

So generally "Hosts win, users loose"? :)
I agree it is way too late for this discussion few days before RC. But this still feels like a wrong thing to do imho.

@peterwilsoncc
Copy link
Contributor

@azaozz is_writable doesn't really work either.

The fonts folder is in a disposable part of the file system. Even basic VPS config providers include Atomic deployments that swap the file system out between deploys (eg Runcloud).

Users lose if the files they have uploaded get wiped out by their host.

@azaozz
Copy link
Contributor

azaozz commented Feb 27, 2024

is_writable doesn't really work either
...
Users lose if the files they have uploaded get wiped out by their host.

Yep, you're right of course. There are several steps to ensure the new wp-content/fonts directory would work as intended. Some are pretty straightforward, like excluding it from version control and ensuring filesystem permissions are correct. Others may be more involved.

I'm starting to thing perhaps we are overthinking this a bit? Likely there will always be some edge cases where the /fonts directory won't work properly. WP should have a fallback for these cases, which is to disable the UI for uploading of fonts and warn the user about the problem(s). Don't think it is that important "why" the /fonts dir won't work, to me it seems much more important to:

  1. Have a fallback and warn the users. Seems this is already implemented.
  2. Have a way for hosting companies and/or developers to fix the problems that prevent uploading of fonts, and enable it directly. Seems this may need a little bit more looking into. Maybe a filter would do?

Seems the above problem (2) is pretty easy to solve, and thinking this is pretty much ready to be committed?

@matiasbenedetto
Copy link
Contributor

Part of the work originally added in this PR, the post-creation capabilities checks, were added in #59332. The only thing that would remain to implement from this PR is the DISALLOW_FILE_MODS check. Given that the restriction was discarded by this @josephahaden's Make WordPress post, I think that PR is not relevant anymore and it can be closed. I quote the relevant part of the post:

Like wp-content/uploads itself, the fonts directory will not adhere to wp_is_file_mod_allowed / DISALLOW_FILE_MODS to prevent font uploads.

I'm closing this PR. Feel free to re-open if I missed something.

@getdave getdave removed the Backport to WP 6.7 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Mar 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Font Library REST API Interaction Related to REST API [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Font Library: add a 'manage font' exclusive user permission to manage the install/remove fonts.