Skip to content

Commit

Permalink
[#111] Installation Fixes (#118)
Browse files Browse the repository at this point in the history
* [N/A] Fix a small bug in Gravatar fix

* [N/A] Fix issue where WordPress isn't installed on repo clone.

* [#111] Pre-populate Site info for fresh install

* [#111] Include ENV reading step

* [#111] Move VigetWP Composer Install to ddev post-start hook

* [#111] Added Composer version to VigetWP MU Plugin Composer File
  • Loading branch information
bd-viget authored Jul 1, 2024
1 parent db1d42d commit 83153f8
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 36 deletions.
1 change: 1 addition & 0 deletions .ddev/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ corepack_enable: false
override_config: true
hooks:
post-start:
- composer: install -d /var/www/html/wp-content/mu-plugins/viget-wp
- composer: install -d /var/www/html/wp-content/themes/wp-starter
- exec-host: ddev launch && exit
web_environment:
Expand Down
3 changes: 2 additions & 1 deletion bin/composer-scripts/ProjectEventHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use Composer\Script\Event;
use Viget\ComposerScripts\ProjectEvents\PostCreateProjectScript;
use Viget\ComposerScripts\ProjectEvents\PostInstallScript;

/**
* Handle Project Events
Expand All @@ -32,6 +33,6 @@ public static function postCreateProject( Event $event ): void {
* @return void
*/
public static function postInstall( Event $event ): void {
// Do nothing.
PostInstallScript::init( $event );
}
}
95 changes: 61 additions & 34 deletions bin/composer-scripts/ProjectEvents/PostInstallScript.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,44 +67,76 @@ class PostInstallScript extends ComposerScript {
];

/**
* Perform the actions within this file.
* Initialize the script.
*
* @param Event $event
* @param bool $fromExecute
*
* @return void
*/
public static function execute( Event $event ): void {
public static function init( Event $event, bool $fromExecute = false ): void {
self::setEvent( $event );

// Only run the rest of the script if we are in development mode.
if ( !$event->isDevMode() ) {
return;
}

// Load DDEV Environment variables.
self::loadDDEVEnvironmentVars();

self::wait();

if ( self::needsSetup() ) {

// Download WordPress
self::downloadWordPress();

self::wait( 2 );

// Populate the database.
self::populateDatabase();
if ( $fromExecute ) {
// Give database population options
self::populateDatabase();
} else {
// Pre-configure the Setup
self::$info = [
'title' => 'WordPress Site Starter',
'description' => 'A project developed by Viget.',
'url' => 'https://wpstarter.ddev.site',
'username' => 'viget',
'email' => '[email protected]',
];

// Do not activate Project Plugins
unset( self::$activatePlugins['seo-by-rank-math'] );
unset( self::$activatePlugins['wordfence'] );

// Automatically install WordPress
self::doFreshInstall();
}

// Remove the core Twenty-X themes.
self::deleteCoreThemes();

// Remove Hello Dolly.
self::deleteCorePlugins();

// Show the success message.
self::renderSuccessMessage();
}
}

/**
* Perform the actions within this file.
*
* @param Event $event
*
* @return void
*/
public static function execute( Event $event ): void {
self::setEvent( $event );

// Only run the rest of the script if we are in development mode.
if ( !$event->isDevMode() ) {
return;
}

// Run the Viget WP Composer Install
self::vigetWPComposerInstall();
// Initialize the script.
self::init( $event, true );
}

/**
Expand Down Expand Up @@ -263,6 +295,16 @@ private static function populateDatabase(): void {
return;
}

// Run a fresh WP Install
self::doFreshInstall();
}

/**
* Perform a fresh WordPress install.
*
* @return void
*/
private static function doFreshInstall(): void {
// Run the WordPress Installation
self::installWordPress();

Expand All @@ -289,9 +331,6 @@ private static function populateDatabase(): void {

// Configure plugins.
self::configurePlugins();

// Show the success message.
self::renderSuccessMessage();
}

/**
Expand Down Expand Up @@ -536,8 +575,13 @@ private static function activatePlugins(): void {
private static function configurePlugins(): void {
self::writeComment( 'Configuring plugins...' );

self::configureRankMath();
self::configureWordfence();
if( ! empty( self::$activatePlugins['seo-by-rank-math'] ) ) {
self::configureRankMath();
}

if( ! empty( self::$activatePlugins['wordfence'] ) ) {
self::configureWordfence();
}

self::writeInfo( 'Plugins configured.' );
}
Expand Down Expand Up @@ -662,21 +706,4 @@ public static function renderSuccessMessage(): void {

self::writeLine( $success );
}

/**
* Run the Viget WP Composer Installer.
*
* @return void
*/
private static function vigetWPComposerInstall(): void {
self::writeInfo( 'Running Viget WP Composer Install...' );

// Run composer install from the viget-wp directory
$directory = self::translatePath( './wp-content/mu-plugins/viget-wp' );
$cmd = 'composer install -d ' . escapeshellarg( $directory );

self::runCommand( $cmd );

self::writeInfo( 'VigetWP Composer Install complete.' );
}
}
1 change: 1 addition & 0 deletions wp-content/mu-plugins/viget-wp/composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "viget/viget-wp",
"version": "1.0.0",
"description": "WordPress Customization from Viget",
"type": "library",
"license": "GPL-3.0-or-later",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ private function avatar_fix(): void {
'pre_get_avatar_data',
function ( array $args, mixed $id_or_email ): array {
if ( is_numeric( $id_or_email ) ) {
$user = get_user_by( 'id', $id_or_email );
$user = get_user_by( 'id', $id_or_email );
if ( ! $user ) {
return $args;
}

$id_or_email = $user->user_email;
}

Expand Down

0 comments on commit 83153f8

Please sign in to comment.