From 28c281d3a4b31ff5fd0b4cb5ed0bd241d773c1a8 Mon Sep 17 00:00:00 2001 From: Brian DiChiara Date: Thu, 2 May 2024 16:09:25 -0500 Subject: [PATCH] [N/A] Stop/Log Emails + Local Config Setup & README update --- client-mu-plugins/goodbids/composer.json | 7 +++- client-mu-plugins/goodbids/composer.lock | 38 ++++++++++++++++++- .../goodbids/src/classes/Core.php | 33 +++++++++++++++- docs/local.md | 16 ++++++++ 4 files changed, 91 insertions(+), 3 deletions(-) diff --git a/client-mu-plugins/goodbids/composer.json b/client-mu-plugins/goodbids/composer.json index e0d8eab9a..13d1dbfba 100644 --- a/client-mu-plugins/goodbids/composer.json +++ b/client-mu-plugins/goodbids/composer.json @@ -35,7 +35,10 @@ "repositories": [ { "type": "composer", - "url": "https://wpackagist.org" + "url": "https://wpackagist.org", + "only": [ + "wpackagist-plugin/*" + ] }, { "type":"composer", @@ -58,8 +61,10 @@ "vlucas/phpdotenv": "^5.5", "wpackagist-plugin/accessibility-checker": "^1.10", "wpackagist-plugin/delete-me": "^3.1", + "wpackagist-plugin/log-emails": "^1.4", "wpackagist-plugin/miniorange-oauth-20-server": "^6.0", "wpackagist-plugin/olympus-google-fonts": "^3.6", + "wpackagist-plugin/stop-emails": "^1.2", "wpackagist-plugin/svg-support": "^2.5", "wpackagist-plugin/tidio-live-chat": "^6.0", "wpackagist-plugin/top-bar": "^3.0", diff --git a/client-mu-plugins/goodbids/composer.lock b/client-mu-plugins/goodbids/composer.lock index bd55df5f5..7b0dd7b95 100644 --- a/client-mu-plugins/goodbids/composer.lock +++ b/client-mu-plugins/goodbids/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "73c7f35c06e441373a208dba119d7bb0", + "content-hash": "3e65cc061d5ca57061744e3c4d569101", "packages": [ { "name": "composer/installers", @@ -1265,6 +1265,24 @@ "type": "wordpress-plugin", "homepage": "https://wordpress.org/plugins/delete-me/" }, + { + "name": "wpackagist-plugin/log-emails", + "version": "1.4.0", + "source": { + "type": "svn", + "url": "https://plugins.svn.wordpress.org/log-emails/", + "reference": "tags/1.4.0" + }, + "dist": { + "type": "zip", + "url": "https://downloads.wordpress.org/plugin/log-emails.1.4.0.zip" + }, + "require": { + "composer/installers": "^1.0 || ^2.0" + }, + "type": "wordpress-plugin", + "homepage": "https://wordpress.org/plugins/log-emails/" + }, { "name": "wpackagist-plugin/miniorange-oauth-20-server", "version": "6.0.5", @@ -1301,6 +1319,24 @@ "type": "wordpress-plugin", "homepage": "https://wordpress.org/plugins/olympus-google-fonts/" }, + { + "name": "wpackagist-plugin/stop-emails", + "version": "1.2.1", + "source": { + "type": "svn", + "url": "https://plugins.svn.wordpress.org/stop-emails/", + "reference": "tags/1.2.1" + }, + "dist": { + "type": "zip", + "url": "https://downloads.wordpress.org/plugin/stop-emails.1.2.1.zip" + }, + "require": { + "composer/installers": "^1.0 || ^2.0" + }, + "type": "wordpress-plugin", + "homepage": "https://wordpress.org/plugins/stop-emails/" + }, { "name": "wpackagist-plugin/svg-support", "version": "2.5.5", diff --git a/client-mu-plugins/goodbids/src/classes/Core.php b/client-mu-plugins/goodbids/src/classes/Core.php index 200a1ca01..18d304f4f 100644 --- a/client-mu-plugins/goodbids/src/classes/Core.php +++ b/client-mu-plugins/goodbids/src/classes/Core.php @@ -314,7 +314,8 @@ private function load_config(): bool { if ( empty( $local['version'] ) || version_compare( $json['version'], $local['version'], '!=' ) ) { Log::warning( 'Local config file version mismatch.' ); } - $json = array_merge( $json, $local ); + + $json = $this->merge_local_config( $json, $local ); } } @@ -323,6 +324,36 @@ private function load_config(): bool { return true; } + /** + * Merge local json config with the base json config. + * + * @since 1.0.1 + * + * @param array $json + * @param array $local + * + * @return array + */ + private function merge_local_config( array $json, array $local ): array { + $merged = []; + + foreach ( $json as $key => $value ) { + $merged[ $key ] = $value; + + if ( empty( $local[ $key] ) ) { + continue; + } + + if ( is_array( $value ) ) { + $merged[ $key ] = array_merge( $value, $local[ $key ] ); + } else { + $merged[ $key ] = $local[ $key ]; + } + } + + return $merged; + } + /** * Get a config value. You can use dot notation to get nested values. * diff --git a/docs/local.md b/docs/local.md index 410ee2e68..6939c067c 100644 --- a/docs/local.md +++ b/docs/local.md @@ -98,3 +98,19 @@ Set your `phpcs` standard to point to `/Absolute/Path/To/goodbids/.phpcs.xml",` ## Local Config Override You can override the default local config by adding a `client-mu-plugins/goodbids/config.local.json` file. This will allow you to override specific settings without risk of committing to the repository. + +Here is a recommended starting point for your local config file: + +```json +{ + "version": "1.0", + "advanced": { + "debug-mode": true, + "logging": true + }, + "active-plugins": [ + "log-emails", + "stop-emails" + ] +} +```