*/ // 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;