PluginProbe
AI Builder – Generate pages, blocks, images & translate with AI / trunk
AI Builder – Generate pages, blocks, images & translate with AI vtrunk
2.7.9 2.7.8 2.0.8 2.0.9 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.3.0 2.3.10 2.3.11 All 121 releases
ai-builder / admin / pages / headers-footers.php

headers-footers.php in AI Builder – Generate pages, blocks, images & translate with AI trunk, at admin/pages/headers-footers.php

391 lines 14.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if (!defined('ABSPATH'))
3 exit;
4
5 $jwt_token = get_option('aibui_jwt_token', '');
6 if (empty($jwt_token)) {
7 echo '<div class="ai-auth-container"><div class="ai-message error">' . esc_html__('Please sign in to access the AI Builder settings.', 'ai-builder') . '</div></div>';
8 return;
9 }
10
11 $is_block_theme = function_exists('wp_is_block_theme') && wp_is_block_theme();
12 $current_theme = wp_get_theme();
13 $theme_name = $current_theme ? $current_theme->get('Name') : '';
14 $theme_slug = $current_theme ? $current_theme->get_stylesheet() : '';
15
16 $header_part = null;
17 $footer_part = null;
18 $header_edit_url = '';
19 $footer_edit_url = '';
20
21 if ($is_block_theme && function_exists('get_block_templates')) {
22 $header_parts = get_block_templates(array('area' => 'header'), 'wp_template_part');
23 $footer_parts = get_block_templates(array('area' => 'footer'), 'wp_template_part');
24
25 if (!empty($header_parts)) {
26 $header_part = $header_parts[0];
27 $header_edit_url = admin_url('site-editor.php?postType=wp_template_part&postId=' . str_replace('//', '%2F%2F', $header_part->id) . '&canvas=edit');
28 }
29 if (!empty($footer_parts)) {
30 $footer_part = $footer_parts[0];
31 $footer_edit_url = admin_url('site-editor.php?postType=wp_template_part&postId=' . str_replace('//', '%2F%2F', $footer_part->id) . '&canvas=edit');
32 }
33 }
34 ?>
35 <div class="wrap ai-builder-headers-footers">
36 <div class="ai-hf-container">
37
38 <div class="ai-hf-page-header">
39 <h1><?php esc_html_e('Headers & Footers', 'ai-builder'); ?></h1>
40 <p><?php esc_html_e('Generate a custom header and footer for your entire site with AI.', 'ai-builder'); ?></p>
41 </div>
42
43 <?php if (!$is_block_theme) : ?>
44 <!-- Non-FSE theme -->
45 <div class="ai-hf-notice ai-hf-notice-warning">
46 <svg width="22" height="22" viewBox="0 0 24 24" fill="none"><path d="M12 9v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>
47 <div>
48 <strong><?php printf(esc_html__('Your current theme (%s) is not a block theme (FSE).', 'ai-builder'), esc_html($theme_name)); ?></strong>
49 <p><?php esc_html_e('Header & footer generation requires a block theme (Full Site Editing). Switch to a block theme to unlock this feature.', 'ai-builder'); ?></p>
50 <p class="ai-hf-theme-suggestions">
51 <?php esc_html_e('Popular block themes:', 'ai-builder'); ?>
52 <span>Twenty Twenty-Five</span> · <span>Ollie</span> · <span>Spectra One</span> · <span>Raft</span>
53 </p>
54 <a href="<?php echo esc_url(admin_url('theme-install.php?browse=block-themes')); ?>" class="ai-hf-btn ai-hf-btn-outline" target="_blank">
55 <?php esc_html_e('Browse block themes →', 'ai-builder'); ?>
56 </a>
57 </div>
58 </div>
59 <?php else : ?>
60 <!-- FSE theme simplified flow -->
61
62 <!-- How it works -->
63 <div class="ai-hf-steps">
64 <div class="ai-hf-step">
65 <div class="ai-hf-step-num">1</div>
66 <div>
67 <strong><?php esc_html_e('Click "Edit with AI" below', 'ai-builder'); ?></strong>
68 <p><?php esc_html_e('This opens the Site Editor on your header or footer template part.', 'ai-builder'); ?></p>
69 </div>
70 </div>
71 <div class="ai-hf-step">
72 <div class="ai-hf-step-num">2</div>
73 <div>
74 <strong><?php esc_html_e('Describe what you want in the AI chat', 'ai-builder'); ?></strong>
75 <p><?php esc_html_e('Use the chat widget in the bottom-left corner (e.g. "Create a modern header with logo and navigation").', 'ai-builder'); ?></p>
76 </div>
77 </div>
78 <div class="ai-hf-step">
79 <div class="ai-hf-step-num">3</div>
80 <div>
81 <strong><?php esc_html_e('Save — it applies site-wide', 'ai-builder'); ?></strong>
82 <p><?php esc_html_e('Template parts are global: your header/footer will appear on every page automatically.', 'ai-builder'); ?></p>
83 </div>
84 </div>
85 </div>
86
87 <!-- Cards -->
88 <div class="ai-hf-cards">
89 <!-- Header card -->
90 <div class="ai-hf-card">
91 <div class="ai-hf-card-icon">
92 <svg width="28" height="28" viewBox="0 0 24 24" fill="none"><rect x="3" y="3" width="18" height="18" rx="2" stroke="currentColor" stroke-width="2"/><path d="M3 9h18" stroke="currentColor" stroke-width="2"/></svg>
93 </div>
94 <h2><?php esc_html_e('Header', 'ai-builder'); ?></h2>
95 <?php if ($header_part) : ?>
96 <span class="ai-hf-badge ai-hf-badge-ready"><?php esc_html_e('Ready to edit', 'ai-builder'); ?></span>
97 <p class="ai-hf-card-desc"><?php printf(esc_html__('Template part: %s', 'ai-builder'), '<code>' . esc_html($header_part->slug) . '</code>'); ?></p>
98 <a href="<?php echo esc_url($header_edit_url); ?>" class="ai-hf-btn ai-hf-btn-primary" target="_blank">
99 <?php esc_html_e('Edit with AI →', 'ai-builder'); ?>
100 </a>
101 <?php else : ?>
102 <span class="ai-hf-badge ai-hf-badge-missing"><?php esc_html_e('No template part found', 'ai-builder'); ?></span>
103 <p class="ai-hf-card-desc"><?php esc_html_e('Create a header template part to get started.', 'ai-builder'); ?></p>
104 <button class="ai-hf-btn ai-hf-btn-primary ai-hf-create-part" data-area="header">
105 <?php esc_html_e('Create & Edit with AI →', 'ai-builder'); ?>
106 </button>
107 <?php endif; ?>
108 </div>
109
110 <!-- Footer card -->
111 <div class="ai-hf-card">
112 <div class="ai-hf-card-icon">
113 <svg width="28" height="28" viewBox="0 0 24 24" fill="none"><rect x="3" y="3" width="18" height="18" rx="2" stroke="currentColor" stroke-width="2"/><path d="M3 15h18" stroke="currentColor" stroke-width="2"/></svg>
114 </div>
115 <h2><?php esc_html_e('Footer', 'ai-builder'); ?></h2>
116 <?php if ($footer_part) : ?>
117 <span class="ai-hf-badge ai-hf-badge-ready"><?php esc_html_e('Ready to edit', 'ai-builder'); ?></span>
118 <p class="ai-hf-card-desc"><?php printf(esc_html__('Template part: %s', 'ai-builder'), '<code>' . esc_html($footer_part->slug) . '</code>'); ?></p>
119 <a href="<?php echo esc_url($footer_edit_url); ?>" class="ai-hf-btn ai-hf-btn-primary" target="_blank">
120 <?php esc_html_e('Edit with AI →', 'ai-builder'); ?>
121 </a>
122 <?php else : ?>
123 <span class="ai-hf-badge ai-hf-badge-missing"><?php esc_html_e('No template part found', 'ai-builder'); ?></span>
124 <p class="ai-hf-card-desc"><?php esc_html_e('Create a footer template part to get started.', 'ai-builder'); ?></p>
125 <button class="ai-hf-btn ai-hf-btn-primary ai-hf-create-part" data-area="footer">
126 <?php esc_html_e('Create & Edit with AI →', 'ai-builder'); ?>
127 </button>
128 <?php endif; ?>
129 </div>
130 </div>
131
132 <!-- Tips -->
133 <div class="ai-hf-tips">
134 <svg width="18" height="18" viewBox="0 0 24 24" fill="none"><path d="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5" stroke="currentColor" stroke-width="2" stroke-linejoin="round"/></svg>
135 <div>
136 <strong><?php esc_html_e('Tips', 'ai-builder'); ?></strong>
137 <ul>
138 <li><?php esc_html_e('Be specific in your prompt: mention colors, layout, elements you want.', 'ai-builder'); ?></li>
139 <li><?php esc_html_e('You can fine-tune the result with the CSS and JS editors in the chat widget.', 'ai-builder'); ?></li>
140 <li><?php esc_html_e('Regenerate anytime — just describe something different.', 'ai-builder'); ?></li>
141 </ul>
142 </div>
143 </div>
144
145 <?php endif; ?>
146 </div>
147 </div>
148
149 <?php if ($is_block_theme) : ?>
150 <script>
151 (function() {
152 document.querySelectorAll('.ai-hf-create-part').forEach(function(btn) {
153 btn.addEventListener('click', function() {
154 var area = this.dataset.area;
155 var button = this;
156 button.disabled = true;
157 button.textContent = '<?php echo esc_js(__('Creating...', 'ai-builder')); ?>';
158
159 var data = new FormData();
160 data.append('action', 'aibui_create_template_part');
161 data.append('nonce', '<?php echo esc_js(wp_create_nonce('aibui_nonce')); ?>');
162 data.append('area', area);
163
164 fetch('<?php echo esc_url(admin_url('admin-ajax.php')); ?>', {
165 method: 'POST',
166 body: data,
167 credentials: 'same-origin'
168 })
169 .then(function(r) { return r.json(); })
170 .then(function(resp) {
171 if (resp.success && resp.data.edit_url) {
172 window.open(resp.data.edit_url, '_blank');
173 location.reload();
174 } else {
175 alert(resp.data || 'Error creating template part');
176 button.disabled = false;
177 button.textContent = area === 'header'
178 ? '<?php echo esc_js(__('Create & Edit with AI ', 'ai-builder')); ?>'
179 : '<?php echo esc_js(__('Create & Edit with AI ', 'ai-builder')); ?>';
180 }
181 })
182 .catch(function() {
183 alert('Network error');
184 button.disabled = false;
185 button.textContent = '<?php echo esc_js(__('Create & Edit with AI ', 'ai-builder')); ?>';
186 });
187 });
188 });
189 })();
190 </script>
191 <?php endif; ?>
192
193 <style>
194 .ai-builder-headers-footers {
195 font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
196 }
197 .ai-hf-container {
198 max-width: 820px;
199 margin-top: 24px;
200 }
201 .ai-hf-page-header {
202 margin-bottom: 32px;
203 }
204 .ai-hf-page-header h1 {
205 font-size: 28px;
206 font-weight: 700;
207 color: #101828;
208 margin: 0 0 6px;
209 }
210 .ai-hf-page-header p {
211 font-size: 15px;
212 color: #475467;
213 margin: 0;
214 }
215
216 /* Notice for non-FSE */
217 .ai-hf-notice {
218 display: flex;
219 gap: 14px;
220 padding: 20px 24px;
221 border-radius: 12px;
222 margin-bottom: 24px;
223 align-items: flex-start;
224 }
225 .ai-hf-notice svg { flex-shrink: 0; margin-top: 2px; }
226 .ai-hf-notice-warning {
227 background: #fffbeb;
228 border: 1px solid #fde68a;
229 color: #92400e;
230 }
231 .ai-hf-notice-warning svg { color: #d97706; }
232 .ai-hf-notice strong { display: block; margin-bottom: 4px; color: #78350f; }
233 .ai-hf-notice p { margin: 4px 0 0; font-size: 14px; line-height: 1.5; }
234 .ai-hf-theme-suggestions { color: #a16207; font-size: 13px !important; }
235 .ai-hf-theme-suggestions span { font-weight: 600; }
236
237 /* Steps */
238 .ai-hf-steps {
239 display: flex;
240 gap: 20px;
241 margin-bottom: 28px;
242 }
243 .ai-hf-step {
244 flex: 1;
245 background: #ffffff;
246 border: 1px solid #e5e7eb;
247 border-radius: 12px;
248 padding: 20px;
249 display: flex;
250 gap: 14px;
251 align-items: flex-start;
252 }
253 .ai-hf-step-num {
254 width: 32px;
255 height: 32px;
256 border-radius: 8px;
257 background: linear-gradient(135deg, #007cba, #005a87);
258 color: #fff;
259 display: flex;
260 align-items: center;
261 justify-content: center;
262 font-size: 15px;
263 font-weight: 700;
264 flex-shrink: 0;
265 }
266 .ai-hf-step strong { display: block; font-size: 14px; color: #101828; margin-bottom: 2px; }
267 .ai-hf-step p { margin: 0; font-size: 13px; color: #6b7280; line-height: 1.4; }
268
269 /* Cards */
270 .ai-hf-cards {
271 display: grid;
272 grid-template-columns: 1fr 1fr;
273 gap: 20px;
274 margin-bottom: 24px;
275 }
276 .ai-hf-card {
277 background: #ffffff;
278 border: 1px solid #e5e7eb;
279 border-radius: 14px;
280 padding: 28px;
281 text-align: center;
282 }
283 .ai-hf-card-icon {
284 width: 52px;
285 height: 52px;
286 border-radius: 12px;
287 background: #eff6ff;
288 color: #2563eb;
289 display: flex;
290 align-items: center;
291 justify-content: center;
292 margin: 0 auto 16px;
293 }
294 .ai-hf-card h2 {
295 font-size: 20px;
296 font-weight: 700;
297 color: #101828;
298 margin: 0 0 10px;
299 }
300 .ai-hf-card-desc {
301 font-size: 13px;
302 color: #6b7280;
303 margin: 8px 0 18px;
304 }
305 .ai-hf-card-desc code {
306 background: #f3f4f6;
307 padding: 2px 6px;
308 border-radius: 4px;
309 font-size: 12px;
310 }
311
312 /* Badges */
313 .ai-hf-badge {
314 display: inline-block;
315 font-size: 12px;
316 font-weight: 600;
317 padding: 3px 10px;
318 border-radius: 20px;
319 }
320 .ai-hf-badge-ready {
321 background: #ecfdf5;
322 color: #065f46;
323 border: 1px solid #a7f3d0;
324 }
325 .ai-hf-badge-missing {
326 background: #fff7ed;
327 color: #9a3412;
328 border: 1px solid #fed7aa;
329 }
330
331 /* Buttons */
332 .ai-hf-btn {
333 display: inline-flex;
334 align-items: center;
335 gap: 6px;
336 padding: 10px 22px;
337 border-radius: 8px;
338 font-size: 14px;
339 font-weight: 600;
340 text-decoration: none;
341 cursor: pointer;
342 border: none;
343 transition: all 0.15s;
344 }
345 .ai-hf-btn-primary {
346 background: linear-gradient(135deg, #007cba, #005a87);
347 color: #ffffff;
348 box-shadow: 0 2px 8px rgba(0, 124, 186, 0.25);
349 }
350 .ai-hf-btn-primary:hover {
351 transform: translateY(-1px);
352 box-shadow: 0 4px 14px rgba(0, 124, 186, 0.35);
353 color: #ffffff;
354 }
355 .ai-hf-btn-primary:disabled {
356 opacity: 0.6;
357 cursor: not-allowed;
358 transform: none;
359 }
360 .ai-hf-btn-outline {
361 background: #ffffff;
362 color: #d97706;
363 border: 1px solid #fbbf24;
364 margin-top: 10px;
365 }
366 .ai-hf-btn-outline:hover {
367 background: #fffbeb;
368 color: #b45309;
369 }
370
371 /* Tips */
372 .ai-hf-tips {
373 display: flex;
374 gap: 14px;
375 background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
376 border: 1px solid #bfdbfe;
377 border-radius: 12px;
378 padding: 20px 24px;
379 align-items: flex-start;
380 }
381 .ai-hf-tips svg { color: #2563eb; flex-shrink: 0; margin-top: 2px; }
382 .ai-hf-tips strong { display: block; font-size: 14px; color: #1e40af; margin-bottom: 6px; }
383 .ai-hf-tips ul { margin: 0; padding-left: 18px; font-size: 13px; color: #1e3a8a; line-height: 1.7; }
384 .ai-hf-tips li { margin-bottom: 2px; }
385
386 @media (max-width: 782px) {
387 .ai-hf-steps { flex-direction: column; }
388 .ai-hf-cards { grid-template-columns: 1fr; }
389 }
390 </style>
391