Skip to content
Open
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
108 changes: 108 additions & 0 deletions app/Console/Commands/WordpressInstall.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Str;

class WordpressInstall extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'wp:install {title?} {username?} {password?} {--email?}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Initiates the Wordpress database';

public $siteDetails = [
'title' => 'Enpress',
'email' => 'admin@example.com',
'username' => '',
'password' => ''
];

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Create a new command instance.
*
* @return void
*/
private function getInput() : void
{
$input = collect($this->input->getArguments())
->only([
'title',
'username',
'password',
'email'
]);

if (!isset($input['title']) || empty($input['title'])) {
$input['title'] = $this->ask('Website title:', 'Enpress');
}

if (!isset($input['username']) || empty($input['username'])) {
$input['username'] = $this->ask('Admin username:');
}

if (!isset($input['password']) || empty($input['password'])) {
$input['password'] = $this->secret('Admin password:');
}

// Any answers to missing data will override existing defaults
$this->siteDetails = $input->union($this->siteDetails);
}

private function validate() : void
{
$requiredDetails = collect($this->siteDetails)->keys();

foreach ($requiredDetails as $detail) {
if (empty($this->siteDetails[$detail])) {
$this->error(Str::title(str_replace('_', ' ', $detail)). ' must not be blank');
exit(1);
}
}
}

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$this->getInput();
$this->validate();

require_once(ABSPATH . 'wp-admin/includes/upgrade.php');

$response = wp_install(
$this->siteDetails['title'],
$this->siteDetails['username'],
$this->siteDetails['email'],
true,
'',
wp_slash( $this->siteDetails['password'] ),
'en_US'
);

return $response;
}
}
6 changes: 6 additions & 0 deletions artisan
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
|
*/

// If the wp:install command is run, indicate to Wordpress we're installing
// to prevent redirects
if (isset($argv[1]) && $argv[1] === 'wp:install') {
define('WP_INSTALLING', true);
}

require __DIR__. '/public/cms/wp-load.php';
$app = app();

Expand Down
13 changes: 13 additions & 0 deletions bootstrap/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@
$_SERVER['HTTPS'] = 'on';
}

/*
|--------------------------------------------------------------------------
| Wordpress non-HTTP request fix
|--------------------------------------------------------------------------
|
| Commands through artisan do not set this server header and Wordpress
| expects it to exist otherwise it crashes.
*/
if ($app->runningInConsole()) {
$_SERVER['SERVER_PROTOCOL'] = null;
$_SERVER['SERVER_NAME'] = 'localhost';
}

/*
|--------------------------------------------------------------------------
| Bind Important Interfaces
Expand Down