Make WordPress Core

Opened 13 years ago

Closed 12 years ago

Last modified 12 years ago

#20731 closed enhancement (wontfix)

Split wp-settings.php in two

Reported by: scribu's profile 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)

20731.diff (464 bytes) - added by scribu 12 years ago.

Download all attachments as: .zip

Change History (6)

#1 @scribu
12 years ago

  • Milestone changed from Awaiting Review to 3.5

#2 @scribu
12 years 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

@scribu
12 years ago

#3 @scribu
12 years ago

  • Keywords has-patch added

#4 @scribu
12 years ago

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

Nevermind, already handled in #21115

#5 @scribu
12 years 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.