Make WordPress Core

Opened 2 years ago

Closed 22 months ago

Last modified 22 months ago

#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:


In wp-settings.php, we have these lines:

// Stop most of WordPress from being loaded if we just want the basics.
	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:


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:


Attachments (1)

20731.diff (464 bytes) - added by scribu 22 months ago.

Download all attachments as: .zip

Change History (6)

comment:1 scribu22 months ago

  • Milestone changed from Awaiting Review to 3.5

comment:2 scribu22 months ago

  • Summary changed from Split wp-settings.php in two to Add early hooks for unit testing

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

scribu22 months ago

comment:3 scribu22 months ago

  • Keywords has-patch added

comment:4 scribu22 months ago

  • Milestone 3.5 deleted
  • Resolution set to wontfix
  • Status changed from new to closed

Nevermind, already handled in #21115

comment:5 scribu22 months ago

  • Keywords has-patch removed
  • Summary changed from Add early hooks for unit testing to Split wp-settings.php in two
Note: See TracTickets for help on using tickets.