From bda9b70f63c3b9adf6175d047bd8e503dc6130c3 Mon Sep 17 00:00:00 2001 From: Brian DiChiara Date: Tue, 5 Dec 2023 11:25:49 -0600 Subject: [PATCH 01/13] Gitignore composer plugins --- .gitignore | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.gitignore b/.gitignore index 3a946e5a8..3d400eea7 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,14 @@ node_modules /plugins/two-factor/ /plugins/vaultpress/ +# Loaded via Composer +/plugins/advanced-custom-fields-pro/ +/plugins/cookie-law-info/ +/plugins/pojo-accessibility/ +/plugins/svg-support/ +/plugins/user-switching/ +/plugins/woocommerce/ + # Uploads directory /uploads/ From 2adc4d643216383751815091e927cdf1de682b8d Mon Sep 17 00:00:00 2001 From: Brian DiChiara Date: Tue, 5 Dec 2023 11:33:46 -0600 Subject: [PATCH 02/13] Documentation for Plugin Installation --- README.md | 10 ++-------- docs/index.md | 29 ++++++++++++++++------------- themes/goodbids-nonprofit/style.css | 2 +- 3 files changed, 19 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index c49cdd25a..401731e58 100644 --- a/README.md +++ b/README.md @@ -62,12 +62,6 @@ See the [PHPCS documentation](https://github.com/squizlabs/PHP_CodeSniffer/wiki/ If you need help with anything, VIP's support team is [just a ticket away](https://wpvip.com/accessing-vip-support/). -## Your documentation here +## Additional Documentation -Feel free to add to or replace this README.md content with content unique to your project, for example: - -* Project-specific notes; like a list of VIP environments and branches, -* Workflow documentation; so everyone working in this repo can follow a defined process, or -* Instructions for testing new features. - -This can be detailed in the `docs/` directory. +More documentation can be found in [docs](docs/index.md). diff --git a/docs/index.md b/docs/index.md index 097821099..7012b5c33 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,20 +1,23 @@ -# Document Your Application Here +# GoodBids -VIP encourages you to document your application in Markdown. This is a great way of keeping your documentation up to date with what the application actually does. +## Getting Started -You can create new Markdown files in this `docs/` directory for each important part of your application. +- [Local installation Guide](local.md) +- [Git Workflow](workflow.md) -## Examples +## Installing Plugins -For example, you might have: -- `docs/local.md` that describes how to run your application locally -- `docs/REST.md` that describes any custom endpoints that your application has -- `docs/syndication.md` might describe how syndication works between subsites in your application -- `docs/build.md` describes what parts of your application gets built into the final deployable application -- `docs/qa.md` describes any manual or automated QA tests and processes that you have run on your application prior to deployment. -- etc. +We are using [Composer](https://getcomposer.org/) and [WPackagist](https://wpackagist.org/) to manage our plugins. To install a new plugin that exists in the WordPress Plugin Repository, run the following command: -## Benefits +```sh +composer require wpackagist-plugin/plugin-name +``` -Not only does this help you onboard your new engineers, it also helps VIP support staff to understand the moving parts or complexities of your application better at a glance, without having to dig into the code. +### Activating Plugins +Plugins can be activated in-code by using: +```php +wpcom_vip_load_plugin( 'plugin-name/plugin-file.php' ) +``` + +You can add to the list of active plugins in `client-mu-plugins/goodbids/src/classes/Core.php` diff --git a/themes/goodbids-nonprofit/style.css b/themes/goodbids-nonprofit/style.css index 14ebc197b..f70788178 100644 --- a/themes/goodbids-nonprofit/style.css +++ b/themes/goodbids-nonprofit/style.css @@ -3,7 +3,7 @@ Theme Name: GoodBids Non-profit Theme URI: https://goodbids.org Author: Viget Author URI: https://viget.com -Description: Twenty Twenty-Four child theme for GoodBids Charity sites. +Description: Twenty Twenty-Four child theme for GoodBids Non-profit sites. Version: 1.0 License: GNU General Public License v2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html From 245e69fe5e37b862addaffd700d9d8146a886231 Mon Sep 17 00:00:00 2001 From: Brian DiChiara Date: Wed, 6 Dec 2023 08:50:57 -0600 Subject: [PATCH 03/13] Config based plugin loading --- client-mu-plugins/goodbids/config.json | 11 ++++ .../goodbids/src/classes/Core.php | 66 +++++++++++++++++-- docs/index.md | 22 ++----- docs/plugins/activating.md | 23 +++++++ docs/plugins/index.md | 4 ++ docs/plugins/installing.md | 7 ++ 6 files changed, 109 insertions(+), 24 deletions(-) create mode 100644 client-mu-plugins/goodbids/config.json create mode 100644 docs/plugins/activating.md create mode 100644 docs/plugins/index.md create mode 100644 docs/plugins/installing.md diff --git a/client-mu-plugins/goodbids/config.json b/client-mu-plugins/goodbids/config.json new file mode 100644 index 000000000..95ee27790 --- /dev/null +++ b/client-mu-plugins/goodbids/config.json @@ -0,0 +1,11 @@ +{ + "version": "1.0", + "active-plugins": [ + "advanced-custom-fields-pro/acf.php", + "woocommerce", + "pojo-accessibility", + "svg-support", + "cookie-law-info", + "user-switching" + ] +} diff --git a/client-mu-plugins/goodbids/src/classes/Core.php b/client-mu-plugins/goodbids/src/classes/Core.php index 15da331b9..2abd31e8b 100644 --- a/client-mu-plugins/goodbids/src/classes/Core.php +++ b/client-mu-plugins/goodbids/src/classes/Core.php @@ -15,12 +15,22 @@ class Core { /** * @since 1.0.0 - * @var Core|null $instance + * @var Core|null */ private static ?Core $instance = null; + /** + * @since 1.0.0 + * @var bool + */ private bool $initialized = false; + /** + * @since 1.0.0 + * @var array + */ + private array $config = []; + /** * Constructor * @@ -52,11 +62,50 @@ public static function get_instance() : Core { * @since 1.0.0 */ public function init() { + if ( ! $this->load_config() ) { + // TODO: Log error. + return; + } + $this->load_plugins(); $this->initialized = true; } + /** + * Sets the Plugin Config. + * + * @since 1.0.0 + * @return bool + */ + private function load_config() { + $json_path = GOODBIDS_PLUGIN_PATH . 'config.json'; + if ( ! file_exists( $json_path ) ) { + return false; + } + + $json = json_decode( file_get_contents( $json_path ), true ); + + if ( ! is_array( $json ) ) { + return false; + } + + $this->config = $json; + + return true; + } + + /** + * Get a config value. + * + * @param string $key Config Key. + * + * @return mixed|null + */ + public function get_config( string $key ) { + return $this->config[ $key ] ?? null; + } + /** * Load 3rd Party Plugins. * @@ -67,11 +116,14 @@ private function load_plugins() { return; } - wpcom_vip_load_plugin( 'advanced-custom-fields-pro/acf.php' ); - wpcom_vip_load_plugin( 'woocommerce' ); - wpcom_vip_load_plugin( 'pojo-accessibility' ); - wpcom_vip_load_plugin( 'svg-support' ); - wpcom_vip_load_plugin( 'cookie-law-info' ); - wpcom_vip_load_plugin( 'user-switching' ); + $plugins = $this->get_config( 'active-plugins' ); + + if ( empty( $plugins ) || ! is_array( $plugins ) ) { + return; + } + + foreach ( $plugins as $plugin ) { + wpcom_vip_load_plugin( $plugin ); + } } } diff --git a/docs/index.md b/docs/index.md index 7012b5c33..15f58b2da 100644 --- a/docs/index.md +++ b/docs/index.md @@ -2,22 +2,10 @@ ## Getting Started -- [Local installation Guide](local.md) -- [Git Workflow](workflow.md) +* [Local installation Guide](local.md) +* [Git Workflow](workflow.md) -## Installing Plugins +## Plugins -We are using [Composer](https://getcomposer.org/) and [WPackagist](https://wpackagist.org/) to manage our plugins. To install a new plugin that exists in the WordPress Plugin Repository, run the following command: - -```sh -composer require wpackagist-plugin/plugin-name -``` - -### Activating Plugins - -Plugins can be activated in-code by using: -```php -wpcom_vip_load_plugin( 'plugin-name/plugin-file.php' ) -``` - -You can add to the list of active plugins in `client-mu-plugins/goodbids/src/classes/Core.php` +* [Installing Plugins](plugins/installing.md) +* [Activating Plugins](plugins/activating.md) diff --git a/docs/plugins/activating.md b/docs/plugins/activating.md new file mode 100644 index 000000000..888526c11 --- /dev/null +++ b/docs/plugins/activating.md @@ -0,0 +1,23 @@ +# Activating Plugins + +## Global Plugins + +Global plugins to be used on all sites can be activated by adding the plugin slug to the `active-plugins` array in the GoodBids MU Plugin `config.json` file. + +If the plugin slug does not match the plugin filename (e.g. `woocommerce/woocommerce.php`), you need to specify the both the slug and plugin filename. (Example: `advanced-custom-fields-pro/acf.php`) + +```json +{ + "active-plugins": [ + "woocommerce", + "advanced-custom-fields-pro/acf.php" + ] +} +``` + +## Site Specific Plugins + +Conditional Plugins can be activated in-code by using: +```php +wpcom_vip_load_plugin( 'plugin-name/plugin-file.php' ) +``` diff --git a/docs/plugins/index.md b/docs/plugins/index.md new file mode 100644 index 000000000..117251072 --- /dev/null +++ b/docs/plugins/index.md @@ -0,0 +1,4 @@ +# Plugins + +* [Installing Plugins](plugins/installing.md) +* [Activating Plugins](plugins/activating.md) diff --git a/docs/plugins/installing.md b/docs/plugins/installing.md new file mode 100644 index 000000000..43f75b626 --- /dev/null +++ b/docs/plugins/installing.md @@ -0,0 +1,7 @@ +## Installing Plugins + +We are using [Composer](https://getcomposer.org/) and [WPackagist](https://wpackagist.org/) to manage our plugins. To install a new plugin that exists in the WordPress Plugin Repository, run the following command: + +```sh +composer require wpackagist-plugin/plugin-name +``` From 74b1843bdffcdb108ec423300b1694e03ef9f34e Mon Sep 17 00:00:00 2001 From: Brian DiChiara Date: Wed, 6 Dec 2023 09:49:05 -0600 Subject: [PATCH 04/13] VIP Updates --- client-mu-plugins/goodbids/src/classes/Core.php | 2 +- composer.json | 2 +- docs/local.md | 6 ++++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/client-mu-plugins/goodbids/src/classes/Core.php b/client-mu-plugins/goodbids/src/classes/Core.php index 2abd31e8b..de101ebae 100644 --- a/client-mu-plugins/goodbids/src/classes/Core.php +++ b/client-mu-plugins/goodbids/src/classes/Core.php @@ -84,7 +84,7 @@ private function load_config() { return false; } - $json = json_decode( file_get_contents( $json_path ), true ); + $json = json_decode( wpcom_vip_file_get_contents( $json_path ), true ); if ( ! is_array( $json ) ) { return false; diff --git a/composer.json b/composer.json index fd4f89af5..9c037a935 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "homepage": "https://github.com/automattic/vip-go-skeleton", "license": "GPL-2.0-or-later", "require": { - "php": ">=8.0" + "php": ">=8.1" }, "require-dev": { "automattic/vipwpcs": "^3", diff --git a/docs/local.md b/docs/local.md index a0b638018..cc6831fe6 100644 --- a/docs/local.md +++ b/docs/local.md @@ -29,6 +29,12 @@ vip dev-env --slug=goodbids start vip dev-env --slug=goodbids stop ``` +### Install Dependencies + +Run `composer install` in the following directories: +1. `root`: Run at project root. +2. `client-mu-plugins/goodbids`: GoodBids MU Plugin + ## Local Environment URL [http://goodbids.vipdev.lndo.site/](http://goodbids.vipdev.lndo.site/) From 34f588e1e7c2a47c78f21136153736ee7bcd6c6a Mon Sep 17 00:00:00 2001 From: Brian DiChiara Date: Wed, 6 Dec 2023 09:53:26 -0600 Subject: [PATCH 05/13] ACF Pro auth.json instructions --- docs/local.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/local.md b/docs/local.md index cc6831fe6..33eb93dbd 100644 --- a/docs/local.md +++ b/docs/local.md @@ -31,7 +31,9 @@ vip dev-env --slug=goodbids stop ### Install Dependencies -Run `composer install` in the following directories: +For ACF Pro, copy `auth.json.dist` to `auth.json` in `client-mu-plugins/goodbids` and use config from [ACF's Website](https://www.advancedcustomfields.com/my-account/view-licenses/). (Credentials are in 1Password) + +Then, run `composer install` in the following directories: 1. `root`: Run at project root. 2. `client-mu-plugins/goodbids`: GoodBids MU Plugin From 7bad4d7ba01a7bc2c9a6f36506d5863f61acd1d5 Mon Sep 17 00:00:00 2001 From: Brian DiChiara Date: Wed, 6 Dec 2023 11:17:11 -0600 Subject: [PATCH 06/13] Fix config loader --- client-mu-plugins/goodbids/src/classes/Core.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client-mu-plugins/goodbids/src/classes/Core.php b/client-mu-plugins/goodbids/src/classes/Core.php index de101ebae..f57abd407 100644 --- a/client-mu-plugins/goodbids/src/classes/Core.php +++ b/client-mu-plugins/goodbids/src/classes/Core.php @@ -84,7 +84,7 @@ private function load_config() { return false; } - $json = json_decode( wpcom_vip_file_get_contents( $json_path ), true ); + $json = json_decode( file_get_contents( $json_path ), true ); // phpcs:ignore if ( ! is_array( $json ) ) { return false; From e1aa0761fc28e425248ad2a4f841cc5ff84e839b Mon Sep 17 00:00:00 2001 From: Brian DiChiara Date: Wed, 6 Dec 2023 11:20:20 -0600 Subject: [PATCH 07/13] Gitignore doc step --- docs/plugins/installing.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/plugins/installing.md b/docs/plugins/installing.md index 43f75b626..db25a33d0 100644 --- a/docs/plugins/installing.md +++ b/docs/plugins/installing.md @@ -5,3 +5,5 @@ We are using [Composer](https://getcomposer.org/) and [WPackagist](https://wpack ```sh composer require wpackagist-plugin/plugin-name ``` + +Once added to composer, update the main `.gitignore` file to exclude the plugin from version control. From 4f6299915be2b545839cc9800baa0a55735b317e Mon Sep 17 00:00:00 2001 From: Brian DiChiara Date: Wed, 6 Dec 2023 11:55:15 -0600 Subject: [PATCH 08/13] Add ACF Module --- .../goodbids/src/classes/Core.php | 44 +++++++++++++++++- .../goodbids/src/classes/plugins/ACF.php | 46 +++++++++++++++++++ 2 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 client-mu-plugins/goodbids/src/classes/plugins/ACF.php diff --git a/client-mu-plugins/goodbids/src/classes/Core.php b/client-mu-plugins/goodbids/src/classes/Core.php index f57abd407..f65bfc2f6 100644 --- a/client-mu-plugins/goodbids/src/classes/Core.php +++ b/client-mu-plugins/goodbids/src/classes/Core.php @@ -8,6 +8,8 @@ namespace GoodBids; +use GoodBids\Plugins\ACF; + /** * Core Class */ @@ -31,6 +33,12 @@ class Core { */ private array $config = []; + /** + * @since 1.0.0 + * @var ACF + */ + public ACF $acf; + /** * Constructor * @@ -46,6 +54,7 @@ public function __construct() { * Get the singleton instance of this class * * @since 1.0.0 + * * @return Core */ public static function get_instance() : Core { @@ -60,14 +69,17 @@ public static function get_instance() : Core { * Initialize the plugin * * @since 1.0.0 + * + * @return void */ - public function init() { + public function init() : void { if ( ! $this->load_config() ) { // TODO: Log error. return; } $this->load_plugins(); + $this->load_modules(); $this->initialized = true; } @@ -76,6 +88,7 @@ public function init() { * Sets the Plugin Config. * * @since 1.0.0 + * * @return bool */ private function load_config() { @@ -110,8 +123,10 @@ public function get_config( string $key ) { * Load 3rd Party Plugins. * * @since 1.0.0 + * + * @return void */ - private function load_plugins() { + private function load_plugins() : void { if ( ! function_exists( 'wpcom_vip_load_plugin' ) ) { return; } @@ -126,4 +141,29 @@ private function load_plugins() { wpcom_vip_load_plugin( $plugin ); } } + + /** + * Check if a plugin is in the active plugins list. + * + * @since 1.0.0 + * + * @param string $plugin + * + * @return bool + */ + public function is_plugin_active( string $plugin ) : bool { + $plugins = $this->get_config( 'active-plugins' ); + return in_array( $plugin, $plugins, true ); + } + + /** + * Initialize Modules + * + * @since 1.0.0 + * + * @return void + */ + private function load_modules() : void { + $this->acf = new ACF(); + } } diff --git a/client-mu-plugins/goodbids/src/classes/plugins/ACF.php b/client-mu-plugins/goodbids/src/classes/plugins/ACF.php new file mode 100644 index 000000000..e2904624a --- /dev/null +++ b/client-mu-plugins/goodbids/src/classes/plugins/ACF.php @@ -0,0 +1,46 @@ +is_plugin_active( $this->slug ) ) { + return; + } + + $this->disble_acf_admin(); + } + + /** + * Disable ACF Admin per WP VIP Documentation + * + * @link https://docs.wpvip.com/technical-references/plugin-incompatibilities/#acf + * + * @since 1.0.0 + */ + private function disble_acf_admin() { + add_filter( 'acf/settings/show_admin', '__return_false' ); + } +} From 8ed734a208902620c689772b245222e38d2eca8c Mon Sep 17 00:00:00 2001 From: Brian DiChiara Date: Wed, 6 Dec 2023 12:47:40 -0600 Subject: [PATCH 09/13] Swap accessibility plugins --- .gitignore | 1 + client-mu-plugins/goodbids/composer.json | 2 +- client-mu-plugins/goodbids/composer.lock | 28 ++++++++++++------------ client-mu-plugins/goodbids/config.json | 2 +- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 3d400eea7..66ad3f863 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,7 @@ node_modules /plugins/advanced-custom-fields-pro/ /plugins/cookie-law-info/ /plugins/pojo-accessibility/ +/plugins/accessibility-checker/ /plugins/svg-support/ /plugins/user-switching/ /plugins/woocommerce/ diff --git a/client-mu-plugins/goodbids/composer.json b/client-mu-plugins/goodbids/composer.json index 707063f35..4ad5479bc 100644 --- a/client-mu-plugins/goodbids/composer.json +++ b/client-mu-plugins/goodbids/composer.json @@ -50,8 +50,8 @@ "cweagans/composer-patches": "^1.7", "oomphinc/composer-installers-extender": "^2.0", "vlucas/phpdotenv": "^5.5", + "wpackagist-plugin/accessibility-checker": "^1.6", "wpackagist-plugin/cookie-law-info": "^3.1", - "wpackagist-plugin/pojo-accessibility": "^2.1", "wpackagist-plugin/svg-support": "^2.5", "wpackagist-plugin/user-switching": "^1.7", "wpackagist-plugin/woocommerce": "^8.3", diff --git a/client-mu-plugins/goodbids/composer.lock b/client-mu-plugins/goodbids/composer.lock index 8ffbb79e0..dfc0fb4e9 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": "43b6b0a2c0e7284e4a1dbacfcd4f9ac1", + "content-hash": "436a15832d1f2bbca2839e99d5f15a0c", "packages": [ { "name": "composer/installers", @@ -726,40 +726,40 @@ "time": "2023-11-12T22:43:29+00:00" }, { - "name": "wpackagist-plugin/cookie-law-info", - "version": "3.1.7", + "name": "wpackagist-plugin/accessibility-checker", + "version": "1.6.10", "source": { "type": "svn", - "url": "https://plugins.svn.wordpress.org/cookie-law-info/", - "reference": "tags/3.1.7" + "url": "https://plugins.svn.wordpress.org/accessibility-checker/", + "reference": "tags/1.6.10" }, "dist": { "type": "zip", - "url": "https://downloads.wordpress.org/plugin/cookie-law-info.3.1.7.zip" + "url": "https://downloads.wordpress.org/plugin/accessibility-checker.1.6.10.zip" }, "require": { "composer/installers": "^1.0 || ^2.0" }, "type": "wordpress-plugin", - "homepage": "https://wordpress.org/plugins/cookie-law-info/" + "homepage": "https://wordpress.org/plugins/accessibility-checker/" }, { - "name": "wpackagist-plugin/pojo-accessibility", - "version": "2.1.0", + "name": "wpackagist-plugin/cookie-law-info", + "version": "3.1.7", "source": { "type": "svn", - "url": "https://plugins.svn.wordpress.org/pojo-accessibility/", - "reference": "tags/2.1.0" + "url": "https://plugins.svn.wordpress.org/cookie-law-info/", + "reference": "tags/3.1.7" }, "dist": { "type": "zip", - "url": "https://downloads.wordpress.org/plugin/pojo-accessibility.2.1.0.zip" + "url": "https://downloads.wordpress.org/plugin/cookie-law-info.3.1.7.zip" }, "require": { "composer/installers": "^1.0 || ^2.0" }, "type": "wordpress-plugin", - "homepage": "https://wordpress.org/plugins/pojo-accessibility/" + "homepage": "https://wordpress.org/plugins/cookie-law-info/" }, { "name": "wpackagist-plugin/svg-support", @@ -1195,5 +1195,5 @@ "ext-mbstring": "*" }, "platform-dev": [], - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } diff --git a/client-mu-plugins/goodbids/config.json b/client-mu-plugins/goodbids/config.json index 95ee27790..2af1c522c 100644 --- a/client-mu-plugins/goodbids/config.json +++ b/client-mu-plugins/goodbids/config.json @@ -3,7 +3,7 @@ "active-plugins": [ "advanced-custom-fields-pro/acf.php", "woocommerce", - "pojo-accessibility", + "accessibility-checker", "svg-support", "cookie-law-info", "user-switching" From 933e3f151824c10f176f2969b9cfe65bdf6fefbc Mon Sep 17 00:00:00 2001 From: Brian DiChiara Date: Wed, 6 Dec 2023 12:47:50 -0600 Subject: [PATCH 10/13] ACF VIP Requirements --- .../goodbids/src/classes/Core.php | 9 +- .../goodbids/src/classes/plugins/ACF.php | 93 ++++++++++++++++++- 2 files changed, 98 insertions(+), 4 deletions(-) diff --git a/client-mu-plugins/goodbids/src/classes/Core.php b/client-mu-plugins/goodbids/src/classes/Core.php index f65bfc2f6..7ae390ea4 100644 --- a/client-mu-plugins/goodbids/src/classes/Core.php +++ b/client-mu-plugins/goodbids/src/classes/Core.php @@ -157,13 +157,18 @@ public function is_plugin_active( string $plugin ) : bool { } /** - * Initialize Modules + * Initialize Modules after GoodBids has initialized. * * @since 1.0.0 * * @return void */ private function load_modules() : void { - $this->acf = new ACF(); + add_action( + 'mu_plugin_loaded', + function() { + $this->acf = new ACF(); + } + ); } } diff --git a/client-mu-plugins/goodbids/src/classes/plugins/ACF.php b/client-mu-plugins/goodbids/src/classes/plugins/ACF.php index e2904624a..b027064f1 100644 --- a/client-mu-plugins/goodbids/src/classes/plugins/ACF.php +++ b/client-mu-plugins/goodbids/src/classes/plugins/ACF.php @@ -30,7 +30,10 @@ public function __construct() { return; } - $this->disble_acf_admin(); + $this->disable_admin(); + $this->discourage_the_field_usage(); + $this->modify_save_directory(); + $this->disable_database_storage(); } /** @@ -39,8 +42,94 @@ public function __construct() { * @link https://docs.wpvip.com/technical-references/plugin-incompatibilities/#acf * * @since 1.0.0 + * + * @return void */ - private function disble_acf_admin() { + private function disable_admin() : void { + if ( defined( 'VIP_GO_APP_ENVIRONMENT' ) && 'local' === VIP_GO_APP_ENVIRONMENT ) { + return; + } + add_filter( 'acf/settings/show_admin', '__return_false' ); } + + /** + * Save ACF JSON to the plugin directory + * + * @since 1.0.0 + * + * @return void + */ + private function modify_save_directory() : void { + add_filter( + 'acf/settings/save_json', + function() { + return GOODBIDS_PLUGIN_PATH; + } + ); + } + + /** + * Disable database setting storage + * + * @since 1.0.0 + * + * @return void + */ + private function disable_database_storage() : void { + add_filter( + 'acf/prepare_field_group_for_export', + function( array $group ) : array { + $group['private'] = true; + return $group; + } + ); + } + + /** + * Throw a warning if the_field is used during local development. + * + * @since 1.0.0 + * + * @return void + */ + private function discourage_the_field_usage() : void { + if ( ! defined( 'VIP_GO_APP_ENVIRONMENT' ) || 'local' !== VIP_GO_APP_ENVIRONMENT ) { + return; + } + + add_filter( + 'acf/pre_load_value', + function( $preload ) { + if ( $this->called_from_the_field() ) { + _doing_it_wrong( 'the_field', 'the_field() should not be used. Use get_field() instead.', '1.0.0' ); + } + + return $preload; + } + ); + } + + /** + * Check if the_field exists in the stack trace + * + * @since 1.0.0 + * + * @return bool + */ + private function called_from_the_field() : bool { + // Create an exception + $ex = new \Exception(); + + // Call getTrace function + $trace = $ex->getTrace(); + + foreach ( $trace as $item ) { + if ( ! empty( $item['function'] ) && 'the_field' === $item['function'] ) { + return true; + } + } + + return false; + } } From 980a59293bb685ffd8d69439b46fdac215946851 Mon Sep 17 00:00:00 2001 From: Brian DiChiara Date: Wed, 6 Dec 2023 12:58:50 -0600 Subject: [PATCH 11/13] Load JSON from GoodBids MU Plugin --- client-mu-plugins/goodbids/src/classes/plugins/ACF.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/client-mu-plugins/goodbids/src/classes/plugins/ACF.php b/client-mu-plugins/goodbids/src/classes/plugins/ACF.php index b027064f1..385e1a494 100644 --- a/client-mu-plugins/goodbids/src/classes/plugins/ACF.php +++ b/client-mu-plugins/goodbids/src/classes/plugins/ACF.php @@ -67,6 +67,14 @@ function() { return GOODBIDS_PLUGIN_PATH; } ); + + add_filter( + 'acf/settings/load_json', + function( array $paths ) { + $paths[] = GOODBIDS_PLUGIN_PATH; + return $paths; + } + ); } /** From 69d2a0b5815509b76724c763e8c31997fbc2c04b Mon Sep 17 00:00:00 2001 From: Brian DiChiara Date: Wed, 6 Dec 2023 13:00:48 -0600 Subject: [PATCH 12/13] Added note about error logs --- docs/local.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/local.md b/docs/local.md index 33eb93dbd..467ca00c0 100644 --- a/docs/local.md +++ b/docs/local.md @@ -41,3 +41,10 @@ Then, run `composer install` in the following directories: [http://goodbids.vipdev.lndo.site/](http://goodbids.vipdev.lndo.site/) +## Error Logs + +Run the following command to [watch the logs](https://docs.wpvip.com/technical-references/vip-local-development-environment/#h-php): + +```sh +vip dev-env logs --service=php --follow --slug=goodbids +``` From f3fae9f15c2b41eb5dbff4c8109ac4a9d7472c3b Mon Sep 17 00:00:00 2001 From: Brian DiChiara Date: Wed, 6 Dec 2023 13:13:08 -0600 Subject: [PATCH 13/13] Fix for child theme usage --- .../goodbids/src/classes/plugins/ACF.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/client-mu-plugins/goodbids/src/classes/plugins/ACF.php b/client-mu-plugins/goodbids/src/classes/plugins/ACF.php index 385e1a494..478f37327 100644 --- a/client-mu-plugins/goodbids/src/classes/plugins/ACF.php +++ b/client-mu-plugins/goodbids/src/classes/plugins/ACF.php @@ -54,7 +54,8 @@ private function disable_admin() : void { } /** - * Save ACF JSON to the plugin directory + * Save ACF JSON to the plugin directory, but only when developing locally. + * We don't want to break this feature if the non-profit is using ACF. * * @since 1.0.0 * @@ -63,8 +64,12 @@ private function disable_admin() : void { private function modify_save_directory() : void { add_filter( 'acf/settings/save_json', - function() { - return GOODBIDS_PLUGIN_PATH; + function( $path ) { + if ( defined( 'VIP_GO_APP_ENVIRONMENT' ) && 'local' === VIP_GO_APP_ENVIRONMENT ) { + return GOODBIDS_PLUGIN_PATH; + } + + return $path; } );