@forgewp/compiler 0.4.2 → 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.
- package/README.md +70 -3
- package/bin/add.js +30 -15
- package/bin/analyze.js +66 -1
- package/bin/cli.js +149 -70
- package/bin/doctor.js +21 -12
- package/bin/export.js +69 -20
- package/bin/fresh.js +6 -1
- package/bin/i18n-extract.js +3 -10
- package/bin/i18n-translate.js +15 -24
- package/bin/make-block.js +24 -0
- package/bin/make-editable.js +166 -0
- package/bin/make-form.js +131 -0
- package/bin/make-island.js +11 -0
- package/bin/make-loop.js +147 -0
- package/bin/make-mail.js +27 -0
- package/bin/make-page.js +83 -0
- package/bin/make-post-type.js +68 -29
- package/bin/make-sandbox.js +609 -0
- package/bin/make-section.js +221 -0
- package/bin/make-shell.js +375 -0
- package/bin/repair.js +14 -26
- package/bin/seed.js +119 -0
- package/bin/sync-routes.js +107 -85
- package/lib/adapters/html-adapter.js +13 -3
- package/lib/adapters/stub-adapter.js +10 -2
- package/lib/add-component.js +153 -92
- package/lib/asset-loader.js +333 -1
- package/lib/assets/asset-graph.js +432 -0
- package/lib/assets/asset-pipeline.js +125 -0
- package/lib/assets/diagnostics-report.js +345 -0
- package/lib/assets/external-fetcher.js +173 -0
- package/lib/assets/font-orchestrator.js +348 -0
- package/lib/assets/font-usage-scanner.js +242 -0
- package/lib/assets/image-optimizer.js +229 -0
- package/lib/assets/index.js +51 -0
- package/lib/assets/preload-generator.js +70 -0
- package/lib/assets/public-url.js +153 -0
- package/lib/block-authoring-help.js +11 -0
- package/lib/blocks/ast-parser.js +67 -0
- package/lib/blocks/discover-blocks.js +146 -0
- package/lib/blocks/editor-scope.js +733 -0
- package/lib/blocks/editor-transpiler.js +1229 -0
- package/lib/blocks/index.js +2838 -0
- package/lib/blocks/php-transpiler.js +4928 -0
- package/lib/blocks/scanner.js +1487 -0
- package/lib/blocks/shared-utils.js +290 -0
- package/lib/blocks/source-sanitize.js +1449 -0
- package/lib/blueprints.js +77 -5
- package/lib/build-assets.js +38 -33
- package/lib/collect-page-template-routes.js +102 -0
- package/lib/collect-static-routes.js +175 -0
- package/lib/diagnostics.js +58 -33
- package/lib/export-theme.js +84 -5
- package/lib/extract-template-content.js +90 -0
- package/lib/forms-preview.js +42 -0
- package/lib/functions/cpt-routing.js +69 -0
- package/lib/functions/forms.js +2461 -0
- package/lib/functions/hydration-enqueuer.js +400 -0
- package/lib/functions/index.js +1623 -0
- package/lib/functions/load-menus.js +112 -0
- package/lib/functions/load-translations.js +148 -0
- package/lib/functions/rest-endpoints.js +2923 -0
- package/lib/functions/routing.js +765 -0
- package/lib/functions/seed-mock-data.js +392 -0
- package/lib/functions/seed-products.js +481 -0
- package/lib/functions/settings-page.js +273 -0
- package/lib/functions/theme-setup.js +494 -0
- package/lib/generate-theme.js +2076 -303
- package/lib/hydration/editable-schemas.js +332 -0
- package/lib/hydration/enter-hidden-initial.js +65 -0
- package/lib/hydration/form-schemas.js +227 -0
- package/lib/hydration/index.js +12 -0
- package/lib/hydration/is-interactive.js +951 -0
- package/lib/hydration/island-split.js +1231 -0
- package/lib/hydration/islands-scanner.js +599 -0
- package/lib/hydration/resolve-island-chunk.js +103 -0
- package/lib/hydration/resolve-island-component.js +52 -0
- package/lib/hydration/rollup-inputs.js +81 -0
- package/lib/hydration/root-class-extractor.js +220 -0
- package/lib/hydration/scan-app-providers.js +154 -0
- package/lib/hydration/static-lint.js +382 -0
- package/lib/hydration/transform.js +257 -0
- package/lib/hydration/uses-block-area.js +49 -0
- package/lib/hydration/utils.js +119 -0
- package/lib/i18n/translation-cache.js +141 -0
- package/lib/icon-registry.js +72 -0
- package/lib/index.d.ts +324 -8
- package/lib/index.js +3 -2
- package/lib/load-config.js +338 -144
- package/lib/mail-templates.js +37 -0
- package/lib/markup-processor.js +483 -92
- package/lib/node-runtime.js +7 -0
- package/lib/page-config-plugin.js +84 -0
- package/lib/php-builders.js +383 -42
- package/lib/react-adapter.js +1053 -246
- package/lib/registration-metadata.js +11 -0
- package/lib/render-theme.mts +1410 -543
- package/lib/route-layout.js +76 -0
- package/lib/template-discovery.js +58 -0
- package/lib/theme-compatibility.js +32 -0
- package/lib/validate-export.js +51 -2
- package/lib/validate.js +27 -5
- package/lib/virtual-plugin.js +319 -0
- package/lib/walkthrough.md +26 -0
- package/package.json +17 -5
- package/templates/PresetsStyle.tsx +1 -1
- package/templates/auth/cms/email-logs.json +9 -0
- package/templates/auth/cms/menus.json +11 -0
- package/templates/auth/cms/mock-data.json +123 -0
- package/templates/auth/cms/roles.json +7 -0
- package/templates/auth/cms/sessions.json +1 -0
- package/templates/auth/cms/site-settings.json +28 -0
- package/templates/auth/cms/translations.json +4 -0
- package/templates/auth/cms/users.json +46 -0
- package/templates/auth/components/dashboard-view-wrapper.tsx +168 -0
- package/templates/auth/components/forgot-password-form-wrapper.tsx +141 -0
- package/templates/auth/components/login-form-wrapper.tsx +300 -0
- package/templates/auth/components/reset-password-form-wrapper.tsx +190 -0
- package/templates/auth/components/signup-form-wrapper.tsx +257 -0
- package/templates/auth/components/verify-email-view-wrapper.tsx +265 -0
- package/templates/auth/pages/DashboardPage.tsx +12 -0
- package/templates/auth/pages/ForgotPasswordPage.tsx +11 -0
- package/templates/auth/pages/LoginPage.tsx +11 -0
- package/templates/auth/pages/ResetPasswordPage.tsx +11 -0
- package/templates/auth/pages/SignUpPage.tsx +11 -0
- package/templates/auth/pages/VerifyEmailPage.tsx +11 -0
- package/templates/auth/ui/button.tsx +57 -0
- package/templates/auth/ui/card.tsx +76 -0
- package/templates/auth/ui/field.tsx +242 -0
- package/templates/auth/ui/input.tsx +22 -0
- package/templates/auth/ui/label.tsx +24 -0
- package/templates/auth/ui/separator.tsx +31 -0
- package/templates/forgewp-config.ts +70 -3
- package/templates/menus.json +12 -10
- package/templates/mock-data.json +122 -433
- package/templates/products.json +5 -0
- package/templates/roles.json +7 -0
- package/templates/sessions.json +1 -0
- package/templates/users.json +38 -0
- package/templates/wordpress.tsx +1835 -1297
- package/bin/make-template.js +0 -145
- package/lib/block-compiler.js +0 -552
- package/lib/functions-builder.js +0 -2044
- package/lib/hydration-scanner.js +0 -821
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export const SUPPORTED_NODE_RANGE = '^22.18.0 || >=24.11.0';
|
|
2
|
+
|
|
3
|
+
export function isSupportedNode(version = process.versions.node) {
|
|
4
|
+
if (!/^\d+\.\d+\.\d+$/.test(version)) return false;
|
|
5
|
+
const [major, minor] = version.split('.').map(Number);
|
|
6
|
+
return (major === 22 && minor >= 18) || (major === 24 && minor >= 11) || major > 24;
|
|
7
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { transformThemeFile } from './hydration/index.js';
|
|
2
|
+
import { scanAndGenerateBlocks } from './blocks/index.js';
|
|
3
|
+
import { splitInteractiveIslands } from './hydration/island-split.js';
|
|
4
|
+
import { hasContentOverride, readComponentSource } from './hydration/is-interactive.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Custom Vite Plugin to statically parse "export const pageConfig = { ... }" configs in pages,
|
|
8
|
+
* and dynamically inject useWpPageProtect(pageConfig) hook call at component startup.
|
|
9
|
+
*
|
|
10
|
+
* It also automatically detects interactive components inside static parents and wraps them in
|
|
11
|
+
* <Hydrate> (automatic island detection) and wraps them in <WpAuthProvider> if they use auth hooks.
|
|
12
|
+
*/
|
|
13
|
+
export function forgewpPageConfigPlugin() {
|
|
14
|
+
let themeRoot = process.cwd();
|
|
15
|
+
return {
|
|
16
|
+
name: 'forgewp-page-config',
|
|
17
|
+
configResolved(config) {
|
|
18
|
+
themeRoot = config.root;
|
|
19
|
+
},
|
|
20
|
+
buildStart() {
|
|
21
|
+
// Must run BEFORE scanAndGenerateBlocks and before Rollup resolves its
|
|
22
|
+
// entry inputs (getHydrationRollupInputs / islands-scanner.js's Smart
|
|
23
|
+
// Discovery scan the filesystem) — any auto-split island file needs to
|
|
24
|
+
// exist on disk by then to be picked up as its own build entry.
|
|
25
|
+
try {
|
|
26
|
+
splitInteractiveIslands(themeRoot);
|
|
27
|
+
} catch (err) {
|
|
28
|
+
console.error('[ForgeWP Compiler] Error running splitInteractiveIslands at build start:', err.message);
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
scanAndGenerateBlocks(themeRoot);
|
|
32
|
+
} catch (err) {
|
|
33
|
+
console.error('[ForgeWP Compiler] Error running scanAndGenerateBlocks at build start:', err.message);
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
transform(code, id) {
|
|
37
|
+
const normalizedPath = id.replace(/\\/g, '/');
|
|
38
|
+
if (normalizedPath.includes('node_modules')) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const fileThemeRoot = normalizedPath.includes('/src/')
|
|
43
|
+
? id.substring(0, normalizedPath.indexOf('/src/'))
|
|
44
|
+
: themeRoot;
|
|
45
|
+
|
|
46
|
+
// If this file was auto-split, substitute the static shell for the raw
|
|
47
|
+
// code Vite just read from disk BEFORE anything below runs — every
|
|
48
|
+
// downstream step (the @forgewp-block re-scan, transformThemeFile's
|
|
49
|
+
// Hydrate auto-wrap, and the final returned module code) must see the
|
|
50
|
+
// shell, not the dev's original, still-fully-interactive file content.
|
|
51
|
+
// Only substitute when THIS path has an actual registered override —
|
|
52
|
+
// never infer one from "a fresh disk read differs from what Vite gave
|
|
53
|
+
// us," since Vite's own code may already be preprocessed by an earlier
|
|
54
|
+
// plugin (that alone would look like a difference for every file, not
|
|
55
|
+
// just split ones, and reverting it breaks Rollup's import analysis).
|
|
56
|
+
let effectiveCode = code;
|
|
57
|
+
if (hasContentOverride(id)) {
|
|
58
|
+
try {
|
|
59
|
+
effectiveCode = readComponentSource(id);
|
|
60
|
+
} catch {}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Trigger real-time block generation if the edited file defines a block
|
|
64
|
+
if (effectiveCode.includes('@forgewp-block')) {
|
|
65
|
+
try {
|
|
66
|
+
scanAndGenerateBlocks(fileThemeRoot);
|
|
67
|
+
} catch (err) {
|
|
68
|
+
console.error('[ForgeWP Compiler] Error running scanAndGenerateBlocks during transform:', err.message);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
try {
|
|
73
|
+
const transformed = transformThemeFile(effectiveCode, id, fileThemeRoot);
|
|
74
|
+
if (transformed !== code) {
|
|
75
|
+
return { code: transformed, map: null };
|
|
76
|
+
}
|
|
77
|
+
} catch (err) {
|
|
78
|
+
console.error(`[ForgeWP Compiler] Error transforming ${id}:`, err);
|
|
79
|
+
}
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
package/lib/php-builders.js
CHANGED
|
@@ -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:
|
|
15
|
-
Tested up to:
|
|
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
|
|
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]) =>
|
|
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
|
-
|
|
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 =
|
|
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
|
-
|
|
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
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
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,8 +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
|
-
|
|
175
|
-
a:hover { text-decoration: none !important; }
|
|
270
|
+
${LINK_RESET_CSS}
|
|
176
271
|
</style>
|
|
177
272
|
</head>
|
|
178
273
|
<body <?php body_class(); ?>>
|
|
@@ -204,32 +299,183 @@ wp_footer();
|
|
|
204
299
|
`;
|
|
205
300
|
}
|
|
206
301
|
|
|
207
|
-
|
|
302
|
+
function shellOwnedFrontPagePhp() {
|
|
208
303
|
return `<?php
|
|
209
304
|
/**
|
|
210
|
-
*
|
|
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.
|
|
211
417
|
*
|
|
212
418
|
* @package forgewp
|
|
213
419
|
*/
|
|
214
420
|
|
|
215
421
|
get_header();
|
|
216
422
|
|
|
217
|
-
$
|
|
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
|
+
}
|
|
218
443
|
|
|
219
|
-
if (
|
|
220
|
-
include $markup_file;
|
|
221
|
-
} elseif (have_posts()) {
|
|
222
|
-
echo '<main class="mx-auto max-w-3xl px-6 py-12">';
|
|
444
|
+
if ($forgewp_use_builder && have_posts()) {
|
|
223
445
|
while (have_posts()) {
|
|
224
446
|
the_post();
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
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
|
+
}
|
|
228
456
|
the_content();
|
|
229
|
-
echo '</
|
|
230
|
-
|
|
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>';
|
|
231
478
|
}
|
|
232
|
-
echo '</main>';
|
|
233
479
|
}
|
|
234
480
|
|
|
235
481
|
get_footer();
|
|
@@ -258,10 +504,12 @@ if (file_exists($single_file)) {
|
|
|
258
504
|
if (have_posts()) {
|
|
259
505
|
while (have_posts()) {
|
|
260
506
|
the_post();
|
|
261
|
-
echo '<main class="
|
|
507
|
+
echo '<main class="px-6 py-12">';
|
|
262
508
|
echo '<article>';
|
|
509
|
+
echo '<div class="forgewp-content-width">';
|
|
263
510
|
echo '<h1 class="text-4xl font-bold mb-6">' . get_the_title() . '</h1>';
|
|
264
|
-
echo '
|
|
511
|
+
echo '</div>';
|
|
512
|
+
echo '<div class="forgewp-content-width prose prose-zinc max-w-none">';
|
|
265
513
|
the_content();
|
|
266
514
|
echo '</div>';
|
|
267
515
|
echo '</article>';
|
|
@@ -315,7 +563,7 @@ $archive_file = get_template_directory() . '/forgewp-static/archive.html';
|
|
|
315
563
|
if (file_exists($archive_file)) {
|
|
316
564
|
include $archive_file;
|
|
317
565
|
} else {
|
|
318
|
-
echo '<main class="
|
|
566
|
+
echo '<main class="forgewp-content-width px-6 py-12">';
|
|
319
567
|
the_archive_title('<h1 class="text-3xl font-bold mb-8">', '</h1>');
|
|
320
568
|
if (have_posts()) {
|
|
321
569
|
echo '<div class="space-y-8">';
|
|
@@ -364,10 +612,17 @@ if (file_exists($page_file)) {
|
|
|
364
612
|
if (have_posts()) {
|
|
365
613
|
while (have_posts()) {
|
|
366
614
|
the_post();
|
|
367
|
-
|
|
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">';
|
|
368
619
|
echo '<article>';
|
|
369
|
-
|
|
370
|
-
|
|
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">';
|
|
371
626
|
the_content();
|
|
372
627
|
echo '</div>';
|
|
373
628
|
echo '</article>';
|
|
@@ -379,3 +634,89 @@ if (file_exists($page_file)) {
|
|
|
379
634
|
get_footer();
|
|
380
635
|
`;
|
|
381
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
|
+
}
|