Преглед изворни кода

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

tags/0.9.0
J пре 4 година
родитељ
комит
0bfe4e7d72

+ 6
- 1
README.md Прегледај датотеку

118
 ```
118
 ```
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
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 Прегледај датотеку

25
     return str_replace('_', '-', $input);
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
 add_action( 'rest_api_init', function () {
38
 add_action( 'rest_api_init', function () {
29
     /**
39
     /**
30
-     * Custom endpoints
40
+     * Custom post type endpoints
31
      */
41
      */
32
     $types = get_all_post_types();
42
     $types = get_all_post_types();
33
     foreach($types as $type) {
43
     foreach($types as $type) {
36
     }
46
     }
37
     
47
     
38
     /**
48
     /**
39
-     * Sticky Endpoint
49
+     * Sticky endpoint
40
      */
50
      */
41
     $sticky_controller = new Make_Sticky_Endpoint();
51
     $sticky_controller = new Make_Sticky_Endpoint();
42
     $sticky_controller->register_custom_route('sticky');
52
     $sticky_controller->register_custom_route('sticky');
44
     /**
54
     /**
45
      * Craft in America custom sort_types
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
     $date_sorts = ['by_past', 'by_current_and_upcoming'];
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
     $episode_sorts = ['by_episode'];
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 Прегледај датотеку

70
         if($params['order']) {
70
         if($params['order']) {
71
             $args['order'] = $params['order'];
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
         return new WP_REST_Response( $this->prepare_all_items_for_response($args), 200 );
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 Прегледај датотеку

1
 <?php
1
 <?php
2
     function create_materials_taxonomy() {
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
         register_taxonomy('material', $post_types_that_show_materials, ['label' => 'Materials']);
12
         register_taxonomy('material', $post_types_that_show_materials, ['label' => 'Materials']);
5
     }
13
     }
6
     function create_types_taxonomy() {
14
     function create_types_taxonomy() {

+ 5
- 22
plugins/cia-post-types/includes/custom-types.php Прегледај датотеку

3
         return [
3
         return [
4
             'artist',
4
             'artist',
5
             'episode',
5
             'episode',
6
-            'event',
7
-            'exhibition',
8
-            'guide',
9
             'short',
6
             'short',
7
+            'guide',
8
+            'exhibition',
9
+            'event',
10
             'object',
10
             'object',
11
             'publication',
11
             'publication',
12
-            // 'talk',
13
-            // 'technique',
14
-            // 'profile',
15
-            // 'product'
16
         ];
12
         ];
17
     }
13
     }
18
 
14
 
27
             case 'short':
23
             case 'short':
28
                 return 'dashicons-video-alt3';
24
                 return 'dashicons-video-alt3';
29
                 break;
25
                 break;
30
-
31
-            case 'object';
32
-                return 'dashicons-visibility';
33
-                break;
34
             case 'guide';
26
             case 'guide';
35
                 return 'dashicons-edit';
27
                 return 'dashicons-edit';
36
                 break;
28
                 break;
43
             case 'technique';
35
             case 'technique';
44
                 return 'dashicons-art';
36
                 return 'dashicons-art';
45
                 break;
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
                 break;
40
                 break;
55
             case 'publication';
41
             case 'publication';
56
                 return 'dashicons-book';
42
                 return 'dashicons-book';
57
                 break;
43
                 break;
58
-            case 'article';
59
-                return 'dashicons-networking';
60
-                break;
61
             default:
44
             default:
62
                 return 'dashicons-admin-post';
45
                 return 'dashicons-admin-post';
63
         endswitch;
46
         endswitch;

Loading…
Откажи
Сачувај