Skip to content

Commit

Permalink
Use “Link” instead of “URL” term
Browse files Browse the repository at this point in the history
  • Loading branch information
getdave committed Dec 10, 2024
1 parent 7106e9f commit 9ab94f3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
14 changes: 7 additions & 7 deletions lib/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,23 @@ function gutenberg_register_edit_site_export_controller_endpoints() {



function gutenberg_register_archive_url_field() {
register_rest_field( 'type', 'archive_url', array(

function gutenberg_register_archive_link_field() {
register_rest_field( 'type', 'archive_link', array(
'get_callback' => function( $object ) {
if ( isset( $object['has_archive'] ) && $object['has_archive'] ) {
$post_type = $object['slug'];
$archive_url = get_post_type_archive_link( $post_type );
return $archive_url ? $archive_url : '';
$archive_link = get_post_type_archive_link( $post_type );
return $archive_link ? $archive_link : '';
}
return '';
},
'update_callback' => null,
'schema' => array(
'description' => __( 'URL to the post type archive page' ),
'description' => __( 'Link to the post type archive page' ),
'type' => 'string',
'context' => array( 'view', 'edit' ),
),
) );
}

add_action( 'rest_api_init', 'gutenberg_register_archive_url_field' );
add_action( 'rest_api_init', 'gutenberg_register_archive_link_field' );
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type MediaAPIResult = {
type PostTypesAPIResult = {
slug: string;
name: string;
archive_url: string;
archive_link: string;
};

export type SearchResult = {
Expand Down Expand Up @@ -257,11 +257,11 @@ export default async function fetchLinkSuggestions(
.then( ( results ) => {
const resultValues = Object.values( results );
return resultValues
.filter( ( result ) => !! result.archive_url ) // Filter out results with falsy archive_url, including empty strings
.filter( ( result ) => !! result.archive_link ) // Filter out results with falsy archive_link, including empty strings
.map( ( result, index ) => {
return {
id: index + 1, // avoid results being filtered due to falsy id
url: result.archive_url,
url: result.archive_link,
title:
decodeEntities( result.name || '' ) ||
__( '(no title)' ),
Expand Down

0 comments on commit 9ab94f3

Please sign in to comment.