Powershell wp-cli
#version 0.1 | |
[CmdletBinding()] | |
Param( | |
[Parameter(Mandatory=$True)] | |
[string]$Database_Name, | |
[Parameter(Mandatory=$True)] | |
[string]$FullUrl | |
) | |
# wp core download | |
wp core config --dbuser=root --dbpass= --dbname=$Database_Name | |
wp db create | |
wp core install --url=$FullUrl --title=WP --admin_user=admin --admin_email=admin@admin.com --admin_password=admin | |
#install theme twentythirteen | |
wp theme install twentythirteen | |
wp theme activate twentythirteen | |
# delete default themes | |
wp theme delete twentyfifteen | |
wp theme delete twentysixteen | |
wp theme delete twentyseventeen | |
# delete akismet and hello dolly | |
wp plugin delete akismet | |
wp plugin delete hello | |
# set pretty urls ... doesnt works on windows | |
# wp rewrite structure '/%postname%/' --hard | |
# wp rewrite flush --hard | |
"`r`n`r`n****************** Enable debug ***************`r`n" | |
$debug_yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes" | |
$debug_no = New-Object System.Management.Automation.Host.ChoiceDescription "&No" | |
$debug_options = [System.Management.Automation.Host.ChoiceDescription[]]($debug_yes, $debug_no) | |
$debug_result = $host.ui.PromptForChoice("", "Do you want to enable debug?`r`n`r`n", $debug_options, 0) | |
switch ($debug_result) | |
{ | |
0 { | |
Add-Content ./wp-config.php "`r`n//Added by powershell START`r`ndefine( 'WP_DEBUG', true );`r`ndefine( 'WP_DEBUG_LOG', true ); `r`n//Added by powershell ends" | |
"Enabled debug on wp-config.php`r`n" | |
} | |
1 {"`r`n*** Not enabling debug. **** `r`n"} | |
} | |
"`r`n`r`n****************** Install WooCommerce ***************`r`n" | |
$wc_yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes" | |
$wc_no = New-Object System.Management.Automation.Host.ChoiceDescription "&No" | |
$wc_options = [System.Management.Automation.Host.ChoiceDescription[]]($wc_yes, $wc_no) | |
$wc_result = $host.ui.PromptForChoice("", "Do you want to install WooCommerce?`r`n`r`n", $wc_options, 1) | |
switch ($wc_result) | |
{ | |
0 { | |
wp plugin install woocommerce --activate | |
"Installed WooCommerce" | |
} | |
1 {"`r`n*** Not installing Woocommerce.***`r`n"} | |
} | |
"`r`n`r`n****************** Add to Hosts file ***************`r`n" | |
$hosts_yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes" | |
$hosts_no = New-Object System.Management.Automation.Host.ChoiceDescription "&No" | |
$hosts_options = [System.Management.Automation.Host.ChoiceDescription[]]($hosts_yes, $hosts_no) | |
$hosts_result = $host.ui.PromptForChoice("", "Do you want to update hosts file ?`r`n`r`n", $hosts_options, 1) | |
switch ($hosts_result) | |
{ | |
0 { | |
Add-Content C:\Windows\System32\drivers\etc\hosts "`r`n127.0.0.1 $FullUrl #Added by powershell" | |
"`r`n*** Updated hosts file ***" | |
} | |
1 { | |
"`r`n*** Not updating hosts file. ****`r`n`r`n`r`n" | |
} | |
} | |
# open browser with the new WP url | |
Start-Process "$FullUrl/wp-admin" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment