Version Description
fix indentation removing unnecessary code removing anonymous function
Download this release
Release Info
Developer | airesvsg |
Plugin | ACF to REST API |
Version | 3.1.0 |
Comparing to | |
See all releases |
Code changes from version 3.0.0-beta to 3.1.0
- class-acf-to-rest-api.php +2 -2
- composer.json +25 -0
- readme.md +4 -3
- readme.txt +17 -2
- v3/lib/class-acf-to-rest-api-acf-api.php +38 -23
- v3/lib/class-acf-to-rest-api-acf-field-settings.php +4 -4
- v3/lib/endpoints/class-acf-to-rest-api-controller.php +7 -5
- v3/lib/endpoints/class-acf-to-rest-api-posts-controller.php +1 -1
class-acf-to-rest-api.php
CHANGED
@@ -4,7 +4,7 @@
|
|
4 |
* Description: Exposes Advanced Custom Fields Endpoints in the WordPress REST API
|
5 |
* Author: Aires Gonçalves
|
6 |
* Author URI: http://github.com/airesvsg
|
7 |
-
* Version: 3.
|
8 |
* Plugin URI: http://github.com/airesvsg/acf-to-rest-api
|
9 |
*/
|
10 |
|
@@ -16,7 +16,7 @@ if ( ! class_exists( 'ACF_To_REST_API' ) ) {
|
|
16 |
|
17 |
class ACF_To_REST_API {
|
18 |
|
19 |
-
const VERSION = '3.
|
20 |
|
21 |
private static $old_request_version = 2;
|
22 |
private static $default_request_version = 3;
|
4 |
* Description: Exposes Advanced Custom Fields Endpoints in the WordPress REST API
|
5 |
* Author: Aires Gonçalves
|
6 |
* Author URI: http://github.com/airesvsg
|
7 |
+
* Version: 3.1.0
|
8 |
* Plugin URI: http://github.com/airesvsg/acf-to-rest-api
|
9 |
*/
|
10 |
|
16 |
|
17 |
class ACF_To_REST_API {
|
18 |
|
19 |
+
const VERSION = '3.1.0';
|
20 |
|
21 |
private static $old_request_version = 2;
|
22 |
private static $default_request_version = 3;
|
composer.json
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "airesvsg/acf-to-rest-api",
|
3 |
+
"description": "Exposes Advanced Custom Fields Endpoints in the WordPress REST API",
|
4 |
+
"type": "wordpress-plugin",
|
5 |
+
"version": "3.1.0",
|
6 |
+
"keywords": ["wordpress", "wp", "rest-api", "acf", "wp-api", "json", "wordpres-plugin", "fields"],
|
7 |
+
"homepage": "https://github.com/airesvsg/acf-to-rest-api",
|
8 |
+
"license": "GPLv2.0+",
|
9 |
+
"authors": [
|
10 |
+
{
|
11 |
+
"name": "Aires Gonçalves",
|
12 |
+
"email": "airesvsg@gmail.com",
|
13 |
+
"homepage": "http://airesgoncalves.com",
|
14 |
+
"role": "Developer"
|
15 |
+
}
|
16 |
+
],
|
17 |
+
"support": {
|
18 |
+
"email": "airesvsg@gmail.com",
|
19 |
+
"issues": "https://github.com/airesvsg/acf-to-rest-api/issues"
|
20 |
+
},
|
21 |
+
"require": {
|
22 |
+
"php": ">=5.3.2",
|
23 |
+
"composer/installers": "~1.0"
|
24 |
+
}
|
25 |
+
}
|
readme.md
CHANGED
@@ -34,11 +34,12 @@ Endpoints
|
|
34 |
| /wp-json/acf/v3/users/**{id}** | ![yes](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/yes.png) | ![yes](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/yes.png) |
|
35 |
| /wp-json/acf/v3/users/**{id}**/**{field-name}** | ![yes](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/yes.png) | ![yes](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/yes.png) |
|
36 |
| /wp-json/acf/v3/**{taxonomy}** ![new](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/new-v3.1.png) | ![yes](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/yes.png) | ![no](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/no.png) |
|
|
|
37 |
| /wp-json/acf/v3/**{taxonomy}**/**{id}**/**{field-name}** ![new](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/new-v3.1.png) | ![yes](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/yes.png) | ![yes](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/yes.png) |
|
38 |
| /wp-json/acf/v3/comments ![new](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/new-v3.1.png) | ![yes](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/yes.png) | ![no](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/no.png) |
|
39 |
| /wp-json/acf/v3/comments/**{id}** | ![yes](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/yes.png) | ![yes](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/yes.png) |
|
40 |
| /wp-json/acf/v3/comments/**{id}**/**{field-name}** | ![yes](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/yes.png) | ![yes](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/yes.png) |
|
41 |
-
| /wp-json/acf/v3/media | ![yes](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/yes.png) | ![no](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/no.png) |
|
42 |
| /wp-json/acf/v3/media/**{id}** | ![yes](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/yes.png) | ![yes](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/yes.png) |
|
43 |
| /wp-json/acf/v3/media/**{id}**/**{field-name}** | ![yes](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/yes.png) | ![yes](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/yes.png) |
|
44 |
| /wp-json/acf/v3/**{post-type}** ![new](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/new-v3.1.png) | ![yes](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/yes.png) | ![no](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/no.png) |
|
@@ -75,7 +76,7 @@ Deprecated filters
|
|
75 |
| acf/rest_api/types | array **$types** |
|
76 |
| acf/rest_api/default_rest_base | boolean **$default**<br>string **$type** |
|
77 |
|
78 |
-
Request API version
|
79 |
====
|
80 |
See below how to select the Request API Version.
|
81 |
|
@@ -92,7 +93,7 @@ The other alternative is to define the constant `ACF_TO_REST_API_REQUEST_VERSION
|
|
92 |
define( 'ACF_TO_REST_API_REQUEST_VERSION', 2 );
|
93 |
```
|
94 |
|
95 |
-
Field Settings
|
96 |
====
|
97 |
In this version is possible to configure the field options via admin.
|
98 |
|
34 |
| /wp-json/acf/v3/users/**{id}** | ![yes](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/yes.png) | ![yes](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/yes.png) |
|
35 |
| /wp-json/acf/v3/users/**{id}**/**{field-name}** | ![yes](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/yes.png) | ![yes](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/yes.png) |
|
36 |
| /wp-json/acf/v3/**{taxonomy}** ![new](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/new-v3.1.png) | ![yes](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/yes.png) | ![no](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/no.png) |
|
37 |
+
| /wp-json/acf/v3/**{taxonomy}**/**{id}** ![new](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/new-v3.1.png) | ![yes](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/yes.png) | ![yes](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/yes.png) |
|
38 |
| /wp-json/acf/v3/**{taxonomy}**/**{id}**/**{field-name}** ![new](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/new-v3.1.png) | ![yes](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/yes.png) | ![yes](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/yes.png) |
|
39 |
| /wp-json/acf/v3/comments ![new](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/new-v3.1.png) | ![yes](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/yes.png) | ![no](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/no.png) |
|
40 |
| /wp-json/acf/v3/comments/**{id}** | ![yes](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/yes.png) | ![yes](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/yes.png) |
|
41 |
| /wp-json/acf/v3/comments/**{id}**/**{field-name}** | ![yes](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/yes.png) | ![yes](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/yes.png) |
|
42 |
+
| /wp-json/acf/v3/media ![new](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/new-v3.1.png) | ![yes](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/yes.png) | ![no](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/no.png) |
|
43 |
| /wp-json/acf/v3/media/**{id}** | ![yes](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/yes.png) | ![yes](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/yes.png) |
|
44 |
| /wp-json/acf/v3/media/**{id}**/**{field-name}** | ![yes](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/yes.png) | ![yes](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/yes.png) |
|
45 |
| /wp-json/acf/v3/**{post-type}** ![new](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/new-v3.1.png) | ![yes](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/yes.png) | ![no](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/no.png) |
|
76 |
| acf/rest_api/types | array **$types** |
|
77 |
| acf/rest_api/default_rest_base | boolean **$default**<br>string **$type** |
|
78 |
|
79 |
+
Request API version
|
80 |
====
|
81 |
See below how to select the Request API Version.
|
82 |
|
93 |
define( 'ACF_TO_REST_API_REQUEST_VERSION', 2 );
|
94 |
```
|
95 |
|
96 |
+
Field Settings
|
97 |
====
|
98 |
In this version is possible to configure the field options via admin.
|
99 |
|
readme.txt
CHANGED
@@ -3,8 +3,8 @@ Contributors: airesvsg
|
|
3 |
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=airesvsg%40gmail%2ecom&lc=BR&item_name=Aires%20Goncalves&no_note=0¤cy_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHostedGuest
|
4 |
Tags: acf, api, rest, wp-api, wp-rest-api, json, wp, wordpress, wp-rest-api, wordpress-rest-api
|
5 |
Requires at least: 4.6
|
6 |
-
Tested up to: 4.
|
7 |
-
Stable tag: 3.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -21,6 +21,21 @@ Exposes [Advanced Custom Fields](https://wordpress.org/plugins/advanced-custom-f
|
|
21 |
|
22 |
== Changelog ==
|
23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
= 3.0.0-beta =
|
25 |
more readable endpoints ( https://github.com/airesvsg/acf-to-rest-api/issues/46 ) - Thanks to Imaginet
|
26 |
change return when acf filed key is empty ( https://github.com/airesvsg/acf-to-rest-api/issues/48 ) - Thanks to Joris Verbogt
|
3 |
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=airesvsg%40gmail%2ecom&lc=BR&item_name=Aires%20Goncalves&no_note=0¤cy_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHostedGuest
|
4 |
Tags: acf, api, rest, wp-api, wp-rest-api, json, wp, wordpress, wp-rest-api, wordpress-rest-api
|
5 |
Requires at least: 4.6
|
6 |
+
Tested up to: 4.9.1
|
7 |
+
Stable tag: 3.1.0
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
21 |
|
22 |
== Changelog ==
|
23 |
|
24 |
+
= 3.1.0 =
|
25 |
+
fix indentation
|
26 |
+
removing unnecessary code
|
27 |
+
removing anonymous function
|
28 |
+
|
29 |
+
= 3.0.2 =
|
30 |
+
stable version
|
31 |
+
|
32 |
+
= 3.0.2-beta =
|
33 |
+
adding fallback to get_fields
|
34 |
+
changing default value to acf field setting
|
35 |
+
|
36 |
+
= 3.0.1-beta =
|
37 |
+
fix default params bug
|
38 |
+
|
39 |
= 3.0.0-beta =
|
40 |
more readable endpoints ( https://github.com/airesvsg/acf-to-rest-api/issues/46 ) - Thanks to Imaginet
|
41 |
change return when acf filed key is empty ( https://github.com/airesvsg/acf-to-rest-api/issues/48 ) - Thanks to Joris Verbogt
|
v3/lib/class-acf-to-rest-api-acf-api.php
CHANGED
@@ -6,9 +6,9 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|
6 |
|
7 |
if ( ! class_exists( 'ACF_To_REST_API_ACF_API' ) ) {
|
8 |
class ACF_To_REST_API_ACF_API {
|
9 |
-
protected $id
|
10 |
-
protected $type
|
11 |
-
protected $controller
|
12 |
protected $field_objects = null;
|
13 |
|
14 |
public function __construct( $type, $controller = null ) {
|
@@ -16,7 +16,7 @@ if ( ! class_exists( 'ACF_To_REST_API_ACF_API' ) ) {
|
|
16 |
$this->controller = $controller;
|
17 |
}
|
18 |
|
19 |
-
protected function format_id(
|
20 |
if ( $this->id ) {
|
21 |
switch ( $this->type ) {
|
22 |
case 'comment' :
|
@@ -38,27 +38,27 @@ if ( ! class_exists( 'ACF_To_REST_API_ACF_API' ) ) {
|
|
38 |
return $this->id;
|
39 |
}
|
40 |
|
41 |
-
public function get_id( $
|
42 |
$this->id = false;
|
43 |
|
44 |
-
if ( is_numeric( $
|
45 |
-
$this->id = $
|
46 |
-
} elseif ( is_array( $
|
47 |
-
$this->id = $
|
48 |
-
} elseif ( is_object( $
|
49 |
-
if ( $
|
50 |
-
$data = $
|
51 |
if ( isset( $data['id'] ) ) {
|
52 |
$this->id = $data['id'];
|
53 |
}
|
54 |
-
} elseif ( $
|
55 |
-
$this->id = $
|
56 |
-
} elseif ( isset( $
|
57 |
-
$this->id = $
|
58 |
-
} elseif ( isset( $
|
59 |
-
$this->id = $
|
60 |
-
} elseif ( isset( $
|
61 |
-
$this->id = $
|
62 |
}
|
63 |
}
|
64 |
|
@@ -68,7 +68,7 @@ if ( ! class_exists( 'ACF_To_REST_API_ACF_API' ) ) {
|
|
68 |
$this->id = absint( $this->id );
|
69 |
}
|
70 |
|
71 |
-
return $this->format_id(
|
72 |
}
|
73 |
|
74 |
public function get_fields( $request ) {
|
@@ -85,7 +85,8 @@ if ( ! class_exists( 'ACF_To_REST_API_ACF_API' ) ) {
|
|
85 |
} else {
|
86 |
$fields = get_fields( $this->id );
|
87 |
if ( ! $fields ) {
|
88 |
-
$
|
|
|
89 |
}
|
90 |
$data['acf'] = $fields;
|
91 |
}
|
@@ -96,7 +97,7 @@ if ( ! class_exists( 'ACF_To_REST_API_ACF_API' ) ) {
|
|
96 |
} else {
|
97 |
foreach ( array_keys( $data['acf'] ) as $key ) {
|
98 |
$this->show_in_rest( $data['acf'], $key, $this->field_objects );
|
99 |
-
}
|
100 |
}
|
101 |
}
|
102 |
} else {
|
@@ -106,6 +107,20 @@ if ( ! class_exists( 'ACF_To_REST_API_ACF_API' ) ) {
|
|
106 |
return apply_filters( 'acf/rest_api/' . $this->type . '/get_fields', $data, $request );
|
107 |
}
|
108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
public function get_field_objects( $id ) {
|
110 |
if ( empty( $id ) ) {
|
111 |
return false;
|
6 |
|
7 |
if ( ! class_exists( 'ACF_To_REST_API_ACF_API' ) ) {
|
8 |
class ACF_To_REST_API_ACF_API {
|
9 |
+
protected $id = null;
|
10 |
+
protected $type = null;
|
11 |
+
protected $controller = null;
|
12 |
protected $field_objects = null;
|
13 |
|
14 |
public function __construct( $type, $controller = null ) {
|
16 |
$this->controller = $controller;
|
17 |
}
|
18 |
|
19 |
+
protected function format_id() {
|
20 |
if ( $this->id ) {
|
21 |
switch ( $this->type ) {
|
22 |
case 'comment' :
|
38 |
return $this->id;
|
39 |
}
|
40 |
|
41 |
+
public function get_id( $object ) {
|
42 |
$this->id = false;
|
43 |
|
44 |
+
if ( is_numeric( $object ) ) {
|
45 |
+
$this->id = $object;
|
46 |
+
} elseif ( is_array( $object ) && isset( $object['id'] ) ) {
|
47 |
+
$this->id = $object['id'];
|
48 |
+
} elseif ( is_object( $object ) ) {
|
49 |
+
if ( $object instanceof WP_REST_Response ) {
|
50 |
+
$data = $object->get_data();
|
51 |
if ( isset( $data['id'] ) ) {
|
52 |
$this->id = $data['id'];
|
53 |
}
|
54 |
+
} elseif ( $object instanceof WP_REST_Request ) {
|
55 |
+
$this->id = $object->get_param( 'id' );
|
56 |
+
} elseif ( isset( $object->ID ) ) {
|
57 |
+
$this->id = $object->ID;
|
58 |
+
} elseif ( isset( $object->comment_ID ) ) {
|
59 |
+
$this->id = $object->comment_ID;
|
60 |
+
} elseif ( isset( $object->term_id ) ) {
|
61 |
+
$this->id = $object->term_id;
|
62 |
}
|
63 |
}
|
64 |
|
68 |
$this->id = absint( $this->id );
|
69 |
}
|
70 |
|
71 |
+
return $this->format_id();
|
72 |
}
|
73 |
|
74 |
public function get_fields( $request ) {
|
85 |
} else {
|
86 |
$fields = get_fields( $this->id );
|
87 |
if ( ! $fields ) {
|
88 |
+
$this->get_field_objects( $this->id );
|
89 |
+
$fields = $this->get_fields_fallback();
|
90 |
}
|
91 |
$data['acf'] = $fields;
|
92 |
}
|
97 |
} else {
|
98 |
foreach ( array_keys( $data['acf'] ) as $key ) {
|
99 |
$this->show_in_rest( $data['acf'], $key, $this->field_objects );
|
100 |
+
}
|
101 |
}
|
102 |
}
|
103 |
} else {
|
107 |
return apply_filters( 'acf/rest_api/' . $this->type . '/get_fields', $data, $request );
|
108 |
}
|
109 |
|
110 |
+
protected function get_fields_fallback() {
|
111 |
+
$fields = array();
|
112 |
+
|
113 |
+
if ( ! empty( $this->field_objects ) ) {
|
114 |
+
foreach ( $this->field_objects as $objects ) {
|
115 |
+
if( isset( $objects['name'] ) && ! empty( $objects['name'] ) ) {
|
116 |
+
$fields[ $objects['name'] ] = get_field( $objects['name'], $this->id );
|
117 |
+
}
|
118 |
+
}
|
119 |
+
}
|
120 |
+
|
121 |
+
return $fields;
|
122 |
+
}
|
123 |
+
|
124 |
public function get_field_objects( $id ) {
|
125 |
if ( empty( $id ) ) {
|
126 |
return false;
|
v3/lib/class-acf-to-rest-api-acf-field-settings.php
CHANGED
@@ -35,7 +35,7 @@ if ( ! class_exists( 'ACF_To_REST_API_ACF_Field_Settings' ) ) {
|
|
35 |
'name' => 'edit_in_rest',
|
36 |
'ui' => 1,
|
37 |
'class' => 'field-edit_in_rest',
|
38 |
-
'default_value' =>
|
39 |
), true );
|
40 |
} else { ?>
|
41 |
<tr>
|
@@ -45,7 +45,7 @@ if ( ! class_exists( 'ACF_To_REST_API_ACF_Field_Settings' ) ) {
|
|
45 |
<td>
|
46 |
<?php
|
47 |
if ( ! isset( $field['edit_in_rest'] ) ) {
|
48 |
-
$field['edit_in_rest'] =
|
49 |
}
|
50 |
do_action( 'acf/create_field', array(
|
51 |
'type' => 'radio',
|
@@ -72,7 +72,7 @@ if ( ! class_exists( 'ACF_To_REST_API_ACF_Field_Settings' ) ) {
|
|
72 |
'name' => 'show_in_rest',
|
73 |
'ui' => 1,
|
74 |
'class' => 'field-show_in_rest',
|
75 |
-
'default_value' =>
|
76 |
), true );
|
77 |
} else { ?>
|
78 |
<tr>
|
@@ -82,7 +82,7 @@ if ( ! class_exists( 'ACF_To_REST_API_ACF_Field_Settings' ) ) {
|
|
82 |
<td>
|
83 |
<?php
|
84 |
if ( ! isset( $field['show_in_rest'] ) ) {
|
85 |
-
$field['show_in_rest'] =
|
86 |
}
|
87 |
do_action( 'acf/create_field', array(
|
88 |
'type' => 'radio',
|
35 |
'name' => 'edit_in_rest',
|
36 |
'ui' => 1,
|
37 |
'class' => 'field-edit_in_rest',
|
38 |
+
'default_value' => 0,
|
39 |
), true );
|
40 |
} else { ?>
|
41 |
<tr>
|
45 |
<td>
|
46 |
<?php
|
47 |
if ( ! isset( $field['edit_in_rest'] ) ) {
|
48 |
+
$field['edit_in_rest'] = 0;
|
49 |
}
|
50 |
do_action( 'acf/create_field', array(
|
51 |
'type' => 'radio',
|
72 |
'name' => 'show_in_rest',
|
73 |
'ui' => 1,
|
74 |
'class' => 'field-show_in_rest',
|
75 |
+
'default_value' => 0,
|
76 |
), true );
|
77 |
} else { ?>
|
78 |
<tr>
|
82 |
<td>
|
83 |
<?php
|
84 |
if ( ! isset( $field['show_in_rest'] ) ) {
|
85 |
+
$field['show_in_rest'] = 0;
|
86 |
}
|
87 |
do_action( 'acf/create_field', array(
|
88 |
'type' => 'radio',
|
v3/lib/endpoints/class-acf-to-rest-api-controller.php
CHANGED
@@ -50,10 +50,7 @@ if ( ! class_exists( 'ACF_To_REST_API_Controller' ) ) {
|
|
50 |
|
51 |
public function register_field() {
|
52 |
register_rest_field( $this->type, 'acf', array(
|
53 |
-
'get_callback' =>
|
54 |
-
$fields = $this->acf->get_fields( $data );
|
55 |
-
return $fields['acf'];
|
56 |
-
},
|
57 |
'schema' => array(
|
58 |
'description' => __( 'Expose advanced custom fields.', 'acf-to-rest-api' ),
|
59 |
'type' => 'object',
|
@@ -61,6 +58,11 @@ if ( ! class_exists( 'ACF_To_REST_API_Controller' ) ) {
|
|
61 |
) );
|
62 |
}
|
63 |
|
|
|
|
|
|
|
|
|
|
|
64 |
public function register() {
|
65 |
$this->register_routes();
|
66 |
$this->register_hooks();
|
@@ -174,7 +176,7 @@ if ( ! class_exists( 'ACF_To_REST_API_Controller' ) ) {
|
|
174 |
if ( $request instanceof WP_REST_Request ) {
|
175 |
$params = $request->get_params();
|
176 |
foreach ( self::$default_params as $k => $v ) {
|
177 |
-
if ( !
|
178 |
$request->set_param( $k, $v );
|
179 |
}
|
180 |
}
|
50 |
|
51 |
public function register_field() {
|
52 |
register_rest_field( $this->type, 'acf', array(
|
53 |
+
'get_callback' => array( $this, 'register_field_callback' ),
|
|
|
|
|
|
|
54 |
'schema' => array(
|
55 |
'description' => __( 'Expose advanced custom fields.', 'acf-to-rest-api' ),
|
56 |
'type' => 'object',
|
58 |
) );
|
59 |
}
|
60 |
|
61 |
+
public function register_field_callback( $data ) {
|
62 |
+
$fields = $this->acf->get_fields( $data );
|
63 |
+
return $fields['acf'];
|
64 |
+
}
|
65 |
+
|
66 |
public function register() {
|
67 |
$this->register_routes();
|
68 |
$this->register_hooks();
|
176 |
if ( $request instanceof WP_REST_Request ) {
|
177 |
$params = $request->get_params();
|
178 |
foreach ( self::$default_params as $k => $v ) {
|
179 |
+
if ( ! isset( $params[ $k ] ) ) {
|
180 |
$request->set_param( $k, $v );
|
181 |
}
|
182 |
}
|
v3/lib/endpoints/class-acf-to-rest-api-posts-controller.php
CHANGED
@@ -4,7 +4,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|
4 |
exit;
|
5 |
}
|
6 |
|
7 |
-
if ( ! class_exists( '
|
8 |
class ACF_To_REST_API_Posts_Controller extends ACF_To_REST_API_Controller {
|
9 |
public function __construct( $type ) {
|
10 |
$this->type = $type->name;
|
4 |
exit;
|
5 |
}
|
6 |
|
7 |
+
if ( ! class_exists( 'ACF_To_REST_API_Posts_Controller' ) ) {
|
8 |
class ACF_To_REST_API_Posts_Controller extends ACF_To_REST_API_Controller {
|
9 |
public function __construct( $type ) {
|
10 |
$this->type = $type->name;
|