@@ -85,29 +85,30 @@ function gutenberg_create_initial_post_types() {
85
85
}
86
86
87
87
/**
88
- * Maps the meta capabilities for modifying font face files .
88
+ * Filters the user capabilities to grant the font family capabilities as necessary .
89
89
*
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.
93
98
*/
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 ;
97
102
}
98
103
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 ;
106
107
}
107
108
108
- return $ caps ;
109
+ return $ allcaps ;
109
110
}
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 ' );
111
112
112
113
/**
113
114
* Initializes REST routes.
0 commit comments