Skip to content

Commit ca91b47

Browse files
committed
fix get_fields
1 parent 201eddb commit ca91b47

3 files changed

+19
-67
lines changed

class-multisite-api.php

+12-26
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ public function register_rest_route()
4848
{
4949
// Get all sites
5050
register_rest_route(
51-
self::NAMESPACE, '/sites',
51+
self::NAMESPACE, '/'.$this->rest_base,
5252
[
5353
'methods' => \WP_REST_Server::READABLE,
5454
'callback' => [$this->get_sites, 'callback'],
55-
// 'permission_callback' => [$this, 'get_item_permissions_check'],
55+
'permission_callback' => '__return_true',
5656
'args' => [
5757
'page' => [
5858
'description' => __('Current page of the result.'),
@@ -69,57 +69,43 @@ public function register_rest_route()
6969
'type' => 'boolean',
7070
'description' => __('Retrieves the ACF fields from the site.'),
7171
],
72-
'gps' => [
73-
'default' => false,
74-
'type' => 'boolean',
75-
'description' => __('Retrieves only the GPS coordinates of the site.'),
76-
],
7772
],
78-
// 'schema' => [$this, 'get_public_item_schema'],
73+
'schema' => [$this, 'get_public_item_schema'],
7974
]
8075
);
8176

8277
// Get site by blog ID
8378
register_rest_route(
8479
self::NAMESPACE, '/'.$this->rest_base.'/(?P<id>[\d]+)',
8580
[
81+
'methods' => \WP_REST_Server::READABLE,
82+
'callback' => [$this->get_site, 'callback'],
83+
'permission_callback' => '__return_true',
8684
'args' => [
8785
'id' => [
8886
'description' => __('Unique identifier for the object.'),
8987
'type' => 'integer',
9088
],
91-
],
92-
[
93-
'methods' => \WP_REST_Server::READABLE,
94-
'callback' => [$this->get_site, 'callback'],
95-
// 'permission_callback' => [$this, 'get_item_permissions_check'],
96-
'args' => [
97-
'fields' => [
98-
'default' => true,
99-
'type' => 'boolean',
100-
'description' => __('Retrieves the ACF fields from the site.'),
101-
],
102-
'gps' => [
103-
'default' => false,
104-
'type' => 'boolean',
105-
'description' => __('Retrieves only the GPS coordinates of the site.'),
106-
],
89+
'fields' => [
90+
'default' => true,
91+
'type' => 'boolean',
92+
'description' => __('Retrieves the ACF fields from the site.'),
10793
],
10894
],
10995
'schema' => [$this, 'get_public_item_schema'],
11096
]
11197
);
11298
}
11399

114-
private function get_item_permissions_check()
100+
public function get_item_permissions_check()
115101
{
116102
global $wp_version;
117103

118104
if (version_compare($wp_version, '4.8', '>=')) {
119105
return current_user_can('setup_network');
120106
}
121107

122-
return is_super_admin();
108+
return is_admin();
123109
}
124110
}
125111

class-multisite-get-site.php

+7-22
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ public function callback($request)
1919
return $site;
2020
}
2121

22+
// Get ACF Fields
23+
switch_to_blog($request['id']);
24+
if ($request['fields']) {
25+
$site = $this->get_fields($site);
26+
}
27+
restore_current_blog();
28+
2229
return $site;
2330
}
2431

@@ -36,16 +43,6 @@ protected function get_site($id)
3643

3744
$site = get_site((int) $id);
3845

39-
// Get ACF Fields
40-
if ($request['fields']) {
41-
$site = $this->get_fields($site);
42-
}
43-
44-
// Get GPS Coordinates
45-
if ($request['gps']) {
46-
$site = $this->get_coordinates($site);
47-
}
48-
4946
if (empty($site) || empty($site->blog_id)) {
5047
return $error;
5148
}
@@ -61,16 +58,4 @@ protected function get_fields($site)
6158

6259
return apply_filters('multisite_api/get_site/fields', $site);
6360
}
64-
65-
protected function get_coordinates($site)
66-
{
67-
$coordinates = $site->fields['business_details']['address'];
68-
69-
$site->gps = [
70-
'lat' => $coordinates['lat'],
71-
'lng' => $coordinates['lng'],
72-
];
73-
74-
return apply_filters('multisite_api/get_site/gps', $site);
75-
}
7661
}

class-multisite-get-sites.php

-19
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,6 @@ public function callback($request)
3333
if ($request['fields']) {
3434
$site = $this->get_fields($site);
3535
}
36-
37-
// Get GPS Coordinates
38-
if ($request['gps']) {
39-
$site = $this->get_coordinates($site);
40-
}
41-
4236
restore_current_blog();
4337
}
4438

@@ -53,17 +47,4 @@ protected function get_fields($site)
5347

5448
return apply_filters('multisite_api/get_sites/fields', $site);
5549
}
56-
57-
protected function get_coordinates($site)
58-
{
59-
$home_id = get_option('page_on_front');
60-
$coordinates = get_field('business_details', $home_id)['address'];
61-
62-
$site->gps = [
63-
'lat' => $coordinates['lat'],
64-
'lng' => $coordinates['lng'],
65-
];
66-
67-
return apply_filters('multisite_api/get_sites/coordinates', $site);
68-
}
6950
}

0 commit comments

Comments
 (0)