WordPress.org

Make WordPress Core

Opened 11 months ago

#39708 new enhancement

Provide suppress_actions argument on WP_Query::get_posts or apply suppress_filters to pre_get_posts

Reported by: aubreypwd Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.7.1
Component: Query Keywords:
Focuses: Cc:

Description

<?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?

Change History (0)

Note: See TracTickets for help on using tickets.