|
|
@@ -39,7 +39,7 @@ class Make_Endpoint_For extends WP_REST_Controller {
|
|
39
|
39
|
// 'orderby' => 'date',
|
|
40
|
40
|
// 'order' => 'DESC'
|
|
41
|
41
|
);
|
|
42
|
|
-
|
|
|
42
|
+
|
|
43
|
43
|
// Get parameters from request
|
|
44
|
44
|
// /<id>?limit=<num>
|
|
45
|
45
|
$params = $request->get_params();
|
|
|
@@ -47,7 +47,7 @@ class Make_Endpoint_For extends WP_REST_Controller {
|
|
47
|
47
|
if(intval($params['id']) > 0) { $args['include'] = array($params['id']); }
|
|
48
|
48
|
// !: Add order asc/desc
|
|
49
|
49
|
// !: Add orderby
|
|
50
|
|
-
|
|
|
50
|
+
|
|
51
|
51
|
return new WP_REST_Response( $this->prepare_item_for_response($args), 200 );
|
|
52
|
52
|
}
|
|
53
|
53
|
|
|
|
@@ -56,19 +56,19 @@ class Make_Endpoint_For extends WP_REST_Controller {
|
|
56
|
56
|
$desiredSizes = ['thumbnail', 'medium', 'large', 'full'];
|
|
57
|
57
|
$all_image_ids_in_gallery = array();
|
|
58
|
58
|
$all_image_ids = array();
|
|
59
|
|
- foreach ($galleries as $gallery) {
|
|
60
|
|
- array_push($all_image_ids_in_gallery, $gallery[attrs][ids]);
|
|
|
59
|
+ foreach ( $galleries as $gallery ) {
|
|
|
60
|
+ array_push( $all_image_ids_in_gallery, $gallery[attrs][ids] );
|
|
61
|
61
|
}
|
|
62
|
|
- foreach ($all_image_ids_in_gallery as $ids) {
|
|
63
|
|
- foreach ($ids as $id) {
|
|
|
62
|
+ foreach ( $all_image_ids_in_gallery as $ids ) {
|
|
|
63
|
+ foreach ( $ids as $id ) {
|
|
64
|
64
|
array_push($all_image_ids, $id);
|
|
65
|
65
|
}
|
|
66
|
66
|
}
|
|
67
|
67
|
$attachment_map = array();
|
|
68
|
|
- foreach ($all_image_ids as $id) {
|
|
|
68
|
+ foreach ( $all_image_ids as $id ) {
|
|
69
|
69
|
$imageSizes = array();
|
|
70
|
|
- foreach ($desiredSizes as $size) {
|
|
71
|
|
- $imageSizes[$size] = wp_get_attachment_image_url($id, $size);
|
|
|
70
|
+ foreach ( $desiredSizes as $size ) {
|
|
|
71
|
+ $imageSizes[$size] = wp_get_attachment_image_url( $id, $size );
|
|
72
|
72
|
}
|
|
73
|
73
|
// store size:url map under image id
|
|
74
|
74
|
$attachment_map[$id] = $imageSizes;
|
|
|
@@ -78,32 +78,32 @@ class Make_Endpoint_For extends WP_REST_Controller {
|
|
78
|
78
|
|
|
79
|
79
|
public function prepare_item_for_response( $args ) {
|
|
80
|
80
|
$collection = array();
|
|
81
|
|
-
|
|
|
81
|
+
|
|
82
|
82
|
// https://developer.wordpress.org/reference/functions/get_posts/
|
|
83
|
83
|
foreach( get_posts($args) as $item ) {
|
|
84
|
|
- $filtered = default_post_format($item);
|
|
85
|
|
-
|
|
|
84
|
+ $filtered = default_post_format( $item );
|
|
|
85
|
+
|
|
86
|
86
|
// Get those Block!
|
|
87
|
|
- $filtered[blocks] = get_rearrange_blocks(
|
|
88
|
|
- parse_blocks( $item->post_content )
|
|
89
|
|
- );
|
|
90
|
|
-
|
|
|
87
|
+ // $filtered[blocks] = get_rearrange_blocks(
|
|
|
88
|
+ // parse_blocks( $item->post_content )
|
|
|
89
|
+ // );
|
|
|
90
|
+
|
|
91
|
91
|
// Galleries From blocks
|
|
92
|
|
- $media_ids = array();
|
|
93
|
|
- foreach ( get_attached_media( '', $item->ID ) as $attached_media ):
|
|
94
|
|
- array_push($media_ids, $attached_media->ID);
|
|
95
|
|
- endforeach;
|
|
96
|
|
- $filtered[galleries] = get_ids_from_gallery_block(
|
|
97
|
|
- parse_blocks( $item->post_content )
|
|
98
|
|
- );
|
|
|
92
|
+ // $media_ids = array();
|
|
|
93
|
+ // foreach ( get_attached_media( '', $item->ID ) as $attached_media ):
|
|
|
94
|
+ // array_push($media_ids, $attached_media->ID);
|
|
|
95
|
+ // endforeach;
|
|
|
96
|
+ // $filtered[galleries] = get_ids_from_gallery_block(
|
|
|
97
|
+ // parse_blocks( $item->post_content )
|
|
|
98
|
+ // );
|
|
99
|
99
|
|
|
100
|
100
|
// Find all image info
|
|
101
|
|
- $filtered[attached] = $this->_getAttachments($item, $filtered[galleries]);
|
|
|
101
|
+ $filtered[attached] = $this->_getAttachments( $item, $filtered[galleries] );
|
|
102
|
102
|
|
|
103
|
103
|
// For your hero URL
|
|
104
|
104
|
$filtered[hero] = get_post_meta( $item->ID, 'hero_header', true );
|
|
105
|
|
-
|
|
106
|
|
- $filtered[relatedto] = p2p_related_to($item->ID, $item->post_type);
|
|
|
105
|
+
|
|
|
106
|
+ // $filtered[relatedto] = p2p_related_to( $item->ID, $item->post_type );
|
|
107
|
107
|
|
|
108
|
108
|
$collection[$item->ID] = $filtered;
|
|
109
|
109
|
}
|