Skip to content

Commit 0b324bb

Browse files
[#91] Adding admin user name to post install (#92)
* [#91] Adding admin user name to post install * [#91] Updating composer to set admin username
1 parent 2288d30 commit 0b324bb

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

README.dist.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ This is the README for your new site. Feel free to update any of this info to ma
1212
* [Docker](https://docs.docker.com/desktop/install/mac-install/) (or compatible container alternative like OrbStack)
1313
* For ACF Pro, create an `auth.json` file in `wp-content/mu-plugins/viget-base/` from the [ACF Website](https://www.advancedcustomfields.com/my-account/view-licenses/). (Credentials are in 1Password)
1414

15-
1615
## Setup and Running
1716
To start the local server and build process, run:
1817

bin/composer-scripts/ProjectEvents/PostInstallScript.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ class PostInstallScript extends ComposerScript {
2828
*/
2929
const IMPORT_DB_OPT = 2;
3030

31+
/**
32+
* Set Default Admin User
33+
*/
34+
const DEFAULT_ADMIN_USER = 'viget';
35+
3136
/**
3237
* @var array
3338
*/
@@ -284,9 +289,10 @@ private static function installWordPress(): void {
284289
self::getSiteInfo();
285290

286291
$command = sprintf(
287-
'wp core install --url=%s --title=%s --admin_user=viget --admin_email=%s --admin_password=%s',
292+
'wp core install --url=%s --title=%s --admin_user=%s --admin_email=%s --admin_password=%s',
288293
escapeshellarg( self::$info['url'] ),
289294
escapeshellarg( self::$info['title'] ),
295+
escapeshellarg( self::$info['username'] ),
290296
escapeshellarg( self::$info['email'] ),
291297
escapeshellarg( self::$info['password'] )
292298
);
@@ -315,16 +321,20 @@ public static function getSiteInfo(): void {
315321
$url = ! empty( self::$info['url'] ) ? self::$info['url'] : $defaultURL;
316322
self::$info['url'] = self::ask( 'What is the URL?*', $url );
317323

324+
// Admin Username.
325+
self::$info['username'] = self::$info['username'] ?? self::DEFAULT_ADMIN_USER;
326+
self::$info['username'] = self::ask( 'Set the admin username:*', self::$info['username'] );
327+
318328
// Admin Email.
319329
self::$info['email'] = self::$info['email'] ?? '[email protected]';
320330
self::$info['email'] = self::ask( 'What is the admin email address?*', self::$info['email'] );
321331

322332
// Admin Password.
323333
self::$info['password'] = self::$info['password'] ?? self::generatePassword();
324-
self::$info['password'] = self::ask( 'Set the Admin User (viget) password:*', self::$info['password'] );
334+
self::$info['password'] = self::ask( 'Set the Admin User password:*', self::$info['password'] );
325335

326336
// Check Required fields
327-
if ( empty( self::$info['title'] ) || empty( self::$info['url'] ) || empty( self::$info['email'] ) || empty( self::$info['password'] ) ) {
337+
if ( empty( self::$info['title'] ) || empty( self::$info['url'] ) || empty( self::$info['username'] ) || empty( self::$info['email'] ) || empty( self::$info['password'] ) ) {
328338
self::writeError( 'Please complete all required fields.' );
329339
self::getSiteInfo();
330340
}
@@ -333,6 +343,7 @@ public static function getSiteInfo(): void {
333343
$summary = PHP_EOL . ' - Site Title: ' . self::$info['title'];
334344
$summary .= PHP_EOL . ' - Site Description: ' . ( self::$info['description'] ?: '[none]' );
335345
$summary .= PHP_EOL . ' - URL: ' . self::$info['url'];
346+
$summary .= PHP_EOL . ' - Admin Username: ' . self::$info['username'];
336347
$summary .= PHP_EOL . ' - Admin Email: ' . self::$info['email'];
337348
$summary .= PHP_EOL . ' - Admin Password: ' . self::$info['password'];
338349

@@ -628,6 +639,7 @@ public static function renderSuccessMessage(): void {
628639
$success = [
629640
'Congratulations!',
630641
'Project has been set up successfully!',
642+
'Admin Username: ' . self::$info['username'],
631643
'<fg=#F26D20>Important!</> Make a note of the Admin Password:',
632644
'<fg=#F26D20>' . self::$info['password'] . '</>',
633645
];

0 commit comments

Comments
 (0)