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 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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: The test plugin that adds rest functionality
  12. * Version: 1.0.0
  13. * Author: TOJ <john@yvvas.com>
  14. */
  15. namespace Craft_Plugins;
  16. // If this file is called directly, abort.
  17. if ( ! defined( 'WPINC' ) ) { die; }
  18. require 'includes/custom-types.php';
  19. /**
  20. * Class that holds all the necessary
  21. * functionality to build custom post types
  22. */
  23. class PostType {
  24. /**
  25. * The custom post type slug
  26. * @var string
  27. */
  28. private $post_type;
  29. /**
  30. * The custom post type icon
  31. * @var string
  32. */
  33. private $icon;
  34. function __construct($post_type, $icon) {
  35. $this->post_type = $post_type;
  36. $this->icon = $icon;
  37. }
  38. /** Register custom post type call-back */
  39. public function register_post_type() {
  40. $args = array(
  41. 'label' => esc_html( $this->post_type, 'test-plugin' ),
  42. 'public' => true,
  43. 'menu_position' => 47,
  44. 'menu_icon' => $this->icon,
  45. 'supports' => array( 'title', 'editor', 'revisions', 'thumbnail' ),
  46. 'has_archive' => false,
  47. 'show_in_rest' => true,
  48. 'publicly_queryable' => false,
  49. );
  50. register_post_type( $this->post_type, $args );
  51. }
  52. }
  53. /**
  54. * Plugin Logic
  55. * Where the magic actually happens
  56. */
  57. $custom_types = get_all_custom_types();
  58. foreach ($custom_types as $type):
  59. $icon = get_icon($type);
  60. add_action( 'init', [ new PostType($type, $icon), 'register_post_type' ] );
  61. endforeach;