*/ // 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', 'exhibition', 'event' ]; register_taxonomy('material', $post_types_that_show_materials, [ "label" => "Materials"]); } add_action('init', 'create_artist_types_taxonomy'); function create_artist_types_taxonomy() { $post_types_that_show_artist_types = [ 'artist' ]; register_taxonomy('artist type', $post_types_that_show_artist_types, [ "label" => "Artist Type"]); } add_action('init', 'create_event_types_taxonomy'); function create_event_types_taxonomy() { $post_types_that_show_event_types = [ 'event' ]; register_taxonomy('event type', $post_types_that_show_event_types, [ "label" => "Event Type"]); } add_action('init', 'create_exhibit_types_taxonomy'); function create_exhibit_types_taxonomy() { $post_types_that_show_exhibit_types = [ 'exhibition' ]; register_taxonomy('Exhibition type', $post_types_that_show_exhibit_types, [ "label" => "Exhibition Type"]); } /* 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 ); ?>

'hero_metabox', 'title' => __( 'Hero', 'cmb2' ), 'object_types' => array( 'artist', ), // Post type 'context' => 'normal', 'priority' => 'high', 'show_names' => true, // Show field names on the left 'show_in_rest' => WP_REST_Server::READABLE // 'cmb_styles' => false, // false to disable the CMB stylesheet // 'closed' => true, // Keep the metabox closed by default ) ); // URL text field $cmb->add_field( array( 'name' => __( 'YouTube URL', 'cmb2' ), 'desc' => __( 'Video for the hero section to display', 'cmb2' ), 'id' => 'hero_header', 'type' => 'text', 'sanitization_cb' => 'sanitize_hero_urls', 'render_row_cb' => 'cmb_hero_render_row_cb' ) ); } add_action( 'cmb2_admin_init', 'cmb2_artist_sort_metaboxes' ); function cmb2_artist_sort_metaboxes() { $cmb = new_cmb2_box( array( 'id' => 'artist_sort_metabox', 'title' => __( 'Name Override', 'cmb2' ), 'object_types' => array( 'artist' ), 'context' => 'normal', 'priority' => 'high', 'show_names' => true, 'show_in_rest' => WP_REST_Server::READABLE ) ); $cmb->add_field( array( 'name' => __( 'Alternate Name', 'cmb2' ), 'desc' => __( 'Name to use for alphabetical sorting', 'cmb2' ), 'id' => 'artist-sort-name', 'type' => 'text' ) ); }