Bladeren bron

:sparkles: added categories for artists | adjusted blocks | added attached and galleries keys

tags/0.9.0
J 5 jaren geleden
bovenliggende
commit
d1b56a6ef0

+ 17
- 0
plugins/cia-endpoints/includes/class.make-endpoint.php Bestand weergeven

@@ -62,6 +62,23 @@ class Make_Endpoint_For extends WP_REST_Controller {
62 62
             $filtered[blocks] = get_rearrange_blocks(
63 63
                 parse_blocks( $item->post_content )
64 64
             );
65
+
66
+            // Get media
67
+            $media_ids = [];
68
+            foreach (get_attached_media( '', $item->ID ) as $attached_media):
69
+                array_push($media_ids, $attached_media->ID);
70
+            endforeach;
71
+            $filtered[attached] = $media_ids;
72
+            
73
+            // Galleries From blocks
74
+            $galleries = [];
75
+            foreach (get_attached_media( '', $item->ID ) as $attached_media):
76
+                array_push($media_ids, $attached_media->ID);
77
+            endforeach;
78
+            $filtered[galleries] = get_ids_from_gallery_block(
79
+                parse_blocks( $item->post_content )
80
+            );
81
+
65 82
             $filtered[hero] = get_post_meta( $item->ID, 'hero_header', true );
66 83
             $filtered[relatedto] = p2p_related_to($item->ID, $item->post_type);
67 84
 

+ 10
- 0
plugins/cia-endpoints/includes/formats.php Bestand weergeven

@@ -11,9 +11,19 @@ function default_post_format( $item ) {
11 11
     $filtered[content] = $item->post_content;
12 12
 
13 13
     $filtered[hero] = get_post_meta( $item->ID, 'hero_header', true );
14
+
14 15
     if($item->post_type === 'artist') {
15 16
         $filtered[sortname] = get_post_meta( $item->ID, 'artist-sort-name', true );
17
+    
18
+        // Parse category IDs and store just the slugs
19
+        $category_slugs = [];
20
+        foreach (wp_get_post_categories( $item->ID ) as $id):
21
+            $category = get_category($id);
22
+            array_push($category_slugs, $category->slug);
23
+        endforeach;
24
+        $filtered[categories] = $category_slugs;
16 25
     }
26
+
17 27
     return $filtered;
18 28
 }
19 29
 

+ 18
- 3
plugins/cia-endpoints/includes/reformat-blocks.php Bestand weergeven

@@ -1,16 +1,31 @@
1 1
 <?php
2 2
     function get_rearrange_blocks($blocks) {
3 3
         $parsed_blocks = array();
4
-
4
+        $i = 0;
5 5
         foreach( $blocks as $block ) {
6
-            if(sizeof($block[innerBlocks]) < 1 && $block[innerHTML] !== "\n\n") {
6
+            // Don't include whole galleries
7
+            if ($block[blockName] === "core/gallery") {
8
+                array_push($parsed_blocks, ['gallery' => $i]);
9
+                
10
+                // Update the gallery counter
11
+                $i++;
12
+            } elseif (sizeof($block[innerBlocks]) < 1 && $block[innerHTML] !== "\n\n") {
7 13
                 array_push($parsed_blocks, $block[innerHTML]);
8 14
             } elseif ($block[innerHTML] === "\n\n") {
9
-                array_push($parsed_blocks, null);
15
+                // Don't do anything!
10 16
             } else {
11 17
                 array_push($parsed_blocks, $block[innerBlocks]);
12 18
             }
13 19
         }
14 20
         return $parsed_blocks;
15 21
     }
22
+    function get_ids_from_gallery_block($blocks){
23
+        $parsed_blocks = array();
24
+        foreach ($blocks as $block) {
25
+            if($block[blockName] === "core/gallery") {
26
+                array_push($parsed_blocks, $block[attrs]);
27
+            }
28
+        }
29
+        return $parsed_blocks;
30
+    }
16 31
 ?>

+ 16
- 10
plugins/cia-post-types/cia-post-types.php Bestand weergeven

@@ -44,16 +44,19 @@ class PostType {
44 44
 
45 45
     /** Register custom post type call-back */
46 46
     public function register_post_type() {
47
-        $args = array(
47
+        $args = [
48 48
             'label'              => esc_html( $this->post_type, 'test-plugin' ),
49 49
             'public'             => true,
50 50
             'menu_position'      => 47,
51 51
             'menu_icon'          => $this->icon,
52
-            'supports'           => array( 'title', 'editor', 'revisions', 'thumbnail' ),
52
+            'supports'           => ['title', 'editor', 'revisions', 'thumbnail'],
53 53
             'has_archive'        => false,
54 54
             'show_in_rest'       => true,
55
-            'publicly_queryable' => false,
56
-        );
55
+            'publicly_queryable' => false
56
+        ];
57
+        
58
+        if( $this->post_type == 'artist' ) { $args['taxonomies'] = ['category']; }
59
+
57 60
         register_post_type( $this->post_type, $args );
58 61
     }
59 62
 }
@@ -65,13 +68,16 @@ class PostType {
65 68
 $custom_types = get_all_custom_types();
66 69
 foreach ($custom_types as $type):
67 70
     $icon = get_icon($type);
68
-    add_action( 'init', [ new PostType($type, $icon), 'register_post_type' ] );
71
+    $custom_type_instance = new PostType($type, $icon);
69 72
 
70
-    // Register custom meta-boxes
71
-    // register_custom_meta_box( 'hero_box' 'Custom Hero Section', 'hero', $type );
73
+    add_action( 'init', [ $custom_type_instance, 'register_post_type' ], 10 );
72 74
 endforeach;
73 75
 
74
-add_action( 'cmb2_admin_init', 'cmb2_sample_metaboxes' );
76
+/**
77
+ * Custom Fields
78
+ * Defining our HERO, and Name override fields
79
+ */
80
+add_action( 'cmb2_admin_init', 'cmb2_hero_metaboxes' );
75 81
 
76 82
 function sanitize_hero_urls( $value, $field_args, $field ) {
77 83
     $encoded = wp_json_encode( array( 'url' => $value ), true );
@@ -101,7 +107,7 @@ function cmb_hero_render_row_cb( $field_args, $field ) {
101 107
 /**
102 108
  * Define the metabox and field configurations.
103 109
  */
104
-function cmb2_sample_metaboxes() {
110
+function cmb2_hero_metaboxes() {
105 111
 
106 112
     /**
107 113
      * Initiate the metabox
@@ -146,4 +152,4 @@ function cmb2_artist_sort_metaboxes() {
146 152
         'id'               => 'artist-sort-name',
147 153
         'type'             => 'text'
148 154
     ) );
149
-}
155
+}

+ 3
- 3
plugins/cia-post-types/includes/custom-types.php Bestand weergeven

@@ -1,13 +1,13 @@
1 1
 <?php
2 2
     function get_all_custom_types() {
3
-        return array(
3
+        return [
4 4
             // 'customtype',
5 5
             'artist',
6 6
             'episode',
7 7
             // 'short',
8 8
             // 'talk',
9 9
             // 'object',
10
-            'guide',
10
+            // 'guide',
11 11
             // 'event',
12 12
             // 'exhibition',
13 13
             // 'technique',
@@ -16,7 +16,7 @@
16 16
             // 'release',
17 17
             // 'article',
18 18
             // 'product'
19
-        );
19
+        ];
20 20
     }
21 21
 
22 22
     function get_icon($type) {

Laden…
Annuleren
Opslaan