Chassis / core_dev

A Chassis extension for WordPress Core development.
2 stars 1 forks source link

Avoid modifying `wp-config.phg`. #25

Closed peterwilsoncc closed 5 years ago

peterwilsoncc commented 5 years ago

Rather than modifying the chassis config file, I am wondering if we should duplicate it and load it as an extension config instead.

The file would need to reproduce everything in the Chassis wp-config file from and including the Load Chassis extensions section.

This would including loading the extensions file again (crazy, but it uses require_once) to make sure all the other extensions are loaded and finishing with an exit statement. So something like:

defined( 'CORE_DEV_VAGRANT_ROOT' ) or define( 'CORE_DEV_VAGRANT_ROOT', '/vagrant' );

// =======================
// Load Chassis extensions
// =======================
if ( file_exists( CORE_DEV_VAGRANT_ROOT . '/local-config-extensions.php' ) ) {
    include( CORE_DEV_VAGRANT_ROOT . '/local-config-extensions.php' );
}

// ==================
// Set up WP location
// ==================
if ( ! defined( 'ABSPATH' ) ) {
    define( 'ABSPATH', CORE_DEV_VAGRANT_ROOT. '/wp/' );
}

// ======================================
// Fake HTTP Host (for CLI compatibility)
// ======================================
if ( ! isset( $_SERVER['HTTP_HOST'] ) ) {
    if ( defined( 'DOMAIN_CURRENT_SITE' ) ) {
        $_SERVER['HTTP_HOST'] = DOMAIN_CURRENT_SITE;
    } else {
        $_SERVER['HTTP_HOST'] = 'vagrant.local';
    }
}

// ========================
// Custom Content Directory
// ========================
defined('WP_CONTENT_DIR') or define( 'WP_CONTENT_DIR', CORE_DEV_VAGRANT_ROOT . '/content' );
defined('WP_CONTENT_URL') or define( 'WP_CONTENT_URL', 'http://' . $_SERVER['HTTP_HOST'] . '/content' );

// =======================
// Use built-in themes too
// =======================
if ( empty( $GLOBALS['wp_theme_directories'] ) ) {
    $GLOBALS['wp_theme_directories'] = array();
}
if ( file_exists( WP_CONTENT_DIR . '/themes' ) ) {
    $GLOBALS['wp_theme_directories'][] = WP_CONTENT_DIR . '/themes';
}
$GLOBALS['wp_theme_directories'][] = ABSPATH . 'wp-content/themes';
$GLOBALS['wp_theme_directories'][] = ABSPATH . 'wp-content/themes';

// =============================
// Configuration for the Content
// =============================
if ( file_exists( WP_CONTENT_DIR . '/config.php' ) ) {
    include( WP_CONTENT_DIR . '/config.php' );
}

// =====================
// URL hacks for Vagrant
// =====================
if ( WP_LOCAL_DEV && ! defined('WP_SITEURL') && ! defined( 'WP_INSTALLING' ) ) {
    define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/wp');

    if ( ! defined( 'WP_HOME' ) ) {
        define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']);
    }
}

// ================================================
// You almost certainly do not want to change these
// ================================================
define( 'DB_CHARSET', 'utf8' );
define( 'DB_COLLATE', '' );

// ==============================================================
// Salts, for security
// Grab these from: https://api.wordpress.org/secret-key/1.1/salt
// ==============================================================
define( 'AUTH_KEY',         'put your unique phrase here' );
define( 'SECURE_AUTH_KEY',  'put your unique phrase here' );
define( 'LOGGED_IN_KEY',    'put your unique phrase here' );
define( 'NONCE_KEY',        'put your unique phrase here' );
define( 'AUTH_SALT',        'put your unique phrase here' );
define( 'SECURE_AUTH_SALT', 'put your unique phrase here' );
define( 'LOGGED_IN_SALT',   'put your unique phrase here' );
define( 'NONCE_SALT',       'put your unique phrase here' );

// ==============================================================
// Table prefix
// Change this if you have multiple installs in the same database
// ==============================================================
if ( empty( $table_prefix ) ) {
    $table_prefix  = 'wp_';
}

// =====================================
// Errors
// Show/hide errors for local/production
// =====================================
if ( WP_LOCAL_DEV ) {
    defined( 'WP_DEBUG' ) or define( 'WP_DEBUG', true );
}
// Only override if not already set
elseif ( ! defined( 'WP_DEBUG_DISPLAY' ) ) {
    ini_set( 'display_errors', 0 );
    define( 'WP_DEBUG_DISPLAY', false );
}

// ===================
// Bootstrap WordPress
// ===================
if ( ! file_exists( ABSPATH . 'wp-settings.php' ) ) {
    header('X-WP-Error: wpmissing', true, 500);
    echo '<h1>WordPress is missing.</h1>';
    die(1);
}
if ( ! defined( 'WP_CLI' ) ) require_once( ABSPATH . 'wp-settings.php' );

// Avoid loading WP twice.
exit;
BronsonQuick commented 5 years ago

Have you tried adding these in a local-config.php the the root of this extension: http://docs.chassis.io/en/latest/extend/#wordpress-configuration I can't remember the load order off the top of my head but I think that will get loaded before wp-config.php and if we need to add in more defined checks in Chassis core we can do that upstream.

peterwilsoncc commented 5 years ago

Well this is a terrible idea because my trace of how WP includes the wp-config file was incorrect.