#20731 closed enhancement (wontfix)
Split wp-settings.php in two
Reported by: | scribu | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | General | Keywords: | dev-feedback |
Focuses: | Cc: |
Description
In wp-settings.php, we have these lines:
// Stop most of WordPress from being loaded if we just want the basics. if ( SHORTINIT ) return false;
What I'm suggesting is that we move everything that follows into a separate file.
Use-case: setting up a unit-testing environment without changing the database:
https://github.com/nb/wordpress-tests/pull/19
Here's the gist of how it's currently done:
// Define the options to be short-circuited $GLOBALS['wp_tests_options'] = array( 'active_plugins' => array( 'akismet.php' ), 'template' => 'twentyeleven' ); // Load the essential parts of WordPress. define('SHORTINIT', true); require_once ABSPATH . '/wp-settings.php'; // Short-circuit the options function wp_tests_options( $value ) { $key = substr( current_filter(), strlen( 'pre_option_' ) ); return $GLOBALS['wp_tests_options'][$key]; } foreach ( array_keys( $GLOBALS['wp_tests_options'] ) as $key ) { add_filter( 'pre_option_'.$key, 'wp_tests_options' ); } // Load the rest of wp-settings.php (start from where we left off) $wp_settings_content = file_get_contents(ABSPATH.'/wp-settings.php'); $offset = strpos($wp_settings_content, '// Load the l18n library.'); eval(substr($wp_settings_content, $offset)); unset($wp_settings_content, $offset);
As you can see, that last part is really ugly and fragile. It would be awesome if we could just do:
require(ABSPATH.'/wp-settings-2.php');
Attachments (1)
Change History (6)
Note: See
TracTickets for help on using
tickets.
In IRC today I learned that SHORTINIT is rather arbitrary and will be deprecated eventually.
The alternative nacin suggested was to populate $wp_filter before loading WP.
This would require removing the
unset( $wp_filter );
line in wp-settings.php