[wp-trac] [WordPress Trac] #39708: Provide suppress_actions argument on WP_Query::get_posts or apply suppress_filters to pre_get_posts

WordPress Trac noreply at wordpress.org
Thu Jan 26 18:03:35 UTC 2017


#39708: Provide suppress_actions argument on WP_Query::get_posts or apply
suppress_filters to pre_get_posts
-------------------------+-----------------------------
 Reporter:  aubreypwd    |      Owner:
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  Query        |    Version:  4.7.1
 Severity:  normal       |   Keywords:
  Focuses:               |
-------------------------+-----------------------------
 {{{#!php
 <?php
         public function get_posts() {
                 global $wpdb;

                 $this->parse_query();

                 /**
                  * Fires after the query variable object is created, but
 before the actual query is run.
                  *
                  * Note: If using conditional tags, use the method
 versions within the passed instance
                  * (e.g. $this->is_main_query() instead of
 is_main_query()). This is because the functions
                  * like is_main_query() test against the global $wp_query
 instance, not the passed one.
                  *
                  * @since 2.0.0
                  *
                  * @param WP_Query &$this The WP_Query instance (passed by
 reference).
                  */
                 do_action_ref_array( 'pre_get_posts', array( &$this ) );

                 // Shorthand.
                 $q = &$this->query_vars;
 }}}

 I'm proposing that, just like we have `$q['suppress_filters']` that we add
 a `$q['suppress_actions']` to prevent actions like `pre_get_posts` from
 running (which is essentially a filter) on my query (if I want).

 We could also apply `$q['suppress_filters']` to the `pre_get_posts` action
 since the user can modify the query since it's passed by reference, and
 may not create another argument, but it is not really a filter.

 I'm not sure how this idea could be problematic, nor can I think of any
 reason why we couldn't do anything like this, but I thought I'd at least
 open it up for discussion and see what becomes of it. I guess my question
 really is why can I suppress filters but not actions?

--
Ticket URL: <https://core.trac.wordpress.org/ticket/39708>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list