-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
1240 lines (1084 loc) · 36.9 KB
/
Copy pathfunctions.php
File metadata and controls
1240 lines (1084 loc) · 36.9 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
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Aera Technology functions and definitions
*
* @link https://developer.wordpress.org/themes/basics/theme-functions/
*
* @package Aera_Technology
*/
if (! defined('_S_VERSION')) {
// Replace the version number of the theme on each release.
define('_S_VERSION', '1.0.0');
}
if (! defined('AERA_THEME_SLUG')) {
define('AERA_THEME_SLUG', 'aera-technology');
}
if (! defined('AERA_THEME_NAME')) {
define('AERA_THEME_NAME', 'Aera Technology');
}
if (! defined('AERA_THEME_README_PATH')) {
define('AERA_THEME_README_PATH', get_template_directory() . '/README.md');
}
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which
* runs before the init hook. The init hook is too late for some features, such
* as indicating support for post thumbnails.
*/
function aera_technology_setup()
{
/*
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
* If you're building a theme based on Aera Technology, use a find and replace
* to change 'aera-technology' to the name of your theme in all the template files.
*/
load_theme_textdomain('aera-technology', get_template_directory() . '/languages');
// Add default posts and comments RSS feed links to head.
add_theme_support('automatic-feed-links');
/*
* Let WordPress manage the document title.
* By adding theme support, we declare that this theme does not use a
* hard-coded <title> tag in the document head, and expect WordPress to
* provide it for us.
*/
add_theme_support('title-tag');
/*
* Enable support for Post Thumbnails on posts and pages.
*
* @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
*/
add_theme_support('post-thumbnails');
// add_image_size('resource_card', 720, 405, true); // TODO: check if used?
// Project-specific image sizes
add_image_size('logo', 480, 204, false); // 2x for 240x102 display (retina)
// add_image_size('author_image', 120, 120, true);
add_image_size('resource_card_image', 342, 96);
add_image_size('webinar_card_image', 333, 180);
add_image_size('webinar_featured', 800, 450, true);
add_image_size('card_logo', 150, 150, false);
add_image_size('blog_hero', 890, 0);
add_image_size('skill_hero', 738, 0);
register_nav_menus(
array(
'primary' => esc_html__('Primary Navigation', 'aera'),
'primary-utility' => esc_html__('Utility Navigation', 'aera'),
'footer-aera' => esc_html__('Footer: Aera Decision Cloud', 'aera'),
'footer-skills' => esc_html__('Footer: Aera Skills', 'aera'),
'footer-company' => esc_html__('Footer: Company', 'aera'),
'footer-resources' => esc_html__('Footer: Resources', 'aera'),
'footer-customers' => esc_html__('Footer: Customers', 'aera'),
'footer-events' => esc_html__('Footer: Events', 'aera'),
'footer-cta' => esc_html__('Footer: CTA', 'aera'),
'footer-social' => esc_html__('Footer: Social Links', 'aera'),
)
);
/*
* Switch default core markup for search form, comment form, and comments
* to output valid HTML5.
*/
add_theme_support(
'html5',
array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
'style',
'script',
)
);
// Set up the WordPress core custom background feature.
add_theme_support(
'custom-background',
apply_filters(
'aera_technology_custom_background_args',
array(
'default-color' => 'ffffff',
'default-image' => '',
)
)
);
// Add theme support for selective refresh for widgets.
add_theme_support('customize-selective-refresh-widgets');
/**
* Add support for core custom logo.
*
* @link https://codex.wordpress.org/Theme_Logo
*/
add_theme_support(
'custom-logo',
array(
'height' => 250,
'width' => 250,
'flex-width' => true,
'flex-height' => true,
)
);
}
add_action('after_setup_theme', 'aera_technology_setup');
/**
* Make custom image sizes available in the media selector.
*
* @param array $sizes Existing sizes.
* @return array
*/
function aera_technology_image_sizes($sizes)
{
return array_merge($sizes, array(
'author_image' => __('Author Image (160x160)', 'aera'),
'resource_card_image' => __('Resource Card (342x96)', 'aera'),
// Use this generic "Card Image" label for webinar/resource/customer cards
'webinar_card_image' => __('Card Image (333x190)', 'aera'),
'blog_hero' => __('Blog Hero (890x670)', 'aera'),
'skill_hero' => __('Skill Hero (738x620)', 'aera'),
));
}
add_filter('image_size_names_choose', 'aera_technology_image_sizes');
/**
* Set the content width in pixels, based on the theme's design and stylesheet.
*
* Priority 0 to make it available to lower priority callbacks.
*
* @global int $content_width
*/
function aera_technology_content_width()
{
$GLOBALS['content_width'] = apply_filters('aera_technology_content_width', 640);
}
add_action('after_setup_theme', 'aera_technology_content_width', 0);
/**
* Register widget area.
*
* @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
*/
function aera_technology_widgets_init()
{
register_sidebar(
array(
'name' => esc_html__('Sidebar', 'aera-technology'),
'id' => 'sidebar-1',
'description' => esc_html__('Add widgets here.', 'aera-technology'),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
}
add_action('widgets_init', 'aera_technology_widgets_init');
/**
* Get the URL and version for a theme script, preferring the minified build.
*
* Falls back to the source file in js/ if the minified version doesn't exist
* (e.g. before running the build).
*
* @param string $script_name The script filename without extension (e.g. 'site').
* @return array{url: string, version: string} The script URL and version string.
*/
function aera_get_script($script_name)
{
$min_path = get_template_directory() . '/assets/js/min/' . $script_name . '.min.js';
if (file_exists($min_path)) {
return array(
'url' => get_template_directory_uri() . '/assets/js/min/' . $script_name . '.min.js',
'version' => (string) filemtime($min_path),
);
}
$src_path = get_template_directory() . '/js/' . $script_name . '.js';
return array(
'url' => get_template_directory_uri() . '/js/' . $script_name . '.js',
'version' => file_exists($src_path) ? (string) filemtime($src_path) : _S_VERSION,
);
}
/**
* Enqueue scripts and styles. test
*/
function aera_technology_scripts()
{
// Canonical theme stylesheet: assets/css/aera.css.
// Build via `npm run build:css` (compressed, no source map).
wp_enqueue_style('aera-theme-components', get_template_directory_uri() . '/assets/css/aera.css', array(), _S_VERSION);
// Keep style.css as a live override layer so WP Admin Theme Editor changes
// affect frontend styling without modifying compiled Sass output.
$style_css_path = get_stylesheet_directory() . '/style.css';
wp_enqueue_style(
'aera-theme-overrides',
get_stylesheet_uri(),
array('aera-theme-components'),
file_exists($style_css_path) ? (string) filemtime($style_css_path) : _S_VERSION
);
// Enqueue GSAP from CDN — loaded in footer since its dependents (site.js) also load in footer
wp_enqueue_script(
'gsap',
'https://cdn.jsdelivr.net/npm/gsap@3.12.2/dist/gsap.min.js',
array(),
'3.12.2',
true
);
$nav = aera_get_script('navigation');
wp_enqueue_script('aera-technology-navigation', $nav['url'], array(), $nav['version'], true);
$site = aera_get_script('site');
wp_enqueue_script('aera-theme-site', $site['url'], array('gsap'), $site['version'], true);
$hubspot_no_lazyload_debug = defined('WP_DEBUG') && WP_DEBUG;
$hubspot_no_lazyload_script = <<<'JS'
(function () {
const AERA_HUBSPOT_NO_LAZYLOAD_DEBUG = __AERA_HUBSPOT_NO_LAZYLOAD_DEBUG__;
const HUBSPOT_IFRAME_SELECTOR = 'iframe[src*="hsforms."], iframe[src*="hubspot" i], iframe.hs-form-iframe';
function debugLog() {
if (!AERA_HUBSPOT_NO_LAZYLOAD_DEBUG || !window.console || typeof window.console.log !== 'function') {
return;
}
window.console.log.apply(window.console, arguments);
}
function isHubSpotIframe(node) {
if (!node || node.tagName !== 'IFRAME') {
return false;
}
const src = (node.getAttribute('src') || '').toLowerCase();
return (
src.includes('hsforms.') ||
src.includes('hubspot') ||
node.classList.contains('hs-form-iframe') ||
node.closest('[id*="HubspotForm" i], [class*="hubspot" i], [class*="hs-form" i]') !== null
);
}
function markNoLazyload(node) {
if (isHubSpotIframe(node)) {
const hadClass = node.classList.contains('no-lazyload');
node.classList.add('no-lazyload');
if (!hadClass) {
debugLog('[Aera] Added no-lazyload to HubSpot iframe', node);
}
}
}
function markAllHubSpotIframes(root) {
const scope = root && root.querySelectorAll ? root : document;
scope.querySelectorAll(HUBSPOT_IFRAME_SELECTOR).forEach(markNoLazyload);
}
function patchHubSpotCreate() {
if (!window.hbspt || !window.hbspt.forms || typeof window.hbspt.forms.create !== 'function') {
return false;
}
if (window.hbspt.forms.create.__aeraNoLazyloadPatched) {
return true;
}
const originalCreate = window.hbspt.forms.create;
const patchedCreate = function (options) {
let nextOptions = options;
if (options && typeof options === 'object') {
nextOptions = Object.assign({}, options);
const originalOnFormReady = nextOptions.onFormReady;
nextOptions.onFormReady = function () {
markAllHubSpotIframes(document);
if (typeof originalOnFormReady === 'function') {
return originalOnFormReady.apply(this, arguments);
}
return undefined;
};
}
const result = originalCreate.call(this, nextOptions);
markAllHubSpotIframes(document);
setTimeout(function () {
markAllHubSpotIframes(document);
}, 100);
return result;
};
patchedCreate.__aeraNoLazyloadPatched = true;
window.hbspt.forms.create = patchedCreate;
debugLog('[Aera] Patched hbspt.forms.create for no-lazyload support');
return true;
}
function watchForHubSpotIframes() {
if (!window.MutationObserver) {
return;
}
const observer = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
mutation.addedNodes.forEach(function (node) {
if (!node || node.nodeType !== 1) {
return;
}
markNoLazyload(node);
if (node.querySelectorAll) {
node.querySelectorAll('iframe').forEach(markNoLazyload);
}
});
});
});
observer.observe(document.documentElement, {
childList: true,
subtree: true,
});
}
function init() {
markAllHubSpotIframes(document);
watchForHubSpotIframes();
debugLog('[Aera] HubSpot no-lazyload observer initialized');
if (patchHubSpotCreate()) {
return;
}
let attempts = 0;
const maxAttempts = 120;
const interval = setInterval(function () {
attempts += 1;
if (patchHubSpotCreate() || attempts >= maxAttempts) {
clearInterval(interval);
}
}, 500);
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init);
} else {
init();
}
})();
JS;
$hubspot_no_lazyload_script = str_replace(
'__AERA_HUBSPOT_NO_LAZYLOAD_DEBUG__',
$hubspot_no_lazyload_debug ? 'true' : 'false',
$hubspot_no_lazyload_script
);
wp_add_inline_script('aera-theme-site', $hubspot_no_lazyload_script, 'after');
// Only load the Three.js background bundle on pages that actually use it
if (aera_is_background_active()) {
$background_bundle_path = get_template_directory() . '/assets/js/dist/background.js';
if (file_exists($background_bundle_path)) {
wp_enqueue_script(
'aera-background',
get_template_directory_uri() . '/assets/js/dist/background.js',
array(),
filemtime($background_bundle_path),
true
);
}
}
if (is_singular() && comments_open() && get_option('thread_comments')) {
wp_enqueue_script('comment-reply');
}
// Enqueue Decision Intelligence page scripts
if (is_page_template('page-what-is-decision-intelligence.php')) {
$script = aera_get_script('decision-intelligence');
wp_enqueue_script('aera-decision-intelligence', $script['url'], array(), $script['version'], true);
}
// Enqueue Landing Page scripts
if (is_page_template('page-landing-page.php')) {
$script = aera_get_script('landing-page');
wp_enqueue_script('aera-landing-page', $script['url'], array(), $script['version'], true);
}
// Enqueue Skill Detail page scripts
if (is_singular('skill')) {
$script = aera_get_script('skill-detail');
wp_enqueue_script('aera-skill-detail', $script['url'], array(), $script['version'], true);
}
// Enqueue Skills Video Modal scripts for skill function taxonomy pages
if (is_tax('skill_function')) {
$script = aera_get_script('skills-video-modal');
wp_enqueue_script('aera-skills-video-modal', $script['url'], array(), $script['version'], true);
}
// Enqueue Skills Archive filtering script
if (is_post_type_archive('skill')) {
$script = aera_get_script('skills-filter');
wp_enqueue_script('aera-skills-filter', $script['url'], array(), $script['version'], true);
}
// Enqueue AeraHub 2025 page scripts
if (is_page_template('page-aerahub-2025.php')) {
$script = aera_get_script('aerahub-2025');
wp_enqueue_script('aera-aerahub-2025', $script['url'], array(), $script['version'], true);
}
// Enqueue AeraHub 2025 London On-Demand page scripts
if (is_page_template('page-aerahub-2025-london.php')) {
$script = aera_get_script('aerahub-2025-london');
wp_enqueue_script('aera-aerahub-2025-london', $script['url'], array(), $script['version'], true);
}
// Enqueue Resources page filtering scripts
if (is_page_template('page-resources.php')) {
$script = aera_get_script('resources-filter');
wp_enqueue_script('aera-resources-filter', $script['url'], array(), $script['version'], true);
}
}
add_action('wp_enqueue_scripts', 'aera_technology_scripts');
/**
* Determine if the animated background should be active for the current page.
*
* Mirrors the logic in header.php to avoid loading the 622KB Three.js bundle
* on pages that don't use it.
*
* @return bool
*/
function aera_is_background_active()
{
if (
is_page_template('page-demo.php') ||
is_page_template('page-contact-us.php') ||
(is_page() && get_page_template_slug() === 'page-demo.php') ||
(is_page() && get_page_template_slug() === 'page-contact-us.php') ||
is_page('contact-us') ||
is_post_type_archive('partner')
) {
return false;
}
if (
is_front_page() ||
is_page_template('page-resources.php') ||
is_page_template('page-aerahub-2025.php') ||
is_page_template('page-aerahub-2025-london.php') ||
is_page_template('page-decision-cloud.php') ||
is_page_template('page-skills-home.php') ||
(is_page() && get_page_template_slug() === 'page-resources.php') ||
(is_page() && get_page_template_slug() === 'page-aerahub-2025.php') ||
(is_page() && get_page_template_slug() === 'page-aerahub-2025-london.php') ||
(is_page() && get_page_template_slug() === 'page-decision-cloud.php') ||
(is_page() && get_page_template_slug() === 'page-skills-home.php') ||
is_page(array('resources', 'about-us', 'careers', 'webinars', 'aera-decision-cloud', 'test-drive', 'aerahub-2025', 'aerahub-2025-london', 'decision-cloud')) ||
is_post_type_archive('webinar') ||
is_post_type_archive('event') ||
is_post_type_archive('skill')
) {
return true;
}
return false;
}
/**
* Determine if the current page has a HubSpot form.
*
* @return bool
*/
function aera_has_hubspot_form()
{
return is_page_template('page-demo.php') ||
is_page_template('page-landing-page.php') ||
is_page_template('page-test-drive.php') ||
(is_page() && get_page_template_slug() === 'page-demo.php') ||
is_tax('skill_function') ||
is_post_type_archive('webinar');
}
/**
* Add defer attribute to specific scripts for better performance.
*
* @param string $tag The script tag HTML.
* @param string $handle The script handle.
* @param string $src The script source URL.
* @return string Modified script tag.
*/
function aera_script_loader_tag($tag, $handle, $src)
{
$defer_handles = array('gsap', 'aera-technology-navigation', 'aera-theme-site', 'aera-background');
if (in_array($handle, $defer_handles, true)) {
$tag = str_replace(' src=', ' defer src=', $tag);
}
return $tag;
}
add_filter('script_loader_tag', 'aera_script_loader_tag', 10, 3);
/**
* Keep page author and slug controls in the sidebar (classic editor layout).
*
* @return void
*/
function aera_move_page_meta_boxes_to_sidebar(): void
{
add_post_type_support('page', 'author');
remove_meta_box('slugdiv', 'page', 'normal');
add_meta_box('slugdiv', __('Slug'), 'post_slug_meta_box', 'page', 'side', 'default');
remove_meta_box('authordiv', 'page', 'normal');
add_meta_box('authordiv', __('Author'), 'post_author_meta_box', 'page', 'side', 'default');
}
add_action('admin_menu', 'aera_move_page_meta_boxes_to_sidebar', 99);
/**
* Ensure archive pages that are meant to be fully browsable are not paginated.
*
* @param WP_Query $query The query object.
* @return void
*/
function aera_force_unlimited_archive_posts(WP_Query $query): void
{
if (is_admin() || !$query->is_main_query()) {
return;
}
if (
is_post_type_archive(array('partner', 'customer', 'event', 'webinar', 'skill')) ||
is_tax('skill_function')
) {
$query->set('posts_per_page', -1);
}
}
add_action('pre_get_posts', 'aera_force_unlimited_archive_posts', 50);
/**
* Add resource hints for performance: preconnect, dns-prefetch, and font preloading.
* Also conditionally preloads HubSpot forms script only on pages that use forms.
*/
function aera_resource_hints()
{
$theme_uri = get_template_directory_uri();
?>
<link rel="preconnect" href="https://cdn.jsdelivr.net" crossorigin>
<link rel="dns-prefetch" href="//cdn.jsdelivr.net">
<link rel="dns-prefetch" href="//js.hsforms.net">
<link rel="preload" href="<?php echo esc_url($theme_uri . '/assets/fonts/FreightSans-Pro-Book.woff2'); ?>" as="font" type="font/woff2" crossorigin>
<link rel="preload" href="<?php echo esc_url($theme_uri . '/assets/fonts/Gilroy-Semibold.woff2'); ?>" as="font" type="font/woff2" crossorigin>
<?php
if (aera_has_hubspot_form()) {
echo '<link rel="preconnect" href="https://js.hsforms.net" crossorigin>' . "\n";
echo '<link rel="dns-prefetch" href="//js.hs-scripts.com">' . "\n";
echo '<link rel="preload" href="https://js.hsforms.net/forms/embed/v2.js" as="script" crossorigin="anonymous">' . "\n";
}
}
add_action('wp_head', 'aera_resource_hints', 1);
/**
* Implement the Custom Header feature.
*/
require get_template_directory() . '/inc/custom-header.php';
/**
* Custom template tags for this theme.
*/
require get_template_directory() . '/inc/template-tags.php';
/**
* Functions which enhance the theme by hooking into WordPress.
*/
require get_template_directory() . '/inc/template-functions.php';
/**
* Custom post types.
*/
require get_template_directory() . '/inc/post-types.php';
/**
* Custom taxonomies.
*/
require get_template_directory() . '/inc/taxonomies.php';
/**
* Resource helpers.
*/
require get_template_directory() . '/inc/resources.php';
/**
* Lever API integration.
*/
require get_template_directory() . '/inc/lever.php';
/**
* Admin enhancements.
*/
require get_template_directory() . '/inc/admin.php';
/**
* FAQ helpers and shortcode.
*/
require get_template_directory() . '/inc/faq.php';
/**
* Advanced Custom Fields helpers.
*/
require get_template_directory() . '/inc/acf.php';
/**
* ACF Content Analysis for Yoast SEO integration.
*/
require get_template_directory() . '/inc/yoast-acf.php';
/**
* HubSpot page tracking (setPath/trackPageView) so form submissions have correct URL context.
*/
require get_template_directory() . '/inc/hubspot-tracker.php';
/**
* Head meta and favicons (match original site).
*/
require get_template_directory() . '/inc/head-meta.php';
/**
* Announcement banner helpers.
*/
require get_template_directory() . '/inc/banner.php';
/**
* Custom navigation walker.
*/
require get_template_directory() . '/inc/class-navigation-walker.php';
/**
* Custom footer walker.
*/
require get_template_directory() . '/inc/class-footer-walker.php';
/**
* Custom footer social walker.
*/
require get_template_directory() . '/inc/class-footer-social-walker.php';
/**
* Customizer additions.
*/
require get_template_directory() . '/inc/customizer.php';
/**
* Load Jetpack compatibility file.
*/
if (defined('JETPACK__VERSION')) {
require get_template_directory() . '/inc/jetpack.php';
}
/**
* Modify partner archive query to order by menu_order.
*
* @param WP_Query $query The WordPress query object.
*/
function aera_technology_partner_archive_order($query)
{
if (!is_admin() && $query->is_main_query() && is_post_type_archive('partner')) {
$query->set('orderby', 'menu_order');
$query->set('order', 'ASC');
$query->set('posts_per_page', -1);
}
}
add_action('pre_get_posts', 'aera_technology_partner_archive_order');
/**
* Skills archive: search/sort only. Category filtering is client-side (no reload).
* Load all skills on one page so JS can filter by data-category-ids.
*
* @param WP_Query $query The WordPress query object.
*/
function aera_technology_skill_archive_pre_get_posts($query)
{
if (is_admin() || !$query->is_main_query() || !is_post_type_archive('skill')) {
return;
}
// No category tax_query: categories are filtered client-side via js/skills-filter.js
$query->set('posts_per_page', -1);
if (!empty($_GET['skill_search'])) {
$search = is_array($_GET['skill_search']) ? $_GET['skill_search'][0] : $_GET['skill_search'];
$query->set('s', sanitize_text_field($search));
}
$sort = isset($_GET['sort']) ? sanitize_text_field(is_array($_GET['sort']) ? $_GET['sort'][0] : $_GET['sort']) : 'menu_order';
switch ($sort) {
case 'title':
$query->set('orderby', 'title');
$query->set('order', 'ASC');
break;
case 'date':
$query->set('orderby', 'date');
$query->set('order', 'DESC');
break;
default:
$query->set('orderby', 'menu_order');
$query->set('order', 'ASC');
}
}
add_action('pre_get_posts', 'aera_technology_skill_archive_pre_get_posts');
/**
* Customize the document title for Webinars and Events archives.
*
* @param array $title The document title parts.
* @return array Modified title parts.
*/
function aera_technology_custom_archive_title($title)
{
if (is_post_type_archive('webinar')) {
$title['title'] = __('Webinars', 'aera');
} elseif (is_post_type_archive('event')) {
$title['title'] = __('Events', 'aera');
}
return $title;
}
add_filter('document_title_parts', 'aera_technology_custom_archive_title');
/**
* ============================================
* ICON SELECTOR FUNCTIONALITY
* ============================================
* Populates ACF select fields with icons from assets/images/icons/ folder
* and adds preview functionality
*/
/**
* Populate icon select fields with icons from assets folder
*
* @param array $field The ACF field array
* @return array Modified field array with icon choices
*/
function aera_populate_icon_choices($field)
{
// Reset choices
$field['choices'] = array();
// Path to icons folder
$icons_dir = get_template_directory() . '/assets/images/icons/';
$icons_url = get_template_directory_uri() . '/assets/images/icons/';
// Get all SVG and PNG icons
$icons = glob($icons_dir . '*.{svg,png}', GLOB_BRACE);
if ($icons) {
// Sort alphabetically
sort($icons);
foreach ($icons as $icon_path) {
$filename = basename($icon_path);
$icon_url = $icons_url . $filename;
// Create readable label from filename
$label = ucwords(str_replace(['-', '_', '.svg', '.png'], [' ', ' ', '', ''], $filename));
// Use URL as value, readable name as label
$field['choices'][$icon_url] = $label;
}
}
return $field;
}
// Apply to skill icon fields
add_filter('acf/load_field/name=skill_icon', 'aera_populate_icon_choices');
add_filter('acf/load_field/name=icon_1_icon', 'aera_populate_icon_choices');
add_filter('acf/load_field/name=icon_2_icon', 'aera_populate_icon_choices');
add_filter('acf/load_field/name=icon_3_icon', 'aera_populate_icon_choices');
add_filter('acf/load_field/name=icon_4_icon', 'aera_populate_icon_choices');
/**
* Add icon preview to select fields in ACF admin
*
* @param array $field The ACF field array
*/
function aera_add_icon_preview($field)
{
// Only apply to icon fields
$icon_fields = array('skill_icon', 'icon_1_icon', 'icon_2_icon', 'icon_3_icon', 'icon_4_icon');
if (!in_array($field['name'], $icon_fields)) {
return;
}
// Only in admin
if (!is_admin()) {
return;
}
?>
<style>
.acf-field[data-name="<?php echo esc_attr($field['name']); ?>"] .icon-preview-container {
display: flex;
align-items: center;
gap: 15px;
margin-top: 10px;
}
.acf-field[data-name="<?php echo esc_attr($field['name']); ?>"] .icon-preview {
width: 60px;
height: 60px;
padding: 10px;
background: #f7f9fa;
border: 2px solid #ddd;
border-radius: 6px;
object-fit: contain;
}
</style>
<script>
(function($) {
$(document).ready(function() {
var $field = $('.acf-field[data-name="<?php echo esc_js($field['name']); ?>"]');
var $select = $field.find('select');
// Create preview container
var $previewContainer = $('<div class="icon-preview-container"></div>');
var $preview = $('<img class="icon-preview" style="display:none;">');
$previewContainer.append($preview);
$select.after($previewContainer);
// Update preview on change
$select.on('change', function() {
var iconUrl = $(this).val();
if (iconUrl) {
$preview.attr('src', iconUrl).show();
} else {
$preview.hide();
}
}).trigger('change');
});
})(jQuery);
</script>
<?php
}
add_action('acf/render_field/type=select', 'aera_add_icon_preview', 10, 1);
/**
* Override get_avatar to use author_photo_url from user meta if available
*
* @param string $avatar Avatar image tag.
* @param mixed $id_or_email User ID, email, or object.
* @param int $size Avatar size.
* @param string $default Default avatar URL.
* @param string $alt Alt text.
* @return string Avatar image tag.
*/
function aera_custom_avatar($avatar, $id_or_email, $size, $default, $alt)
{
$user = false;
if (is_numeric($id_or_email)) {
$user = get_user_by('id', (int) $id_or_email);
} elseif (is_object($id_or_email)) {
if (! empty($id_or_email->user_id)) {
$user = get_user_by('id', (int) $id_or_email->user_id);
}
} else {
$user = get_user_by('email', $id_or_email);
}
if ($user && is_object($user)) {
$author_photo_url = get_user_meta($user->ID, 'author_photo_url', true);
if (! empty($author_photo_url)) {
$avatar = sprintf(
'<img alt="%s" src="%s" class="avatar avatar-%d photo" height="%d" width="%d" />',
esc_attr($alt ?: $user->display_name),
esc_url($author_photo_url),
(int) $size,
(int) $size,
(int) $size
);
}
}
return $avatar;
}
add_filter('get_avatar', 'aera_custom_avatar', 10, 5);
/**
* Hide default WordPress Posts from admin menu
*/
function aera_hide_default_posts_menu()
{
remove_menu_page('edit.php');
}
add_action('admin_menu', 'aera_hide_default_posts_menu');
/**
* ============================================
* DISABLE DEFAULT POSTS, COMMENTS & AUTHORS
* ============================================
* The site uses custom post types exclusively.
* Default posts, comments, and author archives are disabled.
*/
/**
* Disable default post type from generating front-end URLs.
*
* @return void
*/
function aera_disable_default_post_type(): void
{
global $wp_post_types;
if (isset($wp_post_types['post'])) {
$wp_post_types['post']->publicly_queryable = false;
$wp_post_types['post']->has_archive = false;
$wp_post_types['post']->rewrite = false;
$wp_post_types['post']->query_var = false;
$wp_post_types['post']->exclude_from_search = true;
}
}
add_action('init', 'aera_disable_default_post_type', 999);
/**
* Redirect any default post, category, tag, date, or author archive pages.
*
* @return void
*/
function aera_redirect_disabled_archives(): void
{
if (is_singular('post') || is_home() || is_category() || is_tag() || is_date()) {
wp_redirect(home_url('/'), 301);
exit;
}
// Disable author archive pages.
if (is_author()) {
wp_redirect(home_url('/'), 301);
exit;
}
}
add_action('template_redirect', 'aera_redirect_disabled_archives');
/**
* Exclude default posts from Yoast XML sitemap.
*
* @param bool $excluded Whether the post type is excluded.
* @param string $post_type The post type slug.
* @return bool
*/
function aera_exclude_default_posts_from_sitemap(bool $excluded, string $post_type): bool
{
if ($post_type === 'post') {