Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/wp-includes/fonts/class-wp-font-library.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,13 @@ public function get_font_collections() {
* @since 6.5.0
*
* @param string $slug Font collection slug.
* @return WP_Font_Collection|WP_Error Font collection object,
* or WP_Error object if the font collection doesn't exist.
* @return WP_Font_Collection|null Font collection object, or null if the font collection doesn't exist.
*/
public function get_font_collection( $slug ) {
if ( $this->is_collection_registered( $slug ) ) {
return $this->collections[ $slug ];
}
return new WP_Error( 'font_collection_not_found', __( 'Font collection not found.' ) );
return null;
}

/**
Expand Down
44 changes: 26 additions & 18 deletions src/wp-includes/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -567,14 +567,14 @@ function create_initial_post_types() {
register_post_type(
'wp_font_family',
array(
'labels' => array(
'labels' => array(
'name' => __( 'Font Families' ),
'singular_name' => __( 'Font Family' ),
),
'public' => false,
'_builtin' => true, /* internal use only. don't use this when registering your own post type. */
'hierarchical' => false,
'capabilities' => array(
'public' => false,
'_builtin' => true, /* internal use only. don't use this when registering your own post type. */
'hierarchical' => false,
'capabilities' => array(
'read' => 'edit_theme_options',
'read_private_posts' => 'edit_theme_options',
'create_posts' => 'edit_theme_options',
Expand All @@ -586,24 +586,28 @@ function create_initial_post_types() {
'delete_others_posts' => 'edit_theme_options',
'delete_published_posts' => 'edit_theme_options',
),
'map_meta_cap' => true,
'query_var' => false,
'show_in_rest' => false,
'rewrite' => false,
'map_meta_cap' => true,
'query_var' => false,
'rewrite' => false,
'show_in_rest' => true,
'rest_base' => 'font-families',
'rest_controller_class' => 'WP_REST_Font_Families_Controller',
// Disable autosave endpoints for font families.
'autosave_rest_controller_class' => 'stdClass',
Comment on lines +595 to +596
Copy link
Member

Choose a reason for hiding this comment

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

Aside:

We should really find a better way to avoid hacks like this. I don't think this is a clean way at all, and devs will just copy this sooner or later.

If workarounds like this are added/needed in GB it's a sign that we should improve core, not just bring the workaround into core.

Maybe it could be handled via post type supports, i.e. add_post_type_support( 'autosave' ) / remove_post_type_support( 'autosave' ). I suppose https://core.trac.wordpress.org/ticket/41172 could be used to track this, maybe I can take a stab at it.

)
);

register_post_type(
'wp_font_face',
array(
'labels' => array(
'labels' => array(
'name' => __( 'Font Faces' ),
'singular_name' => __( 'Font Face' ),
),
'public' => false,
'_builtin' => true, /* internal use only. don't use this when registering your own post type. */
'hierarchical' => false,
'capabilities' => array(
'public' => false,
'_builtin' => true, /* internal use only. don't use this when registering your own post type. */
'hierarchical' => false,
'capabilities' => array(
'read' => 'edit_theme_options',
'read_private_posts' => 'edit_theme_options',
'create_posts' => 'edit_theme_options',
Expand All @@ -615,10 +619,14 @@ function create_initial_post_types() {
'delete_others_posts' => 'edit_theme_options',
'delete_published_posts' => 'edit_theme_options',
),
'map_meta_cap' => true,
'query_var' => false,
'show_in_rest' => false,
'rewrite' => false,
'map_meta_cap' => true,
'query_var' => false,
'rewrite' => false,
'show_in_rest' => true,
'rest_base' => 'font-families/(?P<font_family_id>[\d]+)/font-faces',
'rest_controller_class' => 'WP_REST_Font_Faces_Controller',
// Disable autosave endpoints for font faces.
'autosave_rest_controller_class' => 'stdClass',
)
);

Expand Down
4 changes: 4 additions & 0 deletions src/wp-includes/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,10 @@ function create_initial_rest_routes() {
// Navigation Fallback.
$controller = new WP_REST_Navigation_Fallback_Controller();
$controller->register_routes();

// Font Collections.
$font_collections_controller = new WP_REST_Font_Collections_Controller();
$font_collections_controller->register_routes();
}

/**
Expand Down
Loading