WordPress.org

Make WordPress Core

Opened 2 years ago

Last modified 2 years ago

#41825 closed enhancement

wp_link_query not applied if method finds nothing — at Version 1

Reported by: msebel Owned by:
Milestone: 4.9 Priority: normal
Severity: normal Version: 3.7
Component: Editor Keywords: has-patch has-unit-tests commit
Focuses: Cc:

Description (last modified by swissspidy)

In class-wp-editor.php
https://github.com/WordPress/WordPress/blob/master/wp-includes/class-wp-editor.php

We have the public static function wp_link_query, which allows to search for internal links. There's also the possibility to alter the query 'wp_link_query_args' and to filter the results with 'wp_link_query'

Now the problem is, if a plugin *adds* additional search results in wp_link_query, that is possible, but if the WordPress Query itself finds nothing we return false. It would be nice to apply the filter there as well, as a plugin may be able to find more results, even if WP_Query finds nothing.

So I'd propose to change

if ( ! $get_posts->post_count )
 return false;

to

if ( ! $get_posts->post_count )
 return apply_filters( 'wp_link_query', false, $query );

Behold, as I'm planning to discuss and maybe change this with @swissspidy at a contributor day tomorrow in bern switzerland.

Change History (5)

@mitraval192
2 years ago

Added patch

#1 @swissspidy
2 years ago

  • Description modified (diff)
  • Version changed from trunk to 3.7

@msebel
2 years ago

patch with docs, making sure it still returns false if filter is not used

@msebel
2 years ago

patch, documentation (ideents with tabs, still learning)

@swissspidy
2 years ago

Note: See TracTickets for help on using tickets.