From b402cfe84fa068eb426cf59a23594bb9730eaa82 Mon Sep 17 00:00:00 2001 From: MaggieCabrera Date: Tue, 30 Jan 2024 16:36:32 +0100 Subject: [PATCH 01/11] add image to link preview --- .../src/components/link-control/link-preview.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/block-editor/src/components/link-control/link-preview.js b/packages/block-editor/src/components/link-control/link-preview.js index 17cc851c503a14..f6b5e09d45c6a2 100644 --- a/packages/block-editor/src/components/link-control/link-preview.js +++ b/packages/block-editor/src/components/link-control/link-preview.js @@ -56,8 +56,15 @@ export default function LinkPreview( { let icon; + const attachmentImg = + value.type === 'attachment' && isImageUrl( value?.url ) + ? value.url + : null; + if ( richData?.icon ) { icon = ; + } else if ( attachmentImg ) { + icon = ; } else if ( isEmptyURL ) { icon = ; } else { @@ -155,3 +162,13 @@ export default function LinkPreview( { ); } + +/** + * Checks if the url is an image. + * @param {string} url the url we are checking. + * @return {boolean} true if the url is an image url. + */ +function isImageUrl( url ) { + const pattern = /(http(s?):)([/|.|\w|\s|-])*\.(?:jpg|gif|png)/g; + return pattern.test( url ); +} From 1c1eaafe3bf29c006ca189f39e0061f7dd15e7c1 Mon Sep 17 00:00:00 2001 From: MaggieCabrera Date: Tue, 30 Jan 2024 17:05:06 +0100 Subject: [PATCH 02/11] added thumbnail to the search item --- .../components/link-control/is-url-image.js | 9 +++++++ .../components/link-control/link-preview.js | 24 ++++++++++--------- .../components/link-control/search-item.js | 22 ++++++++++++++++- .../src/components/link-control/style.scss | 6 +++++ 4 files changed, 49 insertions(+), 12 deletions(-) create mode 100644 packages/block-editor/src/components/link-control/is-url-image.js diff --git a/packages/block-editor/src/components/link-control/is-url-image.js b/packages/block-editor/src/components/link-control/is-url-image.js new file mode 100644 index 00000000000000..bd7eabcdd5db45 --- /dev/null +++ b/packages/block-editor/src/components/link-control/is-url-image.js @@ -0,0 +1,9 @@ +/** + * Checks if the url is an image. + * @param {string} url the url we are checking. + * @return {boolean} true if the url is an image url. + */ +export default function isImageUrl( url ) { + const pattern = /(http(s?):)([/|.|\w|\s|-])*\.(?:jpg|gif|png)/g; + return pattern.test( url ); +} diff --git a/packages/block-editor/src/components/link-control/link-preview.js b/packages/block-editor/src/components/link-control/link-preview.js index f6b5e09d45c6a2..c75aae8b078442 100644 --- a/packages/block-editor/src/components/link-control/link-preview.js +++ b/packages/block-editor/src/components/link-control/link-preview.js @@ -3,6 +3,11 @@ */ import classnames from 'classnames'; +/** + * Internal dependencies + */ +import isImageUrl from './is-url-image'; + /** * WordPress dependencies */ @@ -64,7 +69,14 @@ export default function LinkPreview( { if ( richData?.icon ) { icon = ; } else if ( attachmentImg ) { - icon = ; + //TODO we don't have an alt text for this image + icon = ( + + ); } else if ( isEmptyURL ) { icon = ; } else { @@ -162,13 +174,3 @@ export default function LinkPreview( { ); } - -/** - * Checks if the url is an image. - * @param {string} url the url we are checking. - * @return {boolean} true if the url is an image url. - */ -function isImageUrl( url ) { - const pattern = /(http(s?):)([/|.|\w|\s|-])*\.(?:jpg|gif|png)/g; - return pattern.test( url ); -} diff --git a/packages/block-editor/src/components/link-control/search-item.js b/packages/block-editor/src/components/link-control/search-item.js index 7fa8ee1803644c..dee5b2c9c7c927 100644 --- a/packages/block-editor/src/components/link-control/search-item.js +++ b/packages/block-editor/src/components/link-control/search-item.js @@ -18,6 +18,11 @@ import { __unstableStripHTML as stripHTML } from '@wordpress/dom'; import { safeDecodeURI, filterURLForDisplay, getPath } from '@wordpress/url'; import { pipe } from '@wordpress/compose'; +/** + * Internal dependencies + */ +import isImageUrl from './is-url-image'; + const ICONS_MAP = { post: postList, page, @@ -28,6 +33,7 @@ const ICONS_MAP = { function SearchItemIcon( { isURL, suggestion } ) { let icon = null; + let imageURL = null; if ( isURL ) { icon = globe; @@ -41,9 +47,23 @@ function SearchItemIcon( { isURL, suggestion } ) { icon = verse; } } + + if ( suggestion.kind === 'media' && isImageUrl( suggestion.url ) ) { + imageURL = suggestion.url; + } } - if ( icon ) { + if ( imageURL ) { + return ( + + + + ); + } else if ( icon ) { return ( Date: Wed, 31 Jan 2024 12:03:48 +0100 Subject: [PATCH 03/11] improved size and style of images --- .../src/components/link-control/search-item.js | 2 +- .../src/components/link-control/style.scss | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/block-editor/src/components/link-control/search-item.js b/packages/block-editor/src/components/link-control/search-item.js index dee5b2c9c7c927..851fc1ab7dde3d 100644 --- a/packages/block-editor/src/components/link-control/search-item.js +++ b/packages/block-editor/src/components/link-control/search-item.js @@ -55,7 +55,7 @@ function SearchItemIcon( { isURL, suggestion } ) { if ( imageURL ) { return ( - + Date: Thu, 1 Feb 2024 11:45:36 +0100 Subject: [PATCH 04/11] added unit test for isImageUrl --- .../components/link-control/is-url-image.js | 3 +- .../link-control/test/is-url-image.js | 28 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 packages/block-editor/src/components/link-control/test/is-url-image.js diff --git a/packages/block-editor/src/components/link-control/is-url-image.js b/packages/block-editor/src/components/link-control/is-url-image.js index bd7eabcdd5db45..34c05396633121 100644 --- a/packages/block-editor/src/components/link-control/is-url-image.js +++ b/packages/block-editor/src/components/link-control/is-url-image.js @@ -4,6 +4,7 @@ * @return {boolean} true if the url is an image url. */ export default function isImageUrl( url ) { - const pattern = /(http(s?):)([/|.|\w|\s|-])*\.(?:jpg|gif|png)/g; + const pattern = + /^(https?:\/\/)([\w-]+(?:\.[\w-]+)*\/)*[\w-]+\.(?:jpg|JPG|jpeg|gif|png|webp)$/i; return pattern.test( url ); } diff --git a/packages/block-editor/src/components/link-control/test/is-url-image.js b/packages/block-editor/src/components/link-control/test/is-url-image.js new file mode 100644 index 00000000000000..14cf8a80f6144a --- /dev/null +++ b/packages/block-editor/src/components/link-control/test/is-url-image.js @@ -0,0 +1,28 @@ +/** + * Internal dependencies + */ +import isImageUrl from '../is-url-image'; + +describe( 'isImageUrl', () => { + // use .each to test multiple cases + it.each( [ + [ true, 'https://example.com/image.jpg' ], + [ true, 'https://example.com/image.gif' ], + [ true, 'https://example.com/image.png' ], + [ true, 'https://example.com/image.webp' ], + [ true, 'https://example.com/image.jpeg' ], + [ true, 'https://example.com/image.JPG' ], + [ false, 'https://example.com/image.txt' ], + [ false, 'https://example.com/image' ], + [ false, 'https://example.com/image.jpg?query=123' ], + [ false, '' ], + [ false, null ], + [ false, undefined ], + [ false, 123 ], + ] )( + 'returns %s when testing against URL "%s" for a valid image', + ( expected, testString ) => { + expect( isImageUrl( testString ) ).toBe( expected ); + } + ); +} ); From 52ae180e8ca58f650b7d13e74b9553bfed527442 Mon Sep 17 00:00:00 2001 From: MaggieCabrera Date: Wed, 7 Feb 2024 17:25:42 +0100 Subject: [PATCH 05/11] Includes a new REST API endpoint for searching media items Co-authored-by: petitphp --- ...est-media-search-handler-gutenberg-6-6.php | 110 ++++++++++++++++++ lib/compat/wordpress-6.6/rest-api.php | 82 +++++++++++++ lib/load.php | 4 + .../__experimental-fetch-link-suggestions.js | 4 +- 4 files changed, 199 insertions(+), 1 deletion(-) create mode 100644 lib/compat/wordpress-6.6/class-wp-rest-media-search-handler-gutenberg-6-6.php create mode 100644 lib/compat/wordpress-6.6/rest-api.php diff --git a/lib/compat/wordpress-6.6/class-wp-rest-media-search-handler-gutenberg-6-6.php b/lib/compat/wordpress-6.6/class-wp-rest-media-search-handler-gutenberg-6-6.php new file mode 100644 index 00000000000000..9d88bf72afd224 --- /dev/null +++ b/lib/compat/wordpress-6.6/class-wp-rest-media-search-handler-gutenberg-6-6.php @@ -0,0 +1,110 @@ +type = 'media'; + $this->subtypes = array(); + } + + /** + * Searches the object type content for a given search request. + * + * @since 6.6.0 + * + * @param WP_REST_Request $request Full REST request. + * @return array Associative array containing an `WP_REST_Search_Handler::RESULT_IDS` containing + * an array of found IDs and `WP_REST_Search_Handler::RESULT_TOTAL` containing the + * total count for the matching search results. + */ + public function search_items( WP_REST_Request $request ) { + + $query_args = array( + 'post_type' => 'attachment', + 'post_status' => 'inherit', + 'paged' => (int) $request['page'], + 'posts_per_page' => (int) $request['per_page'], + ); + + if ( ! empty( $request['search'] ) ) { + $query_args['s'] = $request['search']; + + // Filter query clauses to include filenames. + add_filter( 'wp_allow_query_attachment_by_filename', '__return_true' ); + } + + if ( ! empty( $request['exclude'] ) ) { + $query_args['post__not_in'] = $request['exclude']; + } + + if ( ! empty( $request['include'] ) ) { + $query_args['post__in'] = $request['include']; + } + + /** + * Filters the query arguments for a REST API search request. + * + * Enables adding extra arguments or setting defaults for a media search request. + * + * @since 6.6.0 + * + * @param array $query_args Key value array of query var to query value. + * @param WP_REST_Request $request The request used. + */ + $query_args = apply_filters( 'rest_media_search_query', $query_args, $request ); + + $query = new WP_Query(); + $posts = $query->query( $query_args ); + // Querying the whole post object will warm the object cache, avoiding an extra query per result. + $found_ids = wp_list_pluck( $posts, 'ID' ); + $total = $query->found_posts; + + return array( + self::RESULT_IDS => $found_ids, + self::RESULT_TOTAL => $total, + ); + } + + /** + * Prepares the search result for a given ID. + * + * @since 6.6.0 + * + * @param int $id Item ID. + * @param array $fields Fields to include for the item. + * @return array Associative array containing all fields for the item. + */ + public function prepare_item( $id, array $fields ) { + $data = parent::prepare_item( $id, $fields ); + + if ( isset( $data[ WP_REST_Search_Controller::PROP_SUBTYPE ] ) ) { + unset( $data[ WP_REST_Search_Controller::PROP_SUBTYPE ] ); + } + + return $data; + } +} \ No newline at end of file diff --git a/lib/compat/wordpress-6.6/rest-api.php b/lib/compat/wordpress-6.6/rest-api.php new file mode 100644 index 00000000000000..c16a22c0f0e63e --- /dev/null +++ b/lib/compat/wordpress-6.6/rest-api.php @@ -0,0 +1,82 @@ + '_gutenberg_get_search_result_thumbnail_field', + 'update_callback' => null, + 'schema' => array( + 'description' => __( 'Object human readable subtype.', 'gutenberg' ), + 'type' => 'string', + 'readonly' => true, + 'context' => array( 'view', 'embed' ), + ), + ) + ); +} + +add_action( 'rest_api_init', '_gutenberg_register_search_result_additional_fields' ); + +/** + * Register custom rest media search handler. + * + * @param array $handlers + * + * @return array + */ +function _gutenberg_register_media_search_handler( $handlers ) { + if ( class_exists( 'WP_REST_Media_Search_Handler_Gutenberg' ) ) { + $handlers[] = new WP_REST_Media_Search_Handler_Gutenberg(); + } + + return $handlers; +} + +add_action( 'wp_rest_search_handlers', '_gutenberg_register_media_search_handler' ); diff --git a/lib/load.php b/lib/load.php index 3d9213ce6e93a9..363e74f60db93f 100644 --- a/lib/load.php +++ b/lib/load.php @@ -45,6 +45,10 @@ function gutenberg_is_experiment_enabled( $name ) { require_once __DIR__ . '/compat/wordpress-6.5/class-gutenberg-rest-global-styles-revisions-controller-6-5.php'; require_once __DIR__ . '/compat/wordpress-6.5/rest-api.php'; + // WordPress 6.6 compat. + require_once __DIR__ . '/compat/wordpress-6.6/class-wp-rest-media-search-handler-gutenberg-6-6.php'; + require_once __DIR__ . '/compat/wordpress-6.6/rest-api.php'; + // Plugin specific code. require_once __DIR__ . '/class-wp-rest-global-styles-controller-gutenberg.php'; require_once __DIR__ . '/rest-api.php'; diff --git a/packages/core-data/src/fetch/__experimental-fetch-link-suggestions.js b/packages/core-data/src/fetch/__experimental-fetch-link-suggestions.js index 3bba760b20c459..b5511ff49c9399 100644 --- a/packages/core-data/src/fetch/__experimental-fetch-link-suggestions.js +++ b/packages/core-data/src/fetch/__experimental-fetch-link-suggestions.js @@ -179,10 +179,11 @@ const fetchLinkSuggestions = async ( if ( ! type || type === 'attachment' ) { queries.push( apiFetch( { - path: addQueryArgs( '/wp/v2/media', { + path: addQueryArgs( '/wp/v2/search', { search, page, per_page: perPage, + type: 'media', } ), } ) .then( ( results ) => { @@ -229,6 +230,7 @@ const fetchLinkSuggestions = async ( ) || __( '(no title)' ), type: result.subtype || result.type, kind: result?.meta?.kind, + thumbnail: result?.thumbnail, }; } ); } ); From 7f1a65987cb0018abcb94b26db4e9886902cf57b Mon Sep 17 00:00:00 2001 From: MaggieCabrera Date: Wed, 7 Feb 2024 17:47:14 +0100 Subject: [PATCH 06/11] used thumbnail for search suggestion --- .../src/components/link-control/search-item.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/packages/block-editor/src/components/link-control/search-item.js b/packages/block-editor/src/components/link-control/search-item.js index 851fc1ab7dde3d..36aeddc34e54ed 100644 --- a/packages/block-editor/src/components/link-control/search-item.js +++ b/packages/block-editor/src/components/link-control/search-item.js @@ -18,11 +18,6 @@ import { __unstableStripHTML as stripHTML } from '@wordpress/dom'; import { safeDecodeURI, filterURLForDisplay, getPath } from '@wordpress/url'; import { pipe } from '@wordpress/compose'; -/** - * Internal dependencies - */ -import isImageUrl from './is-url-image'; - const ICONS_MAP = { post: postList, page, @@ -35,6 +30,10 @@ function SearchItemIcon( { isURL, suggestion } ) { let icon = null; let imageURL = null; + if ( suggestion.kind === 'media' ) { + imageURL = suggestion.thumbnail; + } + if ( isURL ) { icon = globe; } else if ( suggestion.type in ICONS_MAP ) { @@ -47,10 +46,6 @@ function SearchItemIcon( { isURL, suggestion } ) { icon = verse; } } - - if ( suggestion.kind === 'media' && isImageUrl( suggestion.url ) ) { - imageURL = suggestion.url; - } } if ( imageURL ) { From 58d35ba74801daf47d8f8171f1cc8879e994488f Mon Sep 17 00:00:00 2001 From: MaggieCabrera Date: Wed, 7 Feb 2024 17:49:24 +0100 Subject: [PATCH 07/11] removed logs --- lib/compat/wordpress-6.6/rest-api.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/compat/wordpress-6.6/rest-api.php b/lib/compat/wordpress-6.6/rest-api.php index c16a22c0f0e63e..eeb316b18f855f 100644 --- a/lib/compat/wordpress-6.6/rest-api.php +++ b/lib/compat/wordpress-6.6/rest-api.php @@ -9,8 +9,7 @@ if ( ! defined( 'ABSPATH' ) ) { die( 'Silence is golden.' ); } -//var_dump(wp_get_attachment_image_src( 7, 'thumbnail' )); -//die(); + /** * Registers additional fields for search result rest api. * From 59f980f1a5e9513d536332d545edc372f2eb05e0 Mon Sep 17 00:00:00 2001 From: MaggieCabrera Date: Wed, 7 Feb 2024 17:55:13 +0100 Subject: [PATCH 08/11] make sure imageURL is not empty --- lib/compat/wordpress-6.6/rest-api.php | 2 ++ .../block-editor/src/components/link-control/search-item.js | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/compat/wordpress-6.6/rest-api.php b/lib/compat/wordpress-6.6/rest-api.php index eeb316b18f855f..5236567a7f0024 100644 --- a/lib/compat/wordpress-6.6/rest-api.php +++ b/lib/compat/wordpress-6.6/rest-api.php @@ -32,6 +32,8 @@ function _gutenberg_get_search_result_thumbnail_field( $result_object, $field_na return $thumbnail[0] ? $thumbnail[0] : ''; } +//ALT: $alt_text = get_post_meta($attachment_id, '_wp_attachment_image_alt', true); + /** * Registers additional fields for search result rest api. * diff --git a/packages/block-editor/src/components/link-control/search-item.js b/packages/block-editor/src/components/link-control/search-item.js index 36aeddc34e54ed..2e8a738eb77c99 100644 --- a/packages/block-editor/src/components/link-control/search-item.js +++ b/packages/block-editor/src/components/link-control/search-item.js @@ -31,7 +31,7 @@ function SearchItemIcon( { isURL, suggestion } ) { let imageURL = null; if ( suggestion.kind === 'media' ) { - imageURL = suggestion.thumbnail; + imageURL = suggestion.thumbnail ? suggestion.thumbnail : null; } if ( isURL ) { From eb93565d5609634b4bd63ee00f7f4e0f23490add Mon Sep 17 00:00:00 2001 From: MaggieCabrera Date: Wed, 7 Feb 2024 18:02:03 +0100 Subject: [PATCH 09/11] added alt text --- lib/compat/wordpress-6.6/rest-api.php | 37 ++++++++++++++++++- .../components/link-control/search-item.js | 4 +- .../__experimental-fetch-link-suggestions.js | 1 + 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/lib/compat/wordpress-6.6/rest-api.php b/lib/compat/wordpress-6.6/rest-api.php index 5236567a7f0024..f4257a97ffee14 100644 --- a/lib/compat/wordpress-6.6/rest-api.php +++ b/lib/compat/wordpress-6.6/rest-api.php @@ -32,7 +32,27 @@ function _gutenberg_get_search_result_thumbnail_field( $result_object, $field_na return $thumbnail[0] ? $thumbnail[0] : ''; } -//ALT: $alt_text = get_post_meta($attachment_id, '_wp_attachment_image_alt', true); +/** + * Registers additional fields for search result rest api. + * + * @access private* @internal + * + * @param array $result_object Search result object. + * @param string $field_name Current additional field's name (unused). + * @param \WP_REST_Request $request Rest request object. + * @return string Alt text for the result object. + */ +function _gutenberg_get_search_result_alt_text_field( $result_object, $field_name, $request ) { + + $object_id = $result_object['id']; + if ( empty( $object_id ) ) { + return ''; + } + + $alt_text = get_post_meta($object_id, '_wp_attachment_image_alt', true); + + return $alt_text; +} /** * Registers additional fields for search result rest api. @@ -61,6 +81,21 @@ function _gutenberg_register_search_result_additional_fields() { ), ) ); + + register_rest_field( + 'search-result', + 'alt_text', + array( + 'get_callback' => '_gutenberg_get_search_result_alt_text_field', + 'update_callback' => null, + 'schema' => array( + 'description' => __( 'Object human readable subtype.', 'gutenberg' ), + 'type' => 'string', + 'readonly' => true, + 'context' => array( 'view', 'embed' ), + ), + ) + ); } add_action( 'rest_api_init', '_gutenberg_register_search_result_additional_fields' ); diff --git a/packages/block-editor/src/components/link-control/search-item.js b/packages/block-editor/src/components/link-control/search-item.js index 2e8a738eb77c99..22ab57a5544297 100644 --- a/packages/block-editor/src/components/link-control/search-item.js +++ b/packages/block-editor/src/components/link-control/search-item.js @@ -29,9 +29,11 @@ const ICONS_MAP = { function SearchItemIcon( { isURL, suggestion } ) { let icon = null; let imageURL = null; + let altText = ''; if ( suggestion.kind === 'media' ) { imageURL = suggestion.thumbnail ? suggestion.thumbnail : null; + altText = suggestion.alt_text; } if ( isURL ) { @@ -54,7 +56,7 @@ function SearchItemIcon( { isURL, suggestion } ) { ); diff --git a/packages/core-data/src/fetch/__experimental-fetch-link-suggestions.js b/packages/core-data/src/fetch/__experimental-fetch-link-suggestions.js index b5511ff49c9399..41a14f74531c3a 100644 --- a/packages/core-data/src/fetch/__experimental-fetch-link-suggestions.js +++ b/packages/core-data/src/fetch/__experimental-fetch-link-suggestions.js @@ -231,6 +231,7 @@ const fetchLinkSuggestions = async ( type: result.subtype || result.type, kind: result?.meta?.kind, thumbnail: result?.thumbnail, + alt_text: result?.alt_text, }; } ); } ); From fc302a1fde81286e1c2c580fd5585c907cda4625 Mon Sep 17 00:00:00 2001 From: MaggieCabrera Date: Wed, 7 Feb 2024 18:08:53 +0100 Subject: [PATCH 10/11] renamed class to follow convention --- .../class-wp-rest-media-search-handler-gutenberg-6-6.php | 2 +- lib/compat/wordpress-6.6/rest-api.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/compat/wordpress-6.6/class-wp-rest-media-search-handler-gutenberg-6-6.php b/lib/compat/wordpress-6.6/class-wp-rest-media-search-handler-gutenberg-6-6.php index 9d88bf72afd224..d52a0413ea57b9 100644 --- a/lib/compat/wordpress-6.6/class-wp-rest-media-search-handler-gutenberg-6-6.php +++ b/lib/compat/wordpress-6.6/class-wp-rest-media-search-handler-gutenberg-6-6.php @@ -18,7 +18,7 @@ * * @see WP_REST_Search_Handler */ -class WP_REST_Media_Search_Handler_Gutenberg extends WP_REST_Post_Search_Handler { +class WP_REST_Media_Search_Handler_Gutenberg_6_6 extends WP_REST_Post_Search_Handler { /** * Constructor. diff --git a/lib/compat/wordpress-6.6/rest-api.php b/lib/compat/wordpress-6.6/rest-api.php index f4257a97ffee14..dc384c703c2cb3 100644 --- a/lib/compat/wordpress-6.6/rest-api.php +++ b/lib/compat/wordpress-6.6/rest-api.php @@ -108,8 +108,8 @@ function _gutenberg_register_search_result_additional_fields() { * @return array */ function _gutenberg_register_media_search_handler( $handlers ) { - if ( class_exists( 'WP_REST_Media_Search_Handler_Gutenberg' ) ) { - $handlers[] = new WP_REST_Media_Search_Handler_Gutenberg(); + if ( class_exists( 'WP_REST_Media_Search_Handler_Gutenberg_6_6' ) ) { + $handlers[] = new WP_REST_Media_Search_Handler_Gutenberg_6_6(); } return $handlers; From f8eb9296b8d2a65ca11ec1c23a033968623e7aea Mon Sep 17 00:00:00 2001 From: MaggieCabrera Date: Thu, 8 Feb 2024 10:32:06 +0100 Subject: [PATCH 11/11] linting errors --- .../class-wp-rest-media-search-handler-gutenberg-6-6.php | 2 +- lib/compat/wordpress-6.6/rest-api.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/compat/wordpress-6.6/class-wp-rest-media-search-handler-gutenberg-6-6.php b/lib/compat/wordpress-6.6/class-wp-rest-media-search-handler-gutenberg-6-6.php index d52a0413ea57b9..53b4dc02ecbc16 100644 --- a/lib/compat/wordpress-6.6/class-wp-rest-media-search-handler-gutenberg-6-6.php +++ b/lib/compat/wordpress-6.6/class-wp-rest-media-search-handler-gutenberg-6-6.php @@ -107,4 +107,4 @@ public function prepare_item( $id, array $fields ) { return $data; } -} \ No newline at end of file +} diff --git a/lib/compat/wordpress-6.6/rest-api.php b/lib/compat/wordpress-6.6/rest-api.php index dc384c703c2cb3..24040fde2762ed 100644 --- a/lib/compat/wordpress-6.6/rest-api.php +++ b/lib/compat/wordpress-6.6/rest-api.php @@ -20,7 +20,7 @@ * @param \WP_REST_Request $request Rest request object. * @return string Thumbnail for the result object. */ -function _gutenberg_get_search_result_thumbnail_field( $result_object, $field_name, $request ) { +function _gutenberg_get_search_result_thumbnail_field( $result_object ) { $object_id = $result_object['id']; if ( empty( $object_id ) ) { @@ -42,14 +42,14 @@ function _gutenberg_get_search_result_thumbnail_field( $result_object, $field_na * @param \WP_REST_Request $request Rest request object. * @return string Alt text for the result object. */ -function _gutenberg_get_search_result_alt_text_field( $result_object, $field_name, $request ) { +function _gutenberg_get_search_result_alt_text_field( $result_object ) { $object_id = $result_object['id']; if ( empty( $object_id ) ) { return ''; } - $alt_text = get_post_meta($object_id, '_wp_attachment_image_alt', true); + $alt_text = get_post_meta( $object_id, '_wp_attachment_image_alt', true ); return $alt_text; }