diff --git a/client-mu-plugins/goodbids/src/classes/Core.php b/client-mu-plugins/goodbids/src/classes/Core.php index b6d176120..2528471f8 100644 --- a/client-mu-plugins/goodbids/src/classes/Core.php +++ b/client-mu-plugins/goodbids/src/classes/Core.php @@ -78,7 +78,7 @@ public function __construct() { * * @return Core */ - public static function get_instance() : Core { + public static function get_instance(): Core { if ( null === self::$instance ) { self::$instance = new self(); } @@ -93,7 +93,7 @@ public static function get_instance() : Core { * * @return string */ - public function get_version() : string { + public function get_version(): string { $data = get_plugin_data( GOODBIDS_PLUGIN_FILE ); return $data['Version']; } @@ -105,7 +105,7 @@ public function get_version() : string { * * @return void */ - public function init() : void { + public function init(): void { if ( ! $this->load_config() ) { // TODO: Log error. return; @@ -124,7 +124,7 @@ public function init() : void { * * @return bool */ - private function load_config() : bool { + private function load_config(): bool { $json_path = GOODBIDS_PLUGIN_PATH . 'config.json'; if ( ! file_exists( $json_path ) ) { return false; @@ -159,7 +159,7 @@ public function get_config( string $key ) : mixed { * * @return void */ - private function load_plugins() : void { + private function load_plugins(): void { if ( ! function_exists( 'wpcom_vip_load_plugin' ) ) { return; } @@ -184,7 +184,7 @@ private function load_plugins() : void { * * @return bool */ - public function is_plugin_active( string $plugin ) : bool { + public function is_plugin_active( string $plugin ): bool { $plugins = $this->get_config( 'active-plugins' ); return in_array( $plugin, $plugins, true ); } @@ -196,7 +196,7 @@ public function is_plugin_active( string $plugin ) : bool { * * @return void */ - private function load_modules() : void { + private function load_modules(): void { add_action( 'mu_plugin_loaded', function () { diff --git a/client-mu-plugins/goodbids/src/classes/network/Sites.php b/client-mu-plugins/goodbids/src/classes/network/Sites.php index c781bda4d..4532d00b4 100644 --- a/client-mu-plugins/goodbids/src/classes/network/Sites.php +++ b/client-mu-plugins/goodbids/src/classes/network/Sites.php @@ -41,6 +41,7 @@ public function __construct() { $this->save_edit_site_fields(); $this->new_site_form_fields(); $this->edit_site_form_fields(); + $this->activate_child_theme(); } /** @@ -50,7 +51,7 @@ public function __construct() { * * @return void */ - private function init_np_fields() : void { + private function init_np_fields(): void { $this->np_fields = apply_filters( 'goodbids_nonprofit_custom_fields', [ @@ -78,7 +79,7 @@ private function init_np_fields() : void { 'required' => true, 'context' => 'both', ], - 'status' => [ + 'status' => [ 'label' => __( 'Site Status', 'goodbids' ), 'type' => 'select', 'default' => 'pending', @@ -114,7 +115,7 @@ private function init_np_fields() : void { * * @return array */ - public function get_np_fields( string $context = 'both' ) : array { + public function get_np_fields( string $context = 'both' ): array { if ( empty( $this->np_fields ) ) { $this->init_np_fields(); } @@ -148,7 +149,7 @@ public function get_np_fields( string $context = 'both' ) : array { * * @return mixed */ - public function get_np_data( int $site_id, string $field_id = '' ) : mixed { + public function get_np_data( int $site_id, string $field_id = '' ): mixed { $data = []; foreach ( $this->get_np_fields() as $key => $field ) { @@ -176,7 +177,7 @@ public function get_np_data( int $site_id, string $field_id = '' ) : mixed { * * @return void */ - private function validate_new_site_fields() : void { + private function validate_new_site_fields(): void { add_action( 'admin_init', function () { @@ -236,7 +237,7 @@ function () { * * @return void */ - private function new_site_form_fields() : void { + private function new_site_form_fields(): void { add_action( 'network_site_new_form', function () { @@ -254,7 +255,7 @@ function () { * * @return void */ - private function edit_site_form_fields() : void { + private function edit_site_form_fields(): void { add_action( 'network_site_info_form', function ( $site_id ) { @@ -273,10 +274,9 @@ function ( $site_id ) { * * @return void */ - private function save_new_site_fields() : void { + private function save_new_site_fields(): void { add_action( 'wp_initialize_site', - /** * @param WP_Site $new_site New site object. * @param array $args Arguments for the initialization. @@ -311,10 +311,9 @@ function ( WP_Site $new_site, array $args ) { * * @return void */ - private function save_edit_site_fields() : void { + private function save_edit_site_fields(): void { add_action( 'wp_update_site', - /** * @param WP_Site $new_site New site object. * @param WP_Site $old_site Old site object. @@ -347,4 +346,33 @@ function ( WP_Site $new_site, WP_Site $old_site ) { 2 ); } + + /** + * Activate nonprofit child theme. + * + * @since 1.0.0 + * + * @param int $site_id Site ID. + * + * @return void + */ + private function activate_child_theme(): void { + add_action( + 'wpmu_new_blog', + function ( $site_id ) { + $stylesheet = 'goodbids-nonprofit'; + + // Switch to the new site + switch_to_blog( $site_id ); + + // Check if we the Goodbids child theme exists + if ( ! wp_get_theme( $stylesheet )->exists() ) { + return; + } + switch_theme( $stylesheet ); + + restore_current_blog(); + } + ); + } }