(@joyously)
I think it doesn’t use the REST API, but it has an AJAX handler that might have a filter.
Ajax handler is wp_ajax_wp_link_ajax(), but no immediate filter there. You could use ‘wp_link_query’ filter, which passes an array of post data. For API endpoints you’d need to compose fake post data. I think post $ID = 0
should be OK for all, but untested.
Thanks! I was able to get it to work as using the wp_link_query
filter. I’ve provided an example below that may not make much sense out of context.
/**
* Add Endpoints to Inline Linking Tool
*
* @param Array $results
* @param Array $query
*
* @return Array $results
*/
function prefix_add_endpoints_to_inline_links( $results, $query ) {
$endpoints = prefix_get_endpoints(); // Array of endpoint data keyed by group then by endpoint
$possibilities = array();
foreach( $endpoints as $group => $groupdata ) {
foreach( $groupdata as $endpoint => $epdata ) {
if( ! $epdata['show_in_nav'] ) { // Custom flag to skip showing endpoint
continue;
// Search Endpoint Nicename against query
} else if( false !== stripos( $epdata['nicename'], $query['s'] ) ) {
$possibilities[] = array(
'ID' => 0,
'title' => $epdata['nicename'],
'permalink' => prefix_endpoint_url( $endpoint, $group ), // Grab the endpoint URL
'info' => 'EP ' . ucfirst( $group ),
);
}
}
}
$results = array_merge( $results, $possibilities );
array_multisort( array_column( $results, 'title' ), SORT_ASC, $results );
return $results;
}
add_filter( 'wp_link_query', 'prefix_add_endpoints_to_inline_links', 10, 2 );
Thanks again!