From de7e018b3edcc50a4a1fedf94ef0cf89522e2cab Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Fri, 2 Feb 2024 14:34:52 +0000 Subject: [PATCH 1/4] Remove empty line after @return --- .../fonts/class-wp-rest-font-families-controller.php | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/compat/wordpress-6.5/fonts/class-wp-rest-font-families-controller.php b/lib/compat/wordpress-6.5/fonts/class-wp-rest-font-families-controller.php index 8d178a2848a35e..9750f45b1e2442 100644 --- a/lib/compat/wordpress-6.5/fonts/class-wp-rest-font-families-controller.php +++ b/lib/compat/wordpress-6.5/fonts/class-wp-rest-font-families-controller.php @@ -405,7 +405,6 @@ public function get_endpoint_args_for_item_schema( $method = WP_REST_Server::CRE * * @param int $font_family_id Font family post ID. * @return int[] Array of child font face post IDs. - * . */ protected function get_font_face_ids( $font_family_id ) { $query = new WP_Query( From 815b0880d24681c5ed352e7a62d094adc2ccfb11 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Fri, 2 Feb 2024 14:37:26 +0000 Subject: [PATCH 2/4] Fix comment format --- ...ass-wp-rest-font-collections-controller.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/compat/wordpress-6.5/fonts/class-wp-rest-font-collections-controller.php b/lib/compat/wordpress-6.5/fonts/class-wp-rest-font-collections-controller.php index 6772a8c3b44088..491df0c4ef2415 100644 --- a/lib/compat/wordpress-6.5/fonts/class-wp-rest-font-collections-controller.php +++ b/lib/compat/wordpress-6.5/fonts/class-wp-rest-font-collections-controller.php @@ -157,15 +157,15 @@ public function get_item( $request ) { return $item; } - /* - * Prepare a single collection output for response. - * - * @since 6.5.0 - * - * @param WP_Font_Collection $collection Collection object. - * @param WP_REST_Request $request Request object. - * @return array|WP_Error - */ + /** + * Prepare a single collection output for response. + * + * @since 6.5.0 + * + * @param WP_Font_Collection $collection Collection object. + * @param WP_REST_Request $request Request object. + * @return array|WP_Error + */ public function prepare_item_for_response( $collection, $request ) { $fields = $this->get_fields_for_response( $request ); $item = array(); From 048d0d30f80a5fa9c3ffc25938e6a546ad8716e9 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Fri, 2 Feb 2024 20:55:18 +0100 Subject: [PATCH 3/4] Applying fixes from https://github.com/WordPress/gutenberg/pull/58607 --- ...ss-wp-rest-font-collections-controller.php | 33 ++++++++----------- .../class-wp-rest-font-faces-controller.php | 10 +++--- 2 files changed, 17 insertions(+), 26 deletions(-) diff --git a/lib/compat/wordpress-6.5/fonts/class-wp-rest-font-collections-controller.php b/lib/compat/wordpress-6.5/fonts/class-wp-rest-font-collections-controller.php index 491df0c4ef2415..2fe8e7bcefb9ca 100644 --- a/lib/compat/wordpress-6.5/fonts/class-wp-rest-font-collections-controller.php +++ b/lib/compat/wordpress-6.5/fonts/class-wp-rest-font-collections-controller.php @@ -84,7 +84,7 @@ public function get_items( $request ) { if ( $page > $max_pages && $total_items > 0 ) { return new WP_Error( 'rest_post_invalid_page_number', - __( 'The page number requested is larger than the number of pages available.', 'default' ), + __( 'The page number requested is larger than the number of pages available.' ), array( 'status' => 400 ) ); } @@ -148,24 +148,18 @@ public function get_item( $request ) { return $collection; } - $item = $this->prepare_item_for_response( $collection, $request ); - - if ( is_wp_error( $item ) ) { - return $item; - } - - return $item; + return $this->prepare_item_for_response( $collection, $request ); } /** - * Prepare a single collection output for response. - * - * @since 6.5.0 - * - * @param WP_Font_Collection $collection Collection object. - * @param WP_REST_Request $request Request object. - * @return array|WP_Error - */ + * Prepare a single collection output for response. + * + * @since 6.5.0 + * + * @param WP_Font_Collection $collection Collection object. + * @param WP_REST_Request $request Request object. + * @return WP_REST_Response Response object. + */ public function prepare_item_for_response( $collection, $request ) { $fields = $this->get_fields_for_response( $request ); $item = array(); @@ -195,9 +189,9 @@ public function prepare_item_for_response( $collection, $request ) { * * @since 6.5.0 * - * @param WP_REST_Response $response The response object. + * @param WP_REST_Response $response The response object. * @param WP_Font_Collection $collection The Font Collection object. - * @param WP_REST_Request $request Request used to generate the response. + * @param WP_REST_Request $request Request used to generate the response. */ return apply_filters( 'rest_prepare_font_collection', $response, $collection, $request ); } @@ -262,7 +256,7 @@ public function get_item_schema() { * @return array Links for the given font collection. */ protected function prepare_links( $collection ) { - $links = array( + return array( 'self' => array( 'href' => rest_url( sprintf( '%s/%s/%s', $this->namespace, $this->rest_base, $collection->slug ) ), ), @@ -270,7 +264,6 @@ protected function prepare_links( $collection ) { 'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ), ), ); - return $links; } /** diff --git a/lib/compat/wordpress-6.5/fonts/class-wp-rest-font-faces-controller.php b/lib/compat/wordpress-6.5/fonts/class-wp-rest-font-faces-controller.php index 01ffce1eea4838..efecd6c6821c32 100644 --- a/lib/compat/wordpress-6.5/fonts/class-wp-rest-font-faces-controller.php +++ b/lib/compat/wordpress-6.5/fonts/class-wp-rest-font-faces-controller.php @@ -151,7 +151,7 @@ public function get_item_permissions_check( $request ) { * * @param string $value Encoded JSON string of font face settings. * @param WP_REST_Request $request Request object. - * @return false|WP_Error True if the settings are valid, otherwise a WP_Error object. + * @return true|WP_Error True if the settings are valid, otherwise a WP_Error object. */ public function validate_create_font_face_settings( $value, $request ) { $settings = json_decode( $value, true ); @@ -698,7 +698,7 @@ protected function get_parent_font_family_post( $font_family_id ) { */ protected function prepare_links( $post ) { // Entity meta. - $links = array( + return array( 'self' => array( 'href' => rest_url( $this->namespace . '/font-families/' . $post->post_parent . '/font-faces/' . $post->ID ), ), @@ -709,8 +709,6 @@ protected function prepare_links( $post ) { 'href' => rest_url( $this->namespace . '/font-families/' . $post->post_parent ), ), ); - - return $links; } /** @@ -788,7 +786,7 @@ public function handle_font_file_upload_error( $file, $message ) { $status = 500; $code = 'rest_font_upload_unknown_error'; - if ( __( 'Sorry, you are not allowed to upload this file type.', 'default' ) === $message ) { + if ( __( 'Sorry, you are not allowed to upload this file type.' ) === $message ) { $status = 400; $code = 'rest_font_upload_invalid_file_type'; } @@ -799,7 +797,7 @@ public function handle_font_file_upload_error( $file, $message ) { /** * Returns relative path to an uploaded font file. * - * The path is relative to the current fonts dir. + * The path is relative to the current fonts directory. * * @since 6.5.0 * @access private From 8810a3241dbdd28f5f3da00687539411fe474738 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Fri, 2 Feb 2024 22:31:16 +0100 Subject: [PATCH 4/4] Improve readability. --- ...ss-wp-rest-font-collections-controller.php | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/compat/wordpress-6.5/fonts/class-wp-rest-font-collections-controller.php b/lib/compat/wordpress-6.5/fonts/class-wp-rest-font-collections-controller.php index 2fe8e7bcefb9ca..6ff54ed11c3611 100644 --- a/lib/compat/wordpress-6.5/fonts/class-wp-rest-font-collections-controller.php +++ b/lib/compat/wordpress-6.5/fonts/class-wp-rest-font-collections-controller.php @@ -298,17 +298,17 @@ public function get_collection_params() { * @return true|WP_Error True if the request has write access for the item, WP_Error object otherwise. */ public function get_items_permissions_check( $request ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable - - if ( ! current_user_can( 'edit_theme_options' ) ) { - return new WP_Error( - 'rest_cannot_read', - __( 'Sorry, you are not allowed to use the Font Library on this site.', 'gutenberg' ), - array( - 'status' => rest_authorization_required_code(), - ) - ); + if ( current_user_can( 'edit_theme_options' ) ) { + return true; } - return true; + + return new WP_Error( + 'rest_cannot_read', + __( 'Sorry, you are not allowed to use the Font Library on this site.', 'gutenberg' ), + array( + 'status' => rest_authorization_required_code(), + ) + ); } } }