WordPress.org

Make WordPress Core

Opened 8 months ago

Last modified 8 months ago

#49296 new enhancement

Split up WP_Query into more manageable classes

Reported by: madpeter Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.3.2
Component: Query Keywords:
Focuses: Cc:

Description

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 
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
/**
 * 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.

Change History (2)

#1 @SergeyBiryukov
8 months ago

  • Component changed from General to Query

Related: #49149

#2 @SergeyBiryukov
8 months ago

  • Summary changed from class: WP_Query is a needs some help to Split up WP_Query into more manageable classes
Note: See TracTickets for help on using tickets.