Advertisement
Guest User

Untitled

a guest
Apr 26th, 2015
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. <?php
  2.  
  3. // Define array of Custom Post Types and register each
  4.  
  5. add_action( 'init', 'bolt_custom_post_types' );
  6.  
  7. function bolt_custom_post_types() {
  8.  
  9. $cpts = array(
  10. 'cpt_name' => array(
  11. 'singular' => 'Single',
  12. 'plural' => 'Plural',
  13. 'show_in_menu' => true,
  14. 'supports' => array('excerpt'),
  15. 'taxonomies' => array('post_tag', 'category'),
  16. 'has_archive' => true,
  17. 'public' => true,
  18. // 'rewrite_slug' => 'cpt-name'
  19. )
  20. );
  21.  
  22.  
  23. foreach ( $cpts as $key => $cpt ) {
  24. $db_cpt_name = THEME_PREFIX . $key;
  25. $singular = $cpt['singular'];
  26. $plural = $cpt['plural'];
  27. $show_in_menu = $cpt['show_in_menu'];
  28. $passed_supports_args = (isset($cpt['supports']) ? (array) $cpt['supports'] : array() );
  29. $passed_taxonomies = (isset($cpt['taxonomies']) ? (array) $cpt['taxonomies'] : array() );
  30.  
  31. $supports_defaults = array( 'title', 'editor', 'comments', 'thumbnail', 'custom-fields' );
  32. $supports_array = array_merge($supports_defaults, $passed_supports_args);
  33.  
  34. $taxonomies_defaults = array();
  35. $taxonomies_array = array_merge($taxonomies_defaults, $passed_taxonomies);
  36.  
  37. $hasArchive = isset($cpt['has_archive']) ? $cpt['has_archive'] : true;
  38. $exclude_from_search = isset($cpt['exclude_from_search']) ? $cpt['exclude_from_search'] : false;
  39.  
  40. $public = isset($cpt['public']) ? $cpt['public'] : false;
  41.  
  42. $rewrite_slug = isset($cpt['rewrite_slug']) ? $cpt['rewrite_slug'] : sanitize_title( $cpt['plural'] );
  43.  
  44. $hierarchical = isset( $cpt['hierarchical'] ) ? $cpt['hierarchical'] : false;
  45.  
  46. register_post_type( $db_cpt_name,
  47. array(
  48. 'labels' => array(
  49. 'name' => $plural,
  50. 'singular_name' => $singular,
  51. 'add_new' => 'Add New',
  52. 'add_new_item' => 'Add New '. $singular,
  53. 'edit' => 'Edit',
  54. 'edit_item' => 'Edit '. $singular,
  55. 'new_item' => 'New '. $singular,
  56. 'view' => 'View',
  57. 'view_item' => 'View '. $singular,
  58. 'search_items' => 'Search '. $plural,
  59. 'not_found' => 'No '. $plural .' found',
  60. 'not_found_in_trash' => 'No '. $plural .' found in Trash',
  61. 'parent' => 'Parent '. $singular
  62. ),
  63. 'public' => $public,
  64. 'menu_position' => 15,
  65. 'supports' => $supports_array,
  66. 'taxonomies' => $taxonomies_array,
  67. // 'menu_icon' => get_bloginfo('stylesheet_directory') . '/images/'.strtolower($plural).'.png',
  68. 'has_archive' => $hasArchive,
  69. 'rewrite' => array( 'slug' => $rewrite_slug ),
  70. // 'rewrite' => true,
  71. 'hierarchical' => $hierarchical,
  72. 'show_in_menu' => $show_in_menu,
  73. // 'exclude_from_search' => $exclude_from_search,
  74.  
  75. )
  76. );
  77. } // end foreach cpt
  78.  
  79. } // END create_post_types()
  80.  
  81.  
  82. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement