Skip to content

Commit a770c6d

Browse files
committed
REST API: Introduce the necessary endpoints for the font library.
This commits add three endpoints to retrieve and manipulate fonts in WordPress. This commit also means that we now have a fully functional Font Library in the site editor. Props get_dave, youknowriad, mmaattiiaass, grantmkin, swissspidy, mcsf, jorbin, ocean90. See #59166. git-svn-id: https://develop.svn.wordpress.org/trunk@57548 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 952004a commit a770c6d

13 files changed

Lines changed: 4731 additions & 22 deletions

src/wp-includes/fonts/class-wp-font-library.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,13 @@ public function get_font_collections() {
115115
* @since 6.5.0
116116
*
117117
* @param string $slug Font collection slug.
118-
* @return WP_Font_Collection|WP_Error Font collection object,
119-
* or WP_Error object if the font collection doesn't exist.
118+
* @return WP_Font_Collection|null Font collection object, or null if the font collection doesn't exist.
120119
*/
121120
public function get_font_collection( $slug ) {
122121
if ( $this->is_collection_registered( $slug ) ) {
123122
return $this->collections[ $slug ];
124123
}
125-
return new WP_Error( 'font_collection_not_found', __( 'Font collection not found.' ) );
124+
return null;
126125
}
127126

128127
/**

src/wp-includes/post.php

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -567,14 +567,14 @@ function create_initial_post_types() {
567567
register_post_type(
568568
'wp_font_family',
569569
array(
570-
'labels' => array(
570+
'labels' => array(
571571
'name' => __( 'Font Families' ),
572572
'singular_name' => __( 'Font Family' ),
573573
),
574-
'public' => false,
575-
'_builtin' => true, /* internal use only. don't use this when registering your own post type. */
576-
'hierarchical' => false,
577-
'capabilities' => array(
574+
'public' => false,
575+
'_builtin' => true, /* internal use only. don't use this when registering your own post type. */
576+
'hierarchical' => false,
577+
'capabilities' => array(
578578
'read' => 'edit_theme_options',
579579
'read_private_posts' => 'edit_theme_options',
580580
'create_posts' => 'edit_theme_options',
@@ -586,24 +586,28 @@ function create_initial_post_types() {
586586
'delete_others_posts' => 'edit_theme_options',
587587
'delete_published_posts' => 'edit_theme_options',
588588
),
589-
'map_meta_cap' => true,
590-
'query_var' => false,
591-
'show_in_rest' => false,
592-
'rewrite' => false,
589+
'map_meta_cap' => true,
590+
'query_var' => false,
591+
'rewrite' => false,
592+
'show_in_rest' => true,
593+
'rest_base' => 'font-families',
594+
'rest_controller_class' => 'WP_REST_Font_Families_Controller',
595+
// Disable autosave endpoints for font families.
596+
'autosave_rest_controller_class' => 'stdClass',
593597
)
594598
);
595599

596600
register_post_type(
597601
'wp_font_face',
598602
array(
599-
'labels' => array(
603+
'labels' => array(
600604
'name' => __( 'Font Faces' ),
601605
'singular_name' => __( 'Font Face' ),
602606
),
603-
'public' => false,
604-
'_builtin' => true, /* internal use only. don't use this when registering your own post type. */
605-
'hierarchical' => false,
606-
'capabilities' => array(
607+
'public' => false,
608+
'_builtin' => true, /* internal use only. don't use this when registering your own post type. */
609+
'hierarchical' => false,
610+
'capabilities' => array(
607611
'read' => 'edit_theme_options',
608612
'read_private_posts' => 'edit_theme_options',
609613
'create_posts' => 'edit_theme_options',
@@ -615,10 +619,14 @@ function create_initial_post_types() {
615619
'delete_others_posts' => 'edit_theme_options',
616620
'delete_published_posts' => 'edit_theme_options',
617621
),
618-
'map_meta_cap' => true,
619-
'query_var' => false,
620-
'show_in_rest' => false,
621-
'rewrite' => false,
622+
'map_meta_cap' => true,
623+
'query_var' => false,
624+
'rewrite' => false,
625+
'show_in_rest' => true,
626+
'rest_base' => 'font-families/(?P<font_family_id>[\d]+)/font-faces',
627+
'rest_controller_class' => 'WP_REST_Font_Faces_Controller',
628+
// Disable autosave endpoints for font faces.
629+
'autosave_rest_controller_class' => 'stdClass',
622630
)
623631
);
624632

src/wp-includes/rest-api.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,10 @@ function create_initial_rest_routes() {
391391
// Navigation Fallback.
392392
$controller = new WP_REST_Navigation_Fallback_Controller();
393393
$controller->register_routes();
394+
395+
// Font Collections.
396+
$font_collections_controller = new WP_REST_Font_Collections_Controller();
397+
$font_collections_controller->register_routes();
394398
}
395399

396400
/**

0 commit comments

Comments
 (0)