| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?php
- /**
- * Craft in America Custom Types Plugin
- *
- * @since 1.0.0
- * @package cia_post_types
- *
- * @wordpress-plugin
- * Plugin Name: Craft in America - Content Types
- * Plugin URI:
- * Description: Adds custom custom types, and p2p relationships
- * Version: 1.0.0
- * Author: TOJ <john@yvvas.com>
- */
-
- // If this file is called directly, abort.
- if ( ! defined( 'WPINC' ) ) { die; }
-
- include('includes/custom-types.php');
- include('includes/p2p-mappings.php');
-
- /**
- * Class that holds all the necessary
- * functionality to build custom post types
- */
- class PostType {
- /**
- * The custom post type slug
- * @var string
- */
- private $post_type;
- /**
- * The custom post type icon
- * @var string
- */
- private $icon;
-
- function __construct($post_type, $icon) {
- $this->post_type = $post_type;
- $this->icon = $icon;
- }
-
- /** Register custom post type call-back */
- public function register_post_type() {
- $args = array(
- 'label' => esc_html( $this->post_type, 'test-plugin' ),
- 'public' => true,
- 'menu_position' => 47,
- 'menu_icon' => $this->icon,
- 'supports' => array( 'title', 'editor', 'revisions', 'thumbnail' ),
- 'has_archive' => false,
- 'show_in_rest' => true,
- 'publicly_queryable' => false,
- );
- register_post_type( $this->post_type, $args );
- }
- }
-
- /**
- * Plugin Logic
- * Where the magic actually happens
- */
- $custom_types = get_all_custom_types();
- foreach ($custom_types as $type):
- $icon = get_icon($type);
- add_action( 'init', [ new PostType($type, $icon), 'register_post_type' ] );
- endforeach;
|