|
|
@@ -19,40 +19,66 @@ if ( ! defined( 'WPINC' ) ) { die; }
|
|
19
|
19
|
require_once('includes/class.make-endpoint.php');
|
|
20
|
20
|
require_once('includes/class.make-sortby.php');
|
|
21
|
21
|
|
|
22
|
|
-/**
|
|
23
|
|
- * The standard wordpress post_types
|
|
24
|
|
- */
|
|
25
|
|
-add_action( 'rest_api_init', function () {
|
|
26
|
|
- $post_controller = new Make_Endpoint_For('post');
|
|
27
|
|
- $post_controller->register_custom_route('posts');
|
|
28
|
|
-});
|
|
29
|
22
|
add_action( 'rest_api_init', function () {
|
|
|
23
|
+ /**
|
|
|
24
|
+ * The standard wordpress post_types
|
|
|
25
|
+ */
|
|
30
|
26
|
$page_controller = new Make_Endpoint_For('page');
|
|
31
|
27
|
$page_controller->register_custom_route('pages');
|
|
32
|
|
-});
|
|
33
|
|
-add_action( 'rest_api_init', function () {
|
|
|
28
|
+
|
|
34
|
29
|
$media_controller = new Make_Endpoint_For('media');
|
|
35
|
30
|
$media_controller->register_custom_route('media');
|
|
36
|
|
-});
|
|
37
|
31
|
|
|
38
|
|
-/**
|
|
39
|
|
- * Craft in America custom post_types
|
|
40
|
|
- */
|
|
41
|
|
-add_action( 'rest_api_init', function () {
|
|
42
|
|
- $media_controller = new Make_Endpoint_For('episode');
|
|
43
|
|
- $media_controller->register_custom_route('episodes');
|
|
44
|
|
-});
|
|
45
|
|
-add_action( 'rest_api_init', function () {
|
|
46
|
|
- $media_controller = new Make_Endpoint_For('artist');
|
|
47
|
|
- $media_controller->register_custom_route('artists');
|
|
|
32
|
+ $post_controller = new Make_Endpoint_For('post');
|
|
|
33
|
+ $post_controller->register_custom_route('posts');
|
|
|
34
|
+
|
|
|
35
|
+ /**
|
|
|
36
|
+ * Craft in America custom post_types
|
|
|
37
|
+ */
|
|
|
38
|
+ $episode_controller = new Make_Endpoint_For('episode');
|
|
|
39
|
+ $episode_controller->register_custom_route('episodes');
|
|
|
40
|
+
|
|
|
41
|
+ $artist_controller = new Make_Endpoint_For('artist');
|
|
|
42
|
+ $artist_controller->register_custom_route('artists');
|
|
|
43
|
+
|
|
|
44
|
+ $event_controller = new Make_Endpoint_For('event');
|
|
|
45
|
+ $event_controller->register_custom_route('events');
|
|
|
46
|
+
|
|
|
47
|
+ $exhibition_controller = new Make_Endpoint_For('exhibition');
|
|
|
48
|
+ $exhibition_controller->register_custom_route('exhibitions');
|
|
|
49
|
+
|
|
|
50
|
+ /**
|
|
|
51
|
+ * Craft in America custom sort_types
|
|
|
52
|
+ */
|
|
|
53
|
+ $sort_controller = new Make_Sort_By('artist', 'by_alpha');
|
|
|
54
|
+ $sort_controller->register_custom_route('artists/by-alpha');
|
|
|
55
|
+ $sort_controller = new Make_Sort_By('artist', 'by_material');
|
|
|
56
|
+ $sort_controller->register_custom_route('artists/by-material');
|
|
48
|
57
|
});
|
|
49
|
58
|
|
|
50
|
59
|
/**
|
|
51
|
|
- * Craft in America custom sort_types
|
|
|
60
|
+ * Register the /wp-json/craft/v2/<custom endpoint> so it will be cached
|
|
|
61
|
+ * Depends on: WP REST Cache
|
|
|
62
|
+ * https://medium.com/@lodewijkm/our-headless-wordpress-journey-part-i-speeding-up-the-rest-api-aef76a898418
|
|
52
|
63
|
*/
|
|
53
|
|
-add_action( 'rest_api_init', function () {
|
|
54
|
|
- $media_controller = new Make_Sort_By('artist', 'by_alpha');
|
|
55
|
|
- $media_controller->register_custom_route('artists/by-alpha');
|
|
56
|
|
- $media_controller = new Make_Sort_By('artist', 'by_material');
|
|
57
|
|
- $media_controller->register_custom_route('artists/by-material');
|
|
58
|
|
-});
|
|
|
64
|
+add_filter('wp_rest_cache/allowed_endpoints', function () {
|
|
|
65
|
+ // The standard wordpress post_types
|
|
|
66
|
+ if ( !isset($allowed_endpoints['craft/v2']) || !in_array('posts', $allowed_endpoints['craft/v2']) )
|
|
|
67
|
+ $allowed_endpoints['craft/v2'][] = 'posts';
|
|
|
68
|
+ if ( !isset($allowed_endpoints['craft/v2']) || !in_array('pages', $allowed_endpoints['craft/v2']) )
|
|
|
69
|
+ $allowed_endpoints['craft/v2'][] = 'pages';
|
|
|
70
|
+ if ( !isset($allowed_endpoints['craft/v2']) || !in_array('media', $allowed_endpoints['craft/v2']) )
|
|
|
71
|
+ $allowed_endpoints['craft/v2'][] = 'media';
|
|
|
72
|
+
|
|
|
73
|
+ // Craft in America custom post_types
|
|
|
74
|
+ if ( !isset($allowed_endpoints['craft/v2']) || !in_array('episodes', $allowed_endpoints['craft/v2']) )
|
|
|
75
|
+ $allowed_endpoints['craft/v2'][] = 'episodes';
|
|
|
76
|
+ if ( !isset($allowed_endpoints['craft/v2']) || !in_array('events', $allowed_endpoints['craft/v2']) )
|
|
|
77
|
+ $allowed_endpoints['craft/v2'][] = 'events';
|
|
|
78
|
+ if ( !isset($allowed_endpoints['craft/v2']) || !in_array('exhibitions', $allowed_endpoints['craft/v2']) )
|
|
|
79
|
+ $allowed_endpoints['craft/v2'][] = 'exhibitions';
|
|
|
80
|
+ if ( !isset($allowed_endpoints['craft/v2']) || !in_array('artists', $allowed_endpoints['craft/v2']) )
|
|
|
81
|
+ $allowed_endpoints['craft/v2'][] = 'artists';
|
|
|
82
|
+
|
|
|
83
|
+ return $allowed_endpoints;
|
|
|
84
|
+}, 10, 1);
|