@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,494 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { generateDynamicAcfFieldPhp } from '../php-builders.js';
|
|
4
|
+
|
|
5
|
+
export function buildThemeSetupPhp(
|
|
6
|
+
config,
|
|
7
|
+
schemas,
|
|
8
|
+
registeredTaxonomies,
|
|
9
|
+
postTypes,
|
|
10
|
+
uniqueMetaKeys,
|
|
11
|
+
metaKeyTypes,
|
|
12
|
+
metaKeysToSkip,
|
|
13
|
+
socialKeys,
|
|
14
|
+
defaultPasswordResetEmailSubject,
|
|
15
|
+
defaultPasswordResetEmailBody,
|
|
16
|
+
defaultVerificationEmailSubject,
|
|
17
|
+
defaultVerificationEmailBody,
|
|
18
|
+
defaultLoginField,
|
|
19
|
+
defaultEmailVerificationEnabled,
|
|
20
|
+
defaultRegistrationEnabled,
|
|
21
|
+
defaultBlockLoginUntilVerified,
|
|
22
|
+
menus = {}
|
|
23
|
+
) {
|
|
24
|
+
const version = config.version.replace(/'/g, "\\'");
|
|
25
|
+
const googleFonts = config.settings?.typography?.googleFonts || [];
|
|
26
|
+
|
|
27
|
+
// Menus
|
|
28
|
+
const navMenuLines = [];
|
|
29
|
+
const registeredLocations = new Set();
|
|
30
|
+
|
|
31
|
+
if (config.settings?.menus) {
|
|
32
|
+
for (const [location, details] of Object.entries(config.settings.menus)) {
|
|
33
|
+
const description = details.description || `${location} menu`;
|
|
34
|
+
navMenuLines.push(` '${location}' => __('${description.replace(/'/g, "\\'")}', '${config.textDomain}'),`);
|
|
35
|
+
registeredLocations.add(location);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (menus) {
|
|
40
|
+
for (const location of Object.keys(menus)) {
|
|
41
|
+
if (location.startsWith('_')) continue;
|
|
42
|
+
if (registeredLocations.has(location)) continue;
|
|
43
|
+
|
|
44
|
+
const description = `${location.charAt(0).toUpperCase() + location.slice(1)} Navigation`;
|
|
45
|
+
navMenuLines.push(` '${location}' => __('${description}', '${config.textDomain}'),`);
|
|
46
|
+
registeredLocations.add(location);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const menuRegistration = navMenuLines.length > 0
|
|
51
|
+
? `register_nav_menus(array(
|
|
52
|
+
${navMenuLines.join('\n')}
|
|
53
|
+
));`
|
|
54
|
+
: '';
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
// Fonts enqueuing (self-hosted WOFF2 with remote fallback)
|
|
58
|
+
const fontConfig = config.fonts?.google || config.settings?.typography?.googleFonts || [];
|
|
59
|
+
const googleFontsList = Array.isArray(fontConfig) ? fontConfig : (fontConfig.families || []);
|
|
60
|
+
let fontsEnqueueCode = '';
|
|
61
|
+
|
|
62
|
+
if (googleFontsList.length > 0) {
|
|
63
|
+
const fontFamilies = googleFontsList.map(f => {
|
|
64
|
+
if (typeof f === 'string') {
|
|
65
|
+
return f.replace(/\s+/g, '+');
|
|
66
|
+
}
|
|
67
|
+
if (f && typeof f === 'object') {
|
|
68
|
+
const name = (f.family || '').replace(/\s+/g, '+');
|
|
69
|
+
const weights = f.weights ? `:${f.weights.join(',')}` : '';
|
|
70
|
+
return `${name}${weights}`;
|
|
71
|
+
}
|
|
72
|
+
return '';
|
|
73
|
+
}).filter(Boolean).join('&family=');
|
|
74
|
+
|
|
75
|
+
fontsEnqueueCode = `
|
|
76
|
+
// Load custom typography (prefers local self-hosted WOFF2, falls back to remote)
|
|
77
|
+
$fonts_file = get_template_directory() . '/assets/fonts/fonts.css';
|
|
78
|
+
if (file_exists($fonts_file)) {
|
|
79
|
+
wp_enqueue_style(
|
|
80
|
+
'forgewp-fonts',
|
|
81
|
+
get_theme_file_uri('assets/fonts/fonts.css'),
|
|
82
|
+
array(),
|
|
83
|
+
filemtime($fonts_file)
|
|
84
|
+
);
|
|
85
|
+
} elseif ( ! empty('${fontFamilies}') ) {
|
|
86
|
+
wp_enqueue_style(
|
|
87
|
+
'forgewp-google-fonts',
|
|
88
|
+
'https://fonts.googleapis.com/css2?family=${fontFamilies}&display=swap',
|
|
89
|
+
array(),
|
|
90
|
+
null
|
|
91
|
+
);
|
|
92
|
+
}`;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Dashicons on the frontend so WpIcon provider="dashicons" (and Lucide miss fallbacks) paint
|
|
96
|
+
fontsEnqueueCode += `
|
|
97
|
+
wp_enqueue_style('dashicons');
|
|
98
|
+
`;
|
|
99
|
+
|
|
100
|
+
// Favicon dynamic registration
|
|
101
|
+
let faviconPhp = '';
|
|
102
|
+
if (config.favicon) {
|
|
103
|
+
const faviconPath = config.favicon.replace(/^\//, ''); // Clean leading slash
|
|
104
|
+
faviconPhp = `
|
|
105
|
+
/**
|
|
106
|
+
* Enqueue Favicon dynamically in WordPress head (generated from wp.config.ts).
|
|
107
|
+
*/
|
|
108
|
+
function forgewp_add_favicon() {
|
|
109
|
+
$uri = get_template_directory_uri() . '/${faviconPath}';
|
|
110
|
+
$ext = strtolower(pathinfo($uri, PATHINFO_EXTENSION));
|
|
111
|
+
$type = 'image/x-icon';
|
|
112
|
+
if ($ext === 'svg') {
|
|
113
|
+
$type = 'image/svg+xml';
|
|
114
|
+
} elseif ($ext === 'png') {
|
|
115
|
+
$type = 'image/png';
|
|
116
|
+
} elseif ($ext === 'gif') {
|
|
117
|
+
$type = 'image/gif';
|
|
118
|
+
} elseif ($ext === 'jpg' || $ext === 'jpeg') {
|
|
119
|
+
$type = 'image/jpeg';
|
|
120
|
+
}
|
|
121
|
+
echo '<link rel="icon" type="' . esc_attr($type) . '" href="' . esc_url($uri) . '">';
|
|
122
|
+
}
|
|
123
|
+
add_action('wp_head', 'forgewp_add_favicon');
|
|
124
|
+
`;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// XML Segmented Sitemaps
|
|
128
|
+
let sitemapsPhp = '';
|
|
129
|
+
if (config.seo && config.seo.sitemaps) {
|
|
130
|
+
const { postTypes = [], taxonomies = [] } = config.seo.sitemaps;
|
|
131
|
+
let postTypesLines = '';
|
|
132
|
+
for (const pt of postTypes) {
|
|
133
|
+
postTypesLines += ` $post_types['${pt}'] = get_post_type_object('${pt}');\n`;
|
|
134
|
+
}
|
|
135
|
+
let taxonomiesLines = '';
|
|
136
|
+
for (const tax of taxonomies) {
|
|
137
|
+
taxonomiesLines += ` $taxonomies['${tax}'] = get_taxonomy('${tax}');\n`;
|
|
138
|
+
}
|
|
139
|
+
sitemapsPhp = `
|
|
140
|
+
/**
|
|
141
|
+
* Custom XML Segmented Sitemaps Configuration (generated from wp.config.ts).
|
|
142
|
+
*/
|
|
143
|
+
function forgewp_register_segmented_xml_sitemaps() {
|
|
144
|
+
if (!function_exists('wp_sitemaps_get_server')) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
if (forgewp_seo_plugin_active()) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
add_filter('wp_sitemaps_post_types', function($post_types) {
|
|
151
|
+
${postTypesLines} return $post_types;
|
|
152
|
+
});
|
|
153
|
+
add_filter('wp_sitemaps_taxonomies', function($taxonomies) {
|
|
154
|
+
${taxonomiesLines} return $taxonomies;
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
add_action('init', 'forgewp_register_segmented_xml_sitemaps', 99);
|
|
158
|
+
`;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// CPT Meta field registrations (Tier 2)
|
|
162
|
+
let nativeMetaRegisters = '';
|
|
163
|
+
if (uniqueMetaKeys.size > 0) {
|
|
164
|
+
const metaArray = Array.from(uniqueMetaKeys);
|
|
165
|
+
const ptListStr = postTypes.length > 0 ? postTypes.map(pt => `'${pt}'`).join(', ') : '';
|
|
166
|
+
const allPtExpr = ptListStr ? `array_merge(array('post', 'page'), array(${ptListStr}))` : `array('post', 'page')`;
|
|
167
|
+
|
|
168
|
+
nativeMetaRegisters = `
|
|
169
|
+
/**
|
|
170
|
+
* Register native post meta fields for all templates (Tier 2 Structured Content).
|
|
171
|
+
*
|
|
172
|
+
* These same keys are also exposed via ACF local field groups (Tier 3, see
|
|
173
|
+
* forgewp_register_acf_field_groups()) whenever ACF is active, and ACF registers its
|
|
174
|
+
* own REST meta exposure for 'show_in_rest' field groups. Registering the same
|
|
175
|
+
* object_type + meta_key twice (once here, once via ACF) creates two competing REST
|
|
176
|
+
* meta registrations that WordPress does not support — the block editor's Document
|
|
177
|
+
* sidebar / meta panel then fails to save with "Could not update the meta value of
|
|
178
|
+
* X in database." This Tier 2 registration is therefore only a fallback for sites
|
|
179
|
+
* without ACF installed; when ACF is active, it defers entirely to Tier 3.
|
|
180
|
+
*/
|
|
181
|
+
function forgewp_register_custom_post_meta(): void {
|
|
182
|
+
if (function_exists('acf_add_local_field_group')) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
$post_types = ${allPtExpr};
|
|
186
|
+
foreach ($post_types as $pt) {
|
|
187
|
+
${metaArray.filter(key => !metaKeysToSkip.has(key)).map(key => {
|
|
188
|
+
const phpType = metaKeyTypes[key];
|
|
189
|
+
return ` register_post_meta($pt, '${key}', array(
|
|
190
|
+
'show_in_rest' => true,
|
|
191
|
+
'single' => true,
|
|
192
|
+
'type' => '${phpType}',
|
|
193
|
+
));`;
|
|
194
|
+
}).join('\n')}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
add_action('init', 'forgewp_register_custom_post_meta');
|
|
198
|
+
`;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// ACF Local Field Groups (Tier 3)
|
|
202
|
+
let acfFieldGroups = '';
|
|
203
|
+
if (Object.keys(schemas).length > 0 || registeredTaxonomies.length > 0) {
|
|
204
|
+
const groups = [];
|
|
205
|
+
for (const [templateSlug, schema] of Object.entries(schemas)) {
|
|
206
|
+
const groupKey = `group_${templateSlug.replace(/-/g, '_')}`;
|
|
207
|
+
const groupTitle = templateSlug.split('-').map(w => w.charAt(0).toUpperCase() + w.slice(1)).join(' ') + ' Content';
|
|
208
|
+
|
|
209
|
+
let fieldsPhp = ' $fields = array();\n';
|
|
210
|
+
for (const [key, field] of Object.entries(schema)) {
|
|
211
|
+
fieldsPhp += generateDynamicAcfFieldPhp(key, field, templateSlug);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
let locationRule = '';
|
|
215
|
+
if (templateSlug === 'front-page') {
|
|
216
|
+
locationRule = `array(
|
|
217
|
+
array(
|
|
218
|
+
array(
|
|
219
|
+
'param' => 'page_type',
|
|
220
|
+
'operator' => '==',
|
|
221
|
+
'value' => 'front_page',
|
|
222
|
+
),
|
|
223
|
+
),
|
|
224
|
+
)`;
|
|
225
|
+
} else if (templateSlug.startsWith('single-')) {
|
|
226
|
+
let postType = templateSlug.replace('single-', '');
|
|
227
|
+
if (postType.endsWith('-page')) {
|
|
228
|
+
postType = postType.slice(0, -5);
|
|
229
|
+
}
|
|
230
|
+
locationRule = `array(
|
|
231
|
+
array(
|
|
232
|
+
array(
|
|
233
|
+
'param' => 'post_type',
|
|
234
|
+
'operator' => '==',
|
|
235
|
+
'value' => '${postType}',
|
|
236
|
+
),
|
|
237
|
+
),
|
|
238
|
+
)`;
|
|
239
|
+
} else {
|
|
240
|
+
const pageTemplateName = `page-${templateSlug}.php`;
|
|
241
|
+
locationRule = `array(
|
|
242
|
+
array(
|
|
243
|
+
array(
|
|
244
|
+
'param' => 'page_template',
|
|
245
|
+
'operator' => '==',
|
|
246
|
+
'value' => '${pageTemplateName}',
|
|
247
|
+
),
|
|
248
|
+
),
|
|
249
|
+
)`;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
groups.push(` ${fieldsPhp}
|
|
253
|
+
acf_add_local_field_group(array(
|
|
254
|
+
'key' => '${groupKey}',
|
|
255
|
+
'title' => '${groupTitle}',
|
|
256
|
+
'fields' => $fields,
|
|
257
|
+
'location' => ${locationRule},
|
|
258
|
+
'menu_order' => 0,
|
|
259
|
+
'position' => 'normal',
|
|
260
|
+
'style' => 'default',
|
|
261
|
+
'label_placement' => 'top',
|
|
262
|
+
'instruction_placement' => 'label',
|
|
263
|
+
'hide_on_screen' => '',
|
|
264
|
+
'active' => true,
|
|
265
|
+
'description' => 'Colocated React structured content fields managed by ForgeWP.',
|
|
266
|
+
'show_in_rest' => true,
|
|
267
|
+
));`);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
for (const tax of registeredTaxonomies) {
|
|
271
|
+
const taxGroupKey = `group_taxonomy_${tax}`;
|
|
272
|
+
const taxGroupTitle = tax.split(/[_-]/).map(w => w.charAt(0).toUpperCase() + w.slice(1)).join(' ') + ' Settings';
|
|
273
|
+
groups.push(` // Custom fields for taxonomy: ${tax}
|
|
274
|
+
acf_add_local_field_group(array(
|
|
275
|
+
'key' => '${taxGroupKey}',
|
|
276
|
+
'title' => '${taxGroupTitle}',
|
|
277
|
+
'fields' => array(
|
|
278
|
+
array(
|
|
279
|
+
'key' => 'field_${tax}_featured_image',
|
|
280
|
+
'label' => 'Featured Image',
|
|
281
|
+
'name' => 'featured_image',
|
|
282
|
+
'type' => 'image',
|
|
283
|
+
'instructions' => 'Set the cover/featured image for this term.',
|
|
284
|
+
'required' => 0,
|
|
285
|
+
'conditional_logic' => 0,
|
|
286
|
+
'return_format' => 'url',
|
|
287
|
+
'preview_size' => 'medium',
|
|
288
|
+
'library' => 'all',
|
|
289
|
+
),
|
|
290
|
+
array(
|
|
291
|
+
'key' => 'field_${tax}_flag',
|
|
292
|
+
'label' => 'Flag Emoji',
|
|
293
|
+
'name' => 'flag',
|
|
294
|
+
'type' => 'text',
|
|
295
|
+
'instructions' => 'Set the flag emoji or brief code for this term (e.g. 🇩🇪 or DE).',
|
|
296
|
+
'required' => 0,
|
|
297
|
+
'conditional_logic' => 0,
|
|
298
|
+
'default_value' => '🌍',
|
|
299
|
+
),
|
|
300
|
+
),
|
|
301
|
+
'location' => array(
|
|
302
|
+
array(
|
|
303
|
+
array(
|
|
304
|
+
'param' => 'taxonomy',
|
|
305
|
+
'operator' => '==',
|
|
306
|
+
'value' => '${tax}',
|
|
307
|
+
),
|
|
308
|
+
),
|
|
309
|
+
),
|
|
310
|
+
'menu_order' => 0,
|
|
311
|
+
'position' => 'normal',
|
|
312
|
+
'style' => 'default',
|
|
313
|
+
'label_placement' => 'top',
|
|
314
|
+
'instruction_placement' => 'label',
|
|
315
|
+
'hide_on_screen' => '',
|
|
316
|
+
'active' => true,
|
|
317
|
+
'show_in_rest' => true,
|
|
318
|
+
));`);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
acfFieldGroups = `
|
|
322
|
+
/**
|
|
323
|
+
* Register Advanced Custom Fields (ACF) local field groups (Tier 3 Interoperability Presentation).
|
|
324
|
+
*/
|
|
325
|
+
function forgewp_register_acf_field_groups(): void {
|
|
326
|
+
if ( ! function_exists('acf_add_local_field_group') ) {
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
${groups.join('\n\n')}
|
|
331
|
+
}
|
|
332
|
+
add_action('acf/init', 'forgewp_register_acf_field_groups');
|
|
333
|
+
`;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// Social settings section customizer controls
|
|
337
|
+
let socialSettingsPhp = '';
|
|
338
|
+
for (const key of socialKeys) {
|
|
339
|
+
const optionName = `social_${key}`;
|
|
340
|
+
const capitalizedLabel = key.split('_').map(w => w.charAt(0).toUpperCase() + w.slice(1)).join(' ');
|
|
341
|
+
socialSettingsPhp += `
|
|
342
|
+
// ${optionName}
|
|
343
|
+
$wp_customize->add_setting(
|
|
344
|
+
'${optionName}',
|
|
345
|
+
array(
|
|
346
|
+
'type' => 'option',
|
|
347
|
+
'default' => '',
|
|
348
|
+
'sanitize_callback' => 'esc_url_raw',
|
|
349
|
+
)
|
|
350
|
+
);
|
|
351
|
+
$wp_customize->add_control(
|
|
352
|
+
'${optionName}',
|
|
353
|
+
array(
|
|
354
|
+
'label' => __('${capitalizedLabel} URL', '${config.textDomain}'),
|
|
355
|
+
'section' => 'forgewp_social_section',
|
|
356
|
+
'type' => 'url',
|
|
357
|
+
)
|
|
358
|
+
);`;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
// Main theme setup block
|
|
362
|
+
const setupBlock = `
|
|
363
|
+
/**
|
|
364
|
+
* Dynamic WordPress Theme Setup & Configuration.
|
|
365
|
+
*/
|
|
366
|
+
if ( ! function_exists( 'forgewp_theme_setup' ) ) :
|
|
367
|
+
function forgewp_theme_setup() {
|
|
368
|
+
// Essential theme features
|
|
369
|
+
${config.presets?.wordpressCoreStyles === false ? '' : " add_theme_support( 'wp-block-styles' );\n"}
|
|
370
|
+
add_theme_support( 'post-thumbnails' );
|
|
371
|
+
add_theme_support( 'title-tag' );
|
|
372
|
+
add_theme_support( 'responsive-embeds' );
|
|
373
|
+
add_theme_support( 'html5', array( 'style', 'script' ) );
|
|
374
|
+
add_theme_support( 'align-wide' );
|
|
375
|
+
// Gates Appearance → Menus in wp-admin (current_theme_supports('menus')).
|
|
376
|
+
add_theme_support( 'menus' );
|
|
377
|
+
|
|
378
|
+
// Navigation menus
|
|
379
|
+
${menuRegistration}
|
|
380
|
+
}
|
|
381
|
+
endif;
|
|
382
|
+
add_action( 'after_setup_theme', 'forgewp_theme_setup' );
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* WordPress redirect_canonical() guesses 404s with post_name LIKE '{slug}%'.
|
|
386
|
+
* Visiting /about then 301s to /product/about-a-chair-aa51/ when no About page
|
|
387
|
+
* exists. Local React routing never fuzzy-matches like that.
|
|
388
|
+
*/
|
|
389
|
+
add_filter('do_redirect_guess_404_permalink', '__return_false');
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* Register core theme block categories.
|
|
393
|
+
*/
|
|
394
|
+
function forgewp_register_block_categories( $block_categories, $block_editor_context ) {
|
|
395
|
+
return array_merge(
|
|
396
|
+
$block_categories,
|
|
397
|
+
array(
|
|
398
|
+
array(
|
|
399
|
+
'slug' => 'forgewp-theme',
|
|
400
|
+
'title' => __( 'ForgeWP Theme Blocks', '${config.textDomain}' ),
|
|
401
|
+
'icon' => 'layout',
|
|
402
|
+
),
|
|
403
|
+
array(
|
|
404
|
+
'slug' => 'forgewp-design',
|
|
405
|
+
'title' => __( 'ForgeWP Design Blocks', '${config.textDomain}' ),
|
|
406
|
+
'icon' => 'art',
|
|
407
|
+
),
|
|
408
|
+
array(
|
|
409
|
+
'slug' => 'forgewp-content',
|
|
410
|
+
'title' => __( 'ForgeWP Content Blocks', '${config.textDomain}' ),
|
|
411
|
+
'icon' => 'welcome-write-blog',
|
|
412
|
+
),
|
|
413
|
+
)
|
|
414
|
+
);
|
|
415
|
+
}
|
|
416
|
+
add_filter( 'block_categories_all', 'forgewp_register_block_categories', 10, 2 );
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* Register Theme Options & Social Customizer section.
|
|
420
|
+
*/
|
|
421
|
+
function forgewp_customize_register( $wp_customize ) {
|
|
422
|
+
$wp_customize->add_section(
|
|
423
|
+
'forgewp_social_section',
|
|
424
|
+
array(
|
|
425
|
+
'title' => __('Social Media Accounts', '${config.textDomain}'),
|
|
426
|
+
'priority' => 30,
|
|
427
|
+
)
|
|
428
|
+
);
|
|
429
|
+
${socialSettingsPhp}
|
|
430
|
+
}
|
|
431
|
+
add_action( 'customize_register', 'forgewp_customize_register' );
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* Enqueue theme styles and Google Fonts dynamically.
|
|
435
|
+
*/
|
|
436
|
+
function forgewp_enqueue_theme_styles() {
|
|
437
|
+
wp_enqueue_style(
|
|
438
|
+
'forgewp-theme-styles',
|
|
439
|
+
get_template_directory_uri() . '/style.css',
|
|
440
|
+
array(),
|
|
441
|
+
FORGEWP_THEME_VERSION
|
|
442
|
+
);${fontsEnqueueCode}
|
|
443
|
+
}
|
|
444
|
+
add_action( 'wp_enqueue_scripts', 'forgewp_enqueue_theme_styles' );
|
|
445
|
+
add_action( 'enqueue_block_editor_assets', 'forgewp_enqueue_theme_styles' );
|
|
446
|
+
`;
|
|
447
|
+
|
|
448
|
+
// "Hide page title" toggle — Document sidebar checkbox (forgewp-editor.js) reads/writes
|
|
449
|
+
// this meta; page.php and template-forgewp-builder.php both check it before rendering
|
|
450
|
+
// the title, so title visibility is no longer implied by which template is selected.
|
|
451
|
+
const pageTitleMetaPhp = `
|
|
452
|
+
/**
|
|
453
|
+
* Register the "Hide page title" toggle exposed in the Page editor's Document sidebar.
|
|
454
|
+
*/
|
|
455
|
+
function forgewp_register_page_title_meta(): void {
|
|
456
|
+
register_post_meta('page', '_forgewp_hide_title', array(
|
|
457
|
+
'show_in_rest' => true,
|
|
458
|
+
'single' => true,
|
|
459
|
+
'type' => 'boolean',
|
|
460
|
+
// ForgeWP pages are block/section layouts — hide the core title by default.
|
|
461
|
+
'default' => true,
|
|
462
|
+
'auth_callback' => function() {
|
|
463
|
+
return current_user_can('edit_pages');
|
|
464
|
+
},
|
|
465
|
+
));
|
|
466
|
+
}
|
|
467
|
+
add_action('init', 'forgewp_register_page_title_meta');
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* Whether the page title should be hidden.
|
|
471
|
+
* Unset meta defaults to true (hide) to match the Document sidebar default.
|
|
472
|
+
*/
|
|
473
|
+
function forgewp_should_hide_page_title( $post_id = null ): bool {
|
|
474
|
+
$post_id = $post_id ? (int) $post_id : (int) get_the_ID();
|
|
475
|
+
if ( $post_id <= 0 ) {
|
|
476
|
+
return true;
|
|
477
|
+
}
|
|
478
|
+
if ( ! metadata_exists( 'post', $post_id, '_forgewp_hide_title' ) ) {
|
|
479
|
+
return true;
|
|
480
|
+
}
|
|
481
|
+
return (bool) get_post_meta( $post_id, '_forgewp_hide_title', true );
|
|
482
|
+
}
|
|
483
|
+
`;
|
|
484
|
+
|
|
485
|
+
return `
|
|
486
|
+
define('FORGEWP_THEME_VERSION', '${version}');
|
|
487
|
+
${setupBlock}
|
|
488
|
+
${faviconPhp}
|
|
489
|
+
${sitemapsPhp}
|
|
490
|
+
${nativeMetaRegisters}
|
|
491
|
+
${acfFieldGroups}
|
|
492
|
+
${pageTitleMetaPhp}
|
|
493
|
+
`;
|
|
494
|
+
}
|