diff --git a/environments/README.md b/environments/README.md index 020dd05e94..63e97faa5b 100644 --- a/environments/README.md +++ b/environments/README.md @@ -118,6 +118,44 @@ npm run translate:env -- run cli -- wp **Local overrides:** create `translate/.wp-env.override.json` (git-ignored) to override config values like `WP_HOME` / `WP_SITEURL` for testing behind a custom hostname. +### Support Forums + +A local instance of the WordPress.org Support Forums with bbPress, the support theme, and supporting plugins. + +**Start:** + +```bash +npm run support:env start +``` + +First start automatically sets up a multisite network, creates sub-sites for Plugins (`/plugins`) and Themes (`/themes`), and provisions the default user accounts. + +**Note that these plugin and theme directories are only used for forum references, not for development of the respective environments.** + +**Access:** `http://localhost:8888` + +**WP CLI:** + +```bash +npm run support:env -- run cli -- wp +``` + +**User accounts:** + +All accounts use the password `password`. + +| Username | Forum role | Notes | +|---|---|---| +| `admin` | Network administrator | Full network admin access | +| `keymaster` | `bbp_keymaster` | Top-level forum admin; can manage all forum content | +| `moderator` | `bbp_moderator` | Can moderate topics and replies | +| `pluginauthor` | `bbp_participant` | Subscriber on the Plugins sub-site | +| `plugincontributor` | `bbp_participant` | Subscriber on the Plugins sub-site | +| `pluginsupport` | `bbp_participant` | Plugin support rep; subscriber on the Plugins sub-site | +| `themeauthor` | `bbp_participant` | Subscriber on the Themes sub-site | +| `themesupport` | `bbp_participant` | Theme support rep; subscriber on the Themes sub-site (unused) | +| `visitor` | `bbp_participant` | Regular site visitor | + ### Handbook (in-plugin) The Handbook plugin has its own `.wp-env.json` in `wordpress.org/public_html/wp-content/plugins/handbook/`. diff --git a/environments/package.json b/environments/package.json index 8deccf4440..701a46e3ab 100644 --- a/environments/package.json +++ b/environments/package.json @@ -15,7 +15,8 @@ "browsehappy:env": "wp-env --config browsehappy/.wp-env.json", "translate:env": "wp-env --config translate/.wp-env.json", "translate:import": "npm run translate:env -- run cli -- wp eval-file wp-content/env-bin/import-from-wporg.php", - "translate:refresh": "npm run translate:env -- run cli -- wp option delete wporg_translate_env_seeded" + "translate:refresh": "npm run translate:env -- run cli -- wp option delete wporg_translate_env_seeded", + "support:env": "wp-env --config support-forums/.wp-env.json" }, "devDependencies": { "@wordpress/env": "^11" diff --git a/environments/support-forums/.wp-env.json b/environments/support-forums/.wp-env.json new file mode 100644 index 0000000000..b4e1797d41 --- /dev/null +++ b/environments/support-forums/.wp-env.json @@ -0,0 +1,47 @@ +{ + "core": "WordPress/WordPress#master", + "phpVersion": "8.4", + "testsEnvironment": false, + "plugins": [ + "https://downloads.wordpress.org/plugin/bbpress.zip", + "https://downloads.wordpress.org/plugin/gutenberg.17.9.0.zip", + "https://downloads.wordpress.org/plugin/blocks-everywhere.zip", + "../wordpress.org/public_html/wp-content/plugins/wporg-bbp-user-moderation", + "../wordpress.org/public_html/wp-content/plugins/wporg-bbp-user-mention-autocomplete", + "../wordpress.org/public_html/wp-content/plugins/wporg-bbp-user-badges", + "../wordpress.org/public_html/wp-content/plugins/wporg-bbp-topic-resolution", + "../wordpress.org/public_html/wp-content/plugins/wporg-bbp-topic-archive", + "../wordpress.org/public_html/wp-content/plugins/wporg-bbp-term-subscription", + "../wordpress.org/public_html/wp-content/plugins/wporg-bbp-redirect", + "../wordpress.org/public_html/wp-content/plugins/wporg-bbp-codexify", + "../wordpress.org/public_html/wp-content/plugins/wporg-bbp-code-blocks-expand-contract", + "../wordpress.org/public_html/wp-content/plugins/support-forums" + ], + "themes": [ + "../wordpress.org/public_html/wp-content/themes/pub/wporg-support-2024", + "WordPress/wporg-parent-2021#build" + ], + "mappings": { + ".htaccess": "./support-forums/bin/.htaccess", + "wp-content/wporg/style": "../wordpress.org/public_html/style", + "wp-content/mu-plugins": "./mocks/mu-plugins", + "wp-content/mu-plugins/pub": "../wordpress.org/public_html/wp-content/mu-plugins/pub", + "wp-content/mu-plugins/wporg-mu-plugins": "WordPress/wporg-mu-plugins#build", + "wp-content/plugins/plugin-directory": "../wordpress.org/public_html/wp-content/plugins/plugin-directory", + "wp-content/plugins/theme-directory": "../wordpress.org/public_html/wp-content/plugins/theme-directory", + "wp-content/plugins/wporg-two-factor": "../wordpress.org/public_html/wp-content/plugins/wporg-two-factor" + }, + "lifecycleScripts": { + "afterStart": "bash support-forums/bin/after-start.sh" + }, + "config": { + "WP_DEBUG": true, + "JETPACK_DEV_DEBUG": true, + "WPORGPATH": "/var/www/html/wp-content/wporg", + "WP_ENVIRONMENT_TYPE": "local", + "WPORG_SUPPORT_FORUMS_BLOGID": 1, + "WPORG_PLUGIN_DIRECTORY_BLOGID": 2, + "WPORG_THEME_DIRECTORY_BLOGID": 3, + "PLUGINS_TABLE_PREFIX": "wp_2_" + } +} diff --git a/environments/support-forums/bin/.htaccess b/environments/support-forums/bin/.htaccess new file mode 100644 index 0000000000..2130d24f62 --- /dev/null +++ b/environments/support-forums/bin/.htaccess @@ -0,0 +1,15 @@ +# BEGIN WordPress +# The directives (lines) between "BEGIN WordPress" and "END WordPress" are +# dynamically generated, and should only be modified via WordPress filters. +# Any changes to the directives between these markers will be overwritten. + +RewriteEngine On +RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] +RewriteBase / +RewriteRule ^index\.php$ - [L] +RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_FILENAME} !-d +RewriteRule . /index.php [L] + + +# END WordPress diff --git a/environments/support-forums/bin/after-start.sh b/environments/support-forums/bin/after-start.sh new file mode 100644 index 0000000000..566a3f667e --- /dev/null +++ b/environments/support-forums/bin/after-start.sh @@ -0,0 +1,140 @@ +#!/bin/bash +# +# Runs after wp-env start. Sets up permalinks, creates pages, and imports plugins. +# + +SETUP_VALIDATION_FILE="/var/www/html/.wp-env-setup-complete" + +CONFIG="--config support-forums/.wp-env.json" +WP="npx wp-env $CONFIG run cli --" + +# Check if the setup has already been completed. +if $WP bash -c "[ -f '$SETUP_VALIDATION_FILE' ]"; then + echo "Setup already completed. Skipping first-run environment configuration." + exit 0 +fi + +### +# Create multisite framework +### +echo "Setting up multisite framework..." +$WP wp core multisite-convert + +# Network enable the themes +$WP wp theme enable wporg-support-2024 + +# Create the plugins site. +echo "Creating sub-sites..." +$WP wp site create --slug=plugins --title=Plugins + +# Create the site. +$WP wp site create --slug=themes --title=Themes + +# WordPress, per now, does not properly identify port numbers in multisite URLs when creating +# sites. Because of this, when we set it up using `wp-env`, followed by a `wp core multisite-convert` +# from the WP-CLI package, strange things happen. +# This search-replace is in place to undo the weirdness, and make the environment workable. +echo "Fixing multisite URLs..." +$WP wp search-replace 'localhost:8888/:8888' 'localhost:8888' --skip-plugins --skip-themes --all-tables +$WP wp search-replace 'localhost8888' 'localhost:8888' --skip-plugins --skip-themes --all-tables + +### +# Create the various users we will need +### +echo "Creating users..." + +# Add a forum keymaster account (User ID 2). +$WP wp user create keymaster keymaster@example.com --role=subscriber --user_pass=password + +# Add a forum moderator account (User ID 3). +$WP wp user create moderator moderator@example.com --role=subscriber --user_pass=password + +# Add a plugin author (User ID 4). +$WP wp user create pluginauthor plugin-author@example.com --role=subscriber --user_pass=password + +# Add a plugin contributor (User ID 5). +$WP wp user create plugincontributor plugin-contributor@example.com --role=subscriber --user_pass=password + +# Add a plugin support representative (User ID 6). +$WP wp user create pluginsupport plugin-support@example.com --role=subscriber --user_pass=password + +# Add a theme author (User ID 7). +$WP wp user create themeauthor theme-author@example.com --role=subscriber --user_pass=password + +# Add a site support representative (user ID 8) - Currently unused, but added in anticipation. +$WP wp user create themesupport theme-support@example.com --role=subscriber --user_pass=password + +# Add a forum visitor +$WP wp user create visitor visitor@example.com --role=subscriber --user_pass=password + +### +# Set up the `plugins` sub-site with associated content. +### + +echo "Setting up minimum required plugins sub-site..." + +# Add site-specific plugins. +$WP wp plugin install jetpack --activate --url=localhost:8888/plugins +$WP wp plugin activate plugin-directory --url=localhost:8888/plugins + +# Add the plugin-related roles to this subsite. +$WP wp user set-role pluginauthor subscriber --url=localhost:8888/plugins +$WP wp user set-role plugincontributor subscriber --url=localhost:8888/plugins +$WP wp user set-role pluginsupport subscriber --url=localhost:8888/plugins + +# Add `Hello Dolly` as a plugin. +$WP wp post create --post_type=plugin --post_status=publish --post_author=4 --post_title='Hello Dolly' --post_date='2022-08-20 01:00:00' --post_modified='2022-08-20 01:00:00' --post_modified_gmt='2022-08-20 01:00:00' --url=localhost:8888/plugins + +### +# Set up the `themes` sub-site with associated content. +### + +echo "Setting up minimum required themes sub-site..." + +# Set up the site identity. +$WP wp option update blogname 'WordPress.org Forums' + +# Add site-specific plugins. +$WP wp plugin activate theme-directory --url=localhost:8888/themes + +# Add the theme-related roles to this subsite. +$WP wp user set-role themeauthor subscriber --url=localhost:8888/themes +$WP wp user set-role themesupport subscriber --url=localhost:8888/themes + +### +# Set up the primary network site, the forums, with associated content. +### + +echo "Setting up forums site..." + +# Add all roles to the forums. +$WP wp user set-role keymaster bbp_keymaster +$WP wp user set-role moderator bbp_moderator +$WP wp user set-role pluginauthor bbp_participant +$WP wp user set-role plugincontributor bbp_participant +$WP wp user set-role pluginsupport bbp_participant +$WP wp user set-role themeauthor bbp_participant +$WP wp user set-role themesupport bbp_participant +$WP wp user set-role visitor bbp_participant + +# Add the initial set of forums. +$WP wp post create --post_type=forum --post_status=publish --post_title='Installing WordPress' --post_content='If you encounter any problems while setting up WordPress.' --post_date='2022-08-20 01:00:00' --post_modified='2022-08-20 01:00:00' --post_modified_gmt='2022-08-20 01:00:00' +$WP wp post create --post_type=forum --post_status=publish --post_title='Fixing WordPress' --post_content='For any problems encountered after setting up WordPress.' --post_date='2022-08-20 01:00:00' --post_modified='2022-08-20 01:00:00' --post_modified_gmt='2022-08-20 01:00:00' +$WP wp post create --post_type=forum --post_status=publish --post_title='Plugins' --post_content='Forum for plugin-specific support topics (hidden on WordPress.org).' --post_date='2022-08-20 01:00:00' --post_modified='2022-08-20 01:00:00' --post_modified_gmt='2022-08-20 01:00:00' +$WP wp post create --post_type=forum --post_status=publish --post_title='Themes' --post_content='Forum for theme-specific support topics (hidden on WordPress.org).' --post_date='2022-08-20 01:00:00' --post_modified='2022-08-20 01:00:00' --post_modified_gmt='2022-08-20 01:00:00' +$WP wp post create --post_type=forum --post_status=publish --post_title='Reviews' --post_content='Forum for plugin and theme reviews (hidden on WordPress.org).' --post_date='2022-08-20 01:00:00' --post_modified='2022-08-20 01:00:00' --post_modified_gmt='2022-08-20 01:00:00' + +# Activate the forum theme. +$WP wp theme activate wporg-support-2024 + +echo "Setting up network-wide plugins..." + +# Activate network-wide plugins +$WP wp plugin activate wporg-two-factor --network + +# Setup, and flush rewrite rules. +echo "Setting up permalinks..." +$WP wp rewrite structure '/%postname%/' +$WP wp rewrite flush + +$WP bash -c "touch '$SETUP_VALIDATION_FILE'"