|
|
@@ -16,6 +16,8 @@
|
|
16
|
16
|
// If this file is called directly, abort.
|
|
17
|
17
|
if ( ! defined( 'WPINC' ) ) { die; }
|
|
18
|
18
|
|
|
|
19
|
+require_once 'includes/cmb2/init.php';
|
|
|
20
|
+
|
|
19
|
21
|
include('includes/custom-types.php');
|
|
20
|
22
|
include('includes/p2p-mappings.php');
|
|
21
|
23
|
|
|
|
@@ -64,4 +66,65 @@ $custom_types = get_all_custom_types();
|
|
64
|
66
|
foreach ($custom_types as $type):
|
|
65
|
67
|
$icon = get_icon($type);
|
|
66
|
68
|
add_action( 'init', [ new PostType($type, $icon), 'register_post_type' ] );
|
|
|
69
|
+
|
|
|
70
|
+ // Register custom meta-boxes
|
|
|
71
|
+ // register_custom_meta_box( 'hero_box' 'Custom Hero Section', 'hero', $type );
|
|
67
|
72
|
endforeach;
|
|
|
73
|
+
|
|
|
74
|
+add_action( 'cmb2_admin_init', 'cmb2_sample_metaboxes' );
|
|
|
75
|
+
|
|
|
76
|
+function sanitize_hero_urls( $value, $field_args, $field ) {
|
|
|
77
|
+ $encoded = wp_json_encode( array( 'url' => $value ), true );
|
|
|
78
|
+ return $encoded;
|
|
|
79
|
+}
|
|
|
80
|
+
|
|
|
81
|
+function cmb_hero_render_row_cb( $field_args, $field ) {
|
|
|
82
|
+ $id = $field->args( 'id' );
|
|
|
83
|
+ $label = $field->args( 'name' );
|
|
|
84
|
+ $name = $field->args( '_name' );
|
|
|
85
|
+ $value = $field->escaped_value();
|
|
|
86
|
+ $description = $field->args( 'description' );
|
|
|
87
|
+ // !: Impossible to fine " conversion
|
|
|
88
|
+ $decoded = json_decode( str_replace('"', '"', $value), true );
|
|
|
89
|
+ ?>
|
|
|
90
|
+ <div class="custom-field-row">
|
|
|
91
|
+ <p>
|
|
|
92
|
+ <label for="<?php echo $id; ?>"><?php echo $label; ?></label>
|
|
|
93
|
+ <input style="width: 100%;" id="<?php echo $id; ?>" type="text" name="<?php echo $name; ?>"
|
|
|
94
|
+ value="<?php echo $decoded['url']; ?>"/>
|
|
|
95
|
+ </p>
|
|
|
96
|
+ <p class="description"><?php echo $description; ?></p>
|
|
|
97
|
+ </div>
|
|
|
98
|
+ <?php
|
|
|
99
|
+}
|
|
|
100
|
+
|
|
|
101
|
+/**
|
|
|
102
|
+ * Define the metabox and field configurations.
|
|
|
103
|
+ */
|
|
|
104
|
+function cmb2_sample_metaboxes() {
|
|
|
105
|
+
|
|
|
106
|
+ /**
|
|
|
107
|
+ * Initiate the metabox
|
|
|
108
|
+ */
|
|
|
109
|
+ $cmb = new_cmb2_box( array(
|
|
|
110
|
+ 'id' => 'hero_metabox',
|
|
|
111
|
+ 'title' => __( 'Hero', 'cmb2' ),
|
|
|
112
|
+ 'object_types' => array( 'artist', ), // Post type
|
|
|
113
|
+ 'context' => 'normal',
|
|
|
114
|
+ 'priority' => 'high',
|
|
|
115
|
+ 'show_names' => true, // Show field names on the left
|
|
|
116
|
+ 'show_in_rest' => WP_REST_Server::READABLE
|
|
|
117
|
+ // 'cmb_styles' => false, // false to disable the CMB stylesheet
|
|
|
118
|
+ // 'closed' => true, // Keep the metabox closed by default
|
|
|
119
|
+ ) );
|
|
|
120
|
+
|
|
|
121
|
+ // URL text field
|
|
|
122
|
+ $cmb->add_field( array(
|
|
|
123
|
+ 'name' => __( 'YouTube URL', 'cmb2' ),
|
|
|
124
|
+ 'desc' => __( 'Video for the hero section to display', 'cmb2' ),
|
|
|
125
|
+ 'id' => 'hero_header',
|
|
|
126
|
+ 'type' => 'text',
|
|
|
127
|
+ 'sanitization_cb' => 'sanitize_hero_urls',
|
|
|
128
|
+ 'render_row_cb' => 'cmb_hero_render_row_cb'
|
|
|
129
|
+ ) );
|
|
|
130
|
+}
|