/
class-geodir-compatibility.php
4230 lines (3579 loc) · 135 KB
/
class-geodir-compatibility.php
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
/**
* Compatibility functions for third party plugins.
*
* @since 2.0.0
* @package GeoDirectory
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class GeoDir_Compatibility {
/**
* Initiate the compatibility class.
*
* @since 2.0.0
*/
public static function init() {
add_action( 'plugins_loaded', array( __CLASS__, 'plugins_loaded' ) );
add_action( 'cron_schedules', array( __CLASS__, 'cron_schedules' ), 10, 1 );
/*######################################################
Yoast (WP SEO)
######################################################*/
add_filter( 'option_wpseo_taxonomy_meta', array( __CLASS__, 'wpseo_taxonomy_meta' ), 10, 2 );
// add setting to be able to disable yoast on GD pages
add_filter( 'Yoast\WP\SEO\prominent_words_post_types', array( __CLASS__, 'wpseo_prominent_words_post_types' ), 20, 1 );
add_filter( 'rank_math/opengraph/url', array( __CLASS__, 'rank_math_location_url_callback' ), 10 );
add_action( 'rank_math/opengraph/facebook/add_additional_images', array( __CLASS__, 'rank_math_cat_image' ), 10 );
add_action( 'rank_math/opengraph/twitter/add_additional_images', array( __CLASS__, 'rank_math_cat_image' ), 10 );
/*######################################################
Rank Math SEO
######################################################*/
// add setting to be able to disable Rank Math on GD pages
add_filter( 'rank_math/sitemap/urlimages', array( __CLASS__, 'rank_math_add_images_to_sitemap' ), 10, 2 );
add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue_rank_math_disable' ), 20 );
// SEO Plugin Options
add_filter( 'geodir_seo_options', array( __CLASS__, 'seo_plugin_options' ), 10, 1 );
/*######################################################
Disqus (comments system) :: If Disqus plugin is active, do some fixes to show on blogs but no on GD post types
######################################################*/
if ( function_exists( 'dsq_can_replace' ) ) {
remove_filter( 'comments_template', array( __CLASS__, 'dsq_comments_template' ) );
add_filter( 'comments_template', array( __CLASS__, 'dsq_comments_template' ), 100 );
add_filter( 'pre_option_disqus_active', array( __CLASS__, 'disqus_active' ), 10, 1 );
}
/*######################################################
JetPack :: Disable JetPack comments on GD post types.
######################################################*/
add_action( 'plugins_loaded', array( __CLASS__, 'jetpack' ) );
/*######################################################
Ninja Forms :: Add our own form tags.
######################################################*/
add_action( 'ninja_forms_loaded', array( __CLASS__, 'ninja_forms' ) );
/*######################################################
Primer (theme) :: Fix single page title.
######################################################*/
add_filter( 'primer_the_page_title', array( __CLASS__, 'primer_title' ) );
/*######################################################
Beaver Builder :: Fix Page templates.
######################################################*/
add_filter( 'geodir_bypass_setup_archive_loop_as_page', array( __CLASS__, 'beaver_builder_loop_bypass' ) );
if(class_exists( 'FLBuilderLoader' )){
add_action('wp_footer', array( __CLASS__, 'beaver_builder_template_warning' ) );
add_filter( 'geodir_bypass_archive_item_template_content', array( __CLASS__, 'beaver_archive_item_template_content' ), 10, 3 );
add_filter( 'fl_builder_do_render_content', array( __CLASS__, 'beaver_builder_do_render_content' ), 20, 2 );
}
/*######################################################
Beaver Themer
######################################################*/
if ( class_exists( 'FLThemeBuilderLoader' ) ) {
add_filter( 'geodir_page_options', array( __CLASS__, 'fl_theme_builder_page_options' ), 100, 1 );
add_filter( 'fl_theme_builder_current_page_layouts', array( __CLASS__, 'fl_theme_builder_current_page_layouts' ), 1, 1 );
add_filter( 'fl_theme_builder_page_archive_get_title', array( __CLASS__, 'fl_theme_builder_page_archive_get_title' ), 1, 1 );
}
/*######################################################
Elementor :: Fix Page templates.
######################################################*/
add_filter( 'geodir_bypass_setup_archive_loop_as_page', array( __CLASS__, 'elementor_loop_bypass' ) );
add_filter( 'geodir_bypass_setup_singular_page', array( __CLASS__, 'elementor_loop_bypass' ) );
/*######################################################
Genesis (theme) :: Fix archive pages excerpt.
######################################################*/
add_filter( 'genesis_pre_get_option_content_archive', array( __CLASS__, 'genesis_content_archive' ) );
add_filter( 'genesis_entry_title_wrap', array( __CLASS__, 'genesis_entry_title_wrap' ) );
/*######################################################
Kleo (theme) :: Fix page titles.
######################################################*/
add_filter( 'kleo_title_args', array( __CLASS__, 'kleo_title_args' ) );
// after_setup_theme checks
add_action( 'after_setup_theme', array( __CLASS__, 'for_later_checks' ) );
/*######################################################
Astra (theme) :: Fix page layouts.
######################################################*/
add_filter( 'astra_page_layout', array( __CLASS__, 'astra_page_layout' ) );
add_filter( 'astra_get_content_layout', array( __CLASS__, 'astra_get_content_layout' ) );
add_filter( 'astra_is_content_layout_boxed', array( __CLASS__, 'astra_is_content_layout_boxed' ), 10, 1 );
add_filter( 'astra_is_sidebar_layout_boxed', array( __CLASS__, 'astra_is_sidebar_layout_boxed' ), 10, 1 );
add_action( 'wp', array( __CLASS__, 'astra_wp' ), 20, 1 );
// Astra Theme v4.1 compatibility
add_filter( 'astra_single_layout_one_banner_visibility', array( __CLASS__, 'astra_single_layout_one_banner_visibility' ), 9999, 1 );
add_filter( 'astra_entry_header_class', array( __CLASS__, 'astra_entry_header_class' ), 10, 1 );
add_filter( 'astra_get_option_ast-dynamic-archive-page-structure', array( __CLASS__, 'astra_filter_option' ), 10, 3 );
/*######################################################
Divi (theme) :: maps api
######################################################*/
add_filter( 'et_pb_enqueue_google_maps_script', '__return_false' );
add_filter( 'et_builder_load_actions', array( __CLASS__,'divi_builder_ajax_load_actions') );
add_filter( 'et_theme_builder_template_settings_options', array( __CLASS__, 'et_theme_builder_template_settings_options' ), 20, 1 );
add_filter( 'et_builder_default_post_types', array( __CLASS__, 'et_builder_default_post_types' ), 20, 1 );
/*######################################################
The7 (theme) :: rewind the posts, the_excerpt function call seems to set the current_post number and cause have_posts() to return false.
######################################################*/
add_action( 'presscore_body_top', 'rewind_posts' );
if(isset($_REQUEST['geodir_search'])){
remove_filter('the_content','wpautop'); // for some reason this is added to the content on search.
}
/*######################################################
BuddyPress
######################################################*/
if ( class_exists( 'BuddyPress' ) ) {
add_action( 'admin_init', array( __CLASS__, 'buddypress_notices' ) );
}
/*######################################################
FORCE LEGACY STYLES
######################################################*/
add_action( 'init', array( __CLASS__, 'maybe_force_legacy_styles' ) );
// Set custom hook for theme compatibility
add_action( 'template_redirect', array( __CLASS__, 'template_redirect' ) );
// Avada theme
add_filter( 'avada_hide_page_options', array( __CLASS__, 'avada_hide_page_options' ), 100, 1 );
add_filter( 'fusion-page-id', array( __CLASS__, 'avada_fusion_page_id' ), 100, 1 );
add_filter( 'avada_sidebar_context', array( __CLASS__, 'avada_62_sidebar_context' ), 11, 4 );
add_filter( 'fusion_should_get_page_option', array( __CLASS__, 'fusion_should_get_page_option' ), 999, 1 );
add_filter( 'is_hundred_percent_template', array( __CLASS__, 'fusion_is_hundred_percent_template' ), 20, 2 );
add_filter( 'fusion_is_hundred_percent_template', array( __CLASS__, 'fusion_is_hundred_percent_template' ), 20, 2 );
if ( ! is_admin() ) {
// Filter post meta
add_filter( 'get_post_metadata', array( __CLASS__, 'dynamically_add_post_meta' ), 10, 4 );
add_filter( 'avada_has_sidebar', array( __CLASS__, 'avada_has_sidebar' ), 100, 3 );
add_filter( 'avada_has_double_sidebars', array( __CLASS__, 'avada_has_double_sidebars' ), 100, 3 );
add_filter( 'avada_setting_get_posts_sidebar', array( __CLASS__, 'avada_sidebar' ), 100, 1 );
add_filter( 'avada_setting_get_posts_sidebar_2', array( __CLASS__, 'avada_sidebar_2' ), 100, 1 );
add_filter( 'avada_setting_get_blog_archive_sidebar', array( __CLASS__, 'avada_sidebar' ), 100, 1 );
add_filter( 'avada_setting_get_blog_archive_sidebar_2', array( __CLASS__, 'avada_sidebar_2' ), 100, 1 );
add_filter( 'avada_setting_get_blog_sidebar_position', array( __CLASS__, 'avada_sidebar_position' ), 100, 1 );
add_filter( 'avada_setting_get_search_sidebar', array( __CLASS__, 'avada_sidebar' ), 100, 1 );
add_filter( 'avada_setting_get_search_sidebar_2', array( __CLASS__, 'avada_sidebar_2' ), 100, 1 );
add_filter( 'avada_setting_get_search_sidebar_position', array( __CLASS__, 'avada_sidebar_position' ), 100, 1 );
add_filter( 'avada_setting_get_sidebar_sticky', array( __CLASS__, 'avada_sidebar_sticky' ), 100, 1 );
// Fusion Builder (Avada)
if ( defined( 'FUSION_BUILDER_VERSION' ) ) {
// GD Listings
add_filter( 'geodir_before_template_part',array( __CLASS__, 'avada_get_temp_globals' ), 10);
add_filter( 'geodir_after_template_part',array( __CLASS__, 'avada_set_temp_globals' ), 10);
// GD Loop
add_filter( 'geodir_before_get_template_part',array( __CLASS__, 'avada_get_temp_globals' ), 10);
add_filter( 'geodir_after_get_template_part',array( __CLASS__, 'avada_set_temp_globals' ), 10);
// Avada header / footer actions
add_action( 'wp_head', array( __CLASS__, 'avada_wp_head_setup' ), 99 );
add_action( 'get_footer', array( __CLASS__, 'avada_get_footer_setup' ), 99 );
add_action( 'fusion_template_content', array( __CLASS__, 'avada_fusion_template_content_pause' ), 1 );
add_action( 'fusion_template_content', array( __CLASS__, 'avada_fusion_template_content_resume' ), 101 );
add_action( 'fusion_tb_override', array( __CLASS__, 'avada_fusion_tb_override' ), 10, 2 );
}
} else {
add_action( 'admin_notices', array( __CLASS__, 'page_builder_notices' ) );
}
if ( wp_doing_ajax() ) {
add_action( 'admin_init', array( __CLASS__, 'ajax_admin_init' ), 5 );
}
add_filter( 'geodir_link_to_lightbox_attrs', array( __CLASS__, 'link_to_lightbox_attrs' ), 10, 1 );
// Borlabs Cookie setting
if ( defined( 'BORLABS_COOKIE_VERSION' ) ) {
add_filter( 'geodir_get_settings_general', array( __CLASS__, 'borlabs_cookie_setting' ), 20, 3 );
}
// Complianz | GDPR/CCPA Cookie Consent plugin integration
if ( class_exists( 'COMPLIANZ' ) ) {
add_filter( 'cmplz_integrations', array( __CLASS__, 'complianz_gdpr_integration' ), 21, 1 );
add_filter( 'cmplz_integration_path', array( __CLASS__, 'complianz_integration_path' ), 21, 2 );
}
// Handle pre AJAX widget listings.
add_action( 'geodir_widget_ajax_listings_before', array( __CLASS__, 'ajax_listings_before' ), 10, 1 );
// Register scripts on block theme.
add_action( 'wp_super_duper_widget_init', array( __CLASS__, 'block_theme_load_scripts' ), 5, 2 );
// Astra Pro
if ( defined( 'ASTRA_EXT_VER' ) ) {
add_filter( 'post_class', array( __CLASS__, 'astra_pro_post_class' ), 99, 3 );
$astra_meta = array(
'adv-header-id-meta',
'ast-above-header-display',
'ast-below-header-display',
'ast-hfb-above-header-display',
'ast-hfb-below-header-display',
'footer-adv-display',
'footer-sml-layout',
'header-above-stick-meta',
'header-below-stick-meta',
'header-main-stick-meta',
'stick-header-meta',
'sticky-header-on-devices',
'sticky-header-style',
'sticky-hide-on-scroll',
'theme-transparent-header-meta',
'ast-page-background-enabled',
'ast-page-background-meta',
'ast-banner-title-visibility',
'ast-main-header-display',
'site-post-title',
'ast-breadcrumbs-content',
'ast-featured-img'
);
foreach ( $astra_meta as $meta_key ) {
add_filter( 'astra_get_option_meta_' . $meta_key, array( __CLASS__, 'astra_get_option_meta' ), 20, 2 );
}
}
// Relevanssi compatibility
add_filter( 'relevanssi_search_ok', array( __CLASS__, 'relevanssi_search_ok' ), 10, 2 );
add_filter( 'relevanssi_prevent_default_request', array( __CLASS__, 'relevanssi_prevent_default_request' ), 10, 2 );
// Apply filters to textarea output before display.
add_filter( 'geodir_filter_textarea_output', 'make_clickable', 9 );
add_filter( 'geodir_filter_textarea_output', 'wptexturize' );
add_filter( 'geodir_filter_textarea_output', 'convert_chars' );
add_filter( 'geodir_filter_textarea_output', 'convert_smilies', 20 );
add_filter( 'geodir_filter_textarea_output', 'force_balance_tags', 25 );
add_filter( 'geodir_filter_textarea_output', 'wpautop', 30 );
add_filter( 'geodir_filter_textarea_output', 'capital_P_dangit', 31 );
}
/**
* Add more cron schedules.
*
* @since 2.3.10
*
* @param array $schedules List of WP scheduled cron jobs.
* @return array Cron schedules.
*/
public static function cron_schedules( $schedules ) {
// Monthly
if ( empty( $schedules['monthly'] ) ) {
$schedules['monthly'] = array(
'interval' => MONTH_IN_SECONDS,
'display' => __( 'Once Monthly', 'geodirectory' ),
);
}
return $schedules;
}
/**
* Add options to manage overwrite titles & meta by SEO plugins.
*
* @since 2.2.7
*
* @param array $options SEO settings.
* @return array SEO settings.
*/
public static function seo_plugin_options( $options ) {
// Yoast SEO
if ( defined( 'WPSEO_VERSION' ) ) {
$new_options = array(
array(
'title' => __( 'Yoast SEO detected', 'geodirectory' ),
'type' => 'title',
'desc' => geodir_notification( array( 'info' => __( 'The Yoast SEO plugin has been detected and will take over the GeoDirectory meta Settings unless disabled below. (titles from here will still be used, but not meta)', 'geodirectory' ) ) ),
'id' => 'yoast_detected',
//'desc_tip' => true,
),
array(
'name' => __( 'Disable Yoast', 'geodirectory' ),
'desc' => __( 'Disable overwrite by Yoast SEO titles & metas on GD pages?', 'geodirectory' ),
'id' => 'wpseo_disable',
'type' => 'checkbox',
'default' => '0',
),
array( 'type' => 'sectionend', 'id' => 'yoast_detected' )
);
array_splice( $options, 2, 0, $new_options );
}
// Rank Math SEO
if ( defined( 'RANK_MATH_VERSION' ) ) {
$new_options = array(
array(
'title' => __( 'Rank Math SEO detected', 'geodirectory' ),
'type' => 'title',
'desc' => geodir_notification( array( 'info' => __( 'The Rank Math SEO plugin has been detected and will take over the GeoDirectory meta Settings unless disabled below. (titles from here will still be used, but not meta)', 'geodirectory' ) ) ),
'id' => 'rank_math_detected',
//'desc_tip' => true,
),
array(
'name' => __( 'Disable Rank Math', 'geodirectory' ),
'desc' => __( 'Disable overwrite by Rank Math titles & metas on GD pages?', 'geodirectory' ),
'id' => 'rank_math_disable',
'type' => 'checkbox',
'default' => '0',
),
array( 'type' => 'sectionend', 'id' => 'rank_math_detected' )
);
array_splice( $options, 2, 0, $new_options ); // splice in at position 1
}
// SEOPress
if ( function_exists( 'seopress_activation' ) ) {
$new_options = array(
array(
'id' => 'seopress_detected',
'type' => 'title',
'title' => __( 'SEOPress SEO Detected', 'geodirectory' ),
'desc' => geodir_notification( array( 'info' => __( 'The SEOPress SEO plugin has been detected and will take over the GeoDirectory meta Settings unless disabled below. (titles from here will still be used, but not meta)', 'geodirectory' ) ) ),
),
array(
'id' => 'seopress_disable',
'type' => 'checkbox',
'name' => __( 'Disable SEOPress', 'geodirectory' ),
'desc' => __( 'Disable overwrite by SEOPress titles & metas on GD pages?', 'geodirectory' ),
'default' => '0',
),
array(
'id' => 'seopress_detected',
'type' => 'sectionend'
)
);
array_splice( $options, 2, 0, $new_options );
}
return $options;
}
/**
* Maybe force legacy theme styles.
*/
public static function maybe_force_legacy_styles(){
$design_style = geodir_design_style();
// Kleo theme (runs Bootstrap v3 which makes new styles incompatible)
if ( function_exists( 'kleo_setup' ) && $design_style ) {
// disable if older ver ov Kleo
if( defined('SVQ_THEME_VERSION') && version_compare(SVQ_THEME_VERSION,'4.9.170','<') ){
global $aui_disabled_notice;
add_action( 'admin_notices', array( __CLASS__, 'notice_aui_disabled' ) );
$settings_link = admin_url("admin.php?page=gd-settings&tab=general§ion=developer");
$aui_disabled_notice = sprintf( __("Kleo theme works best with GeoDirectory legacy styles, please set legacy styles %shere%s","geodirectory"),"<a href='$settings_link'>","</a>");
}
}elseif ( function_exists( 'listimia_setup' ) && $design_style ) {
global $aui_disabled_notice;
$parent_theme = wp_get_theme();
if ( ! empty( $parent_theme ) && is_child_theme() ) {
$parent_theme = wp_get_theme( $parent_theme->Template );
}
if ( ! empty( $parent_theme ) && version_compare( $parent_theme->Version, '1.1.7', '<' ) ) {
add_action( 'admin_notices', array( __CLASS__, 'notice_aui_disabled' ) );
$settings_link = admin_url("admin.php?page=gd-settings&tab=general§ion=developer");
$aui_disabled_notice = sprintf( __("Listimia theme works best with GeoDirectory legacy styles, please set legacy styles %shere%s","geodirectory"),"<a href='$settings_link'>","</a>");
}
}
}
/**
* Show a notice if AUI is disabled.
*/
public static function notice_aui_disabled() {
global $aui_disabled_notice;
if($aui_disabled_notice && (
isset($_REQUEST['page']) && ( $_REQUEST['page'] == 'ayecode-ui-settings' || $_REQUEST['page'] == 'gd-settings' )
)){
$class = 'notice notice-error';
printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), $aui_disabled_notice );
}
}
/**
* Disable AUI
*
* @param $settings
*
* @return mixed
*/
public static function disable_aui($settings){
$settings['css'] = '';
$settings['js'] = '';
$settings['html_font_size'] = '';
return $settings;
}
/**
* Setup actions on admin AJAX load.
*
* @since 2.0.0.97
*/
public static function ajax_admin_init() {
// WPBakery Page Builder render vc tags in AJAX content.
if ( class_exists( 'WPBMap' ) && ! empty( $_REQUEST['action'] ) && strpos( $_REQUEST['action'], 'geodir_' ) === 0 ) {
WPBMap::addAllMappedShortcodes();
}
}
/**
* Rank Math Category image
*
* @param object $this_var rankmath class object
*/
public static function rank_math_cat_image( $this_var ) {
global $wp_query;
if( is_category() || is_tax() ){
$term = $wp_query->get_queried_object();
if ( ! empty( $term->term_id ) && ! empty( $term->taxonomy ) && geodir_is_gd_taxonomy( $term->taxonomy ) ) {
$image_id = get_term_meta( $term->term_id, "rank_math_facebook_image_id", true );
$this_var->add_image_by_id( $image_id );
}
}
}
/**
* Setup functions on plugins loaded.
*
* @since 2.0.0.81
*/
public static function plugins_loaded() {
// Simple Page Sidebars plugin add sidebar supports.
if ( class_exists( 'Simple_Page_Sidebars' ) ) {
$post_types = geodir_get_posttypes();
add_post_type_support( 'page', 'simple-page-sidebars' );
if ( ! empty( $post_types ) ) {
foreach ( $post_types as $post_type ) {
add_post_type_support( $post_type, 'simple-page-sidebars' );
}
}
}
}
/**
* Set temp globals before looping listings template so we can reset them to proper values after looping.
*
* @param $template_name
*/
public static function avada_get_temp_globals($template_name){
if($template_name == 'content-widget-listing.php' || basename($template_name) == 'content-archive-listing.php'){
global $columns, $global_column_array, $fb_temp_columns, $fb_temp_global_column_array;
$fb_temp_columns = $columns;
$fb_temp_global_column_array = $global_column_array;
}
}
/**
* Reset globals after looping listings template so we can reset them to proper values after looping.
*
* @param $template_name
*/
public static function avada_set_temp_globals($template_name){
if($template_name == 'content-widget-listing.php' || basename($template_name) == 'content-archive-listing.php'){
global $columns, $global_column_array, $fb_temp_columns, $fb_temp_global_column_array;
$columns = $fb_temp_columns;
$global_column_array = $fb_temp_global_column_array;
}
}
/**
* Setup Avada header actions.
*
* @since 2.0.0.102
*/
public static function avada_wp_head_setup() {
if ( geodir_is_geodir_page() ) {
if ( has_action( 'avada_render_header' ) ) {
add_action( 'avada_render_header', array( __CLASS__, 'avada_pause_the_content' ), 1 );
add_action( 'avada_render_header', array( __CLASS__, 'avada_resume_the_content' ), 101 );
}
if ( has_action( 'avada_override_current_page_title_bar' ) ) {
add_action( 'avada_override_current_page_title_bar', array( __CLASS__, 'avada_pause_the_content' ), 1 );
add_action( 'avada_override_current_page_title_bar', array( __CLASS__, 'avada_resume_the_content' ), 101 );
}
}
}
/**
* Setup Avada footer actions.
*
* @since 2.0.0.102
*/
public static function avada_get_footer_setup() {
if ( geodir_is_geodir_page() && has_action( 'avada_render_footer' ) ) {
add_action( 'avada_render_footer', array( __CLASS__, 'avada_pause_the_content' ), 1 );
add_action( 'avada_render_footer', array( __CLASS__, 'avada_resume_the_content' ), 101 );
}
}
public static function avada_fusion_template_content_pause() {
if ( geodir_is_page( 'search' ) ) {
self::avada_pause_the_content();
}
}
public static function avada_fusion_template_content_resume() {
if ( geodir_is_page( 'search' ) ) {
self::avada_resume_the_content();
}
}
public static function avada_fusion_tb_override( $override, $c_page_id ) {
if ( geodir_is_page( 'search' ) ) {
$Fusion_Template_Builder = Fusion_Template_Builder();
$args = [
'post_type' => 'fusion_tb_layout',
'post_status' => 'publish',
'posts_per_page' => -1,
'suppress_filters' => true,
];
if ( class_exists( 'WooCommerce' ) ) {
remove_filter( 'the_posts', [ WC()->query, 'remove_product_query_filters' ] );
$layouts = fusion_cached_query( $args );
add_filter( 'the_posts', [ WC()->query, 'remove_product_query_filters' ] );
} else {
$layouts = fusion_cached_query( $args );
}
$layouts = $layouts->posts;
$target_post = get_post( geodir_search_page_id() );
$target_post->is_singular = true;
/**
* Check if whatever is being loaded should have a template override.
*/
$_layout = null;
if ( is_array( $layouts ) ) {
foreach ( $layouts as $layout ) {
if ( self::check_full_conditions( $layout, $target_post, $Fusion_Template_Builder ) ) {
$layout->permalink = get_permalink( $layout->ID );
$Fusion_Template_Builder->layout = $layout;
$_layout = $layout;
}
}
}
$override = $_layout;
// We're on purpose using wp_reset_query() instead of wp_reset_postdata() here
// because we've altered the main query above.
wp_reset_query(); // phpcs:ignore WordPress.WP.DiscouragedFunctions
}
return $override;
}
/**
* Check if current post matched conditions of template.
*
* @since 2.2
* @param WP_Post $template Section post object.
* @param WP_Post $target_post The target post object.
* @return bool Whether it passed or not.
* @access public
*/
public static function check_full_conditions( $template, $target_post, $Fusion_Template_Builder ) {
global $pagenow;
$conditions = Fusion_Template_Builder::get_conditions( $template );
$backend_pages = [ 'post.php', 'term.php' ];
if ( is_array( $conditions ) ) {
foreach ( $conditions as $condition ) {
if ( isset( $condition['type'] ) && '' !== $condition['type'] && isset( $condition[ $condition['type'] ] ) ) {
$type = $condition['type'];
$exclude = 'exclude' === $condition['mode'];
if ( fusion_is_preview_frame() || ( is_admin() && in_array( $pagenow, $backend_pages ) ) ) { // phpcs:ignore WordPress.PHP.StrictInArray
$pass = 'archives' === $type ? $Fusion_Template_Builder->builder_check_archive_condition( $condition ) : $Fusion_Template_Builder->builder_check_singular_condition( $condition, $target_post );
} else {
$pass = 'archives' === $type && ! is_search() ? $Fusion_Template_Builder->check_archive_condition( $condition ) : $Fusion_Template_Builder->builder_check_singular_condition( $condition, $target_post );
}
// If it doesn't pass all exclude conditions check is false.
// If all exclude conditions are valid and we find one valid condition check is true.
if ( $exclude && ! $pass ) {
return false;
} elseif ( ! $exclude && $pass ) {
return true;
}
}
}
}
// The default behaviour.
return false;
}
/**
* Remove GD archive page template the_content filter.
*
* @since 2.0.0.102
*
* @global bool|null $geodir_avada_the_content Flag to remove filter.
*/
public static function avada_pause_the_content() {
global $geodir_avada_the_content;
if ( has_filter( 'the_content', array( 'GeoDir_Template_Loader', 'setup_archive_page_content' ) ) ) {
$geodir_avada_the_content = true;
remove_filter( 'the_content', array( 'GeoDir_Template_Loader', 'setup_archive_page_content' ) );
}
}
/**
* Add GD archive page template the_content filter.
*
* @since 2.0.0.102
*
* @global bool|null $geodir_avada_the_content Flag to add filter back.
*/
public static function avada_resume_the_content() {
global $geodir_avada_the_content;
if ( $geodir_avada_the_content ) {
$geodir_avada_the_content = false;
if ( ! has_filter( 'the_content', array( 'GeoDir_Template_Loader', 'setup_archive_page_content' ) ) ) {
add_filter( 'the_content', array( 'GeoDir_Template_Loader', 'setup_archive_page_content' ) );
}
}
}
/**
* Make sure divi actions fire on some of our ajax calls so builder shortcodes are rendered.
*
* @param $actions
*
* @return array
*/
public static function divi_builder_ajax_load_actions( $actions ) {
$actions[] = 'geodir_recently_viewed_listings';
$actions[] = 'geodir_widget_listings';
$actions[] = 'geodir_bestof';
$actions[] = 'geodir_ajax_search';
return $actions;
}
/**
* Adds a warning message if a user tries to use BB on a template page.
*/
public static function beaver_builder_template_warning(){
// check if we are in builder
if(!is_admin() && isset($_REQUEST['fl_builder']) && $id = get_the_ID() ){
if(geodir_is_geodir_page_id($id)){
global $geodirectory;
$is_geodir_page_template = false;
if(!empty($geodirectory->settings['page_search']) && $geodirectory->settings['page_search'] == $id ){
$is_geodir_page_template = true;
}elseif(!empty($geodirectory->settings['page_add']) && $geodirectory->settings['page_add'] == $id ){
$is_geodir_page_template = true;
}elseif(!empty($geodirectory->settings['page_details']) && $geodirectory->settings['page_details'] == $id ){
$is_geodir_page_template = true;
}elseif(!empty($geodirectory->settings['page_archive']) && $geodirectory->settings['page_archive'] == $id ){
$is_geodir_page_template = true;
}elseif(!empty($geodirectory->settings['page_archive_item']) && $geodirectory->settings['page_archive_item'] == $id ){
$is_geodir_page_template = true;
}elseif( geodir_is_cpt_template_page( $id ) ){
$is_geodir_page_template = true;
}
if($is_geodir_page_template ){
$warning_message = sprintf(
__('GeoDirectory template pages work much better with %sBeaver Themer%s :: %sLearn more%s', 'geodirectory'),
'<a href="https://www.wpbeaverbuilder.com/beaver-themer/" target="_blank">',
' <i class="fas fa-external-link-alt"></i></a>',
'<a href="https://wpgeodirectory.com/docs-v2/integrations/builders/#bb-themer" target="_blank">',
' <i class="fas fa-external-link-alt"></i></a>'
);
$warning_html = '<div class="gd-notification gd-warning "><i class="fas fa-exclamation-triangle"></i> '.$warning_message.'</div>';
echo "<script>jQuery(function() {beaver_builder_template_warning = lity('<div class=\"lity-show\">$warning_html <a href=\"#\" onclick=\"beaver_builder_template_warning.close();\">Close</a></div>');});</script>";
}
}
}
}
/**
* Fix details page title, primer theme breaks it.
*
* @since 2.0.0
*/
public static function for_later_checks() {
/*######################################################
Boss. (BuddyBoss)
######################################################*/
if ( function_exists( 'buddyboss_theme' ) || class_exists( 'BuddyBoss_Theme' ) ) {
add_action( 'wp_enqueue_scripts', array( __CLASS__, 'buddyboss' ), 100 );
add_filter( 'body_class', array( __CLASS__, 'buddyboss_body_class' ) );
}
/*######################################################
Genesis theme (Corporate Pro)
######################################################*/
if ( function_exists( 'corporate_body_classes' ) ) {
add_filter( 'body_class', array( __CLASS__, 'genesis_corporate_pro_body_class' ) );
}
/*######################################################
Some themes not setting our meta info via our normal hook
::
X
Newspaper
MightyMag
######################################################*/
if ( ! is_admin() &&
(
function_exists( 'x_get_view' )
|| defined( 'TD_THEME_VERSION' )
|| function_exists( 'pi_elv_include_scripts' )
|| ( ( function_exists( 'mfn_body_classes' ) && function_exists( 'mfn_ID' ) ) )
|| function_exists( 'mgm_setup' )
|| function_exists( 'genesis_theme_support' )
|| function_exists( 'ffmp_setup' ) // ffmp theme
)
) {
add_action( 'wp_title', array( 'GeoDir_SEO', 'set_meta' ), 9 );
}
/*######################################################
SEOPress (breaks search page)
######################################################*/
if(function_exists('seopress_activation')){
add_action( 'wp_head', array( __CLASS__, 'seopress' ), 0 );
}
/*######################################################
Enfold
######################################################*/
if ( function_exists('avia_lang_setup') ) {
add_filter( 'avf_preview_window_css_files', array( __CLASS__, 'enfold_preview_styles' ) );
add_filter( 'avf_title_args', array( __CLASS__, 'enfold_avf_title_args' ), 10, 2 );
}
// Flatsome theme breaks search page.
if ( isset( $_REQUEST['geodir_search'] ) && function_exists( 'flatsome_contentfix' ) && has_filter( 'the_content', 'flatsome_contentfix' ) ) {
remove_filter( 'the_content', 'flatsome_contentfix' );
add_filter( 'the_content', 'flatsome_contentfix', 11 );
}
// Astra + Spectra
if ( class_exists( 'UAGB_Post_Assets' ) ) {
add_action( 'wp_enqueue_scripts', array( __CLASS__, 'spectra_uagb_post_assets_enqueue_scripts' ), 99 );
}
// Blocksy Theme
if ( class_exists( 'Blocksy_Manager', false ) ) {
add_filter( 'theme_mod_search_hero_elements', array( __CLASS__, 'blocksy_get_theme_mod' ), 11, 1 );
add_filter( 'theme_mod_custom_description', array( __CLASS__, 'blocksy_get_theme_mod' ), 11, 1 );
add_filter( 'theme_mod_hero_custom_description', array( __CLASS__, 'blocksy_get_theme_mod' ), 11, 1 );
}
}
/**
* Add some basic styles to the editor preview.
*
* @param $css
*
* @return mixed
*/
public static function enfold_preview_styles($css){
// add our preview styles
$css[geodir_plugin_url() . '/assets/css/block_editor.css'] = 1;
return $css;
}
/**
* SEOPress breaks the search page when nothing is searched, so we remove some filters in that case.
*/
public static function seopress(){
if(geodir_is_page( 'search' )){
remove_action( 'wp_head', 'seopress_social_fb_desc_hook', 1 );
remove_action( 'wp_head', 'seopress_social_twitter_desc_hook', 1 );
}
}
/**
* Fix conflicts for title hook priority with SEOPress.
*
* @since 2.2.7
*
* @param int $priority Title hook priority.
* @return int Filtered priority.
*/
public static function seopress_titles_the_title_priority( $priority ) {
$priority = 1500;
return $priority;
}
/**
* Adds warning notices if BuddyPress is active and has issues.
*/
public static function buddypress_notices() {
if ( is_admin() ) {
// In BuddyPress v6.0.0 no /search/ conflict detected.
if ( version_compare( bp_get_version(), '6.0.0', '>=' ) ) {
// Remove existing notice.
if ( GeoDir_Admin_Notices::has_notice( 'buddypress_search_slug_error' ) ) {
GeoDir_Admin_Notices::remove_notice( 'buddypress_search_slug_error' );
}
return;
}
// maybe add search slug warning.
$search_page_id = geodir_search_page_id();
$search_slug = get_post_field( 'post_name', $search_page_id );
if ( GeoDir_Admin_Notices::has_notice( 'buddypress_search_slug_error' ) ) {
if ( $search_slug != 'search' ) {
GeoDir_Admin_Notices::remove_notice( 'buddypress_search_slug_error' );
}
} else {
if ( $search_slug == 'search' ) {
GeoDir_Admin_Notices::add_custom_notice(
'buddypress_search_slug_error',
sprintf(
__( '<b>WARNING:</b> BuddyPress hijacks the slug `search`, GD search will not work until you update the GD search page slug to something different. <a href="%s">Edit page</a>', 'geodirectory' ),
get_edit_post_link( $search_page_id )
)
);
}
}
}
}
/**
* Stop the GD loop setup if elementor is overriding it.
*
* @global int $gd_skip_the_content
*
* @param $bypass
*
* @return bool
*/
public static function elementor_loop_bypass( $bypass ) {
global $gd_skip_the_content;
if ( defined( 'ELEMENTOR_PRO_VERSION' ) && GeoDir_Elementor::is_template_override() ) {
$bypass = true;
}
if ( ! $bypass && $gd_skip_the_content ) {
$bypass = true; // Prevent looping on some themes/plugins.
}
//if ( ! $bypass && function_exists( 'et_theme_builder_get_template_layouts' ) && et_theme_builder_get_template_layouts() ) {
//$bypass = true;
//}
return $bypass;
}
/**
* Dynamically add post meta to some GD pages from their page templates.
*
* This helps trick page builders into using the page template settings.
*
* @global WP_Query $wp_query Global WP_Query instance.
*
* @param $metadata
* @param $object_id
* @param $meta_key
* @param $single
*
* @return null|string
*/
public static function dynamically_add_post_meta( $metadata, $object_id, $meta_key, $single ) {
global $wp_query, $post; // this is needed to make sure get_queried_object_id() if defined.
$object_post_type = get_post_type( (int) $object_id );
// Bail when non related post type.
if ( in_array( $object_post_type, array( 'attachment', 'nav_menu_item', 'card_templates', 'advanced_ads','product' ) ) ) {
return $metadata;
}
// Bail when non related meta_key.
if ( ! empty( $meta_key ) && is_scalar( $meta_key ) && in_array( $meta_key, array( 'amazonS3_cache' ) ) ) {
return $metadata;
}
// Standard WP fields
$wp_keys = array(
'_wp_page_template'
);
// Generic keys
$gen_keys = array(
'primer_layout', // primer theme layout
);
// FusionBuilder (Avada theme), we need to add these on the fly
if ( class_exists( 'FusionBuilder' ) ) {
if ( substr( $meta_key, 0, 5 ) === "pyre_" || substr( $meta_key, 0, 4 ) === "sbg_" ) {
$gen_keys[] = $meta_key;
}
}
// Astra theme
if ( defined('ASTRA_THEME_VERSION') ) {
$gen_keys[] = 'ast-main-header-display';
$gen_keys[] = 'footer-sml-layout';
$gen_keys[] = 'site-post-title';
$gen_keys[] = 'site-sidebar-layout';
$gen_keys[] = 'site-content-layout';
$gen_keys[] = 'ast-featured-img';
$gen_keys[] = 'theme-transparent-header-meta';
}
// Enfold theme
if ( function_exists( 'avia_get_option' ) ) {
if ( strpos( $meta_key, '_avia_' ) === 0 || strpos( $meta_key, '_aviaLayout' ) === 0 ) {
$gen_keys[] = $meta_key;
}
$gen_keys[] = 'header';
$gen_keys[] = 'header_transparency';
$gen_keys[] = 'header_title_bar';
$gen_keys[] = 'footer';
$gen_keys[] = 'sidebar';
$gen_keys[] = 'layout';
}
// Sky theme
if ( function_exists( 'vh_setup' ) ) {
if ( substr( $meta_key, 0, 4 ) === "sbg_" ) {
$gen_keys[] = $meta_key;
}
$gen_keys[] = 'layouts';
}
$backup_post = NULL;
// Elvyre - Retina Ready Wordpress Theme
if ( function_exists( 'pi_elv_include_scripts' ) ) {
if ( strpos( $meta_key, 'pg_' ) === 0 ) {
$elvyre_keys = array( 'pg_sidebar', 'pg_portfolio_style', 'pg_portfolio_taxonomies', 'pg_hide_title', 'pg_page_description', 'pg_title_style', 'pg_title_color', 'pg_title_image', 'pg_additional_title_image', 'pg_parallax' );
$gen_keys = array_merge( $gen_keys, $elvyre_keys );
// Archive page set page post.
if ( in_array( $meta_key, $elvyre_keys ) && ! empty( $wp_query ) && ! empty( $wp_query->post->post_type ) && geodir_is_gd_post_type( $object_post_type ) && $wp_query->post->post_type == 'page' && ( geodir_is_page( 'archive' ) || geodir_is_page( 'post_type' ) || geodir_is_page( 'search' ) ) ) {
$post = $wp_query->post;
$backup_post = $post;
}
}
}