diff --git a/.env.example b/.env.example index e950bee..d8c1c53 100644 --- a/.env.example +++ b/.env.example @@ -1,7 +1,8 @@ # Remove the .example extension on this file to activate it. # Change the settings below as needed to customize it for your environment. -DB_NAME=wp +DB_NAME=local DB_USER=root DB_PASSWORD=root -DEBUG=true \ No newline at end of file +WP_DEBUG=true +SCRIPT_DEBUG=true diff --git a/.gitignore b/.gitignore index ac12047..78fa6ca 100644 --- a/.gitignore +++ b/.gitignore @@ -6,10 +6,10 @@ !.idea/workspace.xml # Composer -/vendor/ +/vendor # WordPress -/wp/ +/wp /salt.php # WordPress: Config File @@ -33,4 +33,4 @@ !/content/uploads/index.php # dotEnv Configuration -.env \ No newline at end of file +.env diff --git a/README.md b/README.md index 87633c8..d8658b2 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,11 @@ Setup a new WordPress installation via Composer ## Requirements -PHP 5.3.2+ +PHP 5.6+ ## Prerequisites -Install Composer by running `curl -sS https://getcomposer.org/installer | php && mv composer.phar /usr/local/bin/composer` on Linux/Unix/OSX +Install [Composer](https://getcomposer.org/doc/00-intro.md) ## Installation @@ -22,4 +22,4 @@ Replace `{directory}` above with the folder name of your new project. ## Configuration -Open up the `.env` file and edit your database credentials. \ No newline at end of file +Open up the `.env` file and edit your database credentials. diff --git a/composer.json b/composer.json index a6c34f7..0c7bce3 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "wpscholar/wp-skeleton", "description": "Setup a new WordPress installation via Composer.", - "license": "GPL-2.0+", + "license": "GPL-2.0-or-later", "type": "project", "keywords": [ "WordPress", @@ -32,7 +32,7 @@ "require": { "johnpbloch/wordpress": "@stable", "composer/installers": "@stable", - "vlucas/phpdotenv": "^2.2" + "wpscholar/phpdotenv": "^1.0" }, "suggest": { "wp-cli/wp-cli": "@stable" diff --git a/index.php b/index.php index 24aaab0..56cd891 100644 --- a/index.php +++ b/index.php @@ -1,3 +1,4 @@ load(); - $dotenv->required( [ 'DB_NAME', 'DB_USER', 'DB_PASSWORD' ] ); -} - -if ( file_exists( __DIR__ . '/wp-config-local.php' ) ) { - require __DIR__ . '/wp-config-local.php'; -} else if ( file_exists( dirname( __DIR__ ) . '/wp-config-local.php' ) ) { - require dirname( __DIR__ ) . '/wp-config-local.php'; -} +use wpscholar\phpdotenv\Loader; -if ( ! defined( 'APP_DOMAIN' ) ) { - define( 'APP_DOMAIN', $_SERVER['HTTP_HOST'] ); -} +/** + * Trick Local by Flywheel into reading these values + * + * define( 'DB_HOST', 'localhost' ); + * define( 'DB_NAME', 'local' ); + * define( 'DB_USER', 'root' ); + * define( 'DB_PASSWORD', 'root' ); + */ $is_ssl = (boolean) getenv( 'HTTPS' ) || 443 == getenv( 'SERVER_PORT' ) || 'https' === getenv( 'HTTP_X_FORWARDED_PROTO' ); $scheme = $is_ssl ? 'https' : 'http'; -define( 'WP_HOME', $scheme . '://' . APP_DOMAIN ); -define( 'WP_SITEURL', WP_HOME . '/wp' ); - -define( 'WP_CONTENT_DIR', __DIR__ . '/content' ); -define( 'WP_CONTENT_URL', WP_HOME . '/content' ); - -if ( ! defined( 'DB_NAME' ) ) { - define( 'DB_NAME', getenv( 'DB_NAME' ) ); -} - -if ( ! defined( 'DB_USER' ) ) { - define( 'DB_USER', getenv( 'DB_USER' ) ); -} - -if ( ! defined( 'DB_PASSWORD' ) ) { - define( 'DB_PASSWORD', getenv( 'DB_PASSWORD' ) ); -} - -if ( ! defined( 'DB_HOST' ) ) { - define( 'DB_HOST', 'localhost' ); -} - -if ( ! defined( 'DB_CHARSET' ) ) { - define( 'DB_CHARSET', 'utf8' ); -} - -if ( ! defined( 'DB_COLLATE' ) ) { - define( 'DB_COLLATE', '' ); -} - -if ( ! defined( 'WP_DEBUG' ) ) { - define( 'WP_DEBUG', filter_var( getenv( 'DEBUG' ), FILTER_VALIDATE_BOOLEAN ) ); -} - -if ( ! defined( 'DISALLOW_FILE_EDIT' ) ) { - define( 'DISALLOW_FILE_EDIT', true ); -} - -if ( ! isset( $table_prefix ) ) { - $table_prefix = 'wp_'; -} +$loader = new Loader(); +$loader + ->config( [ 'adapters' => 'define' ] ) + ->required( [ + 'DB_NAME', + 'DB_USER', + 'DB_PASSWORD', + ] ) + ->setDefaults( [ + 'ABSPATH' => __DIR__ . '/wp', + 'DB_CHARSET' => 'utf8', + 'DB_COLLATE' => '', + 'DB_HOST' => 'localhost', + 'WP_DEBUG' => false, + 'WP_TABLE_PREFIX' => 'wp_', + ] ) + ->parse( __DIR__ . '/.env' ) + ->set( 'WP_HOME', $scheme . '://' . $_SERVER['HTTP_HOST'] ) + ->set( 'WP_SITEURL', $loader->get( 'WP_HOME' ) . '/wp' ) + ->set( 'WP_CONTENT_DIR', __DIR__ . '/content' ) + ->set( 'WP_CONTENT_URL', $loader->get( 'WP_HOME' ) . '/content' ) + ->set( 'DISALLOW_FILE_EDIT', true ) + ->load(); + +$table_prefix = WP_TABLE_PREFIX; // https://api.wordpress.org/secret-key/1.1/salt/ if ( file_exists( __DIR__ . '/salt.php' ) ) { require __DIR__ . '/salt.php'; } -if ( ! defined( 'ABSPATH' ) ) { - define( 'ABSPATH', __DIR__ . '/wp' ); +if ( file_exists( __DIR__ . '/wp-config-local.php' ) ) { + require __DIR__ . '/wp-config-local.php'; +} else if ( file_exists( dirname( __DIR__ ) . '/wp-config-local.php' ) ) { + require dirname( __DIR__ ) . '/wp-config-local.php'; } -require_once( ABSPATH . 'wp-settings.php' ); \ No newline at end of file +require_once( ABSPATH . 'wp-settings.php' );