@forgewp/compiler 0.4.3 → 0.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. package/README.md +59 -0
  2. package/bin/add.js +20 -14
  3. package/bin/cli.js +145 -70
  4. package/bin/doctor.js +21 -12
  5. package/bin/export.js +69 -20
  6. package/bin/fresh.js +5 -0
  7. package/bin/i18n-extract.js +3 -10
  8. package/bin/i18n-translate.js +15 -24
  9. package/bin/make-block.js +13 -0
  10. package/bin/make-editable.js +166 -0
  11. package/bin/make-form.js +131 -0
  12. package/bin/make-loop.js +40 -43
  13. package/bin/make-mail.js +27 -0
  14. package/bin/make-post-type.js +57 -29
  15. package/bin/make-sandbox.js +62 -11
  16. package/bin/make-section.js +221 -0
  17. package/bin/make-shell.js +375 -0
  18. package/bin/repair.js +14 -26
  19. package/bin/seed.js +119 -0
  20. package/bin/sync-routes.js +107 -85
  21. package/lib/adapters/html-adapter.js +5 -0
  22. package/lib/adapters/stub-adapter.js +4 -0
  23. package/lib/add-component.js +153 -92
  24. package/lib/asset-loader.js +313 -3
  25. package/lib/assets/asset-graph.js +432 -0
  26. package/lib/assets/asset-pipeline.js +125 -0
  27. package/lib/assets/diagnostics-report.js +345 -0
  28. package/lib/assets/external-fetcher.js +173 -0
  29. package/lib/assets/font-orchestrator.js +348 -0
  30. package/lib/assets/font-usage-scanner.js +242 -0
  31. package/lib/assets/image-optimizer.js +229 -0
  32. package/lib/assets/index.js +51 -0
  33. package/lib/assets/preload-generator.js +70 -0
  34. package/lib/assets/public-url.js +153 -0
  35. package/lib/block-authoring-help.js +11 -0
  36. package/lib/blocks/ast-parser.js +67 -0
  37. package/lib/blocks/discover-blocks.js +146 -0
  38. package/lib/blocks/editor-scope.js +733 -0
  39. package/lib/blocks/editor-transpiler.js +1229 -0
  40. package/lib/blocks/index.js +2838 -0
  41. package/lib/blocks/php-transpiler.js +4928 -0
  42. package/lib/blocks/scanner.js +1487 -0
  43. package/lib/blocks/shared-utils.js +290 -0
  44. package/lib/blocks/source-sanitize.js +1449 -0
  45. package/lib/blueprints.js +31 -91
  46. package/lib/build-assets.js +38 -33
  47. package/lib/collect-page-template-routes.js +102 -0
  48. package/lib/collect-static-routes.js +175 -0
  49. package/lib/diagnostics.js +58 -33
  50. package/lib/export-theme.js +84 -5
  51. package/lib/extract-template-content.js +90 -0
  52. package/lib/forms-preview.js +42 -0
  53. package/lib/functions/cpt-routing.js +69 -0
  54. package/lib/functions/forms.js +2461 -0
  55. package/lib/functions/hydration-enqueuer.js +400 -0
  56. package/lib/functions/index.js +1623 -0
  57. package/lib/functions/load-menus.js +112 -0
  58. package/lib/functions/load-translations.js +148 -0
  59. package/lib/functions/rest-endpoints.js +2923 -0
  60. package/lib/functions/routing.js +765 -0
  61. package/lib/functions/seed-mock-data.js +392 -0
  62. package/lib/functions/seed-products.js +481 -0
  63. package/lib/functions/settings-page.js +273 -0
  64. package/lib/functions/theme-setup.js +494 -0
  65. package/lib/generate-theme.js +1916 -339
  66. package/lib/hydration/editable-schemas.js +332 -0
  67. package/lib/hydration/enter-hidden-initial.js +65 -0
  68. package/lib/hydration/form-schemas.js +227 -0
  69. package/lib/hydration/index.js +12 -0
  70. package/lib/hydration/is-interactive.js +951 -0
  71. package/lib/hydration/island-split.js +1231 -0
  72. package/lib/hydration/islands-scanner.js +599 -0
  73. package/lib/hydration/resolve-island-chunk.js +103 -0
  74. package/lib/hydration/resolve-island-component.js +52 -0
  75. package/lib/hydration/rollup-inputs.js +81 -0
  76. package/lib/hydration/root-class-extractor.js +220 -0
  77. package/lib/hydration/scan-app-providers.js +154 -0
  78. package/lib/hydration/static-lint.js +382 -0
  79. package/lib/hydration/transform.js +257 -0
  80. package/lib/hydration/uses-block-area.js +49 -0
  81. package/lib/hydration/utils.js +119 -0
  82. package/lib/i18n/translation-cache.js +141 -0
  83. package/lib/icon-registry.js +72 -0
  84. package/lib/index.d.ts +287 -8
  85. package/lib/index.js +2 -1
  86. package/lib/load-config.js +338 -242
  87. package/lib/mail-templates.js +37 -0
  88. package/lib/markup-processor.js +388 -102
  89. package/lib/node-runtime.js +7 -0
  90. package/lib/page-config-plugin.js +64 -20
  91. package/lib/php-builders.js +383 -44
  92. package/lib/react-adapter.js +983 -235
  93. package/lib/registration-metadata.js +11 -0
  94. package/lib/render-theme.mts +1410 -616
  95. package/lib/route-layout.js +76 -0
  96. package/lib/template-discovery.js +58 -0
  97. package/lib/theme-compatibility.js +32 -0
  98. package/lib/validate-export.js +2 -2
  99. package/lib/validate.js +27 -5
  100. package/lib/virtual-plugin.js +319 -0
  101. package/lib/walkthrough.md +26 -0
  102. package/package.json +16 -5
  103. package/templates/auth/cms/email-logs.json +9 -0
  104. package/templates/auth/cms/menus.json +11 -0
  105. package/templates/auth/cms/mock-data.json +123 -0
  106. package/templates/auth/cms/roles.json +7 -0
  107. package/templates/auth/cms/sessions.json +1 -0
  108. package/templates/auth/cms/site-settings.json +28 -0
  109. package/templates/auth/cms/translations.json +4 -0
  110. package/templates/auth/cms/users.json +46 -0
  111. package/templates/auth/components/forgot-password-form-wrapper.tsx +10 -2
  112. package/templates/auth/components/login-form-wrapper.tsx +118 -21
  113. package/templates/auth/components/reset-password-form-wrapper.tsx +10 -2
  114. package/templates/auth/components/signup-form-wrapper.tsx +2 -2
  115. package/templates/auth/components/verify-email-view-wrapper.tsx +5 -5
  116. package/templates/auth/pages/DashboardPage.tsx +1 -4
  117. package/templates/auth/pages/ForgotPasswordPage.tsx +1 -4
  118. package/templates/auth/pages/LoginPage.tsx +1 -4
  119. package/templates/auth/pages/ResetPasswordPage.tsx +1 -4
  120. package/templates/auth/pages/SignUpPage.tsx +1 -4
  121. package/templates/auth/pages/VerifyEmailPage.tsx +1 -4
  122. package/templates/auth/ui/button.tsx +57 -0
  123. package/templates/auth/ui/card.tsx +76 -0
  124. package/templates/auth/ui/field.tsx +242 -0
  125. package/templates/auth/ui/input.tsx +22 -0
  126. package/templates/auth/ui/label.tsx +24 -0
  127. package/templates/auth/ui/separator.tsx +31 -0
  128. package/templates/menus.json +12 -10
  129. package/templates/users.json +8 -4
  130. package/templates/wordpress.tsx +690 -245
  131. package/lib/block-compiler.js +0 -552
  132. package/lib/functions-builder.js +0 -2970
  133. package/lib/hydration-scanner.js +0 -833
