Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#111] Installation Fixes #118

Merged
merged 6 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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