[wp-trac] [WordPress Trac] #36687: Feature to override WP_Query to provide results from other source

WordPress Trac noreply at wordpress.org
Sat Jun 11 03:16:23 UTC 2016


#36687: Feature to override WP_Query to provide results from other source
-----------------------------------+--------------------------
 Reporter:  jpdavoutian            |       Owner:  jpdavoutian
     Type:  feature request        |      Status:  assigned
 Priority:  normal                 |   Milestone:  4.6
Component:  Query                  |     Version:
 Severity:  normal                 |  Resolution:
 Keywords:  has-patch 2nd-opinion  |     Focuses:
-----------------------------------+--------------------------

Comment (by boonebgorges):

 > So, my concern is not how I can handle such a case within my plugin were
 I have set the filter and I can easily bypass it, but how a third party
 plugin could tell the system not to go through the posts_pre_query without
 being aware of my plugin.

 Thanks for the clarification. I think I understand the concern. This hook
 is essentially a forced override: it allows plugin A to prevent WP from
 firing its normal query. You are suggesting that perhaps there should be
 an override for this override, in the form of a `WP_Query` param or
 something like that, so that plugin B can tell plugin A not to bypass the
 query.

 I'm not sure such an override is wise, or helpful. What happens when
 plugin A wants to tell plugin B that, no, *really*, I want to override
 `WP_Query`? Should there be an override of the override of the override?

 The use cases for `pre_posts_query` are varied, and the interaction
 between third-party plugins using it will almost always have to be very
 specific to the two plugins involved. To take your example, say you're
 using something like [comment:8 what I suggested above] to feed external
 posts into the query results. And let's say that you have a plugin that
 occasionally needs "fresh" results from the WP database, for the purpose
 of refreshing the search index. In that case, I would whitelist those
 specific index queries:

 {{{
 function wp36687_do_external_posts_query( $posts, WP_Query $query ) {
     if ( isset( $_GET['get_fresh_posts'] ) ) {
         return $posts;
     }

     ...
 }}}

 You probably want something more sophisticated than this, but you get the
 idea: Like anywhere else in WordPress, when you use an action or filter
 hook, you have to be sure that your callback only fires in the proper
 context. What that context is will differ from case to case, such that I
 don't think WP can make the decision ahead of time.

 My inclination is to go with [attachment:36687.diff] for 4.6. If plugin
 authors find that they're having a hard time overriding the override, we
 can revisit in a future release. Does that seem reasonable to you
 @jpdavoutian ?

--
Ticket URL: <https://core.trac.wordpress.org/ticket/36687#comment:18>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list