Make WordPress Core

Opened 13 years ago

Closed 11 years ago

#18042 closed enhancement (fixed)

Need a way to override wp_link_query()

Reported by: philfreo's profile philfreo Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 3.7 Priority: normal
Severity: normal Version: 3.2
Component: Editor Keywords: has-patch commit
Focuses: Cc:

Description (last modified by DrewAPicture)

In previous versions of WordPress, we were able to write a plugin which called add_filter on tiny_mce_before_init and then we were able to specify external_link_list_url which we gave it a list of all of the URLs on our site (we primarily linked to non-WordPress URLs on our site from this tool). Then when an author created a Link in the post tool the little popup would include a dropdown of all of the URLs/page titles that we specified.

In WordPress 3.2 you have the new fancy "link to existing content" feature in the popup.

The problem is that there is NO hook, filter, or pluggable function whatsoever to allow you to override the functionality of this.

I needed to make the search results box return a list of pages (urls and titles) that I specified from a different database. In order order to do that I had to re-create the entire wp_link_query() function from wp-admin/includes/internal-linking.php to make it return search results from my own database. I put that function into a Plugin (to keep it out of Core) but then I had to hack core to rename wp_link_query() to wp_link_query_ORIGINAL() to get it to use my function and not the existing one.

Either wp_link_query() needs to be a pluggable function or there need to be hooks that let you completely replace how it works.

Attachments (5)

18042.diff (618 bytes) - added by goldenapples 11 years ago.
Since #21861 was closed, I've moved @CoenJacobs's patch from that ticket here. Also added a filter on the return value so plugins can rearrange the order that custom post types appear in the returned array.
18042.2.diff (624 bytes) - added by SergeyBiryukov 11 years ago.
18042-docs.diff (2.0 KB) - added by DrewAPicture 11 years ago.
filter docs
18042-docs.2.diff (2.1 KB) - added by DrewAPicture 11 years ago.
Associative array.
18042-docs.3.diff (1.5 KB) - added by DrewAPicture 11 years ago.
point to WP_Query for args

Download all attachments as: .zip

Change History (44)

#1 @nacin
13 years ago

  • Type changed from defect (bug) to enhancement

We definitely need hooks here. +1

#2 @bainternet
13 years ago

  • Cc bainternet added
  • Version changed from 3.2 to 3.2.1

#3 @dd32
13 years ago

  • Version changed from 3.2.1 to 3.2

The version field is used to track when a bug was first reported.

#4 @bainternet
13 years ago

@dd32yea sorry about that,


anyway +1 for either hooks or pluggable.

#5 @hereswhatidid
13 years ago

Definitely +1 for a hook or pluggable. Need a way to add items other than just published posts to the list of available items to link to.

#6 @pavelevap
13 years ago

  • Cc pavelevap@… added

#7 @nohalfpixels
12 years ago

is there a date set for updating this feature?

#8 @DrewAPicture
12 years ago

  • Cc xoodrew@… added

#19718 closed as duplicate

#9 @heinrichgeps
12 years ago

Definitely +1 for a hook or pluggable.

#10 @rliverman
12 years ago

Agreed, unfortunately looks like a core hack for the time being...ugh. +1 for hook or pluggable.

#12 @mordauk
12 years ago

  • Cc pippin@… added

#13 @ocean90
12 years ago

  • Keywords needs-patch added

Duplicate: #21861

#14 @CoenJacobs
12 years ago

  • Cc coenjacobs@… added

#15 @goldenapples
11 years ago

  • Cc goldenapplesdesign@… added

@goldenapples
11 years ago

Since #21861 was closed, I've moved @CoenJacobs's patch from that ticket here. Also added a filter on the return value so plugins can rearrange the order that custom post types appear in the returned array.

#16 @goldenapples
11 years ago

  • Keywords has-patch added; needs-patch removed

#17 @bradyvercher
11 years ago

  • Cc brady@… added

A hook would definitely be nice here.

