diff --git a/.wp-env.json b/.wp-env.json index ec27b80e..f0eaedd8 100644 --- a/.wp-env.json +++ b/.wp-env.json @@ -5,9 +5,11 @@ "plugins": [ "./plugin" ], - "phpVersion": "8.1", "mappings": { - "php.ini": "./bin/php.ini" + "./../.htaccess": "./htaccess.txt", + "lifecycleScripts": "./bin/lifecycleScripts/", + "wp-cli.yml": "./wp-cli.yml", + "required-plugins": "./required-plugins/" }, "env": { "development": { diff --git a/bin/lifecycleScripts/initialize.sh b/bin/lifecycleScripts/initialize.sh new file mode 100644 index 00000000..e331446d --- /dev/null +++ b/bin/lifecycleScripts/initialize.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +# This script is used to initialize the WordPress system. WP-CLI is available. +# We use it to install plugins, themes and set options as needed. + +# Check if WordPress is installed, if not, exit. +if ! $(wp core is-installed); then + echo "WordPress is not installed. Exiting." + exit 1 +fi + +# Check if this is a clean install, if not, exit. +# We check this by looking for a set option. If it's not set, it will throw an error. +if wp option get lh_is_installed; then + echo "This is not a clean install. Exiting." + exit 1 +fi + +# Set the option to indicate that this is a clean install. +wp option set lh_is_installed true + +# Set the permalink structure. +echo "----- Setting permalink structure." +wp rewrite structure '/%postname%/' --hard + +## Remove all plugins. +echo "----- Removing unwanted plugins." +wp plugin delete --all --exclude=plugin + +## Install plugins. +echo "----- Installing plugins." + +# From the WordPress plugin repository. +wp plugin install wordpress-seo wordpress-importer --activate + +# From a local file. +# wp plugin install ./required-plugins/advanced-custom-fields-pro.zip ./required-plugins/gravityforms.zip --activate + +# Activate the theme we want to use. +echo "----- Activating working theme." +wp theme activate theme + +## Import Demo Content. +echo "----- Importing demo content." + +wget https://raw.githubusercontent.com/WPTT/theme-unit-test/master/themeunittestdata.wordpress.xml +wp import themeunittestdata.wordpress.xml --authors=create diff --git a/bin/php.ini b/bin/php.ini deleted file mode 100644 index 7c5463d2..00000000 --- a/bin/php.ini +++ /dev/null @@ -1,3 +0,0 @@ -post_max_size = 512M -upload_max_filesize = 512M -memory_limit = 512M diff --git a/htaccess.txt b/htaccess.txt new file mode 100644 index 00000000..edbd94ec --- /dev/null +++ b/htaccess.txt @@ -0,0 +1,3 @@ +php_value post_max_size 2G +php_value upload_max_filesize 2G +php_value memory_limit 2G diff --git a/package.json b/package.json index b53d4e89..8ab8c310 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,8 @@ "stop": "npx wp-env stop", "watch": "webpack --watch", "env:clean": "npx wp-env clean all", + "env:init": "npx wp-env run cli sh ./lifecycleScripts/initialize.sh", + "env:reset": "npm run env:clean && npm run env:init", "update:schemas": "node bin/updateThemeJsonSchema.js", "update:versions": "node bin/updatePluginVersion.js && node bin/updateThemeVersion.js", "lint:php": "composer run lint", diff --git a/required-plugins/.gitkeep b/required-plugins/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/wp-cli.yml b/wp-cli.yml new file mode 100644 index 00000000..3cf7565b --- /dev/null +++ b/wp-cli.yml @@ -0,0 +1,2 @@ +apache_modules: + - mod_rewrite