@@ -4,22 +4,47 @@
4
4
  * @param {import('./types.js').ForgeWPThemeConfig} config
5
5
  * @returns {string}
6
6
  */
7
+ import { resolveThemeCompatibility } from './theme-compatibility.js';
8
+
7
9
  export function buildStyleCss(config) {
10
+ const compatibility = resolveThemeCompatibility(config);
8
11
  return `/*
9
12
  Theme Name: ${config.name}
10
13
  Theme URI: https://forgewp.dev
11
14
  Author: ForgeWP
12
15
  Description: ${config.description}
13
16
  Version: ${config.version}
14
- Requires at least: 6.0
15
- Tested up to: 6.7
16
- Requires PHP: 7.4
17
+ Requires at least: ${compatibility.requiresWordPress}
18
+ ${compatibility.testedUpTo ? `Tested up to: ${compatibility.testedUpTo}\n` : ''}Requires PHP: ${compatibility.requiresPhp}
17
19
  License: GNU General Public License v2 or later
18
20
  License URI: https://www.gnu.org/licenses/gpl-2.0.html
19
21
  Text Domain: ${config.textDomain}
20
22
  */
21
23
 
22
24
  /* Compiled styles are enqueued from assets/ via functions.php */
25
+
26
+ /*
27
+ * ForgeWP content-width system — lets classic-template pages (page.php, single.php,
28
+ * index.php, archive.php) support per-block wide/full alignment without a hardcoded
29
+ * pixel cap. Sizes come from theme.json's settings.layout.contentSize/wideSize, which
30
+ * WordPress automatically emits as these CSS custom properties.
31
+ */
32
+ .forgewp-content-width {
33
+ max-width: var(--wp--style--global--content-size, 720px);
34
+ margin-left: auto;
35
+ margin-right: auto;
36
+ }
37
+ .forgewp-content-width > .alignwide {
38
+ max-width: var(--wp--style--global--wide-size, 1200px);
39
+ margin-left: auto;
40
+ margin-right: auto;
41
+ }
42
+ .forgewp-content-width > .alignfull {
43
+ max-width: none;
44
+ width: 100vw;
45
+ margin-left: calc(50% - 50vw);
46
+ margin-right: calc(50% - 50vw);
47
+ }
23
48
  `;
24
49
  }
