NEXT craftinamerica.org. Base setup for headless wordpress https://www.craftinamerica.org
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

cia-post-types.php 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /**
  3. * Craft in America Custom Types Plugin
  4. *
  5. * @since 1.0.0
  6. * @package cia_post_types
  7. *
  8. * @wordpress-plugin
  9. * Plugin Name: Craft in America - Content Types
  10. * Plugin URI:
  11. * Description: Adds custom custom types, and p2p relationships
  12. * Version: 1.0.0
  13. * Author: TOJ <john@yvvas.com>
  14. */
  15. // If this file is called directly, abort.
  16. if ( ! defined( 'WPINC' ) ) { die; }
  17. require_once 'includes/cmb2/init.php';
  18. include('includes/custom-types.php');
  19. include('includes/custom-taxonomies.php');
  20. include('includes/custom-metaboxes.php');
  21. include('includes/p2p-mappings.php');
  22. /**
  23. * Class that holds all the necessary
  24. * functionality to build custom post types
  25. */
  26. class PostType {
  27. /**
  28. * The custom post type slug
  29. * @var string
  30. */
  31. private $post_type;
  32. /**
  33. * The custom post type icon
  34. * @var string
  35. */
  36. private $icon;
  37. function __construct($post_type, $icon) {
  38. $this->post_type = $post_type;
  39. $this->icon = $icon;
  40. }
  41. /** Register custom post type call-back */
  42. public function register_post_type() {
  43. $args = [
  44. 'label' => esc_html( ucfirst($this->post_type), 'test-plugin' ),
  45. 'public' => true,
  46. 'menu_position' => 47,
  47. 'menu_icon' => $this->icon,
  48. 'supports' => ['title', 'editor', 'revisions', 'thumbnail'],
  49. 'has_archive' => false,
  50. 'show_in_rest' => true,
  51. 'publicly_queryable' => true, // Needed for slug
  52. 'rewrite' => array( // Rewrite permalink stuff
  53. 'slug' => $this->post_type,
  54. 'with_front' => false
  55. ),
  56. ];
  57. register_post_type( $this->post_type, $args );
  58. }
  59. }
  60. /**
  61. * Plugin Logic
  62. * Where the magic actually happens
  63. */
  64. $custom_types = get_all_custom_types();
  65. foreach ($custom_types as $type) {
  66. $icon = get_icon($type);
  67. $custom_type_instance = new PostType($type, $icon);
  68. add_action( 'init', [ $custom_type_instance, 'register_post_type' ], 10 );
  69. }
  70. /**
  71. * Create taxonomies
  72. */
  73. add_action('init', 'create_materials_taxonomy');
  74. add_action('init', 'create_types_taxonomy');
  75. /**
  76. * Create CMB Metaboxes
  77. */
  78. add_action( 'cmb2_admin_init', 'cmb2_hero_metaboxes' );
  79. add_action( 'cmb2_admin_init', 'cmb2_sticky_metaboxes' );
  80. add_action( 'cmb2_admin_init', 'cmb2_artist_sort_metaboxes' );
  81. add_action( 'cmb2_admin_init', 'cmb2_episode_credits_metaboxes' );
  82. add_action( 'cmb2_admin_init', 'cmb2_event_date_metaboxes' );
  83. add_action( 'cmb2_admin_init', 'cmb2_exhibition_date_metaboxes' );