Quellcode durchsuchen

:recycle: trimming down custom sort code | adding subntype param to regular endpoints

tags/0.9.0
J vor 4 Jahren
Ursprung
Commit
0bfe4e7d72

+ 6
- 1
README.md Datei anzeigen

@@ -118,4 +118,9 @@ You also need to setup a `post-receive` hook on the host server.
118 118
 ```
119 119
 docker-compose exec -T craft-db mysqldump -u root -p current_cia | gzip > /home/<user_name>/backups/"`date +"%Y-%m-%d"`"-craftdb-backup.sql.gz
120 120
 ```
121
-2. On your development machine: `rsync -av <user>@<host>:/home/<user>/<date>-craftdb-backup.sql.gz <local directory>`
121
+2. On your development machine: `rsync -av <user>@<host>:/home/<user>/<date>-craftdb-backup.sql.gz <local directory>`
122
+
123
+```mysql
124
+update wp_posts
125
+   set guid = replace(guid, 'http://old', 'http://143.110.234.41:8080/');
126
+```

+ 29
- 25
plugins/cia-endpoints/cia-end-points.php Datei anzeigen

@@ -25,9 +25,19 @@ function _unsnake($input) {
25 25
     return str_replace('_', '-', $input);
26 26
 }
27 27
 
28
+function _make_sorts($post_types, $sorts_types) {
29
+    foreach ($sorts_types as $sort) {
30
+        $unsnaked = _unsnake($sort);
31
+        foreach ($post_types as $type) {
32
+            $sort_controller = new Make_Sort_By($type, $sort);
33
+            $sort_controller->register_custom_route("$type/$unsnaked");
34
+        }
35
+    }
36
+}
37
+
28 38
 add_action( 'rest_api_init', function () {
29 39
     /**
30
-     * Custom endpoints
40
+     * Custom post type endpoints
31 41
      */
32 42
     $types = get_all_post_types();
33 43
     foreach($types as $type) {
@@ -36,7 +46,7 @@ add_action( 'rest_api_init', function () {
36 46
     }
37 47
     
38 48
     /**
39
-     * Sticky Endpoint
49
+     * Sticky endpoint
40 50
      */
41 51
     $sticky_controller = new Make_Sticky_Endpoint();
42 52
     $sticky_controller->register_custom_route('sticky');
@@ -44,32 +54,26 @@ add_action( 'rest_api_init', function () {
44 54
     /**
45 55
      * Craft in America custom sort_types
46 56
      */
47
-    $artist_sorts = ['by_alpha', 'by_material', 'by_episode'];
48
-    foreach ($artist_sorts as $sort) {
49
-        $unsnaked = _unsnake($sort);
50
-        $sort_controller = new Make_Sort_By('artist', $sort);
51
-        $sort_controller->register_custom_route("artist/$unsnaked");
52
-    }
53
-
57
+    $artist_sorts = ['by_alpha'];
58
+    $by_alpha_types = ['artist'];
59
+    _make_sorts($by_alpha_types, $artist_sorts);
60
+    
54 61
     $date_sorts = ['by_past', 'by_current_and_upcoming'];
55
-    $date_types = ['exhibition', 'event'];
56
-    foreach ($date_sorts as $sort) {
57
-        $unsnaked = _unsnake($sort);
58
-        foreach ($date_types as $date_type) {
59
-            $sort_controller = new Make_Sort_By($date_type, $sort);
60
-            $sort_controller->register_custom_route("$date_type/$unsnaked");
61
-        }
62
-    }
62
+    $by_date_types = ['exhibition', 'event'];
63
+    _make_sorts($by_date_types, $date_sorts);
63 64
     
64 65
     $episode_sorts = ['by_episode'];
65
-    $episode_types = ['artist','exhibition', 'event'];
66
-    foreach ($episode_sorts as $sort) {
67
-        $unsnaked = _unsnake($sort);
68
-        foreach ($episode_types as $episode_type) {
69
-            $sort_controller = new Make_Sort_By($episode_type, $sort);
70
-            $sort_controller->register_custom_route("$episode_type/$unsnaked");
71
-        }
72
-    }
66
+    $by_episode_types = [
67
+        'artist', 'guide', 'short'
68
+    ];
69
+    _make_sorts($by_episode_types, $episode_sorts);
70
+    
71
+    $material_sorts = ['by_material'];
72
+    $by_material_types = [
73
+        'artist', 'guide', 'short',
74
+        'object', 'publication',
75
+    ];
76
+    _make_sorts($by_material_types, $material_sorts);
73 77
 });
74 78
 
75 79
 /**

+ 13
- 0
plugins/cia-endpoints/includes/class.make-endpoint.php Datei anzeigen

@@ -70,6 +70,19 @@ class Make_Endpoint_For extends WP_REST_Controller {
70 70
         if($params['order']) {
71 71
             $args['order'] = $params['order'];
72 72
         }
73
+        // Unify interface for post categories and <type> subtypes
74
+        // See:custom-taxonomies.php for a list of custom subtypes
75
+        if($params['type']) {
76
+            $taxonomy_name = $this->post_type . '_type';
77
+            if($this->post_type == 'post') { $taxonomy_name = 'category'; }
78
+            $args['tax_query'] = array(
79
+                [
80
+                    'taxonomy' => $taxonomy_name,
81
+                    'field'    => 'slug',
82
+                    'terms'    => $params['type']
83
+                ]
84
+            );
85
+        }
73 86
 
74 87
         return new WP_REST_Response( $this->prepare_all_items_for_response($args), 200 );
75 88
     }

+ 9
- 1
plugins/cia-post-types/includes/custom-taxonomies.php Datei anzeigen

@@ -1,6 +1,14 @@
1 1
 <?php
2 2
     function create_materials_taxonomy() {
3
-        $post_types_that_show_materials = [ 'artist', 'exhibition', 'event', 'guide', 'publication', 'object', 'short' ];
3
+        $post_types_that_show_materials = [
4
+            'artist',
5
+            'short',
6
+            'guide',
7
+            'exhibition',
8
+            'event',
9
+            'object',
10
+            'publication',
11
+        ];
4 12
         register_taxonomy('material', $post_types_that_show_materials, ['label' => 'Materials']);
5 13
     }
6 14
     function create_types_taxonomy() {

+ 5
- 22
plugins/cia-post-types/includes/custom-types.php Datei anzeigen

@@ -3,16 +3,12 @@
3 3
         return [
4 4
             'artist',
5 5
             'episode',
6
-            'event',
7
-            'exhibition',
8
-            'guide',
9 6
             'short',
7
+            'guide',
8
+            'exhibition',
9
+            'event',
10 10
             'object',
11 11
             'publication',
12
-            // 'talk',
13
-            // 'technique',
14
-            // 'profile',
15
-            // 'product'
16 12
         ];
17 13
     }
18 14
 
@@ -27,10 +23,6 @@
27 23
             case 'short':
28 24
                 return 'dashicons-video-alt3';
29 25
                 break;
30
-
31
-            case 'object';
32
-                return 'dashicons-visibility';
33
-                break;
34 26
             case 'guide';
35 27
                 return 'dashicons-edit';
36 28
                 break;
@@ -43,21 +35,12 @@
43 35
             case 'technique';
44 36
                 return 'dashicons-art';
45 37
                 break;
46
-            case 'place';
47
-                return 'dashicons-admin-site';
48
-                break;
49
-            case 'release';
50
-                return 'dashicons-media-text';
51
-                break;
52
-            case 'profile';
53
-                return 'dashicons-businessman';
38
+            case 'object';
39
+                return 'dashicons-visibility';
54 40
                 break;
55 41
             case 'publication';
56 42
                 return 'dashicons-book';
57 43
                 break;
58
-            case 'article';
59
-                return 'dashicons-networking';
60
-                break;
61 44
             default:
62 45
                 return 'dashicons-admin-post';
63 46
         endswitch;

Laden…
Abbrechen
Speichern