-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
executable file
·453 lines (395 loc) · 12.5 KB
/
functions.php
File metadata and controls
executable file
·453 lines (395 loc) · 12.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
<?php
/**
* Frequency Theme Functions
*
* @package Frequency
* @version 1.0.0
*/
if (!defined('ABSPATH')) {
exit;
}
// Theme version
define('FREQUENCY_VERSION', '1.0.0');
define('FREQUENCY_THEME_DIR', get_template_directory());
define('FREQUENCY_THEME_URI', get_template_directory_uri());
/**
* Theme Setup
*/
function frequency_setup() {
// Add default posts and comments RSS feed links to head
add_theme_support('automatic-feed-links');
// Let WordPress manage the document title
add_theme_support('title-tag');
// Enable support for Post Thumbnails
add_theme_support('post-thumbnails');
// Register navigation menus
register_nav_menus([
'primary' => __('Primary Menu', 'frequency'),
'footer' => __('Footer Menu', 'frequency'),
]);
// Switch default core markup to output valid HTML5
add_theme_support('html5', [
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
'style',
'script',
]);
// Add support for custom logo
add_theme_support('custom-logo', [
'height' => 85,
'width' => 200,
'flex-height' => true,
'flex-width' => true,
]);
}
add_action('after_setup_theme', 'frequency_setup');
/**
* Enqueue scripts and styles
*/
function frequency_scripts() {
// Main stylesheet (compiled TailwindCSS)
wp_enqueue_style(
'frequency-style',
FREQUENCY_THEME_URI . '/assets/css/style.css',
[],
FREQUENCY_VERSION
);
// Google Fonts - Poppins
wp_enqueue_style(
'frequency-fonts',
'https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,400;0,500;0,600;0,700;0,900;1,400;1,500&display=swap',
[],
null
);
// Lottie animations library (web component version)
wp_enqueue_script(
'dotlottie-wc',
'https://unpkg.com/@lottiefiles/dotlottie-wc@0.3.0/dist/dotlottie-wc.js',
[],
'0.3.0',
true
);
// Add module type to the script
add_filter('script_loader_tag', function($tag, $handle) {
if ($handle === 'dotlottie-wc') {
return str_replace(' src', ' type="module" src', $tag);
}
return $tag;
}, 10, 2);
// Theme animations (IntersectionObserver)
wp_enqueue_script(
'frequency-animations',
FREQUENCY_THEME_URI . '/assets/js/animations.js',
[],
FREQUENCY_VERSION,
true
);
// Note: Lottie initialization not needed - using dotlottie-wc web component
// Live counter
wp_enqueue_script(
'frequency-counter',
FREQUENCY_THEME_URI . '/assets/js/counter.js',
[],
FREQUENCY_VERSION,
true
);
// Mobile navigation
wp_enqueue_script(
'frequency-navigation',
FREQUENCY_THEME_URI . '/assets/js/navigation.js',
[],
FREQUENCY_VERSION,
true
);
// Pass theme data to JavaScript
wp_localize_script('frequency-counter', 'frequencyData', [
'themeUri' => FREQUENCY_THEME_URI,
'ajaxUrl' => admin_url('admin-ajax.php'),
'nonce' => wp_create_nonce('frequency_nonce'),
]);
}
add_action('wp_enqueue_scripts', 'frequency_scripts');
/**
* ACF Options Page
*/
function frequency_acf_options_page() {
if (function_exists('acf_add_options_page')) {
acf_add_options_page([
'page_title' => __('Theme Settings', 'frequency'),
'menu_title' => __('Theme Settings', 'frequency'),
'menu_slug' => 'theme-settings',
'capability' => 'edit_posts',
'redirect' => false,
'icon_url' => 'dashicons-admin-customizer',
]);
}
}
add_action('acf/init', 'frequency_acf_options_page');
/**
* ACF JSON save point
*/
function frequency_acf_json_save_point($path) {
return FREQUENCY_THEME_DIR . '/acf/fields';
}
add_filter('acf/settings/save_json', 'frequency_acf_json_save_point');
/**
* ACF JSON load point
*/
function frequency_acf_json_load_point($paths) {
$paths[] = FREQUENCY_THEME_DIR . '/acf/fields';
return $paths;
}
add_filter('acf/settings/load_json', 'frequency_acf_json_load_point');
/**
* Custom image sizes
*/
function frequency_image_sizes() {
add_image_size('hero-image', 1700, 900, true);
add_image_size('section-image', 800, 600, true);
add_image_size('card-image', 400, 300, true);
}
add_action('after_setup_theme', 'frequency_image_sizes');
/**
* Contact form handler (AJAX)
*/
function frequency_contact_form_handler() {
check_ajax_referer('frequency_nonce', 'nonce');
$name = sanitize_text_field($_POST['name'] ?? '');
$email = sanitize_email($_POST['email'] ?? '');
$comment = sanitize_textarea_field($_POST['comment'] ?? '');
$isDeveloper = isset($_POST['development']) && $_POST['development'] === 'true';
$isPartnership = isset($_POST['partnerships']) && $_POST['partnerships'] === 'true';
// Honeypot check
if (!empty($_POST['website'])) {
wp_send_json_error(['message' => 'Spam detected']);
return;
}
// Validation
if (empty($name) || empty($email) || empty($comment)) {
wp_send_json_error(['message' => 'Please fill out all required fields']);
return;
}
if (!is_email($email)) {
wp_send_json_error(['message' => 'Please enter a valid email address']);
return;
}
// Send to Lambda endpoint
$lambda_url = 'https://7otsoqfsv4cgqxe6xvc2vyjo6e0sozeg.lambda-url.sa-east-1.on.aws';
$form_data = [
'entry.464666765' => $name,
'entry.626493750' => $email,
'entry.1047518165' => $comment,
];
if ($isDeveloper) {
$form_data['entry.334295884'] = 'Developer';
}
if ($isPartnership) {
$form_data['entry.266517677'] = 'Partner';
}
$response = wp_remote_post($lambda_url, [
'body' => http_build_query($form_data),
'headers' => [
'Content-Type' => 'application/x-www-form-urlencoded',
],
'timeout' => 30,
]);
if (is_wp_error($response)) {
wp_send_json_error(['message' => 'Form submission failed. Please try again.']);
return;
}
$response_code = wp_remote_retrieve_response_code($response);
if ($response_code >= 200 && $response_code < 300) {
wp_send_json_success(['message' => 'Thank you for your message!']);
} else {
wp_send_json_error(['message' => 'Form submission failed. Please try again.']);
}
}
add_action('wp_ajax_frequency_contact', 'frequency_contact_form_handler');
add_action('wp_ajax_nopriv_frequency_contact', 'frequency_contact_form_handler');
/**
* Helper function: Get Lottie animation HTML
* Uses dotlottie-wc web component
*
* Note: The web component requires explicit sizing via CSS since its shadow DOM
* doesn't properly inherit h-full/w-full. We use inline styles to ensure proper sizing.
*/
function frequency_lottie($src, $options = []) {
$defaults = [
'autoplay' => true,
'loop' => true,
'play_on_visible' => false,
'speed' => 1,
'fit' => 'contain',
'align_x' => 0.5,
'align_y' => 0.5,
'class' => '',
];
$opts = wp_parse_args($options, $defaults);
$attrs = [];
$attrs[] = sprintf('src="%s"', esc_url($src));
if ($opts['autoplay']) {
$attrs[] = 'autoplay';
}
if ($opts['loop']) {
$attrs[] = 'loop';
}
if ($opts['speed'] != 1) {
$attrs[] = sprintf('speed="%s"', esc_attr($opts['speed']));
}
// Build layout config for fit and align
$layout = [
'fit' => $opts['fit'],
'align' => [$opts['align_x'], $opts['align_y']]
];
$attrs[] = sprintf("layout='%s'", json_encode($layout));
// Build render config to match Svelte's renderConfig={{ autoResize: true }}
$render_config = [
'autoResize' => true
];
$attrs[] = sprintf("renderConfig='%s'", json_encode($render_config));
// The web component needs explicit width/height via inline styles
// since its shadow DOM doesn't properly inherit CSS classes.
// flex: 1 and min-width: 0 ensure proper flex behavior and prevent overflow
return sprintf(
'<dotlottie-wc class="block %s" style="width: 100%%; height: 100%%; flex: 1; min-width: 0;" %s></dotlottie-wc>',
esc_attr($opts['class']),
implode(' ', $attrs)
);
}
/**
* Helper function: Button component
*/
function frequency_button($text, $href = '', $options = []) {
$defaults = [
'intent' => 'filled-dark', // filled-dark, filled-light, outlined-dark, outlined-light
'size' => 'normal', // xs, sm, normal, md, lg, auto, full
'class' => '',
'target' => '_self',
'disabled' => false,
];
$opts = wp_parse_args($options, $defaults);
// Base classes
$base = 'h-[46px] px-f24 cursor-pointer rounded-full text-center transition-all text-nowrap inline-flex items-center justify-center font-bold';
// Intent classes
$intents = [
'filled-dark' => 'bg-black text-white hover:bg-primary',
'filled-light' => 'bg-cream text-black hover:bg-purple50 hover:text-white',
'outlined-dark' => 'bg-transparent border-2 text-black border-black hover:text-primary hover:border-primary',
'outlined-light' => 'text-cream border-2 border-cream bg-transparent hover:text-purple50 hover:border-purple50',
];
// Size classes
$sizes = [
'xs' => 'w-[115px]',
'sm' => 'w-[197px]',
'normal' => 'w-[263px]',
'md' => 'w-[339px]',
'lg' => 'w-[388px]',
'auto' => 'w-auto',
'full' => 'w-full',
];
$classes = implode(' ', [
$base,
$intents[$opts['intent']] ?? $intents['filled-dark'],
$sizes[$opts['size']] ?? $sizes['normal'],
$opts['class'],
$opts['disabled'] ? 'bg-gray3 text-gray2 cursor-default pointer-events-none' : '',
]);
if ($href) {
return sprintf(
'<a href="%s" target="%s" class="%s"%s>%s</a>',
esc_url($href),
esc_attr($opts['target']),
esc_attr($classes),
$opts['disabled'] ? ' aria-disabled="true"' : '',
esc_html($text)
);
}
return sprintf(
'<button type="submit" class="%s"%s>%s</button>',
esc_attr($classes),
$opts['disabled'] ? ' disabled' : '',
esc_html($text)
);
}
/**
* Helper function: Slide-in animation wrapper
*/
function frequency_slide_in($content, $class = '') {
return sprintf(
'<div class="slide-out transition-all duration-1000 %s" data-animate="slide-in">%s</div>',
esc_attr($class),
$content
);
}
/**
* Helper function: Grow animation wrapper
*/
function frequency_grow($content, $class = '') {
return sprintf(
'<div class="grow-out transition-all duration-1000 %s" data-animate="grow-in">%s</div>',
esc_attr($class),
$content
);
}
/**
* Helper function: Safe ACF get_sub_field wrapper
* Returns default value if ACF is not installed or field is empty
*/
function frequency_get_field($field_name, $default = null) {
if (function_exists('get_sub_field')) {
$value = get_sub_field($field_name);
return $value ?: $default;
}
return $default;
}
/**
* Helper function: Safe ACF get_field wrapper (for non-repeater fields)
*/
function frequency_get_page_field($field_name, $default = null) {
if (function_exists('get_field')) {
$value = get_field($field_name);
return $value ?: $default;
}
return $default;
}
/**
* Helper function: Safe ACF have_rows wrapper
*/
function frequency_have_rows($field_name) {
if (function_exists('have_rows')) {
return have_rows($field_name);
}
return false;
}
/**
* Helper function: Safe ACF the_row wrapper
*/
function frequency_the_row() {
if (function_exists('the_row')) {
the_row();
}
}
/**
* Disable Gutenberg for pages using ACF flexible content
*/
function frequency_disable_gutenberg($use_block_editor, $post_type) {
if ($post_type === 'page') {
return false;
}
return $use_block_editor;
}
add_filter('use_block_editor_for_post_type', 'frequency_disable_gutenberg', 10, 2);
/**
* Add body classes
*/
function frequency_body_classes($classes) {
$classes[] = 'font-sans text-normal bg-white text-black';
if (is_front_page()) {
$classes[] = 'front-page';
}
return $classes;
}
add_filter('body_class', 'frequency_body_classes');