-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand.php
More file actions
43 lines (34 loc) · 1.44 KB
/
Copy pathcommand.php
File metadata and controls
43 lines (34 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
if ( ! class_exists( 'WP_CLI' ) ) {
return;
}
/**
* Installs WordPress with custom settings.
*/
class Install_Command {
/**
* Run the installation script.
*
* ## EXAMPLES
*
* wp install
*
* @when before_wp_load
*/
public function __invoke() {
$foldername = basename( getcwd() );
// Confirm with the user if they are sure about installing WordPress in the current directory
WP_CLI::confirm( "Are you sure you want to install WordPress in the directory '{$foldername}'?" );
WP_CLI::log( "Downloading WordPress core..." );
WP_CLI::runcommand( 'core download' );
WP_CLI::log( "Creating MySQL database 'wp_{$foldername}'..." );
$create_db_command = sprintf( 'mysql -u root -e "CREATE DATABASE wp_%s;"', $foldername );
shell_exec( $create_db_command );
WP_CLI::log( "Creating WordPress configuration file..." );
WP_CLI::runcommand( "config create --dbname=wp_{$foldername} --dbuser=root" );
WP_CLI::log( "Installing WordPress..." );
WP_CLI::runcommand( sprintf( "core install --url=http://%s.test --title=%s --admin_user=%s --admin_password=%s --admin_email=admin@%s.test", $foldername, $foldername, $foldername, $foldername, $foldername ) );
WP_CLI::success( "Installation complete. You can now open your site at http://{$foldername}.test" );
}
}
WP_CLI::add_command( 'install', 'Install_Command' );