Skip to content

Commit

Permalink
[#15] Activate Child theme (#60)
Browse files Browse the repository at this point in the history
* [#15] setting the child theme when a new site is created
* Readme update for phpcs
* [#15] updating PR format
  • Loading branch information
nathan-schmidt-viget committed Dec 13, 2023
1 parent b6ec436 commit 46923a0
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 20 deletions.
16 changes: 8 additions & 8 deletions client-mu-plugins/goodbids/src/classes/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,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();
}
Expand All @@ -100,7 +100,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'];
}
Expand All @@ -112,7 +112,7 @@ public function get_version() : string {
*
* @return void
*/
public function init() : void {
public function init(): void {
if ( ! $this->load_config() ) {
// TODO: Log error.
return;
Expand All @@ -132,7 +132,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;
Expand All @@ -156,7 +156,7 @@ private function load_config() : bool {
*
* @return mixed
*/
public function get_config( string $key ) : mixed {
public function get_config( string $key ): mixed {
return $this->config[ $key ] ?? null;
}

Expand All @@ -178,7 +178,7 @@ private function load_dependencies() : void {
*
* @return void
*/
private function load_plugins() : void {
private function load_plugins(): void {
if ( ! function_exists( 'wpcom_vip_load_plugin' ) ) {
return;
}
Expand All @@ -203,7 +203,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 );
}
Expand All @@ -215,7 +215,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 () {
Expand Down
52 changes: 40 additions & 12 deletions client-mu-plugins/goodbids/src/classes/network/Sites.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function __construct() {
$this->save_edit_site_fields();
$this->new_site_form_fields();
$this->edit_site_form_fields();
$this->activate_child_theme_on_new_site();
}

/**
Expand All @@ -51,7 +52,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',
[
Expand Down Expand Up @@ -79,7 +80,7 @@ private function init_np_fields() : void {
'required' => true,
'context' => 'both',
],
'status' => [
'status' => [
'label' => __( 'Site Status', 'goodbids' ),
'type' => 'select',
'default' => 'pending',
Expand Down Expand Up @@ -115,7 +116,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();
}
Expand Down Expand Up @@ -149,7 +150,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 ) {
Expand Down Expand Up @@ -177,7 +178,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 () {
Expand Down Expand Up @@ -237,7 +238,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 () {
Expand All @@ -255,7 +256,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 ) {
Expand All @@ -274,10 +275,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.
Expand Down Expand Up @@ -314,10 +314,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',

'wp_initialize_site',
/**
* @param WP_Site $new_site New site object.
* @param WP_Site $old_site Old site object.
Expand Down Expand Up @@ -366,5 +365,34 @@ private function init_site_defaults( int $site_id ) : void {
do_action( 'goodbids_init_site', $site_id );

restore_current_blog();

}

/**
* Activate nonprofit child theme.
*
* @since 1.0.0
*
* @return void
*/
private function activate_child_theme_on_new_site(): void {
add_action(
'wp_initialize_site',
function ( $site_id ) {
$stylesheet = 'goodbids-nonprofit';

// Switch to the new site
switch_to_blog( $site_id );

// Check if the Goodbids child theme exists
if ( ! wp_get_theme( $stylesheet )->exists() ) {
return;
}

switch_theme( $stylesheet );

restore_current_blog();
}
);
}
}
6 changes: 6 additions & 0 deletions docs/local.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,9 @@ In order to get IntelliSense to work you will need to do these steps:
1. You may need to reload your code editor once you have added both include paths.


## Code Standards
We are using `WordPress-VIP-Go` as the code standard. Follow the install instructions on [WP VIP](https://docs.wpvip.com/how-tos/php_codesniffer/) to set up `phpcs`.

Once that is all set up, copy the file `phpcs.xml.dist` in the goodbids repo and save it as `phpcs.xml`

Set your `phpcs` standard to point to `/Absolute/Path/To/goodbids/.phpcs.xml",`

0 comments on commit 46923a0

Please sign in to comment.