[wp-trac] [WordPress Trac] #56689: Use WP_Query in get_page_by_path
WordPress Trac
noreply at wordpress.org
Thu Feb 2 22:40:30 UTC 2023
#56689: Use WP_Query in get_page_by_path
-------------------------------------------------+-------------------------
Reporter: spacedmonkey | Owner:
| spacedmonkey
Type: defect (bug) | Status: reopened
Priority: normal | Milestone: 6.2
Component: Query | Version: trunk
Severity: normal | Resolution:
Keywords: needs-testing has-patch has-unit- | Focuses:
tests has-testing-info 2nd-opinion | performance
-------------------------------------------------+-------------------------
Comment (by iandunn):
`pre_get_posts` has a generic purpose, and there's an infinite number of
things that a plugin's business logic might need to do there. If we were
talking about new code, I'd be fine with saying a plugin just needs to
work around the inherent problem with recursion, but I feel like the main
issue here is back-compat.
Here's a few other potential solutions:
* Solve the performance issue without `WP_Query`, like by manually add
caching to `get_page_by_path`. Add a comment explaining why it can't use
`WP_Query`.
* Keep the `WP_Query` in most cases, but fallback to the old direct
queries when a potential infinite loop is detected.
...and a few half-baked ones in case brainstorming sparks something
better:
* Maybe something around calling `WP_Query` with `suppress_filters`. That
doesn't actually avoid `pre_get_posts`, but maybe a similar concept could
be applied somewhere.
* Detect the infinite loop, throw a `doing_it_wrong()` notice, and return
early with an empty array. This would still need a dev note, since it's
breaking the functionality. It's probably better to cause a fatal than to
trigger some unpredictable behavior, though.
Manually adding caching to the function seems like the simplest to me.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/56689#comment:15>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list