Ver código fonte

feat: building-on cmb fields | feat: working custom fields for hero videos

tags/0.9.0
J 6 anos atrás
pai
commit
5f1a4dfd01

+ 63
- 0
plugins/cia-post-types/cia-post-types.php Ver arquivo

16
 // If this file is called directly, abort.
16
 // If this file is called directly, abort.
17
 if ( ! defined( 'WPINC' ) ) { die; }
17
 if ( ! defined( 'WPINC' ) ) { die; }
18
 
18
 
19
+require_once 'includes/cmb2/init.php';
20
+
19
 include('includes/custom-types.php');
21
 include('includes/custom-types.php');
20
 include('includes/p2p-mappings.php');
22
 include('includes/p2p-mappings.php');
21
 
23
 
64
 foreach ($custom_types as $type):
66
 foreach ($custom_types as $type):
65
     $icon = get_icon($type);
67
     $icon = get_icon($type);
66
     add_action( 'init', [ new PostType($type, $icon), 'register_post_type' ] );
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
 endforeach;
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
+}

+ 4
- 3
vue-theme/src/components/gallery.vue Ver arquivo

47
         }
47
         }
48
     },
48
     },
49
     watch: {
49
     watch: {
50
-        fullscreengallery(newVal, oldVal) { 
50
+        fullscreengallery(newVal, oldVal) {
51
+
51
             this.selected = newVal
52
             this.selected = newVal
52
         }
53
         }
53
     },
54
     },
54
     mounted() {
55
     mounted() {
55
         // Set the first selection
56
         // Set the first selection
56
         this.selected = this.fullscreengallery
57
         this.selected = this.fullscreengallery
57
-        
58
+
58
         window.addEventListener('keydown', this.interpretKeypress)
59
         window.addEventListener('keydown', this.interpretKeypress)
59
     },
60
     },
60
     destroyed() {
61
     destroyed() {
66
 <style lang="postcss">
67
 <style lang="postcss">
67
 .gallery
68
 .gallery
68
     position: fixed
69
     position: fixed
69
-    top: 0
70
+    top: 0q
70
     left: 0
71
     left: 0
71
     width: 100%
72
     width: 100%
72
     height: 100%
73
     height: 100%

Carregando…
Cancelar
Salvar