*/ // If this file is called directly, abort. if ( ! defined( 'WPINC' ) ) { die; } require_once 'includes/cmb2/init.php'; 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 = [ 'label' => esc_html( $this->post_type, 'test-plugin' ), 'public' => true, 'menu_position' => 47, 'menu_icon' => $this->icon, 'supports' => ['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); $custom_type_instance = new PostType($type, $icon); add_action( 'init', [ $custom_type_instance, 'register_post_type' ], 10 ); endforeach; /** * Create taxonomies */ add_action('init', 'create_materials_taxonomy'); function create_materials_taxonomy() { $post_types_that_show_materials = [ 'artist' ]; register_taxonomy('material', $post_types_that_show_materials, [ "label" => "Materials"]); } /* Plugin Logic -- END * / /** * Custom Fields * Defining our HERO, and Name override fields */ add_action( 'cmb2_admin_init', 'cmb2_hero_metaboxes' ); function sanitize_hero_urls( $value, $field_args, $field ) { $encoded = wp_json_encode( array( 'url' => $value ), true ); return $encoded; } function cmb_hero_render_row_cb( $field_args, $field ) { $id = $field->args( 'id' ); $label = $field->args( 'name' ); $name = $field->args( '_name' ); $value = $field->escaped_value(); $description = $field->args( 'description' ); // !: Impossible to fine " conversion $decoded = json_decode( str_replace('"', '"', $value), true ); ?>