Skip to content

Commit 428ef1f

Browse files
committed
Use faux primitive cap rather than meta cap.
1 parent bd51863 commit 428ef1f

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

lib/compat/wordpress-6.5/fonts/fonts.php

+17-16
Original file line numberDiff line numberDiff line change
@@ -85,29 +85,30 @@ function gutenberg_create_initial_post_types() {
8585
}
8686

8787
/**
88-
* Maps the meta capabilities for modifying font face files.
88+
* Filters the user capabilities to grant the font family capabilities as necessary.
8989
*
90-
* @param array $caps The primitive capabilities for the given capability.
91-
* @param string $cap The capability being checked.
92-
* @return array The modified primitive capabilities for the given capability.
90+
* Files must be modifiable to grant these capabilities and the user must als
91+
* have the `edit_theme_options` capability.
92+
*
93+
* These are created as faux primitive capabilities to allow for the use
94+
* if the delete_post meta capability.
95+
*
96+
* @param bool[] $allcaps An array of all the user's capabilities.
97+
* @return bool[] Filtered array of the user's capabilities.
9398
*/
94-
function gutenberg_map_meta_caps_font_faces( $caps, $cap ) {
95-
if ( ! in_array( $cap, array( 'install_font_faces', 'delete_font_faces' ), true ) ) {
96-
return $caps;
99+
function gutenberg_maybe_grant_font_family_caps( $allcaps ) {
100+
if ( ! wp_is_file_mod_allowed( 'can_modify_font_faces' ) ) {
101+
return $allcaps;
97102
}
98103

99-
// Remove the font capability as it's not a primitive.
100-
$caps = array_diff( $caps, array( 'install_font_faces', 'delete_font_faces' ) );
101-
$caps[] = 'edit_theme_options';
102-
103-
// Only allow font uploads on systems with file mods enabled.
104-
if ( ! wp_is_file_mod_allowed( 'can_modify_font_faces' ) ) {
105-
$caps[] = 'do_not_allow';
104+
if ( ! empty( $allcaps['edit_theme_options'] ) ) {
105+
$allcaps['install_font_faces'] = true;
106+
$allcaps['delete_font_faces'] = true;
106107
}
107108

108-
return $caps;
109+
return $allcaps;
109110
}
110-
add_filter( 'map_meta_cap', 'gutenberg_map_meta_caps_font_faces', 10, 2 );
111+
add_filter( 'user_has_cap', 'gutenberg_maybe_grant_font_family_caps' );
111112

112113
/**
113114
* Initializes REST routes.

0 commit comments

Comments
 (0)