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
861 lines (764 loc) · 34.4 KB
/
Copy pathcustom-post-type-ui.php
File metadata and controls
861 lines (764 loc) · 34.4 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
<?php
/*
Plugin Name: Custom Post Type UI
Plugin URI: https://github.com/WebDevStudios/custom-post-type-ui/
Description: Admin panel for creating custom post types and custom taxonomies in WordPress
Author: WebDevStudios
Version: 1.2.3
Author URI: http://webdevstudios.com/
Text Domain: custom-post-type-ui
Domain Path: /languages
License: GPLv2
*/
# Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
define( 'CPT_VERSION', '1.2.3' );
define( 'CPTUI_WP_VERSION', get_bloginfo( 'version' ) );
/**
* Load our Admin UI class that powers our form inputs.
*
* @since 1.0.0
*/
function cptui_load_ui_class() {
require_once( plugin_dir_path( __FILE__ ) . 'classes/class.cptui_admin_ui.php' );
require_once( plugin_dir_path( __FILE__ ) . 'classes/class.cptui_debug_info.php' );
}
add_action( 'init', 'cptui_load_ui_class' );
/**
* Flush our rewrite rules on deactivation.
*
* @since 0.8.0
*/
function cptui_deactivation() {
flush_rewrite_rules();
}
register_deactivation_hook( __FILE__, 'cptui_deactivation' );
/**
* Register our text domain.
*
* @since 0.8.0
*/
function cptui_load_textdomain() {
load_plugin_textdomain( 'custom-post-type-ui', false, basename( dirname( __FILE__ ) ) . '/languages' );
}
add_action( 'init', 'cptui_load_textdomain' );
/**
* Load our main menu.
*
* Submenu items added in version 1.1.0
*
* @since 0.1.0
*/
function cptui_plugin_menu() {
add_menu_page( __( 'Custom Post Types', 'custom-post-type-ui' ), __( 'CPT UI', 'custom-post-type-ui' ), 'manage_options', 'cptui_main_menu', 'cptui_settings', cptui_menu_icon() );
add_submenu_page( 'cptui_main_menu', __( 'Add/Edit Post Types', 'custom-post-type-ui' ), __( 'Add/Edit Post Types', 'custom-post-type-ui' ), 'manage_options', 'cptui_manage_post_types', 'cptui_manage_post_types' );
add_submenu_page( 'cptui_main_menu', __( 'Add/Edit Taxonomies', 'custom-post-type-ui' ), __( 'Add/Edit Taxonomies', 'custom-post-type-ui' ), 'manage_options', 'cptui_manage_taxonomies', 'cptui_manage_taxonomies' );
add_submenu_page( 'cptui_main_menu', __( 'Registered Types and Taxes', 'custom-post-type-ui' ), __( 'Registered Types/Taxes', 'custom-post-type-ui' ), 'manage_options', 'cptui_listings', 'cptui_listings' );
add_submenu_page( 'cptui_main_menu', __( 'Import/Export', 'custom-post-type-ui' ), __( 'Import/Export', 'custom-post-type-ui' ), 'manage_options', 'cptui_importexport', 'cptui_importexport' );
add_submenu_page( 'cptui_main_menu', __( 'Help/Support', 'custom-post-type-ui' ), __( 'Help/Support', 'custom-post-type-ui' ), 'manage_options', 'cptui_support', 'cptui_support' );
# Remove the default one so we can add our customized version.
remove_submenu_page('cptui_main_menu', 'cptui_main_menu');
add_submenu_page( 'cptui_main_menu', __( 'About CPT UI', 'custom-post-type-ui' ), __( 'About CPT UI', 'custom-post-type-ui' ), 'manage_options', 'cptui_main_menu', 'cptui_settings' );
}
add_action( 'admin_menu', 'cptui_plugin_menu' );
/**
* Load our submenus.
*
* @since 1.0.0
*/
function cptui_create_submenus() {
require_once( plugin_dir_path( __FILE__ ) . 'inc/post-types.php' );
require_once( plugin_dir_path( __FILE__ ) . 'inc/taxonomies.php' );
require_once( plugin_dir_path( __FILE__ ) . 'inc/listings.php' );
require_once( plugin_dir_path( __FILE__ ) . 'inc/import_export.php' );
require_once( plugin_dir_path( __FILE__ ) . 'inc/support.php' );
}
add_action( 'init', 'cptui_create_submenus' );
function cptui_add_styles() {
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
return;
}
wp_enqueue_style( 'cptui-css', plugins_url( 'css/cptui.css', __FILE__ ) );
}
add_action( 'admin_enqueue_scripts', 'cptui_add_styles' );
/**
* Register our users' custom post types.
*
* @since 0.5.0
*/
function cptui_create_custom_post_types() {
$cpts = get_option( 'cptui_post_types' );
if ( is_array( $cpts ) ) {
foreach ( $cpts as $post_type ) {
cptui_register_single_post_type( $post_type );
}
}
return;
}
add_action( 'init', 'cptui_create_custom_post_types', 10 );
/**
* Helper function to register the actual post_type.
*
* @since 1.0.0
*
* @param array $post_type Post type array to register.
*
* @return null Result of register_post_type.
*/
function cptui_register_single_post_type( $post_type = array() ) {
/**
* Filters the map_meta_cap value.
*
* @since 1.0.0
*
* @param bool $value True.
* @param string $name Post type name being registered.
* @param array $post_type All parameters for post type registration.
*/
$post_type['map_meta_cap'] = apply_filters( 'cptui_map_meta_cap', true, $post_type['name'], $post_type );
/**
* Filters custom supports parameters for 3rd party plugins.
*
* @since 1.0.0
*
* @param array $value Empty array to add supports keys to.
* @param string $name Post type slug being registered.
* @param array $post_type Array of post type arguments to be registered.
*/
$user_supports_params = apply_filters( 'cptui_user_supports_params', array(), $post_type['name'], $post_type );
if ( is_array( $user_supports_params ) ) {
$post_type['supports'] = array_merge( $post_type['supports'], $user_supports_params );
}
$yarpp = false; # Prevent notices.
if ( ! empty( $post_type['custom_supports'] ) ) {
$custom = explode( ',', $post_type['custom_supports'] );
foreach( $custom as $part ) {
# We'll handle YARPP separately.
if ( in_array( $part, array( 'YARPP', 'yarpp' ) ) ) {
$yarpp = true;
continue;
}
$post_type['supports'][] = $part;
}
}
if ( in_array( 'none', $post_type['supports'] ) ) {
$post_type['supports'] = false;
}
$labels = array(
'name' => $post_type['label'],
'singular_name' => $post_type['singular_label']
);
$preserved = cptui_get_preserved_keys( 'post_types' );
foreach( $post_type['labels'] as $key => $label ) {
if ( !empty( $label ) ) {
$labels[ $key ] = $label;
} elseif ( empty( $label ) && in_array( $key, $preserved ) ) {
$labels[ $key ] = cptui_get_preserved_label( 'post_types', $key, $post_type['label'], $post_type['singular_label'] );
}
}
$has_archive = get_disp_boolean( $post_type['has_archive'] );
if ( !empty( $post_type['has_archive_string'] ) ) {
$has_archive = $post_type['has_archive_string'];
}
$show_in_menu = get_disp_boolean( $post_type['show_in_menu'] );
if ( !empty( $post_type['show_in_menu_string'] ) ) {
$show_in_menu = $post_type['show_in_menu_string'];
}
$rewrite = get_disp_boolean( $post_type['rewrite' ] );
if ( false !== $rewrite ) {
//Core converts to an empty array anyway, so safe to leave this instead of passing in boolean true.
$rewrite = array();
$rewrite['slug'] = ( !empty( $post_type['rewrite_slug'] ) ) ? $post_type['rewrite_slug'] : $post_type['name'];
$rewrite['with_front'] = ( 'false' === disp_boolean( $post_type['rewrite_withfront'] ) ) ? false : true;
}
$menu_icon = ( !empty( $post_type['menu_icon'] ) ) ? $post_type['menu_icon'] : null;
if ( in_array( $post_type['query_var'], array( 'true', 'false', '0', '1' ) ) ) {
$post_type['query_var'] = get_disp_boolean( $post_type['query_var'] );
}
if ( ! empty( $post_type['query_var_slug'] ) ) {
$post_type['query_var'] = $post_type['query_var_slug'];
}
$menu_position = null;
if ( !empty( $post_type['menu_position'] ) ) {
$menu_position = (int) $post_type['menu_position'];
}
$public = get_disp_boolean( $post_type['public'] );
if ( ! empty( $post_type['exclude_from_search'] ) ) {
$exclude_from_search = get_disp_boolean( $post_type['exclude_from_search'] );
} else {
$exclude_from_search = ( false === $public ) ? true : false;
}
if ( empty( $post_type['show_in_nav_menus'] ) ) {
// Defaults to value of public.
$post_type['show_in_nav_menus'] = $public;
}
if ( empty( $post_type['show_in_rest'] ) ) {
$post_type['show_in_rest'] = false;
}
$rest_base = null;
if ( ! empty( $post_type['rest_base'] ) ) {
$rest_base = $post_type['rest_base'];
}
$args = array(
'labels' => $labels,
'description' => $post_type['description'],
'public' => get_disp_boolean( $post_type['public'] ),
'show_ui' => get_disp_boolean( $post_type['show_ui'] ),
'show_in_nav_menus' => get_disp_boolean( $post_type['show_in_nav_menus'] ),
'has_archive' => $has_archive,
'show_in_menu' => $show_in_menu,
'show_in_rest' => get_disp_boolean( $post_type['show_in_rest'] ),
'rest_base' => $rest_base,
'exclude_from_search' => $exclude_from_search,
'capability_type' => $post_type['capability_type'],
'map_meta_cap' => $post_type['map_meta_cap'],
'hierarchical' => get_disp_boolean( $post_type['hierarchical'] ),
'rewrite' => $rewrite,
'menu_position' => $menu_position,
'menu_icon' => $menu_icon,
'query_var' => $post_type['query_var'],
'supports' => $post_type['supports'],
'taxonomies' => $post_type['taxonomies']
);
if ( true === $yarpp ) {
$args['yarpp_support'] = $yarpp;
}
/**
* Filters the arguments used for a post type right before registering.
*
* @since 1.0.0
*
* @param array $args Array of arguments to use for registering post type.
* @param string $value Post type slug to be registered.
*/
$args = apply_filters( 'cptui_pre_register_post_type', $args, $post_type['name'] );
return register_post_type( $post_type['name'], $args );
}
/**
* Register our users' custom taxonomies.
*
* @since 0.5.0
*/
function cptui_create_custom_taxonomies() {
$taxes = get_option('cptui_taxonomies');
if ( is_array( $taxes ) ) {
foreach ( $taxes as $tax ) {
cptui_register_single_taxonomy( $tax );
}
}
}
add_action( 'init', 'cptui_create_custom_taxonomies', 9 );
/**
* Helper function to register the actual taxonomy.
*
* @param array $taxonomy Taxonomy array to register.
*
* @return null Result of register_taxonomy.
*/
function cptui_register_single_taxonomy( $taxonomy = array() ) {
$labels = array(
'name' => $taxonomy['label'],
'singular_name' => $taxonomy['singular_label']
);
$description = '';
if ( !empty( $taxonomy['description'] ) ) {
$description = $taxonomy['description'];
}
$preserved = cptui_get_preserved_keys( 'taxonomies' );
foreach( $taxonomy['labels'] as $key => $label ) {
if ( !empty( $label ) ) {
$labels[ $key ] = $label;
} elseif ( empty( $label ) && in_array( $key, $preserved ) ) {
$labels[ $key ] = cptui_get_preserved_label( 'taxonomies', $key, $taxonomy['label'], $taxonomy['singular_label'] );
}
}
$rewrite = get_disp_boolean( $taxonomy['rewrite'] );
if ( false !== get_disp_boolean( $taxonomy['rewrite'] ) ) {
$rewrite = array();
$rewrite['slug'] = ( !empty( $taxonomy['rewrite_slug'] ) ) ? $taxonomy['rewrite_slug'] : $taxonomy['name'];
$rewrite['with_front'] = ( 'false' === disp_boolean( $taxonomy['rewrite_withfront'] ) ) ? false : true;
$rewrite['hierarchical'] = ( 'true' === disp_boolean( $taxonomy['rewrite_hierarchical'] ) ) ? true : false;
}
if ( in_array( $taxonomy['query_var'], array( 'true', 'false', '0', '1' ) ) ) {
$taxonomy['query_var'] = get_disp_boolean( $taxonomy['query_var'] );
}
if ( true === $taxonomy['query_var'] && !empty( $taxonomy['query_var_slug'] ) ) {
$taxonomy['query_var'] = $taxonomy['query_var_slug'];
}
$show_admin_column = ( !empty( $taxonomy['show_admin_column'] ) && false !== get_disp_boolean( $taxonomy['show_admin_column'] ) ) ? true : false;
$show_in_rest = ( ! empty( $taxonomy['show_in_rest'] ) && false !== get_disp_boolean( $taxonomy['show_in_rest'] ) ) ? true : false;
$rest_base = null;
if ( ! empty( $taxonomy['rest_base'] ) ) {
$rest_base = $taxonomy['rest_base'];
}
$args = array(
'labels' => $labels,
'label' => $taxonomy['label'],
'description' => $description,
'hierarchical' => get_disp_boolean( $taxonomy['hierarchical'] ),
'show_ui' => get_disp_boolean( $taxonomy['show_ui'] ),
'query_var' => $taxonomy['query_var'],
'rewrite' => $rewrite,
'show_admin_column' => $show_admin_column,
'show_in_rest' => $show_in_rest,
'rest_base' => $rest_base,
);
$object_type = ( !empty( $taxonomy['object_types'] ) ) ? $taxonomy['object_types'] : '';
/**
* Filters the arguments used for a taxonomy right before registering.
*
* @since 1.0.0
*
* @param array $args Array of arguments to use for registering taxonomy.
* @param string $value Taxonomy slug to be registered.
*/
$args = apply_filters( 'cptui_pre_register_taxonomy', $args, $taxonomy['name'] );
return register_taxonomy( $taxonomy['name'], $object_type, $args );
}
/**
* Display our primary menu page.
*
* @since 0.3.0
*
* @return string $value HTML markup for the page.
*/
function cptui_settings() { ?>
<div class="wrap about-wrap">
<?php
/**
* Fires inside and at the top of the wrapper for the main plugin landing page.
*
* @since 1.0.0
*/
do_action( 'cptui_main_page_start' ); ?>
<h1><?php _e( 'Custom Post Type UI', 'custom-post-type-ui' ); ?> <?php echo CPT_VERSION; ?></h1>
<div class="about-text cptui-about-text">
<?php _e( 'Thank you for choosing Custom Post Type UI. We hope that your experience with our plugin provides efficiency and speed in creating post types and taxonomies, to better organize your content, without having to touch code.', 'custom-post-type-ui' ); ?>
</div>
<h2><?php printf( __( 'What\'s new in version %s', 'custom-post-type-ui' ), CPT_VERSION ); ?></h2>
<div class="changelog about-integrations">
<div class="cptui-feature feature-section col three-col">
<div>
<h2><?php _e( 'Updated internationalization', 'custom-post-type-ui' ); ?></h2>
<p><?php _e( 'Our textdomain now matches the plugin slug from our WordPress.org repository to help aid in translating Custom Post Type UI', 'custom-post-type-ui' ); ?></p>
</div>
<div>
<h2><?php _e( 'Debugging information', 'custom-post-type-ui' ); ?></h2>
<p><?php _e( 'We have added a new "Debug Info" tab to the Import/Export area to aid in debugging issues with Custom Post Type UI.', 'custom-post-type-ui' ); ?></p>
</div>
<div>
<h2><?php _e( 'Improved accessibility', 'custom-post-type-ui' ); ?></h2>
<p><?php _e( 'A lot of work was done in the areas of accessibility to help aid users who need it. If you have feedback on where it could be further improved, let us know.', 'custom-post-type-ui' ); ?></p>
</div>
<div>
<h2><?php _e( 'WP REST API support', 'custom-post-type-ui' ); ?></h2>
<p><?php _e( 'We now have support for the required fields for the WP REST API. Now you can add your Custom Post Type UI post types and taxonomies to the available REST API lists.', 'custom-post-type-ui' ); ?></p>
</div>
<div>
<h2><?php _e( 'More parameter support', 'custom-post-type-ui' ); ?></h2>
<p><?php _e( 'We have added more parameters for greater customization of your post type and taxonomy settings.', 'custom-post-type-ui' ); ?></p>
</div>
<div>
<h2><?php _e( 'New individual "Get Code" sections', 'custom-post-type-ui' ); ?></h2>
<p><?php _e( 'The "Get Code" area now has support for copy/paste of individual post types and taxonomies.', 'custom-post-type-ui' ); ?></p>
</div>
<div class="last-feature">
<h2><?php _e( 'Template hierarchy reference', 'custom-post-type-ui' ); ?></h2>
<p><?php _e( 'To help aid your development with post types and taxonomies, we have added a quick reference list of common template files you can use in your theme. They will be listed on the "Registered Types/Taxes" screen.', 'custom-post-type-ui' ); ?></p>
</div>
</div>
</div>
<h1><?php _e( 'Help Support This Plugin!', 'custom-post-type-ui' ); ?></h1>
<table border="0">
<tr>
<td class="one-third valign">
<h2><?php _e( 'Professional WordPress<br />Third Edition', 'custom-post-type-ui' ); ?></h2>
<a href="http://bit.ly/prowp3" target="_blank">
<img src="<?php echo plugins_url( '/images/professional-wordpress-thirdedition.jpg', __FILE__ ); ?>" width="200" alt="<?php esc_attr_e( 'Professional WordPress Design and Development book cover.', 'custom-post-type-ui' ); ?>">
</a>
<br />
<p><?php _e( 'The leading book on WordPress design and development! Brand new third edition!', 'custom-post-type-ui' ); ?></p>
</td>
<td class="one-third valign">
<h2><?php _e( 'Professional WordPress<br />Plugin Development', 'custom-post-type-ui' ); ?></h2>
<a href="http://amzn.to/plugindevbook" target="_blank">
<img src="<?php echo plugins_url( '/images/professional-wordpress-plugin-development.png', __FILE__ ); ?>" width="200" alt="<?php esc_attr_e( 'Professional WordPress Pluing Development book cover.', 'custom-post-type-ui' ); ?>">
</a>
<br />
<p><?php _e( 'Highest rated WordPress development book on Amazon!', 'custom-post-type-ui' ); ?></p>
</td>
<td class="one-third valign">
<h2><?php _e( 'PayPal Donation', 'custom-post-type-ui' ); ?></h2>
<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" name="submit" alt="<?php esc_attr_e( 'PayPal - The safer, easier way to pay online!', 'custom-post-type-ui' ); ?>">
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
<p><?php _e( 'Please donate to the development of Custom Post Type UI:', 'custom-post-type-ui' ); ?></p>
</td>
</tr>
</table>
</div>
<?php
}
/**
* Display footer links and plugin credits.
*
* @since 0.3.0
*
* @param string $original Original footer content.
*
* @return string $value HTML for footer.
*/
function cptui_footer( $original = '' ) {
$screen = get_current_screen();
if ( ! is_object( $screen ) || 'cptui_main_menu' != $screen->parent_base ) {
return $original;
}
return sprintf(
__( '%s version %s by %s', 'custom-post-type-ui' ),
sprintf(
'<a target="_blank" href="http://wordpress.org/support/plugin/custom-post-type-ui">%s</a>',
__( 'Custom Post Type UI', 'custom-post-type-ui' )
),
CPT_VERSION,
'<a href="http://webdevstudios.com" target="_blank">WebDevStudios</a>'
).
' - '.
sprintf(
'<a href="https://github.com/WebDevStudios/custom-post-type-ui/issues" target="_blank">%s</a>',
__( 'Please Report Bugs', 'custom-post-type-ui' )
).
' '.
__( 'Follow on Twitter:', 'custom-post-type-ui' ).
sprintf(
' %s · %s · %s',
'<a href="http://twitter.com/tw2113" target="_blank">Michael</a>',
'<a href="http://twitter.com/williamsba" target="_blank">Brad</a>',
'<a href="http://twitter.com/webdevstudios" target="_blank">WebDevStudios</a>'
);
}
add_filter( 'admin_footer_text', 'cptui_footer' );
/**
* Return boolean status depending on passed in value.
*
* @since 0.5.0
*
* @param mixed $booText text to compare to typical boolean values.
*
* @return bool Which bool value the passed in value was.
*/
function get_disp_boolean( $booText ) {
$booText = (string) $booText;
if ( empty( $booText ) || $booText == '0' || $booText == 'false' ) {
return false;
}
return true;
}
/**
* Return string versions of boolean values.
*
* @since 0.1.0
*
* @param string $booText String boolean value.
*
* @return string standardized boolean text.
*/
function disp_boolean( $booText ) {
$booText = (string) $booText;
if ( empty( $booText ) || $booText == '0' || $booText == 'false' ) {
return 'false';
}
return 'true';
}
/**
* Construct and output tab navigation.
*
* @since 1.0.0
*
* @param string $page Whether it's the CPT or Taxonomy page.
*
* @return string $value HTML tabs.
*/
function cptui_settings_tab_menu( $page = 'post_types' ) {
# initiate our arrays with default classes
$tab1 = $tab2 = $tab3 = $tab4 = array( 'nav-tab' );
$has = false;
if ( 'importexport' == $page ) :
$title = __( 'Import/Export', 'custom-post-type-ui' );
elseif ( 'taxonomies' == $page ) :
$title = __( 'Manage Taxonomies', 'custom-post-type-ui' );
$taxes = get_option( 'cptui_taxonomies' );
$has = ( !empty( $taxes ) ) ? true : false;
else :
$title = __( 'Manage Post Types', 'custom-post-type-ui' );
$types = get_option( 'cptui_post_types' );
$has = ( !empty( $types ) ) ? true : false;
endif;
if ( !empty( $_GET['action'] ) ) {
if ( 'edit' == $_GET['action'] || 'taxonomies' == $_GET['action'] ) {
$tab2[] = 'nav-tab-active';
} elseif ( 'get_code' == $_GET['action'] ) {
$tab3[] = 'nav-tab-active';
} elseif ( 'debuginfo' == $_GET['action'] ) {
$tab4[] = 'nav-tab-active';
}
} else {
$tab1[] = 'nav-tab-active';
}
# implode our arrays for class attributes
$tab1 = implode( ' ', $tab1 ); $tab2 = implode( ' ', $tab2 ); $tab3 = implode( ' ', $tab3 ); $tab4 = implode( ' ', $tab4 );
?>
<h1><?php echo $title; ?></h1>
<h2 class="nav-tab-wrapper">
<?php
# Import/Export area is getting different tabs, so we need to separate out.
if ( 'importexport' != $page ) {
if ( 'post_types' == $page ) {
?>
<a class="<?php echo $tab1; ?>" href="<?php echo admin_url( 'admin.php?page=cptui_manage_' . $page ); ?>"><?php _e( 'Add New Post Type', 'custom-post-type-ui' ); ?></a>
<?php
if ( $has ) { ?>
<a class="<?php echo $tab2; ?>" href="<?php echo esc_url( add_query_arg( array( 'action' => 'edit' ), admin_url( 'admin.php?page=cptui_manage_' . $page ) ) ); ?>"><?php _e( 'Edit Post Types', 'custom-post-type-ui' ); ?></a>
<?php }
} elseif ( 'taxonomies' == $page ) {
?>
<a class="<?php echo $tab1; ?>" href="<?php echo admin_url( 'admin.php?page=cptui_manage_' . $page ); ?>"><?php _e( 'Add New Taxonomy', 'custom-post-type-ui' ); ?></a>
<?php
if ( $has ) { ?>
<a class="<?php echo $tab2; ?>" href="<?php echo esc_url( add_query_arg( array( 'action' => 'edit' ), admin_url( 'admin.php?page=cptui_manage_' . $page ) ) ); ?>"><?php _e( 'Edit Taxonomies', 'custom-post-type-ui' ); ?></a>
<?php }
}
} else { ?>
<a class="<?php echo $tab1; ?>" href="<?php echo admin_url( 'admin.php?page=cptui_' . $page ); ?>"><?php _e( 'Post Types', 'custom-post-type-ui' ); ?></a>
<a class="<?php echo $tab2; ?>" href="<?php echo esc_url( add_query_arg( array( 'action' => 'taxonomies' ), admin_url( 'admin.php?page=cptui_' . $page ) ) ); ?>"><?php _e( 'Taxonomies', 'custom-post-type-ui' ); ?></a>
<a class="<?php echo $tab3; ?>" href="<?php echo esc_url( add_query_arg( array( 'action' => 'get_code' ), admin_url( 'admin.php?page=cptui_' . $page ) ) ); ?>"><?php _e( 'Get Code', 'custom-post-type-ui' ); ?></a>
<a class="<?php echo $tab4; ?>" href="<?php echo esc_url( add_query_arg( array( 'action' => 'debuginfo' ), admin_url( 'admin.php?page=cptui_' . $page ) ) ); ?>"><?php _e( 'Debug Info', 'custom-post-type-ui' ); ?></a>
<?php
}
/**
* Fires inside and at end of the `<h2>` tag for settings tabs area.
*
* @since 1.0.0
*/
do_action( 'cptui_settings_tabs_after' );
?>
</h2>
<?php
}
/**
* Convert our old settings to the new options keys.
*
* @since 1.0.0
*
* @return bool Whether or not options were successfully updated.
*/
function cptui_convert_settings() {
$retval = '';
if ( false === get_option( 'cptui_post_types' ) && ( $post_types = get_option( 'cpt_custom_post_types' ) ) ) {
$new_post_types = array();
foreach( $post_types as $type ) {
$new_post_types[ $type['name'] ] = $type; #This one assigns the # indexes # Named arrays are our friend.
$new_post_types[ $type['name'] ]['supports'] = ( !empty( $type[0] ) ) ? $type[0] : array(); # Especially
$new_post_types[ $type['name'] ]['taxonomies'] = ( !empty( $type[1] ) ) ? $type[1] : array(); # for multidimensional
$new_post_types[ $type['name'] ]['labels'] = ( !empty( $type[2] ) ) ? $type[2] : array(); # arrays
unset(
$new_post_types[ $type['name'] ][0],
$new_post_types[ $type['name'] ][1],
$new_post_types[ $type['name'] ][2]
); # Remove our previous indexed versions.
}
$retval = update_option( 'cptui_post_types', $new_post_types );
}
if ( false === get_option( 'cptui_taxonomies' ) && ( $taxonomies = get_option( 'cpt_custom_tax_types' ) ) ) {
$new_taxonomies = array();
foreach( $taxonomies as $tax ) {
$new_taxonomies[ $tax['name'] ] = $tax; # Yep, still our friend.
$new_taxonomies[ $tax['name'] ]['labels'] = $tax[0]; # Taxonomies are the only thing with
$new_taxonomies[ $tax['name'] ]['object_types'] = $tax[1]; # "tax" in the name that I like.
unset(
$new_taxonomies[ $tax['name'] ][0],
$new_taxonomies[ $tax['name'] ][1]
);
}
$retval = update_option( 'cptui_taxonomies', $new_taxonomies );
}
if ( !empty( $retval ) ) {
flush_rewrite_rules();
}
return $retval;
}
add_action( 'admin_init', 'cptui_convert_settings' );
/**
* Edit links that appear on installed plugins list page, for our plugin.
*
* @since 1.0.0
*
* @param array $links Array of links to display below our plugin listing.
*
* @return array Amended array of links.
*/
function cptui_edit_plugin_list_links( $links ) {
# We shouldn't encourage editing our plugin directly.
unset( $links['edit'] );
# Add our custom links to the returned array value.
return array_merge( array(
'<a href="' . admin_url( 'admin.php?page=cptui_main_menu' ) . '">' . __( 'Settings', 'custom-post-type-ui' ) . '</a>', '<a href="' . admin_url( 'admin.php?page=cptui_support' ) . '">' . __( 'Help', 'custom-post-type-ui' ) . '</a>'
), $links );
}
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'cptui_edit_plugin_list_links' );
/**
* Return a notice based on conditions.
*
* @since 1.0.0
*
* @param string $action The type of action that occurred.
* @param string $object_type Whether it's from a post type or taxonomy.
* @param bool $success Whether the action succeeded or not.
* @param string $custom Custom message if necessary.
*
* @return bool|string false on no message, else HTML div with our notice message.
*/
function cptui_admin_notices( $action = '', $object_type = '', $success = true , $custom = '' ) {
$class = ( $success ) ? 'updated' : 'error';
$object_type = esc_attr( $object_type );
$messagewrapstart = '<div id="message" class="' . $class . '"><p>';
$message = '';
$messagewrapend = '</p></div>';
if ( 'add' == $action ) {
if ( $success ) {
$message .= sprintf( __( '%s has been successfully added', 'custom-post-type-ui' ), $object_type );
} else {
$message .= sprintf( __( '%s has failed to be added', 'custom-post-type-ui' ), $object_type );
}
} elseif ( 'update' == $action ) {
if ( $success ) {
$message .= sprintf( __( '%s has been successfully updated', 'custom-post-type-ui' ), $object_type );
} else {
$message .= sprintf( __( '%s has failed to be updated', 'custom-post-type-ui' ), $object_type );
}
} elseif ( 'delete' == $action ) {
if ( $success ) {
$message .= sprintf( __( '%s has been successfully deleted', 'custom-post-type-ui' ), $object_type );
} else {
$message .= sprintf( __( '%s has failed to be deleted', 'custom-post-type-ui' ), $object_type );
}
} elseif ( 'import' == $action ) {
if ( $success ) {
$message .= sprintf( __( '%s has been successfully imported', 'custom-post-type-ui' ), $object_type );
} else {
$message .= sprintf( __( '%s has failed to be imported', 'custom-post-type-ui' ), $object_type );
}
} elseif ( 'error' == $action ) {
if ( !empty( $custom ) ) {
$message = $custom;
}
}
if ( $message ) {
/**
* Filters the custom admin notice for CPTUI.
*
* @since 1.0.0
*
* @param string $value Complete HTML output for notice.
* @param string $action Action whose message is being generated.
* @param string $message The message to be displayed.
* @param string $messagewrapstart Beginning wrap HTML.
* @param string $messagewrapend Ending wrap HTML.
*/
return apply_filters( 'cptui_admin_notice', $messagewrapstart . $message . $messagewrapend, $action, $message, $messagewrapstart, $messagewrapend );
}
return false;
}
/**
* Return array of keys needing preserved.
*
* @since 1.0.5
*
* @param string $type Type to return. Either 'post_types' or 'taxonomies'.
*
* @return array Array of keys needing preservered for the requested type.
*/
function cptui_get_preserved_keys( $type = '' ) {
$preserved_labels = array(
'post_types' => array(
'add_new_item',
'edit_item',
'new_item',
'view_item',
'all_items',
'search_items',
'not_found',
'not_found_in_trash'
),
'taxonomies' => array(
'search_items',
'popular_items',
'all_items',
'parent_item',
'parent_item_colon',
'edit_item',
'update_item',
'add_new_item',
'new_item_name',
'separate_items_with_commas',
'add_or_remove_items',
'choose_from_most_used'
)
);
return ( !empty( $type ) ) ? $preserved_labels[ $type ] : array();
}
/**
* Return label for the requested type and label key.
*
* @since 1.0.5
*
* @param string $type Type to return. Either 'post_types' or 'taxonomies'.
* @param string $key Requested label key.
* @param string $plural Plural verbiage for the requested label and type.
* @param string $singular Singular verbiage for the requested label and type.
*
* @return string Internationalized default label.
*/
function cptui_get_preserved_label( $type = '', $key = '', $plural = '', $singular = '' ) {
$preserved_labels = array(
'post_types' => array(
'add_new_item' => sprintf( __( 'Add new %s', 'custom-post-type-ui' ), $singular ),
'edit_item' => sprintf( __( 'Edit %s', 'custom-post-type-ui' ), $singular ),
'new_item' => sprintf( __( 'New %s', 'custom-post-type-ui' ), $singular ),
'view_item' => sprintf( __( 'View %s', 'custom-post-type-ui' ), $singular ),
'all_items' => sprintf( __( 'All %s', 'custom-post-type-ui' ), $plural ),
'search_items' => sprintf( __( 'Search %s', 'custom-post-type-ui' ), $plural ),
'not_found' => sprintf( __( 'No %s found.', 'custom-post-type-ui' ), $plural ),
'not_found_in_trash' => sprintf( __( 'No %s found in trash.', 'custom-post-type-ui' ), $plural )
),
'taxonomies' => array(
'search_items' => sprintf( __( 'Search %s', 'custom-post-type-ui' ), $plural ),
'popular_items' => sprintf( __( 'Popular %s', 'custom-post-type-ui' ), $plural ),
'all_items' => sprintf( __( 'All %s', 'custom-post-type-ui' ), $plural ),
'parent_item' => sprintf( __( 'Parent %s', 'custom-post-type-ui' ), $singular ),
'parent_item_colon' => sprintf( __( 'Parent %s:', 'custom-post-type-ui' ), $singular ),
'edit_item' => sprintf( __( 'Edit %s', 'custom-post-type-ui' ), $singular ),
'update_item' => sprintf( __( 'Update %s', 'custom-post-type-ui' ), $singular ),
'add_new_item' => sprintf( __( 'Add new %s', 'custom-post-type-ui' ), $singular ),
'new_item_name' => sprintf( __( 'New %s name', 'custom-post-type-ui' ), $singular ),
'separate_items_with_commas' => sprintf( __( 'Separate %s with commas', 'custom-post-type-ui' ), $plural ),
'add_or_remove_items' => sprintf( __( 'Add or remove %s', 'custom-post-type-ui' ), $plural ),
'choose_from_most_used' => sprintf( __( 'Choose from the most used %s', 'custom-post-type-ui' ), $plural )
)
);
return $preserved_labels[ $type ][ $key ];
}
/**
* Returns SVG icon for custom menu icon
*
* @since 1.2.0
*
* @return string
*/
function cptui_menu_icon() {
return 'data:image/svg;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAABC9pVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs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