Skip to content

Commit

Permalink
Plugin Installation/Activation, Initial Batch of Plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
bd-viget authored Dec 6, 2023
1 parent 94bfcb1 commit 0e014a9
Show file tree
Hide file tree
Showing 14 changed files with 351 additions and 50 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ node_modules
/plugins/two-factor/
/plugins/vaultpress/

# Loaded via Composer
/plugins/advanced-custom-fields-pro/
/plugins/cookie-law-info/
/plugins/pojo-accessibility/
/plugins/accessibility-checker/
/plugins/svg-support/
/plugins/user-switching/
/plugins/woocommerce/

# Uploads directory
/uploads/

Expand Down
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
2 changes: 1 addition & 1 deletion client-mu-plugins/goodbids/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
28 changes: 14 additions & 14 deletions client-mu-plugins/goodbids/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions client-mu-plugins/goodbids/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"version": "1.0",
"active-plugins": [
"advanced-custom-fields-pro/acf.php",
"woocommerce",
"accessibility-checker",
"svg-support",
"cookie-law-info",
"user-switching"
]
}
115 changes: 106 additions & 9 deletions client-mu-plugins/goodbids/src/classes/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,37 @@

namespace GoodBids;

use GoodBids\Plugins\ACF;

/**
* Core Class
*/
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 = [];

/**
* @since 1.0.0
* @var ACF
*/
public ACF $acf;

/**
* Constructor
*
Expand All @@ -36,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 {
Expand All @@ -50,28 +69,106 @@ 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;
}

/**
* 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 ); // phpcs:ignore

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.
*
* @since 1.0.0
*
* @return void
*/
private function load_plugins() {
private function load_plugins() : void {
if ( ! function_exists( 'wpcom_vip_load_plugin' ) ) {
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 );
}
}

/**
* 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 after GoodBids has initialized.
*
* @since 1.0.0
*
* @return void
*/
private function load_modules() : void {
add_action(
'mu_plugin_loaded',
function() {
$this->acf = new ACF();
}
);
}
}
Loading

0 comments on commit 0e014a9

Please sign in to comment.