riderworks

Testimonials CPT and Taxonomy

Jan 8th, 2021
21
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /**
  3. * Plugin Name: Testimonial Custom Post Type and Position Taxonomy
  4. * Description: IRW Custom Plugin for adding Testimonial CPT and Position Taxonomy (for Home page or About page)
  5. * Author: Doug Rider
  6. * Author URI: https://riderworks.com
  7. * Plugin URI: https://riderworks.com
  8. *
  9. * Version: 1.0
  10. */
  11.  
  12. /*
  13. * Testimonials Custom Post Type
  14. */
  15. add_action( 'init', 'irw_testimonial_register_post_type' );
  16. function irw_testimonial_register_post_type() {
  17. $labels = [
  18. 'name' => esc_html__( 'Testimonials', 'irw-testimonial-textdomain' ),
  19. 'singular_name' => esc_html__( 'Testimonial', 'irw-testimonial-textdomain' ),
  20. 'add_new' => esc_html__( 'Add New', 'irw-testimonial-textdomain' ),
  21. 'add_new_item' => esc_html__( 'Add new testimonial', 'irw-testimonial-textdomain' ),
  22. 'edit_item' => esc_html__( 'Edit Testimonial', 'irw-testimonial-textdomain' ),
  23. 'new_item' => esc_html__( 'New Testimonial', 'irw-testimonial-textdomain' ),
  24. 'view_item' => esc_html__( 'View Testimonial', 'irw-testimonial-textdomain' ),
  25. 'view_items' => esc_html__( 'View Testimonials', 'irw-testimonial-textdomain' ),
  26. 'search_items' => esc_html__( 'Search Testimonials', 'irw-testimonial-textdomain' ),
  27. 'not_found' => esc_html__( 'No testimonials found', 'irw-testimonial-textdomain' ),
  28. 'not_found_in_trash' => esc_html__( 'No testimonials found in Trash', 'irw-testimonial-textdomain' ),
  29. 'parent_item_colon' => esc_html__( 'Parent Testimonial:', 'irw-testimonial-textdomain' ),
  30. 'all_items' => esc_html__( 'All Testimonials', 'irw-testimonial-textdomain' ),
  31. 'archives' => esc_html__( 'Testimonial Archives', 'irw-testimonial-textdomain' ),
  32. 'attributes' => esc_html__( 'Testimonial Attributes', 'irw-testimonial-textdomain' ),
  33. 'insert_into_item' => esc_html__( 'Insert into testimonial', 'irw-testimonial-textdomain' ),
  34. 'uploaded_to_this_item' => esc_html__( 'Uploaded to this testimonial', 'irw-testimonial-textdomain' ),
  35. 'featured_image' => esc_html__( 'Featured image', 'irw-testimonial-textdomain' ),
  36. 'set_featured_image' => esc_html__( 'Set featured image', 'irw-testimonial-textdomain' ),
  37. 'remove_featured_image' => esc_html__( 'Remove featured image', 'irw-testimonial-textdomain' ),
  38. 'use_featured_image' => esc_html__( 'Use as featured image', 'irw-testimonial-textdomain' ),
  39. 'menu_name' => esc_html__( 'Testimonials', 'irw-testimonial-textdomain' ),
  40. 'filter_items_list' => esc_html__( 'Filter testimonials list', 'irw-testimonial-textdomain' ),
  41. 'items_list_navigation' => esc_html__( 'Testimonials list navigation', 'irw-testimonial-textdomain' ),
  42. 'items_list' => esc_html__( 'Testimonials list', 'irw-testimonial-textdomain' ),
  43. 'item_published' => esc_html__( 'Testimonial published', 'irw-testimonial-textdomain' ),
  44. 'item_published_privately' => esc_html__( 'Testimonial published privately', 'irw-testimonial-textdomain' ),
  45. 'item_reverted_to_draft' => esc_html__( 'Testimonial reverted to draft', 'irw-testimonial-textdomain' ),
  46. 'item_scheduled' => esc_html__( 'Testimonial scheduled', 'irw-testimonial-textdomain' ),
  47. 'item_updated' => esc_html__( 'Testimonial updated', 'irw-testimonial-textdomain' ),
  48. 'text_domain' => esc_html__( 'irw-testimonial-textdomain', 'irw-testimonial-textdomain' ),
  49. ];
  50. $args = [
  51. 'label' => esc_html__( 'Testimonials', 'irw-testimonial-textdomain' ),
  52. 'labels' => $labels,
  53. 'description' => '',
  54. 'public' => true,
  55. 'hierarchical' => true,
  56. 'exclude_from_search' => false,
  57. 'publicly_queryable' => true,
  58. 'show_ui' => true,
  59. 'show_in_nav_menus' => true,
  60. 'show_in_admin_bar' => true,
  61. 'show_in_rest' => false,
  62. 'menu_position' => 5,
  63. 'query_var' => true,
  64. 'can_export' => true,
  65. 'delete_with_user' => false,
  66. 'has_archive' => false,
  67. 'rest_base' => '',
  68. 'show_in_menu' => true,
  69. 'menu_icon' => 'dashicons-editor-quote',
  70. 'capability_type' => 'post',
  71. 'supports' => ['title', 'thumbnail', 'revisions', 'excerpt'],
  72. 'taxonomies' => ['position'],
  73. 'rewrite' => [
  74. 'with_front' => false,
  75. ],
  76. ];
  77.  
  78. register_post_type( 'testimonial', $args );
  79. }
  80.  
  81.  
  82.  
  83. /*
  84. * Position Taxonomy
  85. */
  86. add_action( 'init', 'irw_position_register_taxonomy' );
  87. function irw_position_register_taxonomy() {
  88. $labels = [
  89. 'name' => esc_html__( 'Positions', 'irw-position-textdomain' ),
  90. 'singular_name' => esc_html__( 'Position', 'irw-position-textdomain' ),
  91. 'menu_name' => esc_html__( 'Positions', 'irw-position-textdomain' ),
  92. 'search_items' => esc_html__( 'Search Positions', 'irw-position-textdomain' ),
  93. 'popular_items' => esc_html__( 'Popular Positions', 'irw-position-textdomain' ),
  94. 'all_items' => esc_html__( 'All Positions', 'irw-position-textdomain' ),
  95. 'parent_item' => esc_html__( 'Parent Position', 'irw-position-textdomain' ),
  96. 'parent_item_colon' => esc_html__( 'Parent Position', 'irw-position-textdomain' ),
  97. 'edit_item' => esc_html__( 'Edit Position', 'irw-position-textdomain' ),
  98. 'view_item' => esc_html__( 'View Position', 'irw-position-textdomain' ),
  99. 'update_item' => esc_html__( 'Update Position', 'irw-position-textdomain' ),
  100. 'add_new_item' => esc_html__( 'Add new position', 'irw-position-textdomain' ),
  101. 'new_item_name' => esc_html__( 'New position name', 'irw-position-textdomain' ),
  102. 'separate_items_with_commas' => esc_html__( 'Separate positions with commas', 'irw-position-textdomain' ),
  103. 'add_or_remove_items' => esc_html__( 'Add or remove positions', 'irw-position-textdomain' ),
  104. 'choose_from_most_used' => esc_html__( 'Choose most used positions', 'irw-position-textdomain' ),
  105. 'not_found' => esc_html__( 'No positions found', 'irw-position-textdomain' ),
  106. 'no_terms' => esc_html__( 'No positions found', 'irw-position-textdomain' ),
  107. 'items_list_navigation' => esc_html__( 'Positions list pagination', 'irw-position-textdomain' ),
  108. 'items_list' => esc_html__( 'Positions list', 'irw-position-textdomain' ),
  109. 'most_used' => esc_html__( 'Most Used', 'irw-position-textdomain' ),
  110. 'back_to_items' => esc_html__( 'Back to positions', 'irw-position-textdomain' ),
  111. 'text_domain' => esc_html__( 'irw-position-textdomain', 'irw-position-textdomain' ),
  112. ];
  113. $args = [
  114. 'label' => esc_html__( 'Positions', 'irw-position-textdomain' ),
  115. 'labels' => $labels,
  116. 'description' => '',
  117. 'public' => true,
  118. 'publicly_queryable' => true,
  119. 'hierarchical' => true,
  120. 'show_ui' => true,
  121. 'show_in_menu' => true,
  122. 'show_in_nav_menus' => true,
  123. 'meta_box_cb' => true,
  124. 'show_in_rest' => false,
  125. 'show_tagcloud' => false,
  126. 'show_in_quick_edit' => true,
  127. 'show_admin_column' => false,
  128. 'query_var' => true,
  129. 'sort' => false,
  130. 'rest_base' => '',
  131. 'rewrite' => [
  132. 'with_front' => false,
  133. 'hierarchical' => false,
  134. ],
  135. ];
  136. register_taxonomy( 'position', ['testimonial'], $args );
  137. }
RAW Paste Data