[wp-trac] [WordPress Trac] #52386: Should WP_Query::get_posts be a private method?

WordPress Trac noreply at wordpress.org
Mon Apr 29 19:52:55 UTC 2024


#52386: Should WP_Query::get_posts be a private method?
-------------------------+------------------------------
 Reporter:  rebasaurus   |       Owner:  (none)
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  Awaiting Review
Component:  Query        |     Version:
 Severity:  normal       |  Resolution:
 Keywords:               |     Focuses:  performance
-------------------------+------------------------------

Comment (by oglekler):

 This method cannot be made private because it will break a lot of themes
 and plugins actually leading to a disaster, but I believe that there is an
 easy fix — this method is not getting any arguments, so, there is no way
 that the result can be changed (apart from a possibility that before
 WP_Query() object creation and this method call some data will be changed
 by something else, but I think it should be fine not to count in most
 cases this method call is the next line after object initialization. And
 $posts property initially is equal to null, so, if $this->posts is an
 array, even an empty one, we can safely return this array on the spot
 without processing the query again.

 @costdev what do you think? 🙏

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


More information about the wp-trac mailing list