-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
1152 lines (1058 loc) · 46.1 KB
/
functions.php
File metadata and controls
1152 lines (1058 loc) · 46.1 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
/**
* Twenty Twenty-Five functions and definitions.
*
* @link https://developer.wordpress.org/themes/basics/theme-functions/
*
* @package WordPress
* @subpackage Twenty_Twenty_Five
* @since Twenty Twenty-Five 1.0
*/
// Adds theme support for post formats.
if ( ! function_exists( 'twentytwentyfive_post_format_setup' ) ) :
/**
* Adds theme support for post formats.
*
* @since Twenty Twenty-Five 1.0
*
* @return void
*/
function twentytwentyfive_post_format_setup() {
add_theme_support( 'post-formats', array( 'aside', 'audio', 'chat', 'gallery', 'image', 'link', 'quote', 'status', 'video' ) );
}
endif;
add_action( 'after_setup_theme', 'twentytwentyfive_post_format_setup' );
// Enqueues editor-style.css in the editors.
if ( ! function_exists( 'twentytwentyfive_editor_style' ) ) :
/**
* Enqueues editor-style.css in the editors.
*
* @since Twenty Twenty-Five 1.0
*
* @return void
*/
function twentytwentyfive_editor_style() {
add_editor_style( 'assets/css/editor-style.css' );
}
endif;
add_action( 'after_setup_theme', 'twentytwentyfive_editor_style' );
// Enqueues style.css on the front.
if ( ! function_exists( 'twentytwentyfive_enqueue_styles' ) ) :
/**
* Enqueues style.css on the front.
*
* @since Twenty Twenty-Five 1.0
*
* @return void
*/
function twentytwentyfive_enqueue_styles() {
wp_enqueue_style( 'twentytwentyfive-style', get_parent_theme_file_uri( 'style.css' ), array(), wp_get_theme()->get( 'Version' ) );
}
endif;
add_action( 'wp_enqueue_scripts', 'twentytwentyfive_enqueue_styles' );
// Registers custom block styles.
if ( ! function_exists( 'twentytwentyfive_block_styles' ) ) :
/**
* Registers custom block styles.
*
* @since Twenty Twenty-Five 1.0
*
* @return void
*/
function twentytwentyfive_block_styles() {
register_block_style( 'core/list', array(
'name' => 'checkmark-list',
'label' => __( 'Checkmark', 'twentytwentyfive' ),
'inline_style' => '
ul.is-style-checkmark-list {
list-style-type: "\2713";
}
ul.is-style-checkmark-list li {
padding-inline-start: 1ch;
}
',
) );
}
endif;
add_action( 'init', 'twentytwentyfive_block_styles' );
// Registers pattern categories.
if ( ! function_exists( 'twentytwentyfive_pattern_categories' ) ) :
/**
* Registers pattern categories.
*
* @since Twenty Twenty-Five 1.0
*
* @return void
*/
function twentytwentyfive_pattern_categories() {
register_block_pattern_category(
'twentytwentyfive_page',
array(
'label' => __( 'Pages', 'twentytwentyfive' ),
'description' => __( 'A collection of full page layouts.', 'twentytwentyfive' ),
)
);
register_block_pattern_category(
'twentytwentyfive_post-format',
array(
'label' => __( 'Post formats', 'twentytwentyfive' ),
'description' => __( 'A collection of post format patterns.', 'twentytwentyfive' ),
)
);
}
endif;
add_action( 'init', 'twentytwentyfive_pattern_categories' );
// Registers block binding sources.
if ( ! function_exists( 'twentytwentyfive_register_block_bindings' ) ) :
/**
* Registers the post format block binding source.
*
* @since Twenty Twenty-Five 1.0
*
* @return void
*/
function twentytwentyfive_register_block_bindings() {
register_block_bindings_source(
'twentytwentyfive/format',
array(
'label' => _x( 'Post format name', 'Label for the block binding placeholder in the editor', 'twentytwentyfive' ),
'get_value_callback' => 'twentytwentyfive_format_binding',
)
);
}
endif;
add_action( 'init', 'twentytwentyfive_register_block_bindings' );
// Registers block binding callback function for the post format name.
if ( ! function_exists( 'twentytwentyfive_format_binding' ) ) :
/**
* Callback function for the post format name block binding source.
*
* @since Twenty Twenty-Five 1.0
*
* @return string|void Post format name, or nothing if the format is 'standard'.
*/
function twentytwentyfive_format_binding() {
$post_format_slug = get_post_format();
if ( $post_format_slug && 'standard' !== $post_format_slug ) {
return get_post_format_string( $post_format_slug );
}
}
endif;
// ========================================
// AGENT CUSTOM POST TYPE
// ========================================
function register_agent_post_type() {
$args = array(
'label' => 'Agents',
'labels' => array(
'name' => 'Agents',
'singular_name' => 'Agent',
'add_new' => 'Add New Agent',
'add_new_item' => 'Add New Agent',
'edit_item' => 'Edit Agent',
'new_item' => 'New Agent',
'view_item' => 'View Agent',
'search_items' => 'Search Agents',
'not_found' => 'No agents found',
'not_found_in_trash' => 'No agents found in trash',
),
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array('slug' => 'agent'),
'capability_type' => 'post',
'has_archive' => false,
'hierarchical' => false,
'menu_position' => 20,
'menu_icon' => 'dashicons-businessman',
'supports' => array('title', 'editor', 'excerpt', 'thumbnail', 'custom-fields'),
'show_in_rest' => true, // Important for REST API
'rest_base' => 'agent',
);
register_post_type('agent', $args);
}
add_action('init', 'register_agent_post_type');
// Register agent custom meta fields for REST API
function register_agent_meta_fields() {
$agent_meta_fields = array(
'agent_name',
'agent_title',
'agent_phone',
'agent_email',
'agent_rating',
'agent_reviews',
'agent_properties_sold',
'agent_experience',
'agent_specialties',
'agent_bio',
'agent_license',
'agent_office',
'agent_office_phone',
'agent_languages',
'agent_awards',
'agent_certifications',
// Individual social media fields
'agent_facebook',
'agent_twitter',
'agent_instagram',
'agent_linkedin',
'agent_youtube',
'agent_tiktok',
'agent_website'
);
foreach ($agent_meta_fields as $field) {
register_meta('post', $field, array(
'object_subtype' => 'agent',
'type' => 'string',
'description' => ucwords(str_replace('_', ' ', $field)),
'single' => true,
'show_in_rest' => true,
'sanitize_callback' => 'sanitize_text_field',
));
}
}
add_action('init', 'register_agent_meta_fields');
// ========================================
// IDX PAGES CUSTOM POST TYPE
// ========================================
// Register IDX Page Custom Post Type
function register_idx_page_post_type() {
$args = array(
'label' => 'IDX Pages',
'labels' => array(
'name' => 'IDX Pages',
'singular_name' => 'IDX Page',
'add_new' => 'Add New IDX Page',
'add_new_item' => 'Add New IDX Page',
'edit_item' => 'Edit IDX Page',
'new_item' => 'New IDX Page',
'view_item' => 'View IDX Page',
'search_items' => 'Search IDX Pages',
'not_found' => 'No IDX pages found',
'not_found_in_trash' => 'No IDX pages found in trash',
),
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array('slug' => 'idx'),
'capability_type' => 'post',
'has_archive' => false,
'hierarchical' => false,
'menu_position' => 21,
'menu_icon' => 'dashicons-admin-page',
'supports' => array('title', 'editor', 'excerpt', 'thumbnail', 'custom-fields'),
'show_in_rest' => true, // Important for REST API
'rest_base' => 'idx_page',
);
register_post_type('idx_page', $args);
}
add_action('init', 'register_idx_page_post_type');
// Add meta boxes for IDX pages
function add_idx_page_meta_boxes() {
add_meta_box(
'idx_page_details',
'IDX Page Details',
'idx_page_details_callback',
'idx_page',
'normal',
'high'
);
add_meta_box(
'idx_page_seo',
'SEO Settings',
'idx_page_seo_callback',
'idx_page',
'normal',
'high'
);
add_meta_box(
'idx_page_navigation',
'Navigation Settings',
'idx_page_navigation_callback',
'idx_page',
'side',
'default'
);
}
add_action('add_meta_boxes', 'add_idx_page_meta_boxes');
// IDX page details meta box
function idx_page_details_callback($post) {
wp_nonce_field('save_idx_page_details', 'idx_page_details_nonce');
// Get existing values
$page_type = get_post_meta($post->ID, 'page_type', true);
$page_description = get_post_meta($post->ID, 'page_description', true);
$page_featured_listings = get_post_meta($post->ID, 'page_featured_listings', true);
$page_city = get_post_meta($post->ID, 'page_city', true);
$page_cities = get_post_meta($post->ID, 'page_cities', true);
$page_state = get_post_meta($post->ID, 'page_state', true);
$page_area_description = get_post_meta($post->ID, 'page_area_description', true);
$page_amenities = get_post_meta($post->ID, 'page_amenities', true);
$page_local_attractions = get_post_meta($post->ID, 'page_local_attractions', true);
$page_school_districts = get_post_meta($post->ID, 'page_school_districts', true);
$page_median_home_price = get_post_meta($post->ID, 'page_median_home_price', true);
$page_market_trends = get_post_meta($post->ID, 'page_market_trends', true);
$page_contact_agent = get_post_meta($post->ID, 'page_contact_agent', true);
$page_contact_email = get_post_meta($post->ID, 'page_contact_email', true);
$page_contact_phone = get_post_meta($post->ID, 'page_contact_phone', true);
$page_auto_fetch_properties = get_post_meta($post->ID, 'page_auto_fetch_properties', true);
$page_properties_limit = get_post_meta($post->ID, 'page_properties_limit', true) ?: 6;
?>
<style>
.content-meta-table { width: 100%; }
.content-meta-table th {
width: 200px;
padding: 10px;
text-align: left;
vertical-align: top;
font-weight: 600;
}
.content-meta-table td { padding: 10px; }
.content-meta-table input[type="text"],
.content-meta-table input[type="email"],
.content-meta-table input[type="tel"],
.content-meta-table input[type="number"],
.content-meta-table select,
.content-meta-table textarea {
width: 100%;
max-width: 400px;
}
.content-meta-table .description {
font-style: italic;
color: #666;
font-size: 12px;
margin-top: 5px;
}
.content-meta-table .large-text { width: 100%; max-width: 600px; }
</style>
<table class="content-meta-table">
<tr>
<th><label for="page_type">Page Type</label></th>
<td>
<select id="page_type" name="page_type" class="regular-text">
<option value="information" <?php selected($page_type, 'information'); ?>>Information</option>
<option value="city" <?php selected($page_type, 'city'); ?>>City Page</option>
<option value="service" <?php selected($page_type, 'service'); ?>>Service</option>
<option value="landing" <?php selected($page_type, 'landing'); ?>>Landing Page</option>
</select>
<p class="description">Type of content page</p>
</td>
</tr>
<tr>
<th><label for="page_description">Page Description</label></th>
<td>
<textarea id="page_description" name="page_description" rows="3" class="large-text"><?php echo esc_textarea($page_description); ?></textarea>
<p class="description">Brief description of the page content</p>
</td>
</tr>
<tr>
<th><label for="page_city">Primary City</label></th>
<td>
<input type="text" id="page_city" name="page_city" value="<?php echo esc_attr($page_city); ?>" class="regular-text" />
<p class="description">Main city name (for city pages)</p>
</td>
</tr>
<tr>
<th><label for="page_cities">Additional Cities</label></th>
<td>
<input type="text" id="page_cities" name="page_cities" value="<?php echo esc_attr($page_cities); ?>" class="regular-text" placeholder="City1, City2, City3" />
<p class="description">Multiple cities (comma-separated) for multi-city pages</p>
</td>
</tr>
<tr>
<th><label for="page_state">State</label></th>
<td>
<input type="text" id="page_state" name="page_state" value="<?php echo esc_attr($page_state); ?>" class="regular-text" placeholder="CA" />
<p class="description">State abbreviation</p>
</td>
</tr>
<tr>
<th><label for="page_zip_codes">ZIP Codes</label></th>
<td>
<input type="text" id="page_zip_codes" name="page_zip_codes" value="<?php echo esc_attr(get_post_meta($post->ID, 'page_zip_codes', true)); ?>" class="regular-text" placeholder="32827, 32832" />
<p class="description">Filter properties by ZIP codes (comma-separated). Useful for neighborhoods like Lake Nona.</p>
</td>
</tr>
<tr>
<th><label for="page_subdivision">Subdivision Filter</label></th>
<td>
<input type="text" id="page_subdivision" name="page_subdivision" value="<?php echo esc_attr(get_post_meta($post->ID, 'page_subdivision', true)); ?>" class="regular-text" placeholder="Lake Nona" />
<p class="description">Filter by subdivision name (e.g., "Lake Nona"). Uses SQL LIKE matching - properties with subdivision names containing this text will be shown.</p>
</td>
</tr>
<tr>
<th><label for="page_area_description">Area Description</label></th>
<td>
<textarea id="page_area_description" name="page_area_description" rows="4" class="large-text"><?php echo esc_textarea($page_area_description); ?></textarea>
<p class="description">Detailed description of the area</p>
</td>
</tr>
<tr>
<th><label for="page_amenities">Amenities (JSON array)</label></th>
<td>
<textarea id="page_amenities" name="page_amenities" rows="3" class="large-text" placeholder='["Shopping Centers", "Parks", "Restaurants"]'><?php echo esc_textarea($page_amenities); ?></textarea>
<p class="description">Local amenities as JSON array</p>
</td>
</tr>
<tr>
<th><label for="page_local_attractions">Local Attractions (JSON array)</label></th>
<td>
<textarea id="page_local_attractions" name="page_local_attractions" rows="3" class="large-text" placeholder='["Museum", "Park", "Theater"]'><?php echo esc_textarea($page_local_attractions); ?></textarea>
<p class="description">Local attractions as JSON array</p>
</td>
</tr>
<tr>
<th><label for="page_school_districts">School Districts (JSON array)</label></th>
<td>
<textarea id="page_school_districts" name="page_school_districts" rows="3" class="large-text" placeholder='["School District 1", "School District 2"]'><?php echo esc_textarea($page_school_districts); ?></textarea>
<p class="description">School districts as JSON array</p>
</td>
</tr>
<tr>
<th><label for="page_median_home_price">Median Home Price</label></th>
<td>
<input type="number" id="page_median_home_price" name="page_median_home_price" value="<?php echo esc_attr($page_median_home_price); ?>" min="0" class="regular-text" />
<p class="description">Median home price for the area</p>
</td>
</tr>
<tr>
<th><label for="page_market_trends">Market Trends</label></th>
<td>
<textarea id="page_market_trends" name="page_market_trends" rows="3" class="large-text"><?php echo esc_textarea($page_market_trends); ?></textarea>
<p class="description">Current market trends and insights</p>
</td>
</tr>
<tr>
<th><label for="page_contact_agent">Contact Agent</label></th>
<td>
<input type="text" id="page_contact_agent" name="page_contact_agent" value="<?php echo esc_attr($page_contact_agent); ?>" class="regular-text" />
<p class="description">Agent name for contact information</p>
</td>
</tr>
<tr>
<th><label for="page_contact_email">Contact Email</label></th>
<td>
<input type="email" id="page_contact_email" name="page_contact_email" value="<?php echo esc_attr($page_contact_email); ?>" class="regular-text" />
<p class="description">Contact email for this page</p>
</td>
</tr>
<tr>
<th><label for="page_contact_phone">Contact Phone</label></th>
<td>
<input type="tel" id="page_contact_phone" name="page_contact_phone" value="<?php echo esc_attr($page_contact_phone); ?>" class="regular-text" />
<p class="description">Contact phone for this page</p>
</td>
</tr>
<tr>
<th><label for="page_auto_fetch_properties">Auto-fetch Properties</label></th>
<td>
<label>
<input type="checkbox" id="page_auto_fetch_properties" name="page_auto_fetch_properties" value="1" <?php checked($page_auto_fetch_properties, '1'); ?> />
Enable automatic property fetching from database
</label>
<p class="description">When enabled, properties will be automatically fetched based on the city/cities above</p>
</td>
</tr>
<tr>
<th><label for="page_properties_limit">Properties Limit</label></th>
<td>
<input type="number" id="page_properties_limit" name="page_properties_limit" value="<?php echo esc_attr($page_properties_limit); ?>" min="1" max="50" class="small-text" />
<p class="description">Number of properties to display (default: 6)</p>
</td>
</tr>
<tr>
<th><label for="page_featured_listings">Featured Listings (JSON array)</label></th>
<td>
<textarea id="page_featured_listings" name="page_featured_listings" rows="6" class="large-text" placeholder='[{"listing_key": "12345", "property_slug": "beautiful-home", "unparsed_address": "123 Main St", "list_price": 500000, "bedrooms_total": 3, "bathrooms_total_decimal": 2, "living_area": 2000, "city": "City", "state": "CA", "postal_code": "12345", "media": [{"url": "https://example.com/image.jpg", "alt": "Property image"}]}]'><?php echo esc_textarea($page_featured_listings); ?></textarea>
<p class="description">Featured property listings as JSON array (optional override for auto-fetch)</p>
</td>
</tr>
</table>
<?php
}
// SEO meta box
function idx_page_seo_callback($post) {
wp_nonce_field('save_idx_page_seo', 'idx_page_seo_nonce');
$page_meta_title = get_post_meta($post->ID, 'page_meta_title', true);
$page_meta_description = get_post_meta($post->ID, 'page_meta_description', true);
?>
<table class="form-table">
<tr>
<th><label for="page_meta_title">Meta Title</label></th>
<td>
<input type="text" id="page_meta_title" name="page_meta_title" value="<?php echo esc_attr($page_meta_title); ?>" class="large-text" />
<p class="description">SEO title for search engines</p>
</td>
</tr>
<tr>
<th><label for="page_meta_description">Meta Description</label></th>
<td>
<textarea id="page_meta_description" name="page_meta_description" rows="3" class="large-text"><?php echo esc_textarea($page_meta_description); ?></textarea>
<p class="description">SEO description for search engines</p>
</td>
</tr>
</table>
<?php
}
// Navigation meta box
function idx_page_navigation_callback($post) {
wp_nonce_field('save_idx_page_navigation', 'idx_page_navigation_nonce');
$page_show_in_nav = get_post_meta($post->ID, 'page_show_in_nav', true);
$page_nav_order = get_post_meta($post->ID, 'page_nav_order', true);
$page_parent_page = get_post_meta($post->ID, 'page_parent_page', true);
?>
<table class="form-table">
<tr>
<th><label for="page_show_in_nav">Show in Navigation</label></th>
<td>
<input type="checkbox" id="page_show_in_nav" name="page_show_in_nav" value="1" <?php checked($page_show_in_nav, '1'); ?> />
<label for="page_show_in_nav">Include in "MORE" dropdown menu</label>
</td>
</tr>
<tr>
<th><label for="page_nav_order">Navigation Order</label></th>
<td>
<input type="number" id="page_nav_order" name="page_nav_order" value="<?php echo esc_attr($page_nav_order); ?>" min="0" class="small-text" />
<p class="description">Order in navigation menu (lower numbers first)</p>
</td>
</tr>
<tr>
<th><label for="page_parent_page">Parent Page</label></th>
<td>
<input type="text" id="page_parent_page" name="page_parent_page" value="<?php echo esc_attr($page_parent_page); ?>" class="regular-text" />
<p class="description">Parent page slug for hierarchical navigation</p>
</td>
</tr>
</table>
<?php
}
// Save IDX page details
function save_idx_page_details($post_id) {
// Check nonce for security
if (!isset($_POST['idx_page_details_nonce']) || !wp_verify_nonce($_POST['idx_page_details_nonce'], 'save_idx_page_details')) {
return;
}
// Check if this is an autosave
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return;
}
// Check user permissions
if (!current_user_can('edit_post', $post_id)) {
return;
}
// List of fields to save
$fields = array(
'page_type', 'page_description', 'page_city', 'page_cities', 'page_state', 'page_zip_codes', 'page_subdivision', 'page_area_description',
'page_amenities', 'page_local_attractions', 'page_school_districts', 'page_median_home_price',
'page_market_trends', 'page_contact_agent', 'page_contact_email', 'page_contact_phone',
'page_auto_fetch_properties', 'page_properties_limit', 'page_featured_listings'
);
// Save each field
foreach ($fields as $field) {
if (isset($_POST[$field])) {
$value = $_POST[$field];
// Validate JSON fields
if (in_array($field, ['page_amenities', 'page_local_attractions', 'page_school_districts', 'page_featured_listings'])) {
if (!empty($value)) {
json_decode($value);
if (json_last_error() === JSON_ERROR_NONE) {
$value = sanitize_textarea_field($value);
} else {
continue; // Skip invalid JSON
}
}
} elseif ($field === 'page_median_home_price') {
$value = intval($value);
} elseif ($field === 'page_properties_limit') {
$value = intval($value);
} elseif ($field === 'page_auto_fetch_properties') {
$value = isset($_POST[$field]) ? '1' : '0';
} else {
$value = sanitize_textarea_field($value);
}
update_post_meta($post_id, $field, $value);
}
}
}
add_action('save_post', 'save_idx_page_details');
// Save SEO settings
function save_idx_page_seo($post_id) {
if (!isset($_POST['idx_page_seo_nonce']) || !wp_verify_nonce($_POST['idx_page_seo_nonce'], 'save_idx_page_seo')) {
return;
}
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return;
}
if (!current_user_can('edit_post', $post_id)) {
return;
}
if (isset($_POST['page_meta_title'])) {
update_post_meta($post_id, 'page_meta_title', sanitize_text_field($_POST['page_meta_title']));
}
if (isset($_POST['page_meta_description'])) {
update_post_meta($post_id, 'page_meta_description', sanitize_textarea_field($_POST['page_meta_description']));
}
}
add_action('save_post', 'save_idx_page_seo');
// Save navigation settings
function save_idx_page_navigation($post_id) {
if (!isset($_POST['idx_page_navigation_nonce']) || !wp_verify_nonce($_POST['idx_page_navigation_nonce'], 'save_idx_page_navigation')) {
return;
}
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return;
}
if (!current_user_can('edit_post', $post_id)) {
return;
}
$page_show_in_nav = isset($_POST['page_show_in_nav']) ? '1' : '0';
update_post_meta($post_id, 'page_show_in_nav', $page_show_in_nav);
if (isset($_POST['page_nav_order'])) {
update_post_meta($post_id, 'page_nav_order', intval($_POST['page_nav_order']));
}
if (isset($_POST['page_parent_page'])) {
update_post_meta($post_id, 'page_parent_page', sanitize_text_field($_POST['page_parent_page']));
}
}
add_action('save_post', 'save_idx_page_navigation');
// Expose meta fields in REST API
function expose_idx_page_meta_in_rest() {
register_rest_field('idx_page', 'meta', array(
'get_callback' => function($object) {
return get_post_meta($object['id']);
},
'update_callback' => null,
'schema' => array(
'description' => 'IDX page custom fields',
'type' => 'object'
)
));
}
add_action('rest_api_init', 'expose_idx_page_meta_in_rest');
// Add custom columns to admin list
function add_idx_page_admin_columns($columns) {
$new_columns = array();
$new_columns['cb'] = $columns['cb'];
$new_columns['title'] = $columns['title'];
$new_columns['page_type'] = 'Type';
$new_columns['page_city'] = 'City';
$new_columns['page_show_in_nav'] = 'Navigation';
$new_columns['date'] = $columns['date'];
return $new_columns;
}
add_filter('manage_idx_page_posts_columns', 'add_idx_page_admin_columns');
// Populate custom admin columns
function populate_idx_page_admin_columns($column, $post_id) {
switch ($column) {
case 'page_type':
$type = get_post_meta($post_id, 'page_type', true);
echo esc_html(ucfirst($type ?: 'information'));
break;
case 'page_city':
$city = get_post_meta($post_id, 'page_city', true);
$cities = get_post_meta($post_id, 'page_cities', true);
if ($city || $cities) {
$display = $city ?: '';
if ($cities) {
$display .= $display ? ', ' : '';
$display .= $cities;
}
echo esc_html($display);
} else {
echo '<span class="text-muted">—</span>';
}
break;
case 'page_show_in_nav':
$show_in_nav = get_post_meta($post_id, 'page_show_in_nav', true);
if ($show_in_nav === '1') {
echo '<span style="color: green;">✓</span>';
} else {
echo '<span style="color: #ccc;">—</span>';
}
break;
}
}
add_action('manage_idx_page_posts_custom_column', 'populate_idx_page_admin_columns', 10, 2);
// ========================================
// AGENT META BOXES
// ========================================
// Add meta boxes for agents
function add_agent_meta_boxes() {
add_meta_box(
'agent_details',
'Agent Details',
'agent_details_callback',
'agent',
'normal',
'high'
);
add_meta_box(
'agent_contact',
'Contact Information',
'agent_contact_callback',
'agent',
'normal',
'high'
);
add_meta_box(
'agent_professional',
'Professional Information',
'agent_professional_callback',
'agent',
'normal',
'high'
);
add_meta_box(
'agent_social_media',
'Social Media & Website',
'agent_social_media_callback',
'agent',
'normal',
'high'
);
}
add_action('add_meta_boxes', 'add_agent_meta_boxes');
// Agent details meta box
function agent_details_callback($post) {
wp_nonce_field('save_agent_details', 'agent_details_nonce');
// Get existing values
$agent_name = get_post_meta($post->ID, 'agent_name', true);
$agent_title = get_post_meta($post->ID, 'agent_title', true);
$agent_bio = get_post_meta($post->ID, 'agent_bio', true);
$agent_experience = get_post_meta($post->ID, 'agent_experience', true);
$agent_specialties = get_post_meta($post->ID, 'agent_specialties', true);
?>
<table class="form-table">
<tr>
<th><label for="agent_name">Agent Name</label></th>
<td><input type="text" id="agent_name" name="agent_name" value="<?php echo esc_attr($agent_name); ?>" class="regular-text" /></td>
</tr>
<tr>
<th><label for="agent_title">Professional Title</label></th>
<td><input type="text" id="agent_title" name="agent_title" value="<?php echo esc_attr($agent_title); ?>" class="regular-text" placeholder="e.g., Senior Real Estate Agent" /></td>
</tr>
<tr>
<th><label for="agent_experience">Years of Experience</label></th>
<td><input type="text" id="agent_experience" name="agent_experience" value="<?php echo esc_attr($agent_experience); ?>" class="regular-text" placeholder="e.g., 5+ years" /></td>
</tr>
<tr>
<th><label for="agent_specialties">Specialties</label></th>
<td>
<textarea id="agent_specialties" name="agent_specialties" rows="3" class="large-text" placeholder="Enter specialties separated by commas (e.g., First-time buyers, Luxury homes, Investment properties)"><?php echo esc_textarea($agent_specialties); ?></textarea>
<p class="description">Separate multiple specialties with commas</p>
</td>
</tr>
<tr>
<th><label for="agent_bio">Bio</label></th>
<td>
<textarea id="agent_bio" name="agent_bio" rows="5" class="large-text" placeholder="Brief professional biography..."><?php echo esc_textarea($agent_bio); ?></textarea>
</td>
</tr>
</table>
<?php
}
// Agent contact meta box
function agent_contact_callback($post) {
wp_nonce_field('save_agent_contact', 'agent_contact_nonce');
// Get existing values
$agent_phone = get_post_meta($post->ID, 'agent_phone', true);
$agent_email = get_post_meta($post->ID, 'agent_email', true);
$agent_office = get_post_meta($post->ID, 'agent_office', true);
$agent_office_phone = get_post_meta($post->ID, 'agent_office_phone', true);
$agent_languages = get_post_meta($post->ID, 'agent_languages', true);
?>
<table class="form-table">
<tr>
<th><label for="agent_phone">Phone Number</label></th>
<td>
<input type="tel" id="agent_phone" name="agent_phone" value="<?php echo esc_attr($agent_phone); ?>" class="regular-text" placeholder="(555) 123-4567" pattern="[0-9\s\(\)\-\+\.]{10,}" title="Please enter a valid phone number (e.g., (555) 123-4567)" />
<p class="description">Enter phone number in any format: (555) 123-4567, 555-123-4567, or 5551234567</p>
</td>
</tr>
<tr>
<th><label for="agent_email">Email Address</label></th>
<td>
<input type="email" id="agent_email" name="agent_email" value="<?php echo esc_attr($agent_email); ?>" class="regular-text" placeholder="agent@example.com" required />
<p class="description">Enter a valid email address</p>
</td>
</tr>
<tr>
<th><label for="agent_office">Office Name</label></th>
<td><input type="text" id="agent_office" name="agent_office" value="<?php echo esc_attr($agent_office); ?>" class="regular-text" placeholder="Real Estate Office" /></td>
</tr>
<tr>
<th><label for="agent_office_phone">Office Phone</label></th>
<td>
<input type="tel" id="agent_office_phone" name="agent_office_phone" value="<?php echo esc_attr($agent_office_phone); ?>" class="regular-text" placeholder="(555) 123-4567" pattern="[0-9\s\(\)\-\+\.]{10,}" title="Please enter a valid phone number (e.g., (555) 123-4567)" />
<p class="description">Enter office phone number in any format: (555) 123-4567, 555-123-4567, or 5551234567</p>
</td>
</tr>
<tr>
<th><label for="agent_languages">Languages Spoken</label></th>
<td>
<textarea id="agent_languages" name="agent_languages" rows="2" class="large-text" placeholder="Enter languages separated by commas (e.g., English, Spanish, French)"><?php echo esc_textarea($agent_languages); ?></textarea>
<p class="description">Separate multiple languages with commas</p>
</td>
</tr>
</table>
<script>
jQuery(document).ready(function($) {
// Real-time email validation
$('#agent_email').on('blur', function() {
var email = $(this).val();
var emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (email && !emailRegex.test(email)) {
$(this).addClass('error');
if (!$(this).next('.validation-error').length) {
$(this).after('<span class="validation-error" style="color: red; font-size: 12px;">Please enter a valid email address</span>');
}
} else {
$(this).removeClass('error');
$(this).next('.validation-error').remove();
}
});
// Real-time phone validation
function validatePhone(phoneInput) {
var phone = $(phoneInput).val();
var phoneRegex = /^[0-9\s\(\)\-\+\.]{10,}$/;
if (phone && !phoneRegex.test(phone)) {
$(phoneInput).addClass('error');
if (!$(phoneInput).next('.validation-error').length) {
$(phoneInput).after('<span class="validation-error" style="color: red; font-size: 12px;">Please enter a valid phone number</span>');
}
} else {
$(phoneInput).removeClass('error');
$(phoneInput).next('.validation-error').remove();
}
}
$('#agent_phone, #agent_office_phone').on('blur', function() {
validatePhone(this);
});
// Auto-format phone numbers as user types
$('#agent_phone, #agent_office_phone').on('input', function() {
var value = $(this).val().replace(/\D/g, '');
if (value.length >= 10) {
var formatted = value.replace(/(\d{3})(\d{3})(\d{4})/, '($1) $2-$3');
$(this).val(formatted);
}
});
});
</script>
<style>
.error {
border-color: #dc3232 !important;
box-shadow: 0 0 2px rgba(204, 74, 74, 0.8) !important;
}
</style>
<?php
}
// Agent professional meta box
function agent_professional_callback($post) {
wp_nonce_field('save_agent_professional', 'agent_professional_nonce');
// Get existing values
$agent_rating = get_post_meta($post->ID, 'agent_rating', true);
$agent_reviews = get_post_meta($post->ID, 'agent_reviews', true);
$agent_properties_sold = get_post_meta($post->ID, 'agent_properties_sold', true);
$agent_license = get_post_meta($post->ID, 'agent_license', true);
$agent_awards = get_post_meta($post->ID, 'agent_awards', true);
$agent_certifications = get_post_meta($post->ID, 'agent_certifications', true);
$agent_social_media = get_post_meta($post->ID, 'agent_social_media', true);
?>
<table class="form-table">
<tr>
<th><label for="agent_rating">Rating (1-5)</label></th>
<td><input type="number" id="agent_rating" name="agent_rating" value="<?php echo esc_attr($agent_rating); ?>" min="0" max="5" step="0.1" class="small-text" /></td>
</tr>
<tr>
<th><label for="agent_reviews">Number of Reviews</label></th>
<td><input type="number" id="agent_reviews" name="agent_reviews" value="<?php echo esc_attr($agent_reviews); ?>" min="0" class="small-text" /></td>
</tr>
<tr>
<th><label for="agent_properties_sold">Properties Sold</label></th>
<td><input type="number" id="agent_properties_sold" name="agent_properties_sold" value="<?php echo esc_attr($agent_properties_sold); ?>" min="0" class="small-text" /></td>
</tr>
<tr>
<th><label for="agent_license">License Number</label></th>
<td><input type="text" id="agent_license" name="agent_license" value="<?php echo esc_attr($agent_license); ?>" class="regular-text" /></td>
</tr>
<tr>
<th><label for="agent_awards">Awards</label></th>
<td>
<textarea id="agent_awards" name="agent_awards" rows="3" class="large-text" placeholder="Enter awards separated by commas"><?php echo esc_textarea($agent_awards); ?></textarea>
<p class="description">Separate multiple awards with commas</p>
</td>
</tr>
<tr>
<th><label for="agent_certifications">Certifications</label></th>
<td>
<textarea id="agent_certifications" name="agent_certifications" rows="3" class="large-text" placeholder="Enter certifications separated by commas"><?php echo esc_textarea($agent_certifications); ?></textarea>
<p class="description">Separate multiple certifications with commas</p>
</td>
</tr>
<tr>
<th><label for="agent_social_media">Social Media Links</label></th>
<td>
<textarea id="agent_social_media" name="agent_social_media" rows="4" class="large-text" placeholder='Enter as JSON: {"linkedin": "https://linkedin.com/in/agent", "facebook": "https://facebook.com/agent"}'><?php echo esc_textarea($agent_social_media); ?></textarea>
<p class="description">Enter social media links as JSON format</p>
</td>
</tr>
</table>
<?php
}
// Save agent details
function save_agent_details($post_id) {
if (!isset($_POST['agent_details_nonce']) || !wp_verify_nonce($_POST['agent_details_nonce'], 'save_agent_details')) {
return;
}
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return;
}
if (!current_user_can('edit_post', $post_id)) {
return;
}
$fields = array('agent_name', 'agent_title', 'agent_bio', 'agent_experience', 'agent_specialties');
foreach ($fields as $field) {
if (isset($_POST[$field])) {
update_post_meta($post_id, $field, sanitize_text_field($_POST[$field]));
}
}
}
add_action('save_post', 'save_agent_details');
// Save agent contact
function save_agent_contact($post_id) {