Opened 4 months ago
Last modified 4 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)
Note: See
TracTickets for help on using
tickets.
Related: #49149