Skip to content

Commit f3a4895

Browse files
committed
refactor(examples): Use production WordPress URL pattern with modular plugins
Updates toolbar demo examples to use production-ready configuration: - WP_HOME points to WordPress instance (not frontend) - HEADLESS_FRONTEND_URL configured separately for frontend application - Replaces mu-plugin template approach with modular plugin references - Updates PHP version to 8.3 - Removes mu-plugin mapping in favor of standard plugin loading This allows WordPress to remain fully functional while supporting headless architecture, and enables composable plugin usage across different projects.
1 parent e16a6f5 commit f3a4895

File tree

4 files changed

+46
-12
lines changed

4 files changed

+46
-12
lines changed

examples/next/toolbar-demo/scripts/setup-env.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,24 @@ console.log(` WP Test: ${ports.WP_TEST_PORT}`);
2929

3030
// Update .wp-env.json
3131
const wpEnvConfig = {
32-
phpVersion: '8.0',
32+
phpVersion: '8.3',
3333
plugins: [
34-
'https://github.com/wp-graphql/wp-graphql/releases/latest/download/wp-graphql.zip'
34+
'https://github.com/wp-graphql/wp-graphql/releases/latest/download/wp-graphql.zip',
35+
'../../../../plugins/hwp-cors-local',
36+
'../../../../plugins/hwp-frontend-links',
37+
'../../../../plugins/hwp-wp-env-helpers'
3538
],
3639
config: {
3740
WP_DEBUG: true,
3841
WP_DEBUG_LOG: true,
39-
GRAPHQL_DEBUG: true
42+
GRAPHQL_DEBUG: true,
43+
WP_HOME: `http://localhost:${ports.WP_PORT}`,
44+
HEADLESS_FRONTEND_URL: `http://localhost:${ports.FRONTEND_PORT}`
4045
},
4146
port: ports.WP_PORT,
4247
testsPort: ports.WP_TEST_PORT,
4348
mappings: {
4449
db: './wp-env/db',
45-
'wp-content/mu-plugins': './mu-plugin.php',
4650
'.htaccess': './.htaccess'
4751
},
4852
lifecycleScripts: {

examples/vanilla/toolbar-demo/.wp-env.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
{
2-
"phpVersion": "8.0",
2+
"phpVersion": "8.3",
33
"plugins": [
44
"https://github.com/wp-graphql/wp-graphql/releases/latest/download/wp-graphql.zip"
55
],
66
"config": {
77
"WP_DEBUG": true,
88
"WP_DEBUG_LOG": true,
9-
"GRAPHQL_DEBUG": true
9+
"GRAPHQL_DEBUG": true,
10+
"WP_HOME": "http://localhost:8644",
11+
"HEADLESS_FRONTEND_URL": "http://localhost:3644"
1012
},
1113
"port": 8644,
1214
"testsPort": 8645,

examples/vanilla/toolbar-demo/scripts/setup-env.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,24 @@ console.log(` WP Test: ${ports.WP_TEST_PORT}`);
2929

3030
// Update .wp-env.json
3131
const wpEnvConfig = {
32-
phpVersion: '8.0',
32+
phpVersion: '8.3',
3333
plugins: [
34-
'https://github.com/wp-graphql/wp-graphql/releases/latest/download/wp-graphql.zip'
34+
'https://github.com/wp-graphql/wp-graphql/releases/latest/download/wp-graphql.zip',
35+
'../../../../plugins/hwp-cors-local',
36+
'../../../../plugins/hwp-frontend-links',
37+
'../../../../plugins/hwp-wp-env-helpers'
3538
],
3639
config: {
3740
WP_DEBUG: true,
3841
WP_DEBUG_LOG: true,
39-
GRAPHQL_DEBUG: true
42+
GRAPHQL_DEBUG: true,
43+
WP_HOME: `http://localhost:${ports.WP_PORT}`,
44+
HEADLESS_FRONTEND_URL: `http://localhost:${ports.FRONTEND_PORT}`
4045
},
4146
port: ports.WP_PORT,
4247
testsPort: ports.WP_TEST_PORT,
4348
mappings: {
4449
db: './wp-env/db',
45-
'wp-content/mu-plugins': './mu-plugin.php',
4650
'.htaccess': './.htaccess'
4751
},
4852
lifecycleScripts: {

scripts/templates/mu-plugin.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Plugin Name: Toolbar Demo CORS
4-
* Description: Enable CORS for dev server
3+
* Plugin Name: Toolbar Demo CORS & Frontend Links
4+
* Description: Enable CORS for dev server and add frontend preview links
55
*/
66

77
add_action('rest_api_init', function() {
@@ -26,3 +26,27 @@
2626
$url = remove_query_arg('rest_route', $url);
2727
return add_query_arg('rest_route', trim(parse_url($url, PHP_URL_PATH), '/'), home_url('/'));
2828
}, 10, 1);
29+
30+
// Add "View on Frontend" link in admin bar
31+
add_action('admin_bar_menu', function($wp_admin_bar) {
32+
if (!defined('HEADLESS_FRONTEND_URL')) {
33+
return;
34+
}
35+
36+
// Only show for singular posts/pages
37+
if (!is_singular()) {
38+
return;
39+
}
40+
41+
global $post;
42+
$frontend_url = HEADLESS_FRONTEND_URL . '/' . $post->post_name;
43+
44+
$wp_admin_bar->add_node([
45+
'id' => 'view-on-frontend',
46+
'title' => 'View on Frontend',
47+
'href' => $frontend_url,
48+
'meta' => [
49+
'target' => '_blank'
50+
]
51+
]);
52+
}, 100);

0 commit comments

Comments
 (0)