This repository was archived by the owner on Jul 24, 2026. It is now read-only.
forked from WebDevStudios/custom-post-type-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom-post-type-ui.php
More file actions
1735 lines (1485 loc) · 95.6 KB
/
Copy pathcustom-post-type-ui.php
File metadata and controls
1735 lines (1485 loc) · 95.6 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
/*
Plugin Name: Custom Post Type UI
Plugin URI: http://webdevstudios.com/plugin/custom-post-type-ui/
Description: Admin panel for creating custom post types and custom taxonomies in WordPress
Author: WebDevStudios.com
Version: 0.8.2
Author URI: http://webdevstudios.com/
Text Domain: cpt-plugin
License: GPLv2
*/
// Define current version constant
define( 'CPT_VERSION', '0.8.2' );
// Define current WordPress version constant
define( 'CPTUI_WP_VERSION', get_bloginfo( 'version' ) );
// Define plugin URL constant
$CPT_URL = cpt_check_return( 'add' );
//load translated strings
add_action( 'init', 'cpt_load_textdomain' );
// create custom plugin settings menu
add_action( 'admin_menu', 'cpt_plugin_menu' );
//call delete post function
add_action( 'admin_init', 'cpt_delete_post_type' );
//call register settings function
add_action( 'admin_init', 'cpt_register_settings' );
//process custom taxonomies if they exist
add_action( 'init', 'cpt_create_custom_taxonomies', 0 );
//process custom taxonomies if they exist
add_action( 'init', 'cpt_create_custom_post_types', 0 );
add_action( 'admin_head', 'cpt_help_style' );
//flush rewrite rules on deactivation
register_deactivation_hook( __FILE__, 'cpt_deactivation' );
function cpt_deactivation() {
// Clear the permalinks to remove our post type's rules
flush_rewrite_rules();
}
function cpt_load_textdomain() {
load_plugin_textdomain( 'cpt-plugin', false, basename( dirname( __FILE__ ) ) . '/languages' );
}
function cpt_plugin_menu() {
//create custom post type menu
add_menu_page( __( 'Custom Post Types', 'cpt-plugin' ), __( 'CPT UI', 'cpt-plugin' ), 'manage_options', 'cpt_main_menu', 'cpt_settings' );
//create submenu items
add_submenu_page( 'cpt_main_menu', __( 'Add New', 'cpt-plugin' ), __( 'Add New', 'cpt-plugin' ), 'manage_options', 'cpt_sub_add_new', 'cpt_add_new' );
add_submenu_page( 'cpt_main_menu', __( 'Manage Post Types', 'cpt-plugin' ), __( 'Manage Post Types', 'cpt-plugin' ), 'manage_options', 'cpt_sub_manage_cpt', 'cpt_manage_cpt' );
add_submenu_page( 'cpt_main_menu', __( 'Manage Taxonomies', 'cpt-plugin' ), __( 'Manage Taxonomies', 'cpt-plugin' ), 'manage_options', 'cpt_sub_manage_taxonomies', 'cpt_manage_taxonomies' );
}
//temp fix, should do: http://planetozh.com/blog/2008/04/how-to-load-javascript-with-your-wordpress-plugin/
//only load JS if on a CPT page
if ( strpos( $_SERVER['REQUEST_URI'], 'cpt' ) > 0 ) {
add_action( 'admin_head', 'cpt_wp_add_styles' );
}
// Add JS Scripts
function cpt_wp_add_styles() {
wp_enqueue_script( 'jquery' ); ?>
<script type="text/javascript" >
jQuery(document).ready(function($) {
$(".comment_button").click(function() {
var element = $(this), I = element.attr("id");
$("#slidepanel"+I).slideToggle(300);
$(this).toggleClass("active");
return false;
});
});
</script>
<?php
}
function cpt_create_custom_post_types() {
//register custom post types
$cpt_post_types = get_option('cpt_custom_post_types');
//check if option value is an Array before proceeding
if ( is_array( $cpt_post_types ) ) {
foreach ($cpt_post_types as $cpt_post_type) {
//set post type values
$cpt_label = ( !empty( $cpt_post_type["label"] ) ) ? esc_html( $cpt_post_type["label"] ) : esc_html( $cpt_post_type["name"] ) ;
$cpt_singular = ( !empty( $cpt_post_type["singular_label"] ) ) ? esc_html( $cpt_post_type["singular_label"] ) : esc_html( $cpt_label );
$cpt_rewrite_slug = ( !empty( $cpt_post_type["rewrite_slug"] ) ) ? esc_html( $cpt_post_type["rewrite_slug"] ) : $cpt_post_type["name"];
$cpt_rewrite_withfront = ( isset($cpt_post_type["rewrite_withfront"]) ) ? get_disp_boolean( $cpt_post_type["rewrite_withfront"] ) : true; //reversed because false is empty, and with_front option is true/false
$cpt_menu_position = ( !empty( $cpt_post_type["menu_position"] ) ) ? intval( $cpt_post_type["menu_position"] ) : null; //must be null
$cpt_menu_icon = ( !empty( $cpt_post_type["menu_icon"] ) ) ? esc_attr( $cpt_post_type["menu_icon"] ) : null; //must be null
$cpt_taxonomies = ( !empty( $cpt_post_type[1] ) ) ? $cpt_post_type[1] : array();
$cpt_supports = ( !empty( $cpt_post_type[0] ) ) ? $cpt_post_type[0] : array();
//Show UI must be true
if ( true == get_disp_boolean( $cpt_post_type["show_ui"] ) ) {
//If the string is empty, we will need boolean, else use the string.
if ( empty( $cpt_post_type['show_in_menu_string'] ) ) {
$cpt_show_in_menu = ( $cpt_post_type["show_in_menu"] == 1 ) ? true : false;
} else {
$cpt_show_in_menu = $cpt_post_type['show_in_menu_string'];
}
} else {
$cpt_show_in_menu = false;
}
//Rewrite combination.
if ( false === (bool) $cpt_post_type["rewrite"] ) {
$rewrite = false;
} else {
$rewrite = array( 'slug' => $cpt_rewrite_slug, 'with_front' => $cpt_rewrite_withfront );
}
//set custom label values
$cpt_labels['name'] = $cpt_label;
$cpt_labels['singular_name'] = $cpt_post_type["singular_label"];
if ( isset ( $cpt_post_type[2]["menu_name"] ) ) {
$cpt_labels['menu_name'] = ( !empty( $cpt_post_type[2]["menu_name"] ) ) ? $cpt_post_type[2]["menu_name"] : $cpt_label;
}
$cpt_has_archive = ( !empty( $cpt_post_type["has_archive"] ) ) ? get_disp_boolean( $cpt_post_type["has_archive"] ) : '';
$cpt_exclude_from_search = ( !empty( $cpt_post_type["exclude_from_search"] ) ) ? get_disp_boolean( $cpt_post_type["exclude_from_search"] ) : '';
$cpt_labels['add_new'] = ( !empty( $cpt_post_type[2]["add_new"] ) ) ? $cpt_post_type[2]["add_new"] : 'Add ' .$cpt_singular;
$cpt_labels['add_new_item'] = ( !empty( $cpt_post_type[2]["add_new_item"] ) ) ? $cpt_post_type[2]["add_new_item"] : 'Add New ' .$cpt_singular;
$cpt_labels['edit'] = ( !empty( $cpt_post_type[2]["edit"] ) ) ? $cpt_post_type[2]["edit"] : 'Edit';
$cpt_labels['edit_item'] = ( !empty( $cpt_post_type[2]["edit_item"] ) ) ? $cpt_post_type[2]["edit_item"] : 'Edit ' .$cpt_singular;
$cpt_labels['new_item'] = ( !empty( $cpt_post_type[2]["new_item"] ) ) ? $cpt_post_type[2]["new_item"] : 'New ' .$cpt_singular;
$cpt_labels['view'] = ( !empty( $cpt_post_type[2]["view"] ) ) ? $cpt_post_type[2]["view"] : 'View ' .$cpt_singular;
$cpt_labels['view_item'] = ( !empty( $cpt_post_type[2]["view_item"] ) ) ? $cpt_post_type[2]["view_item"] : 'View ' .$cpt_singular;
$cpt_labels['search_items'] = ( !empty( $cpt_post_type[2]["search_items"] ) ) ? $cpt_post_type[2]["search_items"] : 'Search ' .$cpt_label;
$cpt_labels['not_found'] = ( !empty( $cpt_post_type[2]["not_found"] ) ) ? $cpt_post_type[2]["not_found"] : 'No ' .$cpt_label. ' Found';
$cpt_labels['not_found_in_trash'] = ( !empty( $cpt_post_type[2]["not_found_in_trash"] ) ) ? $cpt_post_type[2]["not_found_in_trash"] : 'No ' .$cpt_label. ' Found in Trash';
$cpt_labels['parent'] = ( $cpt_post_type[2]["parent"] ) ? $cpt_post_type[2]["parent"] : 'Parent ' .$cpt_singular;
register_post_type( $cpt_post_type["name"], array( 'label' => __($cpt_label),
'public' => get_disp_boolean($cpt_post_type["public"]),
'singular_label' => $cpt_post_type["singular_label"],
'show_ui' => get_disp_boolean($cpt_post_type["show_ui"]),
'has_archive' => $cpt_has_archive,
'show_in_menu' => $cpt_show_in_menu,
'capability_type' => $cpt_post_type["capability_type"],
'map_meta_cap' => true,
'hierarchical' => get_disp_boolean($cpt_post_type["hierarchical"]),
'exclude_from_search' => $cpt_exclude_from_search,
'rewrite' => $rewrite,
'query_var' => get_disp_boolean($cpt_post_type["query_var"]),
'description' => esc_html($cpt_post_type["description"]),
'menu_position' => $cpt_menu_position,
'menu_icon' => $cpt_menu_icon,
'supports' => $cpt_supports,
'taxonomies' => $cpt_taxonomies,
'labels' => $cpt_labels
) );
}
}
}
function cpt_create_custom_taxonomies() {
//register custom taxonomies
$cpt_tax_types = get_option('cpt_custom_tax_types');
//check if option value is an array before proceeding
if ( is_array( $cpt_tax_types ) ) {
foreach ($cpt_tax_types as $cpt_tax_type) {
//set custom taxonomy values
$cpt_label = ( !empty( $cpt_tax_type["label"] ) ) ? esc_html( $cpt_tax_type["label"] ) : esc_html( $cpt_tax_type["name"] );
$cpt_singular_label = ( !empty( $cpt_tax_type["singular_label"] ) ) ? esc_html( $cpt_tax_type["singular_label"] ) : esc_html( $cpt_tax_type["name"] );
$cpt_rewrite_slug = ( !empty( $cpt_tax_type["rewrite_slug"] ) ) ? esc_html( $cpt_tax_type["rewrite_slug"] ) : esc_html( $cpt_tax_type["name"] );
$cpt_tax_show_admin_column = ( !empty( $cpt_tax_type["show_admin_column"] ) ) ? esc_html( $cpt_tax_type["show_admin_column"] ) : false;
$cpt_post_types = ( !empty( $cpt_tax_type[1] ) ) ? $cpt_tax_type[1] : $cpt_tax_type["cpt_name"];
//set custom label values
$cpt_labels['name'] = $cpt_label;
$cpt_labels['singular_name'] = $cpt_tax_type["singular_label"];
$cpt_labels['search_items'] = ( $cpt_tax_type[0]["search_items"] ) ? $cpt_tax_type[0]["search_items"] : 'Search ' .$cpt_label;
$cpt_labels['popular_items'] = ( $cpt_tax_type[0]["popular_items"] ) ? $cpt_tax_type[0]["popular_items"] : 'Popular ' .$cpt_label;
$cpt_labels['all_items'] = ( $cpt_tax_type[0]["all_items"] ) ? $cpt_tax_type[0]["all_items"] : 'All ' .$cpt_label;
$cpt_labels['parent_item'] = ( $cpt_tax_type[0]["parent_item"] ) ? $cpt_tax_type[0]["parent_item"] : 'Parent ' .$cpt_singular_label;
$cpt_labels['parent_item_colon'] = ( $cpt_tax_type[0]["parent_item_colon"] ) ? $cpt_tax_type[0]["parent_item_colon"] : 'Parent ' .$cpt_singular_label. ':';
$cpt_labels['edit_item'] = ( $cpt_tax_type[0]["edit_item"] ) ? $cpt_tax_type[0]["edit_item"] : 'Edit ' .$cpt_singular_label;
$cpt_labels['update_item'] = ( $cpt_tax_type[0]["update_item"] ) ? $cpt_tax_type[0]["update_item"] : 'Update ' .$cpt_singular_label;
$cpt_labels['add_new_item'] = ( $cpt_tax_type[0]["add_new_item"] ) ? $cpt_tax_type[0]["add_new_item"] : 'Add New ' .$cpt_singular_label;
$cpt_labels['new_item_name'] = ( $cpt_tax_type[0]["new_item_name"] ) ? $cpt_tax_type[0]["new_item_name"] : 'New ' .$cpt_singular_label. ' Name';
$cpt_labels['separate_items_with_commas'] = ( $cpt_tax_type[0]["separate_items_with_commas"] ) ? $cpt_tax_type[0]["separate_items_with_commas"] : 'Separate ' .$cpt_label. ' with commas';
$cpt_labels['add_or_remove_items'] = ( $cpt_tax_type[0]["add_or_remove_items"] ) ? $cpt_tax_type[0]["add_or_remove_items"] : 'Add or remove ' .$cpt_label;
$cpt_labels['choose_from_most_used'] = ( $cpt_tax_type[0]["choose_from_most_used"] ) ? $cpt_tax_type[0]["choose_from_most_used"] : 'Choose from the most used ' .$cpt_label;
//register our custom taxonomies
register_taxonomy( $cpt_tax_type["name"],
$cpt_post_types,
array( 'hierarchical' => get_disp_boolean($cpt_tax_type["hierarchical"]),
'label' => $cpt_label,
'show_ui' => get_disp_boolean($cpt_tax_type["show_ui"]),
'query_var' => get_disp_boolean($cpt_tax_type["query_var"]),
'rewrite' => array('slug' => $cpt_rewrite_slug),
'singular_label' => $cpt_singular_label,
'labels' => $cpt_labels,
'show_admin_column' => $cpt_tax_show_admin_column
) );
}
}
}
//delete custom post type or custom taxonomy
function cpt_delete_post_type() {
global $CPT_URL;
//check if we are deleting a custom post type
if( isset( $_GET['deltype'] ) ) {
//nonce security check
check_admin_referer( 'cpt_delete_post_type' );
$delType = intval( $_GET['deltype'] );
$cpt_post_types = get_option( 'cpt_custom_post_types' );
unset( $cpt_post_types[$delType] );
$cpt_post_types = array_values( $cpt_post_types );
update_option( 'cpt_custom_post_types', $cpt_post_types );
if ( isset( $_GET['return'] ) ) {
$RETURN_URL = cpt_check_return( esc_attr( $_GET['return'] ) );
} else {
$RETURN_URL = $CPT_URL;
}
wp_redirect( $RETURN_URL .'&cpt_msg=del' );
}
//check if we are deleting a custom taxonomy
if( isset( $_GET['deltax'] ) ) {
check_admin_referer( 'cpt_delete_tax' );
$delType = intval( $_GET['deltax'] );
$cpt_taxonomies = get_option( 'cpt_custom_tax_types' );
unset( $cpt_taxonomies[$delType] );
$cpt_taxonomies = array_values( $cpt_taxonomies );
update_option( 'cpt_custom_tax_types', $cpt_taxonomies );
if ( isset( $_GET['return'] ) ) {
$RETURN_URL = cpt_check_return( esc_attr( $_GET['return'] ) );
} else {
$RETURN_URL = $CPT_URL;
}
wp_redirect( $RETURN_URL .'&cpt_msg=del' );
}
}
function cpt_register_settings() {
global $cpt_error, $CPT_URL;
if ( isset( $_POST['cpt_edit'] ) ) {
//edit a custom post type
check_admin_referer( 'cpt_add_custom_post_type' );
//custom post type to edit
$cpt_edit = intval( $_POST['cpt_edit'] );
//edit the custom post type
$cpt_form_fields = $_POST['cpt_custom_post_type'];
//add support checkbox values to array
$cpt_supports = ( isset( $_POST['cpt_supports'] ) ) ? $_POST['cpt_supports'] : null;
array_push($cpt_form_fields, $cpt_supports);
//add taxonomies support checkbox values to array
$cpt_addon_taxes = ( isset( $_POST['cpt_addon_taxes'] ) ) ? $_POST['cpt_addon_taxes'] : null;
array_push( $cpt_form_fields, $cpt_addon_taxes );
//add label values to array
array_push( $cpt_form_fields, $_POST['cpt_labels'] );
//load custom posts saved in WP
$cpt_options = get_option( 'cpt_custom_post_types' );
if ( is_array( $cpt_options ) ) {
unset( $cpt_options[$cpt_edit] );
//insert new custom post type into the array
array_push( $cpt_options, $cpt_form_fields );
$cpt_options = array_values( $cpt_options );
$cpt_options = stripslashes_deep( $cpt_options );
//save custom post types
update_option( 'cpt_custom_post_types', $cpt_options );
if ( isset( $_GET['return'] ) ) {
$RETURN_URL = cpt_check_return( esc_attr( $_GET['return'] ) );
} else {
$RETURN_URL = $CPT_URL;
}
wp_redirect( $RETURN_URL );
}
} elseif ( isset( $_POST['cpt_submit'] ) ) {
//create a new custom post type
//nonce security check
check_admin_referer( 'cpt_add_custom_post_type' );
//retrieve new custom post type values
$cpt_form_fields = $_POST['cpt_custom_post_type'];
if ( empty( $cpt_form_fields["name"] ) ) {
if ( isset( $_GET['return'] ) ) {
$RETURN_URL = cpt_check_return( esc_attr( $_GET['return'] ) );
} else {
$RETURN_URL = $CPT_URL;
}
wp_redirect( $RETURN_URL .'&cpt_error=1' );
exit();
}
if ( false !== strpos( $cpt_form_fields["name"], '\'' ) ||
false !== strpos( $cpt_form_fields["name"], '\"' ) ||
false !== strpos( $cpt_form_fields["rewrite_slug"], '\'' ) ||
false !== strpos( $cpt_form_fields["rewrite_slug"], '\"' ) ) {
if ( isset( $_GET['return'] ) ) {
$RETURN_URL = cpt_check_return( esc_attr( $_GET['return'] ) );
} else {
$RETURN_URL = $CPT_URL;
}
wp_redirect( $RETURN_URL .'&cpt_error=4' );
exit();
}
//add support checkbox values to array
$cpt_supports = ( isset( $_POST['cpt_supports'] ) ) ? $_POST['cpt_supports'] : null;
array_push( $cpt_form_fields, $cpt_supports );
//add taxonomies support checkbox values to array
$cpt_addon_taxes = ( isset( $_POST['cpt_addon_taxes'] ) ) ? $_POST['cpt_addon_taxes'] : null;
array_push( $cpt_form_fields, $cpt_addon_taxes );
//add label values to array
array_push( $cpt_form_fields, $_POST['cpt_labels'] );
//load custom posts saved in WP
$cpt_options = get_option( 'cpt_custom_post_types' );
//check if option exists, if not create an array for it
if ( !is_array( $cpt_options ) ) {
$cpt_options = array();
}
//insert new custom post type into the array
array_push( $cpt_options, $cpt_form_fields );
$cpt_options = stripslashes_deep( $cpt_options );
//save new custom post type array in the CPT option
update_option( 'cpt_custom_post_types', $cpt_options );
if ( isset( $_GET['return'] ) ) {
$RETURN_URL = cpt_check_return( esc_attr( $_GET['return'] ) );
} else {
$RETURN_URL = $CPT_URL;
}
wp_redirect( $RETURN_URL .'&cpt_msg=1' );
}
if ( isset( $_POST['cpt_edit_tax'] ) ) {
//edit a custom taxonomy
//nonce security check
check_admin_referer( 'cpt_add_custom_taxonomy' );
//custom taxonomy to edit
$cpt_edit = intval( $_POST['cpt_edit_tax'] );
//edit the custom taxonomy
$cpt_form_fields = $_POST['cpt_custom_tax'];
//add label values to array
array_push( $cpt_form_fields, $_POST['cpt_tax_labels'] );
//add attached post type values to array
array_push( $cpt_form_fields, $_POST['cpt_post_types'] );
//load custom posts saved in WP
$cpt_options = get_option( 'cpt_custom_tax_types' );
if ( is_array( $cpt_options ) ) {
unset( $cpt_options[$cpt_edit] );
//insert new custom post type into the array
array_push( $cpt_options, $cpt_form_fields );
$cpt_options = array_values( $cpt_options );
//save custom post types
update_option( 'cpt_custom_tax_types', $cpt_options );
if ( isset( $_GET['return'] ) ) {
$RETURN_URL = cpt_check_return( esc_attr( $_GET['return'] ) );
} else {
$RETURN_URL = $CPT_URL;
}
wp_redirect( $RETURN_URL );
}
} elseif ( isset( $_POST['cpt_add_tax'] ) ) {
//create new custom taxonomy
//nonce security check
check_admin_referer( 'cpt_add_custom_taxonomy' );
//retrieve new custom taxonomy values
$cpt_form_fields = $_POST['cpt_custom_tax'];
//verify required fields are filled out
if ( empty( $cpt_form_fields["name"] ) ) {
if ( isset( $_GET['return'] ) ) {
$RETURN_URL = cpt_check_return( esc_attr( $_GET['return'] ) );
} else {
$RETURN_URL = $CPT_URL;
}
wp_redirect( $RETURN_URL .'&cpt_error=2' );
exit();
} elseif ( empty( $_POST['cpt_post_types'] ) ) {
if ( isset( $_GET['return'] ) ) {
$RETURN_URL = cpt_check_return( esc_attr( $_GET['return'] ) );
} else {
$RETURN_URL = $CPT_URL;
}
wp_redirect( $RETURN_URL .'&cpt_error=3' );
exit();
}
if ( false !== strpos( $cpt_form_fields["name"], '\'' ) ||
false !== strpos( $cpt_form_fields["name"], '\"' ) ||
false !== strpos( $cpt_form_fields["rewrite_slug"], '\'' ) ||
false !== strpos( $cpt_form_fields["rewrite_slug"], '\"' ) ) {
if ( isset( $_GET['return'] ) ) {
$RETURN_URL = cpt_check_return( esc_attr( $_GET['return'] ) );
} else {
$RETURN_URL = $CPT_URL;
}
wp_redirect( $RETURN_URL .'&cpt_error=5' );
exit();
}
//add label values to array
array_push( $cpt_form_fields, $_POST['cpt_tax_labels'] );
//add attached post type values to array
array_push( $cpt_form_fields, $_POST['cpt_post_types'] );
//load custom taxonomies saved in WP
$cpt_options = get_option( 'cpt_custom_tax_types' );
//check if option exists, if not create an array for it
if ( !is_array( $cpt_options ) ) {
$cpt_options = array();
}
//insert new custom taxonomy into the array
array_push( $cpt_options, $cpt_form_fields );
//save new custom taxonomy array in the CPT option
update_option( 'cpt_custom_tax_types', $cpt_options );
if ( isset( $_GET['return'] ) ) {
$RETURN_URL = cpt_check_return( esc_attr( $_GET['return'] ) );
} else {
$RETURN_URL = $CPT_URL;
}
wp_redirect( $RETURN_URL .'&cpt_msg=2' );
}
}
//main welcome/settings page
function cpt_settings() {
global $CPT_URL, $wp_post_types;
//flush rewrite rules
flush_rewrite_rules();
?>
<div class="wrap">
<?php screen_icon( 'plugins' ); ?>
<h2><?php _e( 'Custom Post Type UI', 'cpt-plugin' ); ?> <?php _e( 'version', 'cpt-plugin' ); ?>: <?php echo CPT_VERSION; ?></h2>
<h2><?php _e( 'Frequently Asked Questions', 'cpt-plugin' ); ?></h2>
<p><?php _e( 'Please note that this plugin will NOT handle display of registered post types or taxonomies in your current theme. It will simply register them for you.', 'cpt-plugin' ); ?>
<h3><?php _e( 'Q: <strong>How can I display content from a custom post type on my website?</strong>', 'cpt-plugin' ); ?></h3>
<p>
<?php _e( 'A: Justin Tadlock has written some great posts on the topic:', 'cpt-plugin' ); ?><br />
<a href="http://justintadlock.com/archives/2010/02/02/showing-custom-post-types-on-your-home-blog-page" target="_blank"><?php _e( 'Showing Custom Post Types on your Home Page', 'cpt-plugin' ); ?></a><br />
<a href="http://justintadlock.com/archives/2010/04/29/custom-post-types-in-wordpress" target="_blank"><?php _e( 'Custom Post Types in WordPress', 'cpt-plugin' ); ?></a>
</p>
<h3><?php _e( 'Q: <strong>How can I add custom meta boxes to my custom post types?</strong>', 'cpt-plugin' ); ?></h3>
<p><?php _e( 'A: The More Fields plugin does a great job at creating custom meta boxes and fully supports custom post types: ', 'cpt-plugin' ); ?><a href="http://wordpress.org/extend/plugins/more-fields/" target="_blank">http://wordpress.org/extend/plugins/more-fields/</a>. The <a href="https://github.com/jaredatch/Custom-Metaboxes-and-Fields-for-WordPress" target="_blank">Custom Metaboxes and Fields for WordPress</a> class is a great alternative to a plugin for more advanced users.</p>
<h3><?php _e( 'Q: <strong>I changed my custom post type name and now I can\'t get to my posts</strong>', 'cpt-plugin' ); ?></h3>
<p><?php _e( 'A: You can either change the custom post type name back to the original name or try the Post Type Switcher plugin: ', 'cpt-plugin' ); ?><a href="http://wordpress.org/extend/plugins/post-type-switcher/" target="_blank">http://wordpress.org/extend/plugins/post-type-switcher/</a></p>
<div class="cp-rss-widget">
<table border="0">
<tr>
<td colspan="3"><h2><?php _e( 'Help Support This Plugin!', 'cpt-plugin' ); ?></h2></td>
</tr>
<tr>
<td width="33%"><h3><?php _e( 'PayPal Donation', 'cpt-plugin' ); ?></h3></td>
<td width="33%"><h3><?php _e( 'Professional WordPress<br />Second Edition', 'cpt-plugin' ); ?></h3></td>
<td width="33%"><h3><?php _e( 'Professional WordPress<br />Plugin Development', 'cpt-plugin' ); ?></h3></td>
</tr>
<tr>
<td valign="top" width="33%">
<p><?php _e( 'Please donate to the development<br />of Custom Post Type UI:', 'cpt-plugin'); ?>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="YJEDXPHE49Q3U">
<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
</p>
</td>
<td valign="top" width="33%"><a href="http://bit.ly/prowp2" target="_blank"><img src="<?php echo plugins_url( '/images/professional-wordpress-secondedition.jpg', __FILE__ ); ?>" width="200"></a><br /><?php _e( 'The leading book on WordPress design and development!<br /><strong>Brand new second edition!', 'cpt-plugin'); ?></strong></td>
<td valign="top" width="33%"><a href="http://amzn.to/plugindevbook" target="_blank"><img src="<?php echo plugins_url( '/images/professional-wordpress-plugin-development.png', __FILE__ ); ?>" width="200"></a><br /><?php _e( 'Highest rated WordPress development book on Amazon!', 'cpt-plugin' ); ?></td>
</tr>
</table>
<h2><?php _e( 'WebDevStudios.com Recent News', 'cpt-plugin' ); ?></h2>
<?php
wp_widget_rss_output( array(
'url' => esc_url( 'http://webdevstudios.com/feed/' ),
'title' => __( 'WebDevStudios.com News', 'cpt-plugin' ),
'items' => 3,
'show_summary' => 1,
'show_author' => 0,
'show_date' => 1
) );
?>
</div>
</div>
<?php
//load footer
cpt_footer();
}
//manage custom post types page
function cpt_manage_cpt() {
global $CPT_URL;
$MANAGE_URL = cpt_check_return( 'add' );
?>
<div class="wrap">
<?php
//check for success/error messages
if ( isset($_GET['cpt_msg'] ) && $_GET['cpt_msg'] == 'del' ) { ?>
<div id="message" class="updated">
<?php _e('Custom post type deleted successfully', 'cpt-plugin'); ?>
</div>
<?php
}
?>
<?php screen_icon( 'plugins' ); ?>
<h2><?php _e('Manage Custom Post Types', 'cpt-plugin') ?></h2>
<p><?php _e('Deleting custom post types will <strong>NOT</strong> delete any content into the database or added to those post types. You can easily recreate your post types and the content will still exist.', 'cpt-plugin') ?></p>
<?php
$cpt_post_types = get_option( 'cpt_custom_post_types', array() );
if (is_array($cpt_post_types)) {
?>
<table width="100%" class="widefat">
<thead>
<tr>
<th><?php _e('Action', 'cpt-plugin');?></th>
<th><?php _e('Name', 'cpt-plugin');?></th>
<th><?php _e('Label', 'cpt-plugin');?></th>
<th><?php _e('Public', 'cpt-plugin');?></th>
<th><?php _e('Show UI', 'cpt-plugin');?></th>
<th><?php _e('Hierarchical', 'cpt-plugin');?></th>
<th><?php _e('Rewrite', 'cpt-plugin');?></th>
<th><?php _e('Rewrite Slug', 'cpt-plugin');?></th>
<th><?php _e('Total Published', 'cpt-plugin');?></th>
<th><?php _e('Total Drafts', 'cpt-plugin');?></th>
<th><?php _e('Supports', 'cpt-plugin');?></th>
</tr>
</thead>
<tfoot>
<tr>
<th><?php _e('Action', 'cpt-plugin');?></th>
<th><?php _e('Name', 'cpt-plugin');?></th>
<th><?php _e('Label', 'cpt-plugin');?></th>
<th><?php _e('Public', 'cpt-plugin');?></th>
<th><?php _e('Show UI', 'cpt-plugin');?></th>
<th><?php _e('Hierarchical', 'cpt-plugin');?></th>
<th><?php _e('Rewrite', 'cpt-plugin');?></th>
<th><?php _e('Rewrite Slug', 'cpt-plugin');?></th>
<th><?php _e('Total Published', 'cpt-plugin');?></th>
<th><?php _e('Total Drafts', 'cpt-plugin');?></th>
<th><?php _e('Supports', 'cpt-plugin');?></th>
</tr>
</tfoot>
<?php
$thecounter=0;
$cpt_names = array();
//Create urls for management
foreach ( $cpt_post_types as $cpt_post_type ) {
$del_url = cpt_check_return( 'cpt' ) .'&deltype=' .$thecounter .'&return=cpt';
$del_url = ( function_exists('wp_nonce_url') ) ? wp_nonce_url($del_url, 'cpt_delete_post_type') : $del_url;
$edit_url = $MANAGE_URL .'&edittype=' .$thecounter .'&return=cpt';
$edit_url = ( function_exists('wp_nonce_url') ) ? wp_nonce_url($edit_url, 'cpt_edit_post_type') : $edit_url;
$cpt_counts = wp_count_posts($cpt_post_type["name"]);
$rewrite_slug = ( $cpt_post_type["rewrite_slug"] ) ? $cpt_post_type["rewrite_slug"] : $cpt_post_type["name"];
?>
<tr>
<td valign="top"><a href="<?php echo $del_url; ?>"><?php _e( 'Delete', 'cpt-plugin' ); ?></a> / <a href="<?php echo $edit_url; ?>"><?php _e( 'Edit', 'cpt-plugin' ); ?></a> / <a href="#" class="comment_button" id="<?php echo $thecounter; ?>"><?php _e( 'Get Code', 'cpt-plugin' ); ?></a></td>
<td valign="top"><?php echo stripslashes($cpt_post_type["name"]); ?></td>
<td valign="top"><?php echo stripslashes($cpt_post_type["label"]); ?></td>
<td valign="top"><?php echo disp_boolean($cpt_post_type["public"]); ?></td>
<td valign="top"><?php echo disp_boolean($cpt_post_type["show_ui"]); ?></td>
<td valign="top"><?php echo disp_boolean($cpt_post_type["hierarchical"]); ?></td>
<td valign="top"><?php echo disp_boolean($cpt_post_type["rewrite"]); ?></td>
<td valign="top"><?php echo $rewrite_slug; ?></td>
<td valign="top"><?php echo $cpt_counts->publish; ?></td>
<td valign="top"><?php echo $cpt_counts->draft; ?></td>
<td>
<?php
if (is_array($cpt_post_type[0])) {
foreach ($cpt_post_type[0] as $cpt_supports) {
echo $cpt_supports .'<br />';
}
}
?>
</td>
</tr>
<tr>
<td colspan="12">
<div style="display:none;" id="slidepanel<?php echo $thecounter; ?>">
<?php
// Begin the display for the "Get code" feature
//display register_post_type code
$custom_post_type = '';
$cpt_support_array = '';
$cpt_tax_array = '';
$cpt_label = ( empty( $cpt_post_type["label"] ) ) ? esc_html($cpt_post_type["name"]) : esc_html($cpt_post_type["label"]);
$cpt_singular = ( empty( $cpt_post_type["singular_label"] ) ) ? $cpt_label : esc_html($cpt_post_type["singular_label"]);
$cpt_rewrite_slug = ( empty( $cpt_post_type["rewrite_slug"] ) ) ? esc_html( $cpt_post_type["name"] ) : esc_html($cpt_post_type["rewrite_slug"]);
$cpt_rewrite_withfront = ( empty( $cpt_post_type['rewrite_withfront'] ) ) ? get_disp_boolean( $cpt_post_type['rewrite_withfront'] ) : 'true'; //not reversed because false is empty, making the assignment go to true
$cpt_menu_position = ( empty( $cpt_post_type["menu_position"] ) ) ? null : intval($cpt_post_type["menu_position"]);
$cpt_menu_icon = ( !empty( $cpt_post_type["menu_icon"] ) ) ? esc_attr($cpt_post_type["menu_icon"]) : null;
if ( true == $cpt_post_type["show_ui"] ) {
$cpt_show_in_menu = ( $cpt_post_type["show_in_menu"] == 1 ) ? 1 : 0;
$cpt_show_in_menu = ( $cpt_post_type["show_in_menu_string"] ) ? '\''.$cpt_post_type["show_in_menu_string"].'\'' : $cpt_show_in_menu;
} else {
$cpt_show_in_menu = 0;
}
//set custom label values
$cpt_labels['name'] = $cpt_label;
$cpt_labels['singular_name'] = $cpt_post_type["singular_label"];
$cpt_labels['menu_name'] = ( $cpt_post_type[2]["menu_name"] ) ? $cpt_post_type[2]["menu_name"] : $cpt_label;
$cpt_labels['add_new'] = ( $cpt_post_type[2]["add_new"] ) ? $cpt_post_type[2]["add_new"] : 'Add ' .$cpt_singular;
$cpt_labels['add_new_item'] = ( $cpt_post_type[2]["add_new_item"] ) ? $cpt_post_type[2]["add_new_item"] : 'Add New ' .$cpt_singular;
$cpt_labels['edit'] = ( $cpt_post_type[2]["edit"] ) ? $cpt_post_type[2]["edit"] : 'Edit';
$cpt_labels['edit_item'] = ( $cpt_post_type[2]["edit_item"] ) ? $cpt_post_type[2]["edit_item"] : 'Edit ' .$cpt_singular;
$cpt_labels['new_item'] = ( $cpt_post_type[2]["new_item"] ) ? $cpt_post_type[2]["new_item"] : 'New ' .$cpt_singular;
$cpt_labels['view'] = ( $cpt_post_type[2]["view"] ) ? $cpt_post_type[2]["view"] : 'View ' .$cpt_singular;
$cpt_labels['view_item'] = ( $cpt_post_type[2]["view_item"] ) ? $cpt_post_type[2]["view_item"] : 'View ' .$cpt_singular;
$cpt_labels['search_items'] = ( $cpt_post_type[2]["search_items"] ) ? $cpt_post_type[2]["search_items"] : 'Search ' .$cpt_label;
$cpt_labels['not_found'] = ( $cpt_post_type[2]["not_found"] ) ? $cpt_post_type[2]["not_found"] : 'No ' .$cpt_label. ' Found';
$cpt_labels['not_found_in_trash'] = ( $cpt_post_type[2]["not_found_in_trash"] ) ? $cpt_post_type[2]["not_found_in_trash"] : 'No ' .$cpt_label. ' Found in Trash';
$cpt_labels['parent'] = ( $cpt_post_type[2]["parent"] ) ? $cpt_post_type[2]["parent"] : 'Parent ' .$cpt_singular;
if ( false == (bool)$cpt_post_type["rewrite"] ) {
$rewrite = 'false';
} else {
if ( !empty( $cpt_post_type["rewrite_slug"] ) ) {
$rewrite = "array('slug' => '" . $cpt_post_type["rewrite_slug"] . "', 'with_front' => " . $cpt_post_type['rewrite_withfront'] . "),\n";
} else {
if( empty( $cpt_post_type['rewrite_withfront'] ) )
$cpt_post_type['rewrite_withfront'] = 1;
$rewrite = "array('slug' => '" . $cpt_post_type["name"] . "', 'with_front' => " . disp_boolean( $cpt_post_type['rewrite_withfront'] ) . "),\n";
}
}
if( is_array( $cpt_post_type[0] ) ) {
$counter = 1;
$count = count( $cpt_post_type[0] );
foreach ( $cpt_post_type[0] as $cpt_supports ) {
//build supports variable
$cpt_support_array .= '\'' . $cpt_supports . '\'';
if ( $counter != $count )
$cpt_support_array .= ',';
$counter++;
}
}
if( is_array( $cpt_post_type[1] ) ) {
$counter = 1;
$count = count( $cpt_post_type[1] );
foreach ( $cpt_post_type[1] as $cpt_taxes ) {
//build taxonomies variable
$cpt_tax_array .= '\''.$cpt_taxes.'\'';
if ( $counter != $count )
$cpt_tax_array .= ',';
$counter++;
}
}
$custom_post_type = "add_action('init', 'cptui_register_my_cpt_" . $cpt_post_type["name"] . "');\n";
$custom_post_type .= "function cptui_register_my_cpt_" . $cpt_post_type["name"] . "() {\n";
$custom_post_type .= "register_post_type('" . $cpt_post_type["name"] . "', array(\n'label' => '" . $cpt_label . "',\n";
$custom_post_type .= "'description' => '" . $cpt_post_type["description"] . "',\n";
$custom_post_type .= "'public' => " . disp_boolean( $cpt_post_type["public"]) . ",\n";
$custom_post_type .= "'show_ui' => " . disp_boolean( $cpt_post_type["show_ui"]) . ",\n";
$custom_post_type .= "'show_in_menu' => " . disp_boolean( $cpt_show_in_menu) . ",\n";
$custom_post_type .= "'capability_type' => '" . $cpt_post_type["capability_type"] . "',\n";
$custom_post_type .= "'map_meta_cap' => " . disp_boolean( '1' ) . ",\n";
$custom_post_type .= "'hierarchical' => " . disp_boolean( $cpt_post_type["hierarchical"] ) . ",\n";
$custom_post_type .= "'rewrite' => " . $rewrite ."\n";
$custom_post_type .= "'query_var' => " . disp_boolean($cpt_post_type["query_var"]) . ",\n";
if ( !empty( $cpt_post_type["has_archive"] ) ) {
$custom_post_type .= "'has_archive' => " . disp_boolean( $cpt_post_type["has_archive"] ) . ",\n";
}
if ( !empty( $cpt_post_type["exclude_from_search"] ) ) {
$custom_post_type .= "'exclude_from_search' => " . disp_boolean( $cpt_post_type["exclude_from_search"] ) . ",\n";
}
if ( !empty( $cpt_menu_position ) ) {
$custom_post_type .= "'menu_position' => " . $cpt_menu_position . ",\n";
}
if ( !empty( $cpt_post_type["menu_icon"] ) ) {
$custom_post_type .= "'menu_icon' => '" . $cpt_post_type["menu_icon"] . "',\n";
}
$custom_post_type .= "'supports' => array(" . $cpt_support_array . "),\n";
if ( !empty( $cpt_tax_array ) ) {
$custom_post_type .= "'taxonomies' => array(" . $cpt_tax_array . "),\n";
}
if ( !empty( $cpt_labels ) ) {
$custom_post_type .= "'labels' => " . var_export( $cpt_labels, true ) . "\n";
}
$custom_post_type .= ") ); }";
echo '<p>';
_e( 'Place the below code in your themes functions.php file to manually create this custom post type.', 'cpt-plugin' ).'<br>';
_e('This is a <strong>BETA</strong> feature. Please <a href="https://github.com/WebDevStudios/custom-post-type-ui">report bugs</a>.','cpt-plugin').'</p>';
echo '<textarea rows="10" cols="100">' .$custom_post_type .'</textarea>';
?>
</div>
</td>
</tr>
<?php
$thecounter++;
$cpt_names[] = strtolower( $cpt_post_type["name"] );
}
$args=array(
'public' => true,
'_builtin' => false
);
$output = 'objects'; // or objects
$post_types = get_post_types( $args, $output );
$cpt_first = false;
if ( $post_types ) {
?></table>
<h3><?php _e('Additional Custom Post Types', 'cpt-plugin') ?></h3>
<p><?php _e('The custom post types below are registered in WordPress but were not created by the Custom Post Type UI Plugin.', 'cpt-plugin') ?></p>
<?php
foreach ( $post_types as $post_type ) {
if ( !in_array( strtolower( $post_type->name ), $cpt_names ) ) {
if ( isset( $cpt_first ) && !$cpt_first ) {
?>
<table width="100%" class="widefat">
<thead>
<tr>
<th><?php _e('Name', 'cpt-plugin');?></th>
<th><?php _e('Label', 'cpt-plugin');?></th>
<th><?php _e('Public', 'cpt-plugin');?></th>
<th><?php _e('Show UI', 'cpt-plugin');?></th>
<th><?php _e('Hierarchical', 'cpt-plugin');?></th>
<th><?php _e('Rewrite', 'cpt-plugin');?></th>
<th><?php _e('Rewrite Slug', 'cpt-plugin');?></th>
<th><?php _e('Query Var', 'cpt-plugin');?></th>
</tr>
</thead>
<tfoot>
<tr>
<th><?php _e('Name', 'cpt-plugin');?></th>
<th><?php _e('Label', 'cpt-plugin');?></th>
<th><?php _e('Public', 'cpt-plugin');?></th>
<th><?php _e('Show UI', 'cpt-plugin');?></th>
<th><?php _e('Hierarchical', 'cpt-plugin');?></th>
<th><?php _e('Rewrite', 'cpt-plugin');?></th>
<th><?php _e('Rewrite Slug', 'cpt-plugin');?></th>
<th><?php _e('Query Var', 'cpt-plugin');?></th>
</tr>
</tfoot>
<?php
$cpt_first = true;
}
$rewrite_slug = ( isset( $post_type->rewrite_slug ) ) ? $post_type->rewrite_slug : $post_type->name;
?>
<tr>
<td valign="top"><?php echo $post_type->name; ?></td>
<td valign="top"><?php echo $post_type->label; ?></td>
<td valign="top"><?php echo disp_boolean($post_type->public); ?></td>
<td valign="top"><?php echo disp_boolean($post_type->show_ui); ?></td>
<td valign="top"><?php echo disp_boolean($post_type->hierarchical); ?></td>
<td valign="top"><?php echo disp_boolean($post_type->rewrite); ?></td>
<td valign="top"><?php echo $rewrite_slug; ?></td>
<td valign="top"><?php echo disp_boolean($post_type->query_var); ?></td>
</tr>
<?php
}
}
}
if ( isset($cpt_first) && !$cpt_first ) {
echo '<tr><td><strong>';
_e( 'No additional post types found', 'cpt-plugin' );
echo '</strong></td></tr>';
}
?>
</table>
</div><?php
//load footer
cpt_footer();
}
}
//manage custom taxonomies page
function cpt_manage_taxonomies() {
global $CPT_URL;
$MANAGE_URL = cpt_check_return( 'add' );
?>
<div class="wrap">
<?php
//check for success/error messages
if (isset($_GET['cpt_msg']) && $_GET['cpt_msg']=='del') { ?>
<div id="message" class="updated">
<?php _e('Custom taxonomy deleted successfully', 'cpt-plugin'); ?>
</div>
<?php
}
?>
<?php screen_icon( 'plugins' ); ?>
<h2><?php _e('Manage Custom Taxonomies', 'cpt-plugin') ?></h2>
<p><?php _e('Deleting custom taxonomies does <strong>NOT</strong> delete any content added to those taxonomies. You can easily recreate your taxonomies and the content will still exist.', 'cpt-plugin') ?></p>
<?php
$cpt_tax_types = get_option( 'cpt_custom_tax_types', array() );
if (is_array($cpt_tax_types)) {
?>
<table width="100%" class="widefat">
<thead>
<tr>
<th><?php _e('Action', 'cpt-plugin');?></th>
<th><?php _e('Name', 'cpt-plugin');?></th>
<th><?php _e('Label', 'cpt-plugin');?></th>
<th><?php _e('Singular Label', 'cpt-plugin');?></th>
<th><?php _e('Attached Post Types', 'cpt-plugin');?></th>
<th><?php _e('Hierarchical', 'cpt-plugin');?></th>
<th><?php _e('Show UI', 'cpt-plugin');?></th>
<th><?php _e('Rewrite', 'cpt-plugin');?></th>
<th><?php _e('Rewrite Slug', 'cpt-plugin');?></th>
</tr>
</thead>
<tfoot>
<tr>
<th><?php _e('Action', 'cpt-plugin');?></th>
<th><?php _e('Name', 'cpt-plugin');?></th>
<th><?php _e('Label', 'cpt-plugin');?></th>
<th><?php _e('Singular Label', 'cpt-plugin');?></th>
<th><?php _e('Attached Post Types', 'cpt-plugin');?></th>
<th><?php _e('Hierarchical', 'cpt-plugin');?></th>
<th><?php _e('Show UI', 'cpt-plugin');?></th>
<th><?php _e('Rewrite', 'cpt-plugin');?></th>
<th><?php _e('Rewrite Slug', 'cpt-plugin');?></th>
</tr>
</tfoot>
<?php
$thecounter=0;
foreach ($cpt_tax_types as $cpt_tax_type) {
$del_url = cpt_check_return( 'cpt' ) .'&deltax=' .$thecounter .'&return=tax';
$del_url = ( function_exists('wp_nonce_url') ) ? wp_nonce_url($del_url, 'cpt_delete_tax') : $del_url;
$edit_url = $MANAGE_URL .'&edittax=' .$thecounter .'&return=tax';
$edit_url = ( function_exists('wp_nonce_url') ) ? wp_nonce_url($edit_url, 'cpt_edit_tax') : $edit_url;
$rewrite_slug = ( $cpt_tax_type["rewrite_slug"] ) ? $cpt_tax_type["rewrite_slug"] : $cpt_tax_type["name"];
?>
<tr>
<td valign="top"><a href="<?php echo $del_url; ?>"><?php _e( 'Delete', 'cpt-plugin' ); ?></a> / <a href="<?php echo $edit_url; ?>"><?php _e( 'Edit', 'cpt-plugin' ); ?></a> / <a href="#" class="comment_button" id="<?php echo $thecounter; ?>"><?php _e( 'Get Code', 'cpt-plugin' ); ?></a></td>
<td valign="top"><?php echo stripslashes($cpt_tax_type["name"]); ?></td>
<td valign="top"><?php echo stripslashes($cpt_tax_type["label"]); ?></td>
<td valign="top"><?php echo stripslashes($cpt_tax_type["singular_label"]); ?></td>
<td valign="top">
<?php
if ( isset( $cpt_tax_type["cpt_name"] ) ) {
echo stripslashes($cpt_tax_type["cpt_name"]);
} elseif ( is_array( $cpt_tax_type[1] ) ) {
foreach ($cpt_tax_type[1] as $cpt_post_types) {
echo $cpt_post_types .'<br />';
}
}
?>
</td>
<td valign="top"><?php echo disp_boolean($cpt_tax_type["hierarchical"]); ?></td>
<td valign="top"><?php echo disp_boolean($cpt_tax_type["show_ui"]); ?></td>
<td valign="top"><?php echo disp_boolean($cpt_tax_type["rewrite"]); ?></td>
<td valign="top"><?php echo $rewrite_slug; ?></td>
</tr>
<tr>
<td colspan="10">
<div style="display:none;" id="slidepanel<?php echo $thecounter; ?>">
<?php
//display register_taxonomy code
$custom_tax = '';
$custom_tax = "add_action('init', 'cptui_register_my_taxes_" . $cpt_tax_type['name'] . "');\n";
$custom_tax .= "function cptui_register_my_taxes_" . $cpt_tax_type['name'] . "() {\n";
if ( !$cpt_tax_type["label"] ) {
$cpt_label = esc_html( $cpt_tax_type["name"] );
} else {
$cpt_label = esc_html( $cpt_tax_type["label"] );
}
//check if singular label was filled out
if ( !$cpt_tax_type["singular_label"] ) {
$cpt_singular_label = esc_html( $cpt_tax_type["name"] );
} else {
$cpt_singular_label = esc_html( $cpt_tax_type["singular_label"] );
}
$labels = var_export( array(
'search_items' => ( !empty( $cpt_tax_type["singular_label"] ) ) ? esc_html( $cpt_tax_type["singular_label"] ) : '',
'popular_items' => ( !empty( $cpt_tax_type[0]["popular_items"] ) ) ? esc_html( $cpt_tax_type[0]["popular_items"] ) : '',
'all_items' => ( !empty( $cpt_tax_type[0]["all_items"] ) ) ? esc_html( $cpt_tax_type[0]["all_items"] ) : '',
'parent_item' => ( !empty( $cpt_tax_type[0]["parent_item"] ) ) ? esc_html( $cpt_tax_type[0]["parent_item"] ) : '',
'parent_item_colon' => ( !empty( $cpt_tax_type[0]["parent_item_colon"] ) ) ? esc_html( $cpt_tax_type[0]["parent_item_colon"] ) : '',
'edit_item' => ( !empty( $cpt_tax_type[0]["edit_item"] ) ) ? esc_html( $cpt_tax_type[0]["edit_item"] ) : '',
'update_item' => ( !empty( $cpt_tax_type[0]["update_item"] ) ) ? esc_html( $cpt_tax_type[0]["update_item"] ) : '',
'add_new_item' => ( !empty( $cpt_tax_type[0]["add_new_item"] ) ) ? esc_html( $cpt_tax_type[0]["add_new_item"] ) : '',
'new_item_name' => ( !empty( $cpt_tax_type[0]["new_item_name"] ) ) ? esc_html( $cpt_tax_type[0]["new_item_name"] ) : '',
'separate_items_with_commas' => ( !empty( $cpt_tax_type[0]["separate_items_with_commas"] ) ) ? esc_html( $cpt_tax_type[0]["separate_items_with_commas"] ) : '',
'add_or_remove_items' => ( !empty( $cpt_tax_type[0]["add_or_remove_items"] ) ) ? esc_html( $cpt_tax_type[0]["add_or_remove_items"] ) : '',
'choose_from_most_used' => ( !empty( $cpt_tax_type[0]["choose_from_most_used"] ) ) ? esc_html( $cpt_tax_type[0]["choose_from_most_used"] ) : ''
), true );
$cpt_post_types = ( !$cpt_tax_type[1] ) ? $cpt_tax_type["cpt_name"] : var_export( $cpt_tax_type[1], true );
//register our custom taxonomies
$custom_tax .= "register_taxonomy( '" . $cpt_tax_type["name"] . "',";
$custom_tax .= $cpt_post_types . ",\n";
$custom_tax .= "array( 'hierarchical' => " . disp_boolean( $cpt_tax_type["hierarchical"] ) . ",\n";
$custom_tax .= "\t'label' => '" . $cpt_label . "',\n";
$custom_tax .= "\t'show_ui' => " . disp_boolean( $cpt_tax_type["show_ui"] ) . ",\n";