[wp-trac] [WordPress Trac] #48193: Improve the WordPress loop

WordPress Trac noreply at wordpress.org
Thu Oct 3 02:55:11 UTC 2019


#48193: Improve the WordPress loop
-------------------------------------------------+-------------------------
 Reporter:  wpscholar                            |       Owner:  (none)
     Type:  enhancement                          |      Status:  new
 Priority:  normal                               |   Milestone:  Awaiting
                                                 |  Review
Component:  Query                                |     Version:
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch dev-feedback needs-        |     Focuses:
  testing                                        |
-------------------------------------------------+-------------------------
Changes (by ayeshrajans):

 * keywords:  has-patch dev-feedback => has-patch dev-feedback needs-testing


Comment:

 This indeed looks interesting! Do you have any use cases in existing core
 loops so we can benchmark for time/memory?

 Speaking from a clean code perspective, using global variables in new
 function seems a bit off, where we could create a function with proper
 typing and be more strict, and hand over the responsibility of passing
 correct `\WP_Query` instance to the caller. This will make writing tests
 quite easy too.

 In the original patch, there is a line ` if ( ! is_array( $posts ) ) {`.
 May be we can use `is_iterable` here? WordPress has a polyfill for this
 PHP 7.1 function, and this will allow callers to pass `Traversable`
 instances too, which the `foreach` block that proceeds it will happily
 accept. Because we are talking about using generators over array, I think
 it's safe to assume the callers would have Traversable objects instead of
 arrays.

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


More information about the wp-trac mailing list