25
50
 
@@ -35,6 +60,10 @@ export function generateAcfFieldPhp(key, field, parentKey = '') {
35
60
  boolean: 'true_false',
36
61
  image: 'image',
37
62
  repeater: 'repeater',
63
+ color: 'color_picker',
64
+ select: 'select',
65
+ number: 'number',
66
+ url: 'url',
38
67
  };
39
68
  const acfType = field.customType || typeMap[field.type] || 'text';
40
69
 
@@ -55,14 +84,33 @@ export function generateAcfFieldPhp(key, field, parentKey = '') {
55
84
  if (acfType === 'image') {
56
85
  php += `\n 'return_format' => 'url',`;
57
86
  } else if (acfType === 'relationship') {
58
- const pts = field.postTypes ? field.postTypes.map(pt => `'${pt}'`).join(', ') : '';
87
+ const pts = field.postTypes
88
+ ? field.postTypes.map((pt) => `'${pt}'`).join(', ')
89
+ : '';
59
90
  const ptExpr = pts ? `array(${pts})` : `array()`;
60
91
  php += `\n 'post_type' => ${ptExpr},\n 'filters' => array('search', 'taxonomy'),\n 'return_format' => 'id',`;
61
92
  } else if (acfType === 'true_false') {
62
93
  php += `\n 'ui' => 1,`;
94
+ } else if (acfType === 'select' && field.options) {
95
+ const choices = field.options
96
+ .map((opt) => {
97
+ if (typeof opt === 'string') {
98
+ return `'${opt.replace(/'/g, "\\'")}' => '${opt.replace(/'/g, "\\'")}'`;
99
+ }
100
+ return `'${String(opt.value).replace(/'/g, "\\'")}' => '${String(opt.label).replace(/'/g, "\\'")}'`;
101
+ })
102
+ .join(', ');
103
+ php += `\n 'choices' => array(${choices}),`;
104
+ } else if (acfType === 'number') {
105
+ if (field.min !== undefined)
106
+ php += `\n 'min' => ${field.min},`;
107
+ if (field.max !== undefined)
108
+ php += `\n 'max' => ${field.max},`;
63
109
  } else if (acfType === 'repeater' && field.fields) {
64
110
  const subFieldsPhp = Object.entries(field.fields)
65
- .map(([subKey, subField]) => generateAcfFieldPhp(subKey, subField, acfKey))
111
+ .map(([subKey, subField]) =>
112
+ generateAcfFieldPhp(subKey, subField, acfKey),
113
+ )
66
114
  .join(',\n');
67
115
  php += `\n 'sub_fields' => array(
68
116
  ${subFieldsPhp}
@@ -76,8 +124,21 @@ ${subFieldsPhp}
76
124
  /**
77
125
  * Generate dynamic ACF fallback PHP generation block.
78
126
  */
79
- export function generateDynamicAcfFieldPhp(key, field) {
80
- const acfKey = `field_${key}`;
127
+ export function generateDynamicAcfFieldPhp(key, field, templateSlug = '') {
128
+ // ACF field 'key' must be globally unique across the whole install — it's
129
+ // ACF's own internal registry identifier, distinct from 'name' (the actual
130
+ // postmeta key, which SHOULD be shared across templates when two pages
131
+ // both use e.g. "hero_subtitle" for their own hero section; that's fine,
132
+ // each post has its own meta row). Without this namespace prefix, every
133
+ // template reusing a common field name (hero_title, hero_subtitle, hero_badge, …)
134
+ // generated the identical key (e.g. 'field_hero_subtitle'), so whichever
135
+ // schema's field group ACF resolved that key against last effectively
136
+ // dictated the formatting (text vs wysiwyg) for every OTHER template's
137
+ // same-named field too — e.g. a richText hero_subtitle on one page could
138
+ // make a plain-text hero_subtitle on another page get wpautop-wrapped.
139
+ const keyNamespace = templateSlug ? templateSlug.replace(/-/g, '_') : '';
140
+ const parentKeyPrefix = keyNamespace ? `field_${keyNamespace}` : '';
141
+ const acfKey = parentKeyPrefix ? `${parentKeyPrefix}_${key}` : `field_${key}`;
81
142
  const label = field.label || key.charAt(0).toUpperCase() + key.slice(1);
82
143
  const typeMap = {
83
144
  text: 'text',
@@ -89,11 +150,11 @@ export function generateDynamicAcfFieldPhp(key, field) {
89
150
  const acfType = typeMap[field.type] || 'text';
90
151
 
91
152
  if (acfType !== 'repeater') {
92
- const fieldDef = generateAcfFieldPhp(key, field);
153
+ const fieldDef = generateAcfFieldPhp(key, field, parentKeyPrefix);
93
154
  return ` $fields[] = ${fieldDef.trim()};\n`;
94
155
  }
95
156
 
96
- const acfProDef = generateAcfFieldPhp(key, field);
157
+ const acfProDef = generateAcfFieldPhp(key, field, parentKeyPrefix);
97
158
  const defaultRows = Array.isArray(field.default) ? field.default : [];
98
159
  const defaultRowCount = defaultRows.length || 4;
99
160
 
@@ -108,17 +169,22 @@ export function generateDynamicAcfFieldPhp(key, field) {
108
169
  for ($i = 0; $i < $count; $i++) {\n`;
109
170
 
110
171
  for (const [subKey, subField] of Object.entries(field.fields)) {
111
- const subLabel = subField.label || subKey.charAt(0).toUpperCase() + subKey.slice(1);
172
+ const subLabel =
173
+ subField.label || subKey.charAt(0).toUpperCase() + subKey.slice(1);
112
174
  const subTypeMap = {
113
175
  text: 'text',
114
176
  richText: 'wysiwyg',
115
177
  boolean: 'true_false',
116
178
  image: 'image',
179
+ color: 'color_picker',
180
+ select: 'select',
181
+ number: 'number',
182
+ url: 'url',
117
183
  };
118
184
  const subType = subTypeMap[subField.type] || 'text';
119
185
 
120
186
  fallbackPhp += ` $fields[] = array(
121
- 'key' => "field_${key}_" . $i . "_${subKey}",
187
+ 'key' => "${parentKeyPrefix ? `${parentKeyPrefix}_` : 'field_'}${key}_" . $i . "_${subKey}",
122
188
  'label' => "${label.replace(/'/g, "\\'")}" . " " . ($i + 1) . ": ${subLabel.replace(/'/g, "\\'")}",
123
189
  'name' => "${key}_" . $i . "_${subKey}",
124
190
  'type' => '${subType}',`;
@@ -127,6 +193,21 @@ export function generateDynamicAcfFieldPhp(key, field) {
127
193
  fallbackPhp += `\n 'return_format' => 'url',`;
128
194
  } else if (subType === 'true_false') {
129
195
  fallbackPhp += `\n 'ui' => 1,`;
196
+ } else if (subType === 'select' && subField.options) {
197
+ const choices = subField.options
198
+ .map((opt) => {
199
+ if (typeof opt === 'string') {
200
+ return `'${opt.replace(/'/g, "\\'")}' => '${opt.replace(/'/g, "\\'")}'`;
201
+ }
202
+ return `'${String(opt.value).replace(/'/g, "\\'")}' => '${String(opt.label).replace(/'/g, "\\'")}'`;
203
+ })
204
+ .join(', ');
205
+ fallbackPhp += `\n 'choices' => array(${choices}),`;
206
+ } else if (subType === 'number') {
207
+ if (subField.min !== undefined)
208
+ fallbackPhp += `\n 'min' => ${subField.min},`;
209
+ if (subField.max !== undefined)
210
+ fallbackPhp += `\n 'max' => ${subField.max},`;
130
211
  }
131
212
  fallbackPhp += `\n );\n`;
132
213
  }
@@ -137,7 +218,25 @@ export function generateDynamicAcfFieldPhp(key, field) {
137
218
  return fallbackPhp;
138
219
  }
139
220
 
140
- export function buildHeaderPhp(config) {
221
+ /**
222
+ * Unlayered link reset printed after wp_head().
223
+ *
224
+ * Tailwind utilities live in `@layer`, so an unlayered `text-decoration`
225
+ * shorthand here beats `.decoration-*` and forces the line color back to
226
+ * currentColor. Set only the line so decoration color, style, thickness,
227
+ * and offset from the page survive on every project.
228
+ */
229
+ export const LINK_RESET_CSS = ` a { text-decoration-line: none; }
230
+ a:hover { text-decoration-line: none; }
231
+ .underline { text-decoration-line: underline !important; }
232
+ .hover\\:underline:hover { text-decoration-line: underline !important; }`;
233
+
234
+ export function buildHeaderPhp(config, options = {}) {
235
+ const preloadHtml =
236
+ Array.isArray(options.preloadTags) && options.preloadTags.length > 0
237
+ ? ' ' + options.preloadTags.join('\n ') + '\n'
238
+ : '';
239
+
141
240
  return `<?php
142
241
  /**
143
242
  * Theme header
@@ -149,15 +248,12 @@ export function buildHeaderPhp(config) {
149
248
  <head>
150
249
  <meta charset="<?php bloginfo('charset'); ?>">
151
250
  <meta name="viewport" content="width=device-width, initial-scale=1">
152
- <?php
153
- // Yield metadata control to active SEO plugins to prevent duplication
154
- $seo_plugin_active = defined('WPSEO_VERSION') ||
155
- class_exists('RankMath') ||
156
- class_exists('All_in_One_SEO_Pack') ||
157
- defined('AIOSEO_VERSION') ||
158
- class_exists('SEOPress\\\\Services\\\\Title');
159
-
160
- if ( ! $seo_plugin_active ) {
251
+ ${preloadHtml} <?php
252
+ // Yield metadata control to active SEO plugins to prevent duplication.
253
+ // forgewp_seo_plugin_active() (functions.php) is the single source of
254
+ // truth for this check — every place ForgeWP yields to a standard SEO
255
+ // plugin uses the same function so the detected plugin list can't drift.
256
+ if ( ! forgewp_seo_plugin_active() ) {
161
257
  $target = forgewp_resolve_head_target();
162
258
  if (file_exists($target)) {
163
259
  ob_start();
@@ -171,10 +267,7 @@ export function buildHeaderPhp(config) {
171
267
  <?php wp_head(); ?>
172
268
  <style>
173
269
  /* Reset WP link underlines to match React/Tailwind expected styling */
174
- a { text-decoration: none; }
175
- a:hover { text-decoration: none; }
176
- .underline { text-decoration: underline !important; }
177
- .hover\\:underline:hover { text-decoration: underline !important; }
270
+ ${LINK_RESET_CSS}
178
271
  </style>
179
272
  </head>
180
273
  <body <?php body_class(); ?>>
@@ -206,32 +299,183 @@ wp_footer();
206
299
  `;
207
300
  }
208
301
 
209
- export function buildIndexPhp() {
302
+ function shellOwnedFrontPagePhp() {
210
303
  return `<?php
211
304
  /**
212
- * Main template — displays ForgeWP compiled static markup
305
+ * Front page whose route renders with a blank layout.
306
+ *
307
+ * The page component already includes its own shell, and that shell shares
308
+ * client state with the page (scroll, motion, refs). Including the default
309
+ * layout header/footer here would paint a second shell and leave the real
310
+ * one static. The Builder template still uses the layout chrome, because
311
+ * that canvas is block markup rather than the page component.
312
+ *
313
+ * @package forgewp
314
+ */
315
+
316
+ $forgewp_use_builder = false;
317
+ if (is_front_page()) {
318
+ // get_queried_object_id() — NOT get_option('page_on_front') — because
319
+ // that option is a single, raw post ID with no guarantee of being
320
+ // language-aware: on a Polylang multilingual site, the German and
321
+ // English homepages are separate posts, each with their own page
322
+ // template setting, and get_queried_object_id() is WordPress's own
323
+ // resolution of whichever one is actually being displayed for this
324
+ // request. Reading page_on_front directly here previously meant a
325
+ // template switched to "ForgeWP Builder" on one language's homepage
326
+ // was silently ignored while viewing any other language — it fell
327
+ // through to the static baked-in markup below instead.
328
+ $front_id = get_queried_object_id();
329
+ if ($front_id > 0) {
330
+ $tpl = get_page_template_slug($front_id);
331
+ if ($tpl === 'template-forgewp-builder.php') {
332
+ $forgewp_use_builder = true;
333
+ }
334
+ }
335
+ }
336
+
337
+ if ($forgewp_use_builder && have_posts()) {
338
+ get_header();
339
+ while (have_posts()) {
340
+ the_post();
341
+ $forgewp_hide_title = function_exists('forgewp_should_hide_page_title')
342
+ ? forgewp_should_hide_page_title(get_the_ID())
343
+ : true;
344
+ echo '<main class="forgewp-builder-canvas">';
345
+ if (!$forgewp_hide_title) {
346
+ echo '<div class="forgewp-content-width">';
347
+ echo '<h1 class="text-4xl font-bold mb-6">' . get_the_title() . '</h1>';
348
+ echo '</div>';
349
+ }
350
+ the_content();
351
+ echo '</main>';
352
+ }
353
+ get_footer();
354
+ } else {
355
+ ?>
356
+ <!DOCTYPE html>
357
+ <html <?php language_attributes(); ?>>
358
+ <head>
359
+ <meta charset="<?php bloginfo('charset'); ?>">
360
+ <meta name="viewport" content="width=device-width, initial-scale=1">
361
+ <?php
362
+ if ( ! forgewp_seo_plugin_active() ) {
363
+ $target = forgewp_resolve_head_target();
364
+ if (file_exists($target)) {
365
+ ob_start();
366
+ include $target;
367
+ echo preg_replace('/<title>.*?<\\/title>/is', '', ob_get_clean());
368
+ }
369
+ }
370
+ ?>
371
+ <?php wp_head(); ?>
372
+ <style>
373
+ ${LINK_RESET_CSS}
374
+ </style>
375
+ </head>
376
+ <body <?php body_class(); ?>>
377
+ <?php wp_body_open(); ?>
378
+ <?php
379
+ $markup_file = get_template_directory() . '/forgewp-static/content.html';
380
+
381
+ if (is_front_page() && file_exists($markup_file)) {
382
+ include $markup_file;
383
+ } elseif (have_posts()) {
384
+ echo '<main class="px-6 py-12">';
385
+ while (have_posts()) {
386
+ the_post();
387
+ echo '<article class="mb-12">';
388
+ echo '<div class="forgewp-content-width">';
389
+ echo '<h1 class="text-3xl font-bold mb-4">' . get_the_title() . '</h1>';
390
+ echo '</div>';
391
+ echo '<div class="forgewp-content-width prose prose-zinc max-w-none">';
392
+ the_content();
393
+ echo '</div>';
394
+ echo '</article>';
395
+ }
396
+ echo '</main>';
397
+ }
398
+ wp_footer();
399
+ ?>
400
+ </body>
401
+ </html>
402
+ <?php
403
+ }
404
+ `;
405
+ }
406
+
407
+ export function buildIndexPhp(options = {}) {
408
+ if (options.ownsShell) return shellOwnedFrontPagePhp();
409
+ return `<?php
410
+ /**
411
+ * Main template / front page — baked static markup by default.
412
+ *
413
+ * WordPress always prefers front-page.php for the site front page, which
414
+ * normally ignores the page template dropdown. We still honor
415
+ * "ForgeWP Builder" (template-forgewp-builder.php) when assigned to the
416
+ * static front page so editors can switch to a block canvas.
213
417
  *
214
418
  * @package forgewp
215
419
  */
216
420
 
217
421
  get_header();
218
422
 
219
- $markup_file = get_template_directory() . '/forgewp-static/content.html';
423
+ $forgewp_use_builder = false;
424
+ if (is_front_page()) {
425
+ // get_queried_object_id() — NOT get_option('page_on_front') — because
426
+ // that option is a single, raw post ID with no guarantee of being
427
+ // language-aware: on a Polylang multilingual site, the German and
428
+ // English homepages are separate posts, each with their own page
429
+ // template setting, and get_queried_object_id() is WordPress's own
430
+ // resolution of whichever one is actually being displayed for this
431
+ // request. Reading page_on_front directly here previously meant a
432
+ // template switched to "ForgeWP Builder" on one language's homepage
433
+ // was silently ignored while viewing any other language — it fell
434
+ // through to the static baked-in markup below instead.
435
+ $front_id = get_queried_object_id();
436
+ if ($front_id > 0) {
437
+ $tpl = get_page_template_slug($front_id);
438
+ if ($tpl === 'template-forgewp-builder.php') {
439
+ $forgewp_use_builder = true;
440
+ }
441
+ }
442
+ }
220
443
 
221
- if (is_front_page() && file_exists($markup_file)) {
222
- include $markup_file;
223
- } elseif (have_posts()) {
224
- echo '<main class="mx-auto max-w-3xl px-6 py-12">';
444
+ if ($forgewp_use_builder && have_posts()) {
225
445
  while (have_posts()) {
226
446
  the_post();
227
- echo '<article class="mb-12">';
228
- echo '<h1 class="text-3xl font-bold mb-4">' . get_the_title() . '</h1>';
229
- echo '<div class="prose prose-zinc max-w-none">';
447
+ $forgewp_hide_title = function_exists('forgewp_should_hide_page_title')
448
+ ? forgewp_should_hide_page_title(get_the_ID())
449
+ : true;
450
+ echo '<main class="forgewp-builder-canvas">';
451
+ if (!$forgewp_hide_title) {
452
+ echo '<div class="forgewp-content-width">';
453
+ echo '<h1 class="text-4xl font-bold mb-6">' . get_the_title() . '</h1>';
454
+ echo '</div>';
455
+ }
230
456
  the_content();
231
- echo '</div>';
232
- echo '</article>';
457
+ echo '</main>';
458
+ }
459
+ } else {
460
+ $markup_file = get_template_directory() . '/forgewp-static/content.html';
461
+
462
+ if (is_front_page() && file_exists($markup_file)) {
463
+ include $markup_file;
464
+ } elseif (have_posts()) {
465
+ echo '<main class="px-6 py-12">';
466
+ while (have_posts()) {
467
+ the_post();
468
+ echo '<article class="mb-12">';
469
+ echo '<div class="forgewp-content-width">';
470
+ echo '<h1 class="text-3xl font-bold mb-4">' . get_the_title() . '</h1>';
471
+ echo '</div>';
472
+ echo '<div class="forgewp-content-width prose prose-zinc max-w-none">';
473
+ the_content();
474
+ echo '</div>';
475
+ echo '</article>';
476
+ }
477
+ echo '</main>';
233
478
  }
234
- echo '</main>';
235
479
  }
236
480
 
237
481
  get_footer();
@@ -260,10 +504,12 @@ if (file_exists($single_file)) {
260
504
  if (have_posts()) {
261
505
  while (have_posts()) {
262
506
  the_post();
263
- echo '<main class="mx-auto max-w-3xl px-6 py-12">';
507
+ echo '<main class="px-6 py-12">';
264
508
  echo '<article>';
509
+ echo '<div class="forgewp-content-width">';
265
510
  echo '<h1 class="text-4xl font-bold mb-6">' . get_the_title() . '</h1>';
266
- echo '<div class="prose prose-zinc max-w-none">';
511
+ echo '</div>';
512
+ echo '<div class="forgewp-content-width prose prose-zinc max-w-none">';
267
513
  the_content();
268
514
  echo '</div>';
269
515
  echo '</article>';
@@ -317,7 +563,7 @@ $archive_file = get_template_directory() . '/forgewp-static/archive.html';
317
563
  if (file_exists($archive_file)) {
318
564
  include $archive_file;
319
565
  } else {
320
- echo '<main class="mx-auto max-w-3xl px-6 py-12">';
566
+ echo '<main class="forgewp-content-width px-6 py-12">';
321
567
  the_archive_title('<h1 class="text-3xl font-bold mb-8">', '</h1>');
322
568
  if (have_posts()) {
323
569
  echo '<div class="space-y-8">';
@@ -366,10 +612,17 @@ if (file_exists($page_file)) {
366
612
  if (have_posts()) {
367
613
  while (have_posts()) {
368
614
  the_post();
369
- echo '<main class="mx-auto max-w-3xl px-6 py-12">';
615
+ $forgewp_hide_title = function_exists('forgewp_should_hide_page_title')
616
+ ? forgewp_should_hide_page_title(get_the_ID())
617
+ : true;
618
+ echo '<main class="px-6 py-12">';
370
619
  echo '<article>';
371
- echo '<h1 class="text-4xl font-bold mb-6">' . get_the_title() . '</h1>';
372
- echo '<div class="prose prose-zinc max-w-none">';
620
+ if (!$forgewp_hide_title) {
621
+ echo '<div class="forgewp-content-width">';
622
+ echo '<h1 class="text-4xl font-bold mb-6">' . get_the_title() . '</h1>';
623
+ echo '</div>';
624
+ }
625
+ echo '<div class="forgewp-content-width prose prose-zinc max-w-none">';
373
626
  the_content();
374
627
  echo '</div>';
375
628
  echo '</article>';
@@ -381,3 +634,89 @@ if (file_exists($page_file)) {
381
634
  get_footer();
382
635
  `;
383
636
  }
637
+
638
+ export function buildPlaceholderPagePhp(config = {}) {
639
+ const td = (config.textDomain || 'forgewp').replace(/'/g, "\\'");
640
+ return `<?php
641
+ /**
642
+ * Template Name: Coming Next
643
+ * Description: Fallback for React routes that exist in local routing/menus but have no dedicated page file yet.
644
+ *
645
+ * @package ${td}
646
+ */
647
+
648
+ get_header();
649
+
650
+ $forgewp_page_desc = get_post_meta(get_the_ID(), '_forgewp_page_description', true);
651
+ if (empty($forgewp_page_desc)) {
652
+ $forgewp_page_desc = get_the_content();
653
+ }
654
+ if (empty($forgewp_page_desc)) {
655
+ $forgewp_page_desc = __('This page is scaffolded and will be built in the next phase of the storefront.', '${td}');
656
+ }
657
+ ?>
658
+ <div class="container-wide py-20 md:py-28 text-center max-w-xl mx-auto">
659
+ <p class="text-xs uppercase tracking-[0.2em] text-muted-foreground mb-3"><?php esc_html_e('Coming next', '${td}'); ?></p>
660
+ <h1 class="font-heading text-3xl md:text-4xl font-medium tracking-tight"><?php echo esc_html(get_the_title()); ?></h1>
661
+ <p class="mt-4 text-muted-foreground leading-relaxed"><?php echo esc_html($forgewp_page_desc); ?></p>
662
+ <div class="mt-8 flex flex-wrap justify-center gap-3">
663
+ <a class="inline-flex items-center justify-center rounded-md bg-primary text-primary-foreground px-4 py-2 text-sm font-medium" href="<?php echo esc_url(home_url('/')); ?>"><?php esc_html_e('Home', '${td}'); ?></a>
664
+ <a class="inline-flex items-center justify-center rounded-md border border-input bg-background px-4 py-2 text-sm font-medium" href="<?php echo esc_url(home_url('/shop')); ?>"><?php esc_html_e('Shop', '${td}'); ?></a>
665
+ </div>
666
+ </div>
667
+ <?php
668
+ get_footer();
669
+ `;
670
+ }
671
+
672
+ export function buildBuilderPageCanvasPhp() {
673
+ return `$forgewp_hide_title = function_exists('forgewp_should_hide_page_title')
674
+ ? forgewp_should_hide_page_title(get_the_ID())
675
+ : true;
676
+ echo '<main class="forgewp-builder-canvas">';
677
+ if (!$forgewp_hide_title) {
678
+ echo '<div class="forgewp-content-width">';
679
+ echo '<h1 class="text-4xl font-bold mb-6">' . get_the_title() . '</h1>';
680
+ echo '</div>';
681
+ }
682
+ the_content();
683
+ echo '</main>';`;
684
+ }
685
+
686
+ export function buildGeneratedPageTemplateContentPhp(staticMarkupFile) {
687
+ return `if (have_posts()) {
688
+ while (have_posts()) {
689
+ the_post();
690
+ if (get_page_template_slug(get_the_ID()) === 'template-forgewp-builder.php') {
691
+ ${buildBuilderPageCanvasPhp()}
692
+ } else {
693
+ $markup_file = get_template_directory() . '/${staticMarkupFile}';
694
+ if (file_exists($markup_file)) {
695
+ include $markup_file;
696
+ }
697
+ }
698
+ }
699
+ }`;
700
+ }
701
+
702
+ export function buildBuilderPagePhp() {
703
+ return `<?php
704
+ /**
705
+ * Template Name: ForgeWP Builder
706
+ * Description: High-fidelity layout canvas for ForgeWP Gutenberg blocks.
707
+ *
708
+ * @package forgewp
709
+ */
710
+
711
+ get_header();
712
+
713
+ if (have_posts()) {
714
+ while (have_posts()) {
715
+ the_post();
716
+ ${buildBuilderPageCanvasPhp()}
717
+ }
718
+ }
719
+
720
+ get_footer();
721
+ `;
722
+ }