I developed a plugin a few months ago (Better Internal Link Search), without realizing this ticket existed, to modify the results and ended up having to filter the AJAX request and recreate a bit of wp_link_query(). The plugin adds a whole lot of useful features and improvements and can be easily extended for anyone that needs this functionality right away. If any of it looks useful for core, I'm happy to help learn how to contribute.

#18 @SergeyBiryukov
11 years ago

#23241 was marked as a duplicate.

#19 @SergeyBiryukov
11 years ago

  • Component changed from Plugins to Editor
  • Milestone changed from Awaiting Review to 3.6

#20 @lumpysimon
11 years ago

  • Cc piemanek@… added

#21 @lumpysimon
11 years ago

+1 for this making it into 3.6

#22 follow-up: @SergeyBiryukov
11 years ago

18042.2.diff passes $query to the resulting filter too.

#23 @DrewAPicture
11 years ago

  • Description modified (diff)

#24 @DrewAPicture
11 years ago

Both filters added in 18042.2.diff work as expected for me. +1

#25 @ocean90
11 years ago

  • Milestone changed from 3.6 to Future Release

#26 @dominicp
11 years ago

  • Cc solaveritasteliberum@… added

+1. The patches looks great to me too. Can't really see a downside to this.

#27 @mjjojo
11 years ago

  • Cc mjjojo added

#28 @sxalexander
11 years ago

  • Cc sxalexander added

#29 @coreygilmore
11 years ago

  • Cc corey@… added

#30 @LucasMS
11 years ago

  • Cc ch4cal@… added

#31 in reply to: ↑ 22 ; follow-up: @CoenJacobs
11 years ago

Replying to SergeyBiryukov:

18042.2.diff passes $query to the resulting filter too.

Thanks, I've tested this patch against the current trunk, still works like a charm.

Just curious: Any reason you prefer wp_link_query over wp_link_query_results in my original modified patch as posted here? Just because that's the function name, best practice to filter results via a similarly named filter?

#32 @SergeyBiryukov
11 years ago

#15349 was marked as a duplicate.

#33 @helen
11 years ago

  • Milestone changed from Future Release to 3.7

#34 in reply to: ↑ 31 @SergeyBiryukov
11 years ago

Replying to CoenJacobs:

Just curious: Any reason you prefer wp_link_query over wp_link_query_results in my original modified patch as posted here? Just because that's the function name, best practice to filter results via a similarly named filter?

Yes, this appears to be the pattern throughout the core.

#35 @SergeyBiryukov
11 years ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 25293:

Add 'wp_link_query_args' and 'wp_link_query' filters to allow for customizing the internal linking dialog. props CoenJacobs, goldenapples. fixes #18042.

@DrewAPicture
11 years ago

filter docs

#36 follow-up: @DrewAPicture
11 years ago

  • Keywords commit added
  • Resolution fixed deleted
  • Status changed from closed to reopened

From this point moving forward, any time we introduce new functions, filters, actions, methods, properties, etc., a ticket shouldn't be marked as closed/fixed until inline docs accompany whatever was introduced.

18042-docs.diff adds docblocks for the wp_link_query_args and wp_link_query filters introduced in [25293].

Last edited 11 years ago by DrewAPicture (previous) (diff)

@DrewAPicture
11 years ago

Associative array.

#37 @DrewAPicture
11 years ago

18042-docs.2.diff fixes $results param in wp_link_query as it's actually an associative array.

@DrewAPicture
11 years ago

point to WP_Query for args

#38 in reply to: ↑ 36 @SergeyBiryukov
11 years ago

Replying to DrewAPicture:

From this point moving forward, any time we introduce new functions, filters, actions, methods, properties, etc., a ticket shouldn't be marked as closed/fixed until inline docs accompany whatever was introduced.

Right, my bad.

#39 @SergeyBiryukov
11 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 25299:

Document 'wp_link_query_args' and 'wp_link_query' filters. props DrewAPicture. fixes #18042.

Note: See TracTickets for help on using tickets.