Skip to content

Commit

Permalink
3.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
airesvsg committed Oct 18, 2017
1 parent 2c61fa0 commit 6f7bff0
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 32 deletions.
4 changes: 2 additions & 2 deletions class-acf-to-rest-api.php
Expand Up @@ -4,7 +4,7 @@
* Description: Exposes Advanced Custom Fields Endpoints in the WordPress REST API
* Author: Aires Gonçalves
* Author URI: http://github.com/airesvsg
* Version: 3.0.2
* Version: 3.1.0
* Plugin URI: http://github.com/airesvsg/acf-to-rest-api
*/

Expand All @@ -16,7 +16,7 @@

class ACF_To_REST_API {

const VERSION = '3.0.2';
const VERSION = '3.1.0';

private static $old_request_version = 2;
private static $default_request_version = 3;
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -2,7 +2,7 @@
"name": "airesvsg/acf-to-rest-api",
"description": "Exposes Advanced Custom Fields Endpoints in the WordPress REST API",
"type": "wordpress-plugin",
"version": "3.0.2",
"version": "3.1.0",
"keywords": ["wordpress", "wp", "rest-api", "acf", "wp-api", "json", "wordpres-plugin", "fields"],
"homepage": "https://github.com/airesvsg/acf-to-rest-api",
"license": "GPLv2.0+",
Expand Down
7 changes: 6 additions & 1 deletion readme.txt
Expand Up @@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=aires
Tags: acf, api, rest, wp-api, wp-rest-api, json, wp, wordpress, wp-rest-api, wordpress-rest-api
Requires at least: 4.6
Tested up to: 4.8.2
Stable tag: 3.0.2
Stable tag: 3.1.0
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand All @@ -21,6 +21,11 @@ Exposes [Advanced Custom Fields](https://wordpress.org/plugins/advanced-custom-f

== Changelog ==

= 3.1.0 =
fix indentation
removing unnecessary code
removing anonymous function

= 3.0.2 =
stable version

Expand Down
48 changes: 24 additions & 24 deletions v3/lib/class-acf-to-rest-api-acf-api.php
Expand Up @@ -6,17 +6,17 @@

if ( ! class_exists( 'ACF_To_REST_API_ACF_API' ) ) {
class ACF_To_REST_API_ACF_API {
protected $id = null;
protected $type = null;
protected $controller = null;
protected $id = null;
protected $type = null;
protected $controller = null;
protected $field_objects = null;

public function __construct( $type, $controller = null ) {
$this->type = $type;
$this->controller = $controller;
}

protected function format_id( $object ) {
protected function format_id() {
if ( $this->id ) {
switch ( $this->type ) {
case 'comment' :
Expand All @@ -38,27 +38,27 @@ protected function format_id( $object ) {
return $this->id;
}

public function get_id( $obj ) {
public function get_id( $object ) {
$this->id = false;

if ( is_numeric( $obj ) ) {
$this->id = $obj;
} elseif ( is_array( $obj ) && isset( $obj['id'] ) ) {
$this->id = $obj['id'];
} elseif ( is_object( $obj ) ) {
if ( $obj instanceof WP_REST_Response ) {
$data = $obj->get_data();
if ( is_numeric( $object ) ) {
$this->id = $object;
} elseif ( is_array( $object ) && isset( $object['id'] ) ) {
$this->id = $object['id'];
} elseif ( is_object( $object ) ) {
if ( $object instanceof WP_REST_Response ) {
$data = $object->get_data();
if ( isset( $data['id'] ) ) {
$this->id = $data['id'];
}
} elseif ( $obj instanceof WP_REST_Request ) {
$this->id = $obj->get_param( 'id' );
} elseif ( isset( $obj->ID ) ) {
$this->id = $obj->ID;
} elseif ( isset( $obj->comment_ID ) ) {
$this->id = $obj->comment_ID;
} elseif ( isset( $obj->term_id ) ) {
$this->id = $obj->term_id;
} elseif ( $object instanceof WP_REST_Request ) {
$this->id = $object->get_param( 'id' );
} elseif ( isset( $object->ID ) ) {
$this->id = $object->ID;
} elseif ( isset( $object->comment_ID ) ) {
$this->id = $object->comment_ID;
} elseif ( isset( $object->term_id ) ) {
$this->id = $object->term_id;
}
}

Expand All @@ -68,7 +68,7 @@ public function get_id( $obj ) {
$this->id = absint( $this->id );
}

return $this->format_id( $this->id );
return $this->format_id();
}

public function get_fields( $request ) {
Expand Down Expand Up @@ -111,9 +111,9 @@ protected function get_fields_fallback() {
$fields = array();

if ( ! empty( $this->field_objects ) ) {
foreach ( $this->field_objects as $obj ) {
if( isset( $obj['name'] ) && ! empty( $obj['name'] ) ) {
$fields[ $obj['name'] ] = get_field( $obj['name'], $this->id );
foreach ( $this->field_objects as $objects ) {
if( isset( $objects['name'] ) && ! empty( $objects['name'] ) ) {
$fields[ $objects['name'] ] = get_field( $objects['name'], $this->id );
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions v3/lib/endpoints/class-acf-to-rest-api-controller.php
Expand Up @@ -50,17 +50,19 @@ public function register_routes() {

public function register_field() {
register_rest_field( $this->type, 'acf', array(
'get_callback' => function( $data ) {
$fields = $this->acf->get_fields( $data );
return $fields['acf'];
},
'get_callback' => array( $this, 'register_field_callback' ),
'schema' => array(
'description' => __( 'Expose advanced custom fields.', 'acf-to-rest-api' ),
'type' => 'object',
),
) );
}

public function register_field_callback( $data ) {
$fields = $this->acf->get_fields( $data );
return $fields['acf'];
}

public function register() {
$this->register_routes();
$this->register_hooks();
Expand Down

0 comments on commit 6f7bff0

Please sign in to comment.