[wp-trac] [WordPress Trac] #49296: class: WP_Query is a needs some help

WordPress Trac noreply at wordpress.org
Sun Jan 26 15:04:24 UTC 2020


#49296: class: WP_Query is a needs some help
-------------------------+-----------------------------
 Reporter:  madpeter     |      Owner:  (none)
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  General      |    Version:  5.3.2
 Severity:  normal       |   Keywords:
  Focuses:               |
-------------------------+-----------------------------
 as it stands the WP_query class file is over 4000 lines
 and with a single function that get_posts that on its own is over 1200
 lines.


 Suggestion
 -------------------------------------------------------------------------
 Split the class into its own folder with
 "vars","get","set","deprecated","process","comments","posts","get_posts"
 as abstract classes

 example
 {{{#!php
 <?php
 abstract class wp_query_vars { ..... }
 abstract class wp_query_get extends wp_query_vars { ..... }
 ?>
 }}}


 and then adjust the class-wp-query.php to load the split class

 {{{#!php
 <?php
 /**
  * Query API: WP_Query class
  *
  * @package WordPress
  * @subpackage Query
  * @since 4.7.0
  */
  $loader =
 array("vars","get","set","deprecated","process","comments","posts","get_posts");
  foreach($loader as $loadclass)
  {
          require_once("wp-query/wp_query_".$loadclass.".php");
  }

 class WP_Query extends wp_query_get_posts
 {
         /**
          * Constructor.
          *
          * Sets up the WordPress query, if parameter is not empty.
          *
          * @since 1.5.0
          *
          * @param string|array $query URL query string or array of vars.
          */
         public function __construct( $query = '' ) {
                 if ( ! empty( $query ) ) {
                         $this->query( $query );
                 }
         }
 }
 }}


 after this is done other improvements should be made to the get_posts
 function.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/49296>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list