/
admin_hooks_actions.php
2663 lines (2220 loc) · 103 KB
/
admin_hooks_actions.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
/**
* GeoDirectory Admin.
*
* Main admin file which loads all settings panels and sets up admin menus.
*
* @since 1.0.0
* @package GeoDirectory
*/
add_action('admin_init', 'geodir_admin_init');
if (!function_exists('geodir_admin_init')) {
/**
* Adds GD setting pages in admin.
*
* @since 1.0.0
* @package GeoDirectory
* @global string $current_tab The current settings tab name.
*/
function geodir_admin_init()
{
if (is_admin()):
global $current_tab;
geodir_redirect_to_admin_panel_on_installed();
$current_tab = (isset($_GET['tab']) && $_GET['tab'] != '') ? $_GET['tab'] : 'general_settings';
if (!(isset($_REQUEST['action']))) // this will avoid Ajax requests
geodir_handle_option_form_submit($current_tab); // located in admin function.php
/**
* Called on the WordPress 'admin_init' hook this hookis used to call everything for the GD settings pages in the admin area.
*
* @since 1.0.0
*/
do_action('admin_panel_init');
add_action('geodir_admin_option_form', 'geodir_get_admin_option_form', 1);
endif;
}
}
/**
* Redirects to admin page after plugin activation.
*
* @since 1.0.0
* @package GeoDirectory
*/
function geodir_redirect_to_admin_panel_on_installed()
{
if (get_option('geodir_installation_redirect', false)) {
delete_option('geodir_installation_redirect');
wp_redirect(admin_url('admin.php?page=geodirectory&installed=yes'));
}
}
/**
* Displays setting form for the given tab.
*
* @since 1.0.0
* @package GeoDirectory
* @param string $current_tab The current settings tab name.
*/
function geodir_get_admin_option_form($current_tab)
{
geodir_admin_option_form($current_tab);// defined in admin template tags.php
}
/* Is used to show success or error message at the top of admin option panel */
add_action('geodir_update_options_compatibility_settings', 'geodir_update_options_compatibility_settings');
add_action('geodir_update_options_default_location_settings', 'geodir_location_form_submit');
add_action('geodir_before_admin_panel', 'geodir_before_admin_panel'); // this function is in admin_functions.php
add_action('geodir_before_update_options', 'geodir_before_update_options',10,2);
//add_action('geodir_before_admin_panel', 'geodir_autoinstall_admin_header');
/**
* Admin scripts loader.
*
* @since 1.0.0
* @since 1.6.0 Changes to work category icon and default image uploader for WP 4.5.
* @since 1.6.3 Modified to fix jQuery chosen js conflicts.
* @since 1.6.16 Fixed VC editor conflicts for GD post types.
* @package GeoDirectory
* @global string $pagenow The current screen.
*/
function geodir_conditional_admin_script_load()
{
global $pagenow;
// Get the current post type
$post_type = geodir_admin_current_post_type();
$geodir_post_types = geodir_get_posttypes();
if ((isset($_REQUEST['page']) && $_REQUEST['page'] == 'geodirectory') || (($pagenow == 'post.php' || $pagenow == 'post-new.php' || $pagenow == 'edit.php') && $post_type && in_array($post_type, $geodir_post_types)) || ($pagenow == 'edit-tags.php' || $pagenow == 'term.php' || $pagenow == 'edit-comments.php' || $pagenow == 'comment.php')) {
add_action('admin_enqueue_scripts', 'geodir_admin_scripts');
add_action('admin_enqueue_scripts', 'geodir_admin_styles');
add_action('admin_enqueue_scripts', 'geodir_admin_dequeue_scripts', 100);
// Disable VC editor for GD post types.
if (class_exists('Vc_Role_Access_Controller')) {
add_filter( 'vc_role_access_with_post_types_can', '__return_false', 100 );
}
}
add_action('admin_enqueue_scripts', 'geodir_admin_styles_req');
}
add_action('init', 'geodir_conditional_admin_script_load');
/**
* Admin Menus
*/
add_action('admin_menu', 'geodir_admin_menu');
/**
* Order admin menus
*/
add_action('menu_order', 'geodir_admin_menu_order');
add_action('admin_panel_init', 'geodir_location_form_submit'); // in location_function.php
add_action('admin_panel_init', 'create_default_admin_main_nav', 1);
add_action('admin_panel_init', 'geodir_admin_list_columns', 2);
/* --- insert dummy post action ---*/
add_action('geodir_insert_dummy_posts', 'geodir_insert_dummy_posts', 1,3);
add_action('geodir_delete_dummy_posts', 'geodir_delete_dummy_posts', 1,3);
/**
* Creates default admin navigation.
*
* @since 1.0.0
* @package GeoDirectory
*/
function create_default_admin_main_nav()
{
add_filter('geodir_settings_tabs_array', 'geodir_default_admin_main_tabs', 1);
add_filter('geodir_settings_tabs_array', 'places_custom_fields_tab', 2);
add_filter('geodir_settings_tabs_array', 'geodir_compatibility_setting_tab', 90);
add_filter('geodir_settings_tabs_array', 'geodir_tools_setting_tab', 95);
add_filter('geodir_settings_tabs_array', 'geodir_extend_geodirectory_setting_tab', 100);
//add_filter('geodir_settings_tabs_array', 'geodir_hide_set_location_default',3);
}
/**
* Adds custom columns on geodirectory post types.
*
* @since 1.0.0
* @since 1.6.24 Remove bulk edit action.
* @package GeoDirectory
*/
function geodir_admin_list_columns()
{
if ($post_types = geodir_get_posttypes()) {
foreach ($post_types as $post_type):
add_filter("manage_edit-{$post_type}_columns", 'geodir_edit_post_columns', 100);
//Filter-Payment-Manager to show Package
add_action("manage_{$post_type}_posts_custom_column", 'geodir_manage_post_columns', 10, 2);
add_filter("manage_edit-{$post_type}_sortable_columns", 'geodir_post_sortable_columns');
// Filter bulk actions
add_filter("bulk_actions-edit-{$post_type}", 'geodir_filter_bulk_actions', 10, 1);
endforeach;
}
}
/**
* Returns an array of main settings tabs.
*
* @since 1.0.0
* @package GeoDirectory
* @param array $tabs Tabs array.
* @return array Tabs array.
*/
function geodir_default_admin_main_tabs($tabs)
{
return $tabs = array(
'general_settings' => array('label' => __('General', 'geodirectory')),
'design_settings' => array('label' => __('Design', 'geodirectory')),
'permalink_settings' => array('label' => __('Permalinks', 'geodirectory')),
'title_meta_settings' => array('label' => __('Titles & Metas', 'geodirectory')),
'notifications_settings' => array('label' => __('Notifications', 'geodirectory')),
'default_location_settings' => array('label' => __('Set Default Location', 'geodirectory')),
);
}
add_action('do_meta_boxes', 'geodir_remove_image_box');
/**
* Removes default thumbnail metabox on GD post types.
*
* @since 1.0.0
* @package GeoDirectory
* @global object $post WordPress Post object.
*/
function geodir_remove_image_box()
{
global $post;
$geodir_posttypes = geodir_get_posttypes();
if (isset($post) && in_array($post->post_type, $geodir_posttypes)):
remove_meta_box('postimagediv', $post->post_type, 'side');
remove_meta_box('revisionsdiv', $post->post_type, 'normal');
endif;
}
add_action('add_meta_boxes', 'geodir_meta_box_add');
/**
* Adds meta boxes to the GD post types.
*
* @since 1.0.0
* @package GeoDirectory
* @global object $post WordPress Post object.
*/
function geodir_meta_box_add()
{
global $post;
$geodir_post_types = geodir_get_posttypes('array');
$geodir_posttypes = array_keys($geodir_post_types);
if (isset($post->post_type) && in_array($post->post_type, $geodir_posttypes)):
$geodir_posttype = $post->post_type;
$post_typename = __($geodir_post_types[$geodir_posttype]['labels']['singular_name'], 'geodirectory');
$post_typename = geodir_ucwords($post_typename);
// Filter-Payment-Manager
add_meta_box('geodir_post_images', $post_typename . ' ' . __('Attachments', 'geodirectory'), 'geodir_post_attachments', $geodir_posttype, 'side');
add_meta_box('geodir_post_info', $post_typename . ' ' . __('Information', 'geodirectory'), 'geodir_post_info_setting', $geodir_posttype, 'normal', 'high');
// no need of this box as all fields moved to main information box
//add_meta_box( 'geodir_post_addinfo', $post_typename. ' ' .__('Additional Information' , 'geodirectory'), 'geodir_post_addinfo_setting', $geodir_posttype,'normal', 'high' );
endif;
}
add_action('save_post', 'geodir_post_information_save',10,2);
//add_filter('geodir_design_settings' , 'geodir_show_hide_location_switcher_nav' ) ;
add_action('admin_menu', 'geodir_hide_post_taxonomy_meta_boxes');
/**
* Removes taxonomy meta boxes.
*
* GeoDirectory hide categories post meta.
*
* @since 1.0.0
* @package GeoDirectory
*/
function geodir_hide_post_taxonomy_meta_boxes()
{
$geodir_post_types = get_option('geodir_post_types');
if (!empty($geodir_post_types)) {
foreach ($geodir_post_types as $geodir_post_type => $geodir_posttype_info) {
$gd_taxonomy = geodir_get_taxonomies($geodir_post_type);
if(!empty($gd_taxonomy)) {
foreach ($gd_taxonomy as $tax) {
remove_meta_box($tax . 'div', $geodir_post_type, 'normal');
}
}
}
}
}
add_filter('geodir_add_listing_map_restrict', 'geodir_add_listing_map_restrict');
/**
* Checks whether to restrict the map for specific address only.
*
* @since 1.0.0
* @package GeoDirectory
* @param bool $map_restirct The value before filter.
* @return bool The value after filter.
*/
function geodir_add_listing_map_restrict($map_restirct)
{
if (is_admin()) {
if (isset($_REQUEST['tab']) && $_REQUEST['tab'] == 'default_location_settings') {
$map_restirct = false;
}
}
return $map_restirct;
}
add_filter('geodir_notifications_settings', 'geodir_enable_editor_on_notifications', 1);
/**
* Converts textarea field to WYSIWYG editor on Notification settings.
*
* WP Admin -> Geodirectory -> Notifications.
*
* @since 1.0.0
* @package GeoDirectory
* @param array $notification The notification settings array.
* @return array Modified notification settings array.
*/
function geodir_enable_editor_on_notifications($notification)
{
if (!empty($notification) && get_option('geodir_tiny_editor') == '1') {
foreach ($notification as $key => $value) {
if ($value['type'] == 'textarea')
$notification[$key]['type'] = 'editor';
}
}
return $notification;
}
add_filter('geodir_design_settings', 'geodir_enable_editor_on_design_settings', 1);
/**
* Converts textarea field to WYSIWYG editor on Design settings.
*
* @since 1.0.0
* @package GeoDirectory
* @param array $design_setting The design settings array.
* @return array Modified design settings array.
*/
function geodir_enable_editor_on_design_settings($design_setting)
{
if (!empty($design_setting) && get_option('geodir_tiny_editor') == '1') {
foreach ($design_setting as $key => $value) {
if ($value['type'] == 'textarea' && $value['id'] == 'geodir_term_condition_content')
$design_setting[$key]['type'] = 'editor';
}
}
return $design_setting;
}
/* ----------- START MANAGE CUSTOM FIELDS ---------------- */
add_action('geodir_manage_available_fields_predefined', 'geodir_manage_available_fields_predefined');
add_action('geodir_manage_available_fields_custom', 'geodir_manage_available_fields_custom');
function geodir_manage_available_fields_predefined($sub_tab){
if($sub_tab=='custom_fields'){
geodir_custom_available_fields('predefined');
}
}
function geodir_manage_available_fields_custom($sub_tab){
if($sub_tab=='custom_fields'){
geodir_custom_available_fields('custom');
}
}
add_action('geodir_manage_available_fields', 'geodir_manage_available_fields');
/**
* Lists available fields for the given sub tab.
*
* WP Admin -> Geodirectory -> (post type) Settings -> Custom Fields -> Add new Place form field.
* WP Admin -> Geodirectory -> (post type) Settings -> Sorting Options -> Available sorting options for Place listing and search results.
*
* @since 1.0.0
* @package GeoDirectory
* @param string $sub_tab The sub tab slug.
*/
function geodir_manage_available_fields($sub_tab)
{
switch ($sub_tab) {
case 'custom_fields':
geodir_custom_available_fields();
break;
case 'sorting_options':
geodir_sorting_options_available_fields();
break;
}
}
add_action('geodir_manage_selected_fields', 'geodir_manage_selected_fields');
/**
* Adds admin html for selected fields of the given sub tab.
*
* @since 1.0.0
* @package GeoDirectory
* @param string $sub_tab The sub tab slug.
*/
function geodir_manage_selected_fields($sub_tab)
{
switch ($sub_tab) {
case 'custom_fields':
geodir_custom_selected_fields();
break;
case 'sorting_options':
geodir_sorting_options_selected_fields();
break;
}
}
/**
* Adds admin html for sorting options available fields.
*
* @since 1.0.0
* @package GeoDirectory
* @global object $wpdb WordPress Database object.
*/
function geodir_sorting_options_available_fields()
{
global $wpdb;
$listing_type = ($_REQUEST['listing_type'] != '') ? sanitize_text_field($_REQUEST['listing_type']) : 'gd_place';
?>
<input type="hidden" name="listing_type" id="new_post_type" value="<?php echo $listing_type;?>"/>
<input type="hidden" name="manage_field_type" class="manage_field_type" value="<?php echo sanitize_text_field($_REQUEST['subtab']); ?>"/>
<ul>
<?php
$sort_options = geodir_get_custom_sort_options($listing_type);
foreach ($sort_options as $key => $val) {
$val = stripslashes_deep($val); // strip slashes
$check_html_variable = $wpdb->get_var(
$wpdb->prepare(
"SELECT htmlvar_name FROM " . GEODIR_CUSTOM_SORT_FIELDS_TABLE . " WHERE htmlvar_name = %s AND post_type = %s AND field_type=%s",
array($val['htmlvar_name'], $listing_type, $val['field_type'])
)
);
$display = $check_html_variable ? ' style="display:none;"' : '';
?>
<li class="gd-cf-tooltip-wrap" <?php echo $display;?>>
<?php
if(isset($val['description']) && $val['description']){
echo '<div class="gdcf-tooltip">'.$val['description'].'</div>';
}?>
<a id="gd-<?php echo $val['field_type'];?>-_-<?php echo $val['htmlvar_name'];?>" data-field-type-key="<?php echo $val['htmlvar_name'];?>" data-field-type="<?php echo $val['field_type'];?>"
title="<?php echo $val['site_title'];?>"
class="gd-draggable-form-items gd-<?php echo $val['field_type'];?> geodir-sort-<?php echo $val['htmlvar_name'];?>" href="javascript:void(0);">
<?php if (isset($val['field_icon']) && strpos($val['field_icon'], ' fa-') !== false) {
echo '<i class="'.$val['field_icon'].'" aria-hidden="true"></i>';
}elseif(isset($val['field_icon']) && $val['field_icon'] ){
echo '<b class="gd-cf-icon" style="background-image: url(\''.$val['field_icon'].'\')"></b>';
}else{
echo '<i class="fas fa-cog" aria-hidden="true"></i>';
}?>
<?php echo (! empty( $val['admin_title'] ) ? $val['admin_title'] : $val['site_title'] );?>
</a>
</li>
<?php
}
?>
</ul>
<?php
}
/**
* Adds admin html for sorting options selected fields.
*
* @since 1.0.0
* @package GeoDirectory
* @global object $wpdb WordPress Database object.
*/
function geodir_sorting_options_selected_fields()
{
$listing_type = ($_REQUEST['listing_type'] != '') ? sanitize_text_field($_REQUEST['listing_type']) : 'gd_place';
?>
<input type="hidden" name="manage_field_type" class="manage_field_type" value="<?php echo sanitize_text_field($_REQUEST['subtab']); ?>"/>
<ul class="core">
<?php
global $wpdb;
$fields = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . GEODIR_CUSTOM_SORT_FIELDS_TABLE . " WHERE post_type = %s AND field_type != 'address' ORDER BY sort_order ASC", array($listing_type)));
if (!empty($fields)) {
foreach ($fields as $field) {
//$result_str = $field->id;
$result_str = $field;
$field_type = $field->field_type;
$field_ins_upd = 'display';
$default = false;
geodir_custom_sort_field_adminhtml($field_type, $result_str, $field_ins_upd, $default);
}
}
?>
</ul>
<?php
}
/**
* Returns the array of custom fields that can be used.
*
* @since 1.6.9
* @package GeoDirectory
*/
function geodir_custom_fields_custom($post_type=''){
$custom_fields = array();
/**
* @see `geodir_custom_fields`
*/
return apply_filters('geodir_custom_fields_custom',$custom_fields,$post_type);
}
/**
* Returns the array of custom fields that can be used.
*
* @since 1.6.6
* @package GeoDirectory
*/
function geodir_custom_fields($post_type=''){
$custom_fields = array(
'text' => array(
'field_type' => 'text',
'class' => 'gd-text',
'icon' => 'fas fa-minus',
'name' => __('Text', 'geodirectory'),
'description' => __('Add any sort of text field, text or numbers', 'geodirectory')
),
'datepicker' => array(
'field_type' => 'datepicker',
'class' => 'gd-datepicker',
'icon' => 'fas fa-calendar-alt',
'name' => __('Date', 'geodirectory'),
'description' => __('Adds a date picker.', 'geodirectory')
),
'textarea' => array(
'field_type' => 'textarea',
'class' => 'gd-textarea',
'icon' => 'fas fa-bars',
'name' => __('Textarea', 'geodirectory'),
'description' => __('Adds a textarea', 'geodirectory')
),
'time' => array(
'field_type' => 'time',
'class' => 'gd-time',
'icon' => 'far fa-clock',
'name' => __('Time', 'geodirectory'),
'description' => __('Adds a time picker', 'geodirectory')
),
'checkbox' => array(
'field_type' => 'checkbox',
'class' => 'gd-checkbox',
'icon' => 'far fa-check-square',
'name' => __('Checkbox', 'geodirectory'),
'description' => __('Adds a checkbox', 'geodirectory')
),
'phone' => array(
'field_type' => 'phone',
'class' => 'gd-phone',
'icon' => 'fas fa-phone',
'name' => __('Phone', 'geodirectory'),
'description' => __('Adds a phone input', 'geodirectory')
),
'radio' => array(
'field_type' => 'radio',
'class' => 'gd-radio',
'icon' => 'far fa-dot-circle',
'name' => __('Radio', 'geodirectory'),
'description' => __('Adds a radio input', 'geodirectory')
),
'email' => array(
'field_type' => 'email',
'class' => 'gd-email',
'icon' => 'far fa-envelope',
'name' => __('Email', 'geodirectory'),
'description' => __('Adds a email input', 'geodirectory')
),
'select' => array(
'field_type' => 'select',
'class' => 'gd-select',
'icon' => 'far fa-caret-square-down',
'name' => __('Select', 'geodirectory'),
'description' => __('Adds a select input', 'geodirectory')
),
'multiselect' => array(
'field_type' => 'multiselect',
'class' => 'gd-multiselect',
'icon' => 'far fa-caret-square-down',
'name' => __('Multi Select', 'geodirectory'),
'description' => __('Adds a multiselect input', 'geodirectory')
),
'url' => array(
'field_type' => 'url',
'class' => 'gd-url',
'icon' => 'fas fa-link',
'name' => __('URL', 'geodirectory'),
'description' => __('Adds a url input', 'geodirectory')
),
'html' => array(
'field_type' => 'html',
'class' => 'gd-html',
'icon' => 'fas fa-code',
'name' => __('HTML', 'geodirectory'),
'description' => __('Adds a html input textarea', 'geodirectory')
),
'file' => array(
'field_type' => 'file',
'class' => 'gd-file',
'icon' => 'fas fa-file',
'name' => __('File Upload', 'geodirectory'),
'description' => __('Adds a file input', 'geodirectory')
)
);
/**
* Filter the custom fields array to be able to add or remove items.
*
* @since 1.6.6
*
* @param array $custom_fields {
* The custom fields array to be filtered.
*
* @type string $field_type The type of field, eg: text, datepicker, textarea, time, checkbox, phone, radio, email, select, multiselect, url, html, file.
* @type string $class The class for the field in backend.
* @type string $icon Can be font-awesome class name or icon image url.
* @type string $name The name of the field.
* @type string $description A short description about the field.
* @type array $defaults {
* Optional. Used to set the default value of the field.
*
* @type string data_type The SQL data type for the field. VARCHAR, TEXT, TIME, TINYINT, INT, FLOAT, DATE
* @type int decimal_point limit if using FLOAT data_type
* @type string admin_title The admin title for the field.
* @type string site_title This will be the title for the field on the frontend.
* @type string admin_desc This will be shown below the field on the add listing form.
* @type string htmlvar_name This is a unique identifier used in the HTML, it MUST NOT contain spaces or special characters.
* @type bool is_active If false the field will not be displayed anywhere.
* @type bool for_admin_use If true then only site admin can see and edit this field.
* @type string default_value The default value for the input on the add listing page.
* @type string show_in The locations to show in. [detail],[moreinfo],[listing],[owntab],[mapbubble]
* @type bool is_required If true the field will be required on the add listing page.
* @type string option_values The option values for select and multiselect only
* @type string validation_pattern HTML5 validation pattern (text input only by default).
* @type string validation_msg HTML5 validation message (text input only by default).
* @type string required_msg Required warning message.
* @type string field_icon Icon url or font awesome class.
* @type string css_class Field custom css class for field custom style.
* @type bool cat_sort If true the field will appear in the category sort options, if false the field will be hidden, leave blank to show option.
* @type bool cat_sort If true the field will appear in the advanced search sort options, if false the field will be hidden, leave blank to show option. (advanced search addon required)
* }
* }
* @param string $post_type The post type requested.
*/
return apply_filters('geodir_custom_fields',$custom_fields,$post_type);
}
/**
* Adds admin html for custom fields available fields.
*
* @since 1.0.0
* @since 1.6.9 Added
* @param string $type The custom field type, predefined, custom or blank for default
* @package GeoDirectory
*/
function geodir_custom_available_fields($type='')
{
$listing_type = ($_REQUEST['listing_type'] != '') ? sanitize_text_field($_REQUEST['listing_type']) : 'gd_place';
?>
<input type="hidden" name="listing_type" id="new_post_type" value="<?php echo $listing_type;?>"/>
<input type="hidden" name="manage_field_type" class="manage_field_type" value="<?php echo sanitize_text_field($_REQUEST['subtab']); ?>" />
<?php
if($type=='predefined'){
$cfs = geodir_custom_fields_predefined($listing_type);
}elseif($type=='custom'){
$cfs = geodir_custom_fields_custom($listing_type);
}else{
$cfs = geodir_custom_fields($listing_type);
?>
<ul class="full gd-cf-tooltip-wrap">
<li>
<div class="gdcf-tooltip">
<?php _e('This adds a section separator with a title.', 'geodirectory');?>
</div>
<a id="gt-fieldset"
class="gd-draggable-form-items gt-fieldset"
href="javascript:void(0);"
data-field-custom-type=""
data-field-type="fieldset"
data-field-type-key="fieldset">
<i class="fas fa-long-arrow-alt-left " aria-hidden="true"></i>
<i class="fas fa-long-arrow-alt-right " aria-hidden="true"></i>
<?php _e('Fieldset (section separator)', 'geodirectory');?>
</a>
</li>
</ul>
<?php
}
if(!empty($cfs)) {
echo '<ul>';
foreach ( $cfs as $id => $cf ) {
?>
<li class="gd-cf-tooltip-wrap">
<?php
if ( isset( $cf['description'] ) && $cf['description'] ) {
echo '<div class="gdcf-tooltip">' . $cf['description'] . '</div>';
} ?>
<a id="gd-<?php echo $id; ?>"
data-field-custom-type="<?php echo $type; ?>"
data-field-type-key="<?php echo $id; ?>"
data-field-type="<?php echo $cf['field_type']; ?>"
class="gd-draggable-form-items <?php echo $cf['class']; ?>"
href="javascript:void(0);">
<?php if ( isset( $cf['icon'] ) && strpos( $cf['icon'], ' fa-' ) !== false ) {
echo '<i class="' . $cf['icon'] . '" aria-hidden="true"></i>';
} elseif ( isset( $cf['icon'] ) && $cf['icon'] ) {
echo '<b class="gd-cf-icon" style="background-image: url(\'' . $cf['icon'] . '\')"></b>';
} else {
echo '<i class="fas fa-cog" aria-hidden="true"></i>';
} ?>
<?php echo $cf['name']; ?>
</a>
</li>
<?php
}
}else{
_e('There are no custom fields here yet.', 'geodirectory');
}
?>
</ul>
<?php
}
/**
* Adds admin html for custom fields selected fields.
*
* @since 1.0.0
* @package GeoDirectory
* @global object $wpdb WordPress Database object.
*/
function geodir_custom_selected_fields()
{
$listing_type = ($_REQUEST['listing_type'] != '') ? sanitize_text_field($_REQUEST['listing_type']) : 'gd_place';
?>
<input type="hidden" name="manage_field_type" class="manage_field_type" value="<?php echo sanitize_text_field($_REQUEST['subtab']); ?>"/>
<ul class="core">
<?php
global $wpdb;
$fields = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . GEODIR_CUSTOM_FIELDS_TABLE . " WHERE post_type = %s ORDER BY sort_order ASC", array($listing_type)));
if (!empty($fields)) {
foreach ($fields as $field) {
//$result_str = $field->id;
$result_str = $field;
$field_type = $field->field_type;
$field_type_key = $field->field_type_key;
$field_ins_upd = 'display';
geodir_custom_field_adminhtml($field_type, $result_str, $field_ins_upd,$field_type_key);
}
}
?></ul>
<?php
}
add_filter('geodir_custom_fields_panel_head', 'geodir_custom_fields_panel_head', 1, 3);
/**
* Returns heading for given sub tab.
*
* @since 1.0.0
* @package GeoDirectory
* @param string $heading The page heading.
* @param string $sub_tab The sub tab slug.
* @param string $listing_type The post type.
* @return string The page heading.
*/
function geodir_custom_fields_panel_head($heading, $sub_tab, $listing_type)
{
switch ($sub_tab) {
case 'custom_fields':
$heading = sprintf(__('Manage %s Custom Fields', 'geodirectory'), get_post_type_singular_label($listing_type, false, true));
break;
case 'sorting_options':
$heading = sprintf(__('Manage %s Listing Sorting Options Fields', 'geodirectory'), get_post_type_singular_label($listing_type, false, true));
break;
}
return $heading;
}
add_filter('geodir_cf_panel_available_fields_head', 'geodir_cf_panel_available_fields_head', 1, 3);
/**
* Returns heading for given sub tab available fields box.
*
* @since 1.0.0
* @package GeoDirectory
* @param string $heading The page heading.
* @param string $sub_tab The sub tab slug.
* @param string $listing_type The post type.
* @return string The page heading.
*/
function geodir_cf_panel_available_fields_head($heading, $sub_tab, $listing_type)
{
switch ($sub_tab) {
case 'custom_fields':
$heading = sprintf(__('Add new %s form field', 'geodirectory'), get_post_type_singular_label($listing_type, false, true));
break;
case 'sorting_options':
$heading = sprintf(__('Available sorting options for %s listing and search results', 'geodirectory'), get_post_type_singular_label($listing_type, false, true));
break;
}
return $heading;
}
add_filter('geodir_cf_panel_available_fields_note', 'geodir_cf_panel_available_fields_note', 1, 3);
/**
* Returns description for given sub tab - available fields box.
*
* @since 1.0.0
* @package GeoDirectory
* @param string $note The box description.
* @param string $sub_tab The sub tab slug.
* @param string $listing_type The post type.
* @return string The box description.
*/
function geodir_cf_panel_available_fields_note($note, $sub_tab, $listing_type)
{
switch ($sub_tab) {
case 'custom_fields':
$note = sprintf(__('Click on any box below to add a field of that type to the add %s listing form. You can use a fieldset to group your fields.', 'geodirectory'), get_post_type_singular_label($listing_type, false, true));
break;
case 'sorting_options':
$note = sprintf(__('Click on any box below to make it appear in the sorting option dropdown on %s listing page.<br />To make a field available here, go to custom fields tab and expand any field from selected fields panel and tick the checkbox saying \'Include this field in sort option\'.', 'geodirectory'), get_post_type_singular_label($listing_type, false, true));
break;
}
return $note;
}
add_filter('geodir_cf_panel_selected_fields_head', 'geodir_cf_panel_selected_fields_head', 1, 3);
/**
* Returns heading for given sub tab selected fields box.
*
* @since 1.0.0
* @package GeoDirectory
* @param string $heading The page heading.
* @param string $sub_tab The sub tab slug.
* @param string $listing_type The post type.
* @return string The page heading.
*/
function geodir_cf_panel_selected_fields_head($heading, $sub_tab, $listing_type)
{
switch ($sub_tab) {
case 'custom_fields':
$heading = sprintf(__('List of fields that will appear on add new %s listing form', 'geodirectory'), get_post_type_singular_label($listing_type, false, true));
break;
case 'sorting_options':
$heading = sprintf(__('List of fields that will appear in %s listing and search results sorting option dropdown box.', 'geodirectory'), get_post_type_singular_label($listing_type, false, true));
break;
}
return $heading;
}
add_filter('geodir_cf_panel_selected_fields_note', 'geodir_cf_panel_selected_fields_note', 1, 3);
/**
* Returns description for given sub tab - selected fields box.
*
* @since 1.0.0
* @package GeoDirectory
* @param string $note The box description.
* @param string $sub_tab The sub tab slug.
* @param string $listing_type The post type.
* @return string The box description.
*/
function geodir_cf_panel_selected_fields_note($note, $sub_tab, $listing_type)
{
switch ($sub_tab) {
case 'custom_fields':
$note = sprintf(__('Click to expand and view field related settings. You may drag and drop to arrange fields order on add %s listing form too.', 'geodirectory'), get_post_type_singular_label($listing_type, false, true));
break;
case 'sorting_options':
$note = sprintf(__('Click to expand and view field related settings. You may drag and drop to arrange fields order in sorting option dropdown box on %s listing page.', 'geodirectory'), get_post_type_singular_label($listing_type, false, true));
break;
}
return $note;
}
add_action('admin_init', 'geodir_remove_unnecessary_fields');
/**
* Removes unnecessary table columns from the database.
*
* @since 1.0.0
* @package GeoDirectory
* @global object $wpdb WordPress Database object.
* @global string $plugin_prefix Geodirectory plugin table prefix.
*/
function geodir_remove_unnecessary_fields()
{
global $wpdb, $plugin_prefix;
if (!get_option('geodir_remove_unnecessary_fields')) {
if ($wpdb->get_var("SHOW COLUMNS FROM " . $plugin_prefix . "gd_place_detail WHERE field = 'categories'"))
$wpdb->query("ALTER TABLE `" . $plugin_prefix . "gd_place_detail` DROP `categories`");
update_option('geodir_remove_unnecessary_fields', '1');
}
}
/* ----------- END MANAGE CUSTOM FIELDS ---------------- */
/* Ajax Handler Start */
add_action('wp_ajax_geodir_admin_ajax', "geodir_admin_ajax_handler");
/**
* Handles admin ajax.
*
* @since 1.0.0
* @package GeoDirectory
*/
function geodir_admin_ajax_handler()
{
if (isset($_REQUEST['geodir_admin_ajax_action']) && $_REQUEST['geodir_admin_ajax_action'] != '') {
$geodir_admin_ajax_action = $_REQUEST['geodir_admin_ajax_action'];
$diagnose_this = "";
switch ($geodir_admin_ajax_action) {
case 'diagnosis' :
if (isset($_REQUEST['diagnose_this']) && $_REQUEST['diagnose_this'] != '') {
$diagnose_this = sanitize_text_field($_REQUEST['diagnose_this']);
call_user_func('geodir_diagnose_' . $diagnose_this);
}
exit();
break;
case 'diagnosis-fix' :
if (isset($_REQUEST['diagnose_this']) && $_REQUEST['diagnose_this'] != '')