Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.67 KB | None | 0 0
  1. /**
  2. * Midwest Dev Custom Post Type & Taxonomy Labels
  3. *
  4. * @since Midwest Dev 1.0
  5. * @param string $singular Singular label name
  6. * @param string $pluarl Plural label name or false if it's just singular with an s
  7. * @param string $type either Custom Post Type (cpt) or taxonomy
  8. * @return array $labels Label array
  9. */
  10. function mwd_get_labels( $singular, $plural = false, $type = 'cpt' ) {
  11.  
  12. $labels = array();
  13.  
  14. if ( !$plural ) {
  15. $plural = $singular . 's';
  16. }
  17.  
  18. if ( $type == 'cpt' ) {
  19.  
  20. $labels = array(
  21. 'name' => __( $plural ),
  22. 'singular_name' => __( $singular ),
  23. 'menu_name' => __( $plural ),
  24. 'name_admin_bar' => __( $singular ),
  25. 'add_new' => __( 'Add New' ),
  26. 'add_new_item' => __( 'Add New ' . $singular ),
  27. 'new_item' => __( 'New ' . $singular ),
  28. 'edit_item' => __( 'Edit ' . $singular ),
  29. 'view_item' => __( 'View ' . $singular ),
  30. 'all_items' => __( 'All ' . $plural ),
  31. 'search_items' => __( 'Search ' . $plural ),
  32. 'parent_item_colon' => __( 'Parent ' . $plural . ':' ),
  33. 'not_found' => __( 'No ' . strtolower( $plural ) . ' found.' ),
  34. 'not_found_in_trash' => __( 'No ' . strtolower( $plural ) . ' found in Trash.' )
  35. );
  36.  
  37. } else if ( $type == 'taxonomy' ) {
  38.  
  39. $labels = array(
  40. 'name' => _x( $plural, 'taxonomy general name' ),
  41. 'singular_name' => _x( $singular, 'taxonomy singular name' ),
  42. 'search_items' => __( 'Search ' . $plural ),
  43. 'popular_items' => __( 'Popular ' . $plural ),
  44. 'all_items' => __( 'All ' . $plural ),
  45. 'parent_item' => null,
  46. 'parent_item_colon' => null,
  47. 'edit_item' => __( 'Edit ' . $singular ),
  48. 'update_item' => __( 'Update ' . $singular ),
  49. 'add_new_item' => __( 'Add New ' . $singular ),
  50. 'new_item_name' => __( 'New ' . $singular . ' Name' ),
  51. 'separate_items_with_commas' => __( 'Separate ' . $plural . ' with commas' ),
  52. 'add_or_remove_items' => __( 'Add or remove ' . $plural ),
  53. 'choose_from_most_used' => __( 'Choose from the most used ' . $plural ),
  54. 'not_found' => __( 'No ' . $plural . ' found.' ),
  55. 'menu_name' => __( $plural ),
  56. );
  57.  
  58. }
  59.  
  60. return $labels;
  61. }
  62.  
  63. /**
  64. * Midwest Dev Custom Post Types
  65. *
  66. * Creates new custom post types
  67. *
  68. * @since Midwest Dev 1.0
  69. * @return null
  70. */
  71. function mwd_custom_post_types() {
  72.  
  73. // Movies (Example)
  74. register_post_type( 'movies',
  75. array(
  76. 'labels' => mwd_get_labels( 'Movie' ),
  77. 'public' => true,
  78. 'supports' => array( 'title', 'thumbnail', 'editor' ),
  79. 'menu_icon' => 'dashicons-location',
  80. )
  81. );
  82.  
  83. }
  84. //add_action( 'init', 'mwd_custom_post_types' ); // Uncomment to enable custom post type creation.
  85.  
  86. /**
  87. * Midwest Dev Custom Taxonomies
  88. *
  89. * Creates new taxonomies
  90. *
  91. * @since Midwest Dev 1.0
  92. * @return null
  93. */
  94. function mwd_custom_taxonomies() {
  95.  
  96. $args = array(
  97. 'labels' => mwd_get_labels( 'Genre', false, 'taxonomy' ),
  98. 'hierarchical' => true, // true == Categories | false == Tags
  99. 'show_ui' => true, // true == Show In Admin UI | false == Hide in Admin UI
  100. 'show_admin_column' => true, // true == Show Column in Admin | false == Hide Column in Admin
  101. 'query_var' => true, //
  102. 'meta_box_cb' => false, // true == Show Meta Box in Admin | false == Hide Meta Box in Admin (usually added through ACF)
  103. 'rewrite' => array( 'slug' => 'genre' ),
  104. );
  105.  
  106. register_taxonomy( 'genre', array( 'movies' ), $args );
  107.  
  108. }
  109. //add_action( 'init', 'mwd_custom_taxonomies' ); // Uncomment to enable custom taxonomy creation.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement