[wp-trac] [WordPress Trac] #56689: Use WP_Query in get_page_by_path
WordPress Trac
noreply at wordpress.org
Fri Feb 3 17:53:58 UTC 2023
#56689: Use WP_Query in get_page_by_path
-------------------------------------------------+-------------------------
Reporter: spacedmonkey | Owner:
| spacedmonkey
Type: defect (bug) | Status: closed
Priority: normal | Milestone:
Component: Query | Version: trunk
Severity: normal | Resolution: wontfix
Keywords: needs-testing has-patch has-unit- | Focuses:
tests has-testing-info 2nd-opinion | performance
-------------------------------------------------+-------------------------
Comment (by Otto42):
Replying to [comment:23 SergeyBiryukov]:
> What if we replace the direct SQL query, but also keep the function's
own caching? Then the infinite loop should not be triggered if my
understanding is correct.
>
> [attachment:56689.diff] illustrates the idea. The tests still pass with
this patch.
I believe that would still trigger the loop.
The problem is the `pre_get_posts` filter is one that may be used for a
lot of different things. In this particular circumstance, it is being
called and then calling `get_page_by_path`. If this function calls a new
WP_Query, that's going to, once again, call the `pre_get_posts` filter.
And that's where the loop is.
Making this a wrapper around WP_Query is going to be essentially a
problem, no matter what, when it can be called by a filter that is called
by WP_Query.
Now it is arguable that a `pre_get_posts` filter should not be used to
call this function. But that's an entirely new restraint on the filter.
And given the age of the function and its use in countless possible
plugins or themes or what have you... it's a very big backward
compatibility break.
One way around it would be to disable the filter on creation of the
WP_Query. However, there's not natively a way to do that, and potentially
other filters could produce similar results as well.
Ultimately, I think this function should simply be deprecated if that is
desired. If a replacement is desired for it that uses WP_Query, it should
have a new name.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/56689#comment:24>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list