Skip to content
Prev Previous commit
Next Next commit
Fix phpcs error and warnings
  • Loading branch information
creativecoder committed Jan 9, 2024
commit 56823bcb59369f8ce5ff55bf4fda282c213572dc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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',
),
),
Expand All @@ -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',
),
),
Expand All @@ -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' ),
),
),
),
Expand All @@ -125,7 +129,7 @@ public function register_routes() {
protected function get_parent( $parent_post_id ) {
Copy link
Member

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.

Copy link
Contributor Author

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_Controller or WP_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.

$error = new WP_Error(
'rest_post_invalid_parent',
__( 'Invalid post parent ID.' ),
__( 'Invalid post parent ID.', 'default' ),
array( 'status' => 404 )
);

Expand Down Expand Up @@ -158,7 +162,7 @@ public function get_font_faces_permissions_check( $request ) {
if ( ! current_user_can( $post_type->cap->edit_posts ) ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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() )
);
}
Expand Down Expand Up @@ -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 )
);
}
Expand All @@ -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 )
);
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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',
Expand Down