-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Font Library: add wp_font_face post type and scaffold font face REST API controller #57656
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
Merged
creativecoder
merged 9 commits into
try/font-library-refactor
from
add/font-faces-post-type-and-controller
Jan 9, 2024
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
11af824
Adds wp_font_face post type and REST API controller
creativecoder 3c2fc75
Adds a basic set of controller tests for WP_REST_Font_Faces_Controller
creativecoder a3e494c
Override GET collection args
creativecoder 894f198
Adds missing property comment
creativecoder c0739dc
Tweaks and cleanup
creativecoder 56823bc
Fix phpcs error and warnings
creativecoder 88eb462
Correct typo
creativecoder 1de34f4
Fix remaining phpcs warnings
creativecoder ee7a0b8
Add error for invalid font face id
creativecoder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix phpcs error and warnings
- Loading branch information
commit 56823bcb59369f8ce5ff55bf4fda282c213572dc
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,10 @@ | |
| * @since 6.5.0 | ||
| */ | ||
|
|
||
| if ( class_exists( 'WP_REST_Font_Families_Controller' ) ) { | ||
| return; | ||
| } | ||
|
|
||
| /** | ||
| * Class to access font faces through the REST API. | ||
| */ | ||
|
|
@@ -55,7 +59,7 @@ public function register_routes() { | |
| array( | ||
| 'args' => array( | ||
| 'parent' => array( | ||
| 'description' => __( 'The ID for the parent font family of the font face.' ), | ||
| 'description' => __( 'The ID for the parent font family of the font face.', 'gutenberg' ), | ||
| 'type' => 'integer', | ||
| ), | ||
| ), | ||
|
|
@@ -82,11 +86,11 @@ public function register_routes() { | |
| array( | ||
| 'args' => array( | ||
| 'parent' => array( | ||
| 'description' => __( 'The ID for the parent font family of the font face.' ), | ||
| 'description' => __( 'The ID for the parent font family of the font face.', 'gutenberg' ), | ||
| 'type' => 'integer', | ||
| ), | ||
| 'id' => array( | ||
| 'description' => __( 'Unique identifier for the font face.' ), | ||
| 'description' => __( 'Unique identifier for the font face.', 'gutenberg' ), | ||
| 'type' => 'integer', | ||
| ), | ||
| ), | ||
|
|
@@ -104,7 +108,7 @@ public function register_routes() { | |
| 'force' => array( | ||
| 'type' => 'boolean', | ||
| 'default' => false, | ||
| 'description' => __( 'Whether to bypass Trash and force deletion.' ), | ||
| 'description' => __( 'Whether to bypass Trash and force deletion.', 'default' ), | ||
| ), | ||
| ), | ||
| ), | ||
|
|
@@ -125,7 +129,7 @@ public function register_routes() { | |
| protected function get_parent( $parent_post_id ) { | ||
| $error = new WP_Error( | ||
| 'rest_post_invalid_parent', | ||
| __( 'Invalid post parent ID.' ), | ||
| __( 'Invalid post parent ID.', 'default' ), | ||
| array( 'status' => 404 ) | ||
| ); | ||
|
|
||
|
|
@@ -158,7 +162,7 @@ public function get_font_faces_permissions_check( $request ) { | |
| if ( ! current_user_can( $post_type->cap->edit_posts ) ) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm using the capabilities registered with the post type to check permissions here, so that creating font families in PHP will also be limited by the appropriate user caps. |
||
| return new WP_Error( | ||
| 'rest_cannot_read', | ||
| __( 'Sorry, you are not allowed to access font faces.' ), | ||
| __( 'Sorry, you are not allowed to access font faces.', 'gutenberg' ), | ||
| array( 'status' => rest_authorization_required_code() ) | ||
| ); | ||
| } | ||
|
|
@@ -215,7 +219,7 @@ public function get_item( $request ) { | |
| return new WP_Error( | ||
| 'rest_font_face_parent_id_mismatch', | ||
| /* translators: %d: A post id. */ | ||
| sprintf( __( 'The font face does not belong to the specified font family with id of "%d"' ), $parent->ID ), | ||
| sprintf( __( 'The font face does not belong to the specified font family with id of "%d"', 'gutenberg' ), $parent->ID ), | ||
| array( 'status' => 404 ) | ||
| ); | ||
| } | ||
|
|
@@ -239,7 +243,7 @@ public function delete_item( $request ) { | |
| return new WP_Error( | ||
| 'rest_trash_not_supported', | ||
| /* translators: %s: force=true */ | ||
| sprintf( __( "Font faces do not support trashing. Set '%s' to delete." ), 'force=true' ), | ||
| sprintf( __( "Font faces do not support trashing. Set '%s' to delete.", 'gutenberg' ), 'force=true' ), | ||
| array( 'status' => 501 ) | ||
| ); | ||
| } | ||
|
|
@@ -291,19 +295,19 @@ public function get_item_schema() { | |
| // Base properties for every Post. | ||
| 'properties' => array( | ||
| 'id' => array( | ||
| 'description' => __( 'Unique identifier for the post.' ), | ||
| 'description' => __( 'Unique identifier for the post.', 'default' ), | ||
| 'type' => 'integer', | ||
| 'readonly' => true, | ||
| ), | ||
| 'theme_json_version' => array( | ||
| 'description' => __( 'Version of the theme.json schema used for the font face typography settings.' ), | ||
| 'description' => __( 'Version of the theme.json schema used for the font face typography settings.', 'gutenberg' ), | ||
| 'type' => 'integer', | ||
| 'default' => 2, | ||
| 'minimum' => 2, | ||
| 'maximum' => 2, | ||
| ), | ||
| 'parent' => array( | ||
| 'description' => __( 'The ID for the parent font family of the font face.' ), | ||
| 'description' => __( 'The ID for the parent font family of the font face.', 'gutenberg' ), | ||
| 'type' => 'integer', | ||
| ), | ||
| // Font face settings come directly from theme.json schema | ||
|
|
@@ -426,15 +430,15 @@ public function get_item_schema() { | |
| public function get_collection_params() { | ||
| return array( | ||
| 'page' => array( | ||
| 'description' => __( 'Current page of the collection.' ), | ||
| 'description' => __( 'Current page of the collection.', 'default' ), | ||
| 'type' => 'integer', | ||
| 'default' => 1, | ||
| 'sanitize_callback' => 'absint', | ||
| 'validate_callback' => 'rest_validate_request_arg', | ||
| 'minimum' => 1, | ||
| ), | ||
| 'per_page' => array( | ||
| 'description' => __( 'Maximum number of items to be returned in result set.' ), | ||
| 'description' => __( 'Maximum number of items to be returned in result set.', 'default' ), | ||
| 'type' => 'integer', | ||
| 'default' => 10, | ||
| 'minimum' => 1, | ||
|
|
@@ -443,7 +447,7 @@ public function get_collection_params() { | |
| 'validate_callback' => 'rest_validate_request_arg', | ||
| ), | ||
| 'search' => array( | ||
| 'description' => __( 'Limit results to those matching a string.' ), | ||
| 'description' => __( 'Limit results to those matching a string.', 'default' ), | ||
| 'type' => 'string', | ||
| 'sanitize_callback' => 'sanitize_text_field', | ||
| 'validate_callback' => 'rest_validate_request_arg', | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto, the parent class method should work here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which parent class method do you mean? I'm not seeing anything for getting the parent of a post in
WP_REST_Posts_ControllerorWP_REST_Controller.Other controllers I see that use this (Autosaves, Global Styles, Revisions) re-implement the method, so that's the pattern we're following here.