Selaa lähdekoodia

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

tags/0.9.0
J 5 vuotta sitten
vanhempi
commit
d1b56a6ef0

+ 17
- 0
plugins/cia-endpoints/includes/class.make-endpoint.php Näytä tiedosto

62
             $filtered[blocks] = get_rearrange_blocks(
62
             $filtered[blocks] = get_rearrange_blocks(
63
                 parse_blocks( $item->post_content )
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
             $filtered[hero] = get_post_meta( $item->ID, 'hero_header', true );
82
             $filtered[hero] = get_post_meta( $item->ID, 'hero_header', true );
66
             $filtered[relatedto] = p2p_related_to($item->ID, $item->post_type);
83
             $filtered[relatedto] = p2p_related_to($item->ID, $item->post_type);
67
 
84
 

+ 10
- 0
plugins/cia-endpoints/includes/formats.php Näytä tiedosto

11
     $filtered[content] = $item->post_content;
11
     $filtered[content] = $item->post_content;
12
 
12
 
13
     $filtered[hero] = get_post_meta( $item->ID, 'hero_header', true );
13
     $filtered[hero] = get_post_meta( $item->ID, 'hero_header', true );
14
+
14
     if($item->post_type === 'artist') {
15
     if($item->post_type === 'artist') {
15
         $filtered[sortname] = get_post_meta( $item->ID, 'artist-sort-name', true );
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
     return $filtered;
27
     return $filtered;
18
 }
28
 }
19
 
29
 

+ 18
- 3
plugins/cia-endpoints/includes/reformat-blocks.php Näytä tiedosto

1
 <?php
1
 <?php
2
     function get_rearrange_blocks($blocks) {
2
     function get_rearrange_blocks($blocks) {
3
         $parsed_blocks = array();
3
         $parsed_blocks = array();
4
-
4
+        $i = 0;
5
         foreach( $blocks as $block ) {
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
                 array_push($parsed_blocks, $block[innerHTML]);
13
                 array_push($parsed_blocks, $block[innerHTML]);
8
             } elseif ($block[innerHTML] === "\n\n") {
14
             } elseif ($block[innerHTML] === "\n\n") {
9
-                array_push($parsed_blocks, null);
15
+                // Don't do anything!
10
             } else {
16
             } else {
11
                 array_push($parsed_blocks, $block[innerBlocks]);
17
                 array_push($parsed_blocks, $block[innerBlocks]);
12
             }
18
             }
13
         }
19
         }
14
         return $parsed_blocks;
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 Näytä tiedosto

44
 
44
 
45
     /** Register custom post type call-back */
45
     /** Register custom post type call-back */
46
     public function register_post_type() {
46
     public function register_post_type() {
47
-        $args = array(
47
+        $args = [
48
             'label'              => esc_html( $this->post_type, 'test-plugin' ),
48
             'label'              => esc_html( $this->post_type, 'test-plugin' ),
49
             'public'             => true,
49
             'public'             => true,
50
             'menu_position'      => 47,
50
             'menu_position'      => 47,
51
             'menu_icon'          => $this->icon,
51
             'menu_icon'          => $this->icon,
52
-            'supports'           => array( 'title', 'editor', 'revisions', 'thumbnail' ),
52
+            'supports'           => ['title', 'editor', 'revisions', 'thumbnail'],
53
             'has_archive'        => false,
53
             'has_archive'        => false,
54
             'show_in_rest'       => true,
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
         register_post_type( $this->post_type, $args );
60
         register_post_type( $this->post_type, $args );
58
     }
61
     }
59
 }
62
 }
65
 $custom_types = get_all_custom_types();
68
 $custom_types = get_all_custom_types();
66
 foreach ($custom_types as $type):
69
 foreach ($custom_types as $type):
67
     $icon = get_icon($type);
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
 endforeach;
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
 function sanitize_hero_urls( $value, $field_args, $field ) {
82
 function sanitize_hero_urls( $value, $field_args, $field ) {
77
     $encoded = wp_json_encode( array( 'url' => $value ), true );
83
     $encoded = wp_json_encode( array( 'url' => $value ), true );
101
 /**
107
 /**
102
  * Define the metabox and field configurations.
108
  * Define the metabox and field configurations.
103
  */
109
  */
104
-function cmb2_sample_metaboxes() {
110
+function cmb2_hero_metaboxes() {
105
 
111
 
106
     /**
112
     /**
107
      * Initiate the metabox
113
      * Initiate the metabox
146
         'id'               => 'artist-sort-name',
152
         'id'               => 'artist-sort-name',
147
         'type'             => 'text'
153
         'type'             => 'text'
148
     ) );
154
     ) );
149
-}
155
+}

+ 3
- 3
plugins/cia-post-types/includes/custom-types.php Näytä tiedosto

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

Loading…
Peruuta
Tallenna