Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CMSP-660] Update to use Pantheon-WP-Coding-Standards #111

Merged
merged 8 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
"php -l web/wp/wp-settings.php"
],
"lint:phpcs": [
"phpcs"
"vendor/bin/phpcs -s ."
],
"lint:bash": [
"shellcheck private/scripts/*.sh"
Expand Down
132 changes: 66 additions & 66 deletions config/application.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
* @var string
*/
$root_dir = dirname(__DIR__);
$root_dir = dirname( __DIR__ );

/**
* Document Root
Expand All @@ -28,121 +28,121 @@
* Use Dotenv to set required environment variables and load .env file in root
* .env.local will override .env if it exists
*/
$env_files = file_exists($root_dir . '/.env.local')
? ['.env', '.env.pantheon', '.env.local']
: ['.env', '.env.pantheon'];
$env_files = file_exists( $root_dir . '/.env.local' )
? [ '.env', '.env.pantheon', '.env.local' ]
: [ '.env', '.env.pantheon' ];

$dotenv = Dotenv\Dotenv::createUnsafeImmutable($root_dir, $env_files, false);
$dotenv = Dotenv\Dotenv::createUnsafeImmutable( $root_dir, $env_files, false );
if (
// Check if a .env file exists.
file_exists($root_dir . '/.env') ||
// Also check if we're using Lando and a .env.local file exists.
( file_exists($root_dir . '/.env.local') && 'lando' === $_ENV['PANTHEON_ENVIRONMENT'] )
// Check if a .env file exists.
file_exists( $root_dir . '/.env' ) ||
// Also check if we're using Lando and a .env.local file exists.
( file_exists( $root_dir . '/.env.local' ) && 'lando' === $_ENV['PANTHEON_ENVIRONMENT'] )
) {
$dotenv->load();
if (!env('DATABASE_URL')) {
$dotenv->required(['DB_NAME', 'DB_USER', 'DB_PASSWORD']);
}
$dotenv->load();
if ( ! env( 'DATABASE_URL' ) ) {
$dotenv->required( [ 'DB_NAME', 'DB_USER', 'DB_PASSWORD' ] );
}
}

/**
* Set up our global environment constant and load its config first
* Default: production
*/
define('WP_ENV', env('WP_ENV') ?: 'production');
define( 'WP_ENV', env( 'WP_ENV' ) ?: 'production' );

/**
* DB settings
*/
Config::define('DB_NAME', env('DB_NAME'));
Config::define('DB_USER', env('DB_USER'));
Config::define('DB_PASSWORD', env('DB_PASSWORD'));
Config::define('DB_HOST', env('DB_HOST') ?: 'localhost');
Config::define('DB_CHARSET', 'utf8mb4');
Config::define('DB_COLLATE', '');
$table_prefix = env('DB_PREFIX') ?: 'wp_';

if (env('DATABASE_URL')) {
$dsn = (object) parse_url(env('DATABASE_URL'));

Config::define('DB_NAME', substr($dsn->path, 1));
Config::define('DB_USER', $dsn->user);
Config::define('DB_PASSWORD', isset($dsn->pass) ? $dsn->pass : null);
Config::define('DB_HOST', isset($dsn->port) ? "{$dsn->host}:{$dsn->port}" : $dsn->host);
Config::define( 'DB_NAME', env( 'DB_NAME' ) );
Config::define( 'DB_USER', env( 'DB_USER' ) );
Config::define( 'DB_PASSWORD', env( 'DB_PASSWORD' ) );
Config::define( 'DB_HOST', env( 'DB_HOST' ) ?: 'localhost' );
Config::define( 'DB_CHARSET', 'utf8mb4' );
Config::define( 'DB_COLLATE', '' );
$table_prefix = env( 'DB_PREFIX' ) ?: 'wp_';

if ( env( 'DATABASE_URL' ) ) {
$dsn = (object) parse_url( env( 'DATABASE_URL' ) );

Config::define( 'DB_NAME', substr( $dsn->path, 1 ) );
Config::define( 'DB_USER', $dsn->user );
Config::define( 'DB_PASSWORD', isset( $dsn->pass ) ? $dsn->pass : null );
Config::define( 'DB_HOST', isset( $dsn->port ) ? "{$dsn->host}:{$dsn->port}" : $dsn->host );
}

/**
* Pantheon modifications
*/
if (isset($_ENV['PANTHEON_ENVIRONMENT']) && 'lando' !== $_ENV['PANTHEON_ENVIRONMENT']) {
Config::define('DB_HOST', $_ENV['DB_HOST'] . ':' . $_ENV['DB_PORT']);
if ( isset( $_ENV['PANTHEON_ENVIRONMENT'] ) && 'lando' !== $_ENV['PANTHEON_ENVIRONMENT'] ) {
Config::define( 'DB_HOST', $_ENV['DB_HOST'] . ':' . $_ENV['DB_PORT'] );
} else {
/**
* URLs
*/
Config::define('WP_HOME', env('WP_HOME'));
Config::define('WP_SITEURL', env('WP_SITEURL'));
Config::define('DB_HOST', env('DB_HOST') ?: 'localhost');
Config::define('DISABLE_WP_CRON', env('DISABLE_WP_CRON') ?: false);
/**
* URLs
*/
Config::define( 'WP_HOME', env( 'WP_HOME' ) );
Config::define( 'WP_SITEURL', env( 'WP_SITEURL' ) );
Config::define( 'DB_HOST', env( 'DB_HOST' ) ?: 'localhost' );
Config::define( 'DISABLE_WP_CRON', env( 'DISABLE_WP_CRON' ) ?: false );
}

/**
* Custom Content Directory
*/
Config::define('CONTENT_DIR', '/app');
Config::define('WP_CONTENT_DIR', $webroot_dir . Config::get('CONTENT_DIR'));
Config::define('WP_CONTENT_URL', Config::get('WP_HOME') . Config::get('CONTENT_DIR'));
Config::define( 'CONTENT_DIR', '/app' );
Config::define( 'WP_CONTENT_DIR', $webroot_dir . Config::get( 'CONTENT_DIR' ) );
Config::define( 'WP_CONTENT_URL', Config::get( 'WP_HOME' ) . Config::get( 'CONTENT_DIR' ) );

/**
* Authentication Unique Keys and Salts
*/
Config::define('AUTH_KEY', env('AUTH_KEY'));
Config::define('SECURE_AUTH_KEY', env('SECURE_AUTH_KEY'));
Config::define('LOGGED_IN_KEY', env('LOGGED_IN_KEY'));
Config::define('NONCE_KEY', env('NONCE_KEY'));
Config::define('AUTH_SALT', env('AUTH_SALT'));
Config::define('SECURE_AUTH_SALT', env('SECURE_AUTH_SALT'));
Config::define('LOGGED_IN_SALT', env('LOGGED_IN_SALT'));
Config::define('NONCE_SALT', env('NONCE_SALT'));
Config::define( 'AUTH_KEY', env( 'AUTH_KEY' ) );
Config::define( 'SECURE_AUTH_KEY', env( 'SECURE_AUTH_KEY' ) );
Config::define( 'LOGGED_IN_KEY', env( 'LOGGED_IN_KEY' ) );
Config::define( 'NONCE_KEY', env( 'NONCE_KEY' ) );
Config::define( 'AUTH_SALT', env( 'AUTH_SALT' ) );
Config::define( 'SECURE_AUTH_SALT', env( 'SECURE_AUTH_SALT' ) );
Config::define( 'LOGGED_IN_SALT', env( 'LOGGED_IN_SALT' ) );
Config::define( 'NONCE_SALT', env( 'NONCE_SALT' ) );

/**
* Custom Settings
*/
Config::define('AUTOMATIC_UPDATER_DISABLED', true);
// Disable the plugin and theme file editor in the admin
Config::define('DISALLOW_FILE_EDIT', true);
// Disable plugin and theme updates and installation from the admin
Config::define('DISALLOW_FILE_MODS', true);
// Limit the number of post revisions that Wordpress stores (true (default WP): store every revision)
Config::define('WP_POST_REVISIONS', env('WP_POST_REVISIONS') ?? true);
Config::define( 'AUTOMATIC_UPDATER_DISABLED', true );
// Disable the plugin and theme file editor in the admin.
Config::define( 'DISALLOW_FILE_EDIT', true );
// Disable plugin and theme updates and installation from the admin.
Config::define( 'DISALLOW_FILE_MODS', true );
// Limit the number of post revisions that Wordpress stores (true (default WP): store every revision).
Config::define( 'WP_POST_REVISIONS', env( 'WP_POST_REVISIONS' ) ?? true );

/**
* Debugging Settings
*/
Config::define('WP_DEBUG_DISPLAY', false);
Config::define('WP_DEBUG_LOG', false);
Config::define('SCRIPT_DEBUG', false);
ini_set('display_errors', '0');
Config::define( 'WP_DEBUG_DISPLAY', false );
Config::define( 'WP_DEBUG_LOG', false );
Config::define( 'SCRIPT_DEBUG', false );
ini_set( 'display_errors', '0' );

/**
* Allow WordPress to detect HTTPS when used behind a reverse proxy or a load balancer
* See https://codex.wordpress.org/Function_Reference/is_ssl#Notes
*/
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
$_SERVER['HTTPS'] = 'on';
if ( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https' ) {
$_SERVER['HTTPS'] = 'on';
}

$env_config = __DIR__ . '/environments/' . WP_ENV . '.php';

if (file_exists($env_config)) {
require_once $env_config;
if ( file_exists( $env_config ) ) {
require_once $env_config;
}

Config::apply();

/**
* Bootstrap WordPress
*/
if (!defined('ABSPATH')) {
define('ABSPATH', $webroot_dir . '/wp/');
if ( ! defined( 'ABSPATH' ) ) {
define( 'ABSPATH', $webroot_dir . '/wp/' );
}
29 changes: 25 additions & 4 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<ruleset name="Roots">
<description>Roots Coding Standards</description>
<ruleset name="Pantheon WP Composer Managed">
<description>Pantheon WordPress Composer Managed Upstream</description>

<!-- Scan all files in directory -->
<file>.</file>
Expand All @@ -16,8 +16,29 @@

<!-- Start Pantheon addition: Ignore plugins and quicksilver scripts -->
<exclude-pattern>web/app/mu-plugins/*</exclude-pattern>
<!-- This line prevents all plugins from being linted. Remove this line if you want to lint plugins. -->
<exclude-pattern>web/app/plugins/*</exclude-pattern>
<exclude-pattern>web/private/*</exclude-pattern>
<exclude-pattern>upstream-configuration/*</exclude-pattern>

<!-- Ignore sniffs against things that we explicitly want for Pantheon upstreams. -->
<rule ref="Pantheon-WP">
<exclude name="WordPress.PHP.IniSet.display_errors_Disallowed">
<exclude-pattern>config/application.php</exclude-pattern>
</exclude>
<exclude name="WordPress.PHP.IniSet.display_errors_Blacklisted">
<exclude-pattern>config/application.php</exclude-pattern>
</exclude>
<exclude name="WordPress.Security.ValidatedSanitizedInput.InputNotSanitized">
<exclude-pattern>config/application.php</exclude-pattern>
</exclude>
<exclude name="WordPress.Security.ValidatedSanitizedInput.InputNotValidated">
<exclude-pattern>config/application.php</exclude-pattern>
</exclude>
<exclude name="WordPress.WP.GlobalVariablesOverride.Prohibited">
<exclude-pattern>config/application.php</exclude-pattern>
</exclude>
</rule>
<!-- End Pantheon addition -->

<!-- Show colors in console -->
Expand All @@ -26,6 +47,6 @@
<!-- Show sniff codes in all reports -->
<arg value="ns"/>

<!-- Use PSR-2 as a base -->
<rule ref="PSR2"/>
<!-- Use Pantheon-WP as a base -->
<rule ref="Pantheon-WP"/>
</ruleset>
Loading