Plugin Directory

Changeset 1752896


Ignore:
Timestamp:
10/26/2017 03:55:50 AM (8 years ago)
Author:
airesvsg
Message:

3.1.0

Location:
acf-to-rest-api
Files:
227 added
2 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • acf-to-rest-api/trunk/class-acf-to-rest-api.php

    r1461787 r1752896  
    22/**
    33 * Plugin Name: ACF to REST API
    4  * Description: Exposes Advanced Custom Fields Endpoints in the WP REST API v2
     4 * Description: Exposes Advanced Custom Fields Endpoints in the WordPress REST API
    55 * Author: Aires Gonçalves
    66 * Author URI: http://github.com/airesvsg
    7  * Version: 2.2.1
     7 * Version: 3.1.0
    88 * Plugin URI: http://github.com/airesvsg/acf-to-rest-api
    99 */
     
    1717    class ACF_To_REST_API {
    1818
    19         const VERSION = '2.2.1';
     19        const VERSION = '3.1.0';
     20
     21        private static $old_request_version     = 2;
     22        private static $default_request_version = 3;
     23        private static $request_version;
     24
     25        private static $instance = null;
    2026
    2127        public static function init() {
     
    2430        }
    2531
     32        protected static function instance() {
     33            if ( is_null( self::$instance ) ) {
     34                $class = 'ACF_To_REST_API_V' . self::handle_request_version();
     35                if ( class_exists( $class ) ) {
     36                    self::$instance = new $class;
     37                }
     38            }
     39            return self::$instance;
     40        }
     41
    2642        private static function includes() {
     43            if ( self::$old_request_version == self::handle_request_version() ) {
     44                require_once dirname( __FILE__ ) . '/legacy/v2/class-acf-to-rest-api-v2.php';
     45            } else {
     46                require_once dirname( __FILE__ ) . '/v3/class-acf-to-rest-api-v3.php';
     47            }
     48
    2749            if ( self::is_plugin_active( 'all' ) ) {
    28                 require_once dirname( __FILE__ ) . '/lib/endpoints/class-acf-to-rest-api-controller.php';
    29                 require_once dirname( __FILE__ ) . '/lib/endpoints/class-acf-to-rest-api-option-controller.php';
    30                 require_once dirname( __FILE__ ) . '/lib/endpoints/class-acf-to-rest-api-term-controller.php';
    31                 require_once dirname( __FILE__ ) . '/lib/endpoints/class-acf-to-rest-api-attachment-controller.php';
     50                if ( is_admin() ) {
     51                    require_once dirname( __FILE__ ) . '/shared/lib/class-acf-to-rest-api-settings.php';
     52                }
     53                self::instance()->includes();
    3254            }
     55        }
     56
     57        public static function handle_request_version() {
     58            if ( is_null( self::$request_version ) ) {
     59                if ( defined( 'ACF_TO_REST_API_REQUEST_VERSION' ) ) {
     60                    self::$request_version = (int) ACF_TO_REST_API_REQUEST_VERSION;
     61                } else {
     62                    self::$request_version = (int) get_option( 'acf_to_rest_api_request_version', self::$default_request_version );
     63                }
     64            }
     65            return self::$request_version;
    3366        }
    3467
    3568        private static function hooks() {
    3669            add_action( 'init', array( __CLASS__, 'load_plugin_textdomain' ) );
     70
    3771            if ( self::is_plugin_active( 'all' ) ) {
    3872                add_action( 'rest_api_init', array( __CLASS__, 'create_rest_routes' ), 10 );
     73                if ( self::$default_request_version == self::handle_request_version() ) {
     74                    ACF_To_REST_API_ACF_Field_Settings::hooks();
     75                }
    3976            } else {
    4077                add_action( 'admin_notices', array( __CLASS__, 'missing_notice' ) );
    4178            }
     79
    4280        }
    4381
     
    4886
    4987        public static function create_rest_routes() {
    50             $default = array( 'user', 'comment', 'term', 'option' );
    51             $types   = get_post_types( array( 'show_in_rest' => true ) );
    52            
    53             if ( $types && isset( $types['attachment'] ) ) {
    54                 unset( $types['attachment'] );
    55                 $default[] = 'media';
    56             }
    57 
    58             $types = apply_filters( 'acf/rest_api/types', array_merge( $types, array_combine( $default, $default ) ) );
    59            
    60             if ( is_array( $types ) && count( $types ) > 0 ) {
    61                 foreach( $types as $type ) {
    62                     if ( 'term' == $type ) {
    63                         $controller = new ACF_To_REST_API_Term_Controller( $type );                     
    64                     } elseif ( 'media' == $type ) {
    65                         $controller = new ACF_To_REST_API_Attachment_Controller( $type );
    66                     } elseif ( 'option' == $type ) {
    67                         $controller = new ACF_To_REST_API_Option_Controller( $type );
    68                     } else {
    69                         $controller = new ACF_To_REST_API_Controller( $type );
    70                     }
    71 
    72                     $controller->register_routes();
    73                     $controller->register_hooks(); 
    74                 }
    75             }
     88            self::instance()->create_rest_routes();
    7689        }
    7790
     
    90103        public static function is_plugin_installed( $plugin ) {
    91104            if ( ! function_exists( 'get_plugins' ) ) {
    92                 include_once( ABSPATH . 'wp-admin/includes/plugin.php' );   
     105                include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
    93106            }
    94107
     
    104117                if ( is_array( $plugins ) && count( $plugins ) > 0 ) {
    105118                    foreach ( $paths as $path ) {
    106                         if ( isset( $plugins[$path] ) && ! empty( $plugins[$path] ) ) {
     119                        if ( isset( $plugins[ $path ] ) && ! empty( $plugins[ $path ] ) ) {
    107120                            return $path;
    108121                        }
    109                     }                   
     122                    }
    110123                }
    111124            }
     
    115128
    116129        public static function missing_notice() {
    117             if ( ! self::is_plugin_active( 'rest-api' ) ) {
    118                 include dirname( __FILE__ ) . '/includes/admin/views/html-notice-missing-rest-api.php';
    119             }
    120 
    121             if ( ! self::is_plugin_active( 'acf' ) ) {
    122                 include dirname( __FILE__ ) . '/includes/admin/views/html-notice-missing-acf.php';             
    123             }
     130            self::instance()->missing_notice();
    124131        }
    125132    }
  • acf-to-rest-api/trunk/readme.md

    r1461787 r1752896  
    11ACF to REST API
    22====
    3 Exposes [Advanced Custom Fields](https://wordpress.org/plugins/advanced-custom-fields/) Endpoints in the [WP REST API v2](https://wordpress.org/plugins/rest-api/)
     3Exposes [Advanced Custom Fields](https://wordpress.org/plugins/advanced-custom-fields/) Endpoints in the [WordPress REST API](https://developer.wordpress.org/rest-api/)
    44
    55https://wordpress.org/plugins/acf-to-rest-api/
     
    88- [Endpoints](#endpoints)
    99- [Filters](#filters)
    10 - [Editing the fields](#editing-the-fields)
    11 - [Example](#example)
     10- [Deprecated Filters ![new](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/new-v3.1.png)](#deprecated-filters)
     11- [Request API Version ![new](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/new-v3.1.png)](#request-api-version)
     12- [Field Settings ![new](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/new-v3.1.png)](#field-settings)
     13- [Editing the Fields](#editing-the-fields)
     14- [Examples](#examples)
    1215- [Cache](#cache)
    1316
     
    2225| Endpoint | READABLE | EDITABLE |
    2326|----------|:--------:|:--------:|
    24 | /wp-json/acf/v2/post/**{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) |
    25 | /wp-json/acf/v2/post/**{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) |
    26 | /wp-json/acf/v2/page/**{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) |
    27 | /wp-json/acf/v2/page/**{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) |
    28 | /wp-json/acf/v2/user/**{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) |
    29 | /wp-json/acf/v2/user/**{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) |
    30 | /wp-json/acf/v2/term/**{taxonomy}**/**{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) |
    31 | /wp-json/acf/v2/term/**{taxonomy}**/**{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) |
    32 | /wp-json/acf/v2/comment/**{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) |
    33 | /wp-json/acf/v2/comment/**{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) |
    34 | /wp-json/acf/v2/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) |
    35 | /wp-json/acf/v2/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) |
    36 | /wp-json/acf/v2/**{post-type}**/**{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) |
    37 | /wp-json/acf/v2/**{post-type}**/**{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) |
    38 | /wp-json/acf/v2/options | ![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/v2/options/**{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) |
     27| /wp-json/acf/v3/posts ![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) |
     28| /wp-json/acf/v3/posts/**{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) |
     29| /wp-json/acf/v3/posts/**{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) |
     30| /wp-json/acf/v3/pages ![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) |
     31| /wp-json/acf/v3/pages/**{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) |
     32| /wp-json/acf/v3/pages/**{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) |
     33| /wp-json/acf/v3/users ![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) |
     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) |
     46| /wp-json/acf/v3/**{post-type}**/**{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) |
     47| /wp-json/acf/v3/**{post-type}**/**{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) |
     48| /wp-json/acf/v3/options/**{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) |
     49| /wp-json/acf/v3/options/**{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) |
    4050
    4151Filters
     
    4353| Filter    | Argument(s) |
    4454|-----------|-----------|
    45 | acf/rest_api/types | array **$types** |
    46 | acf/rest_api/type | string **$type** |
    47 | acf/rest_api/id | mixed ( string, integer, boolean ) **$id** |
     55| acf/rest_api/id | mixed ( string, integer, boolean ) **$id**<br>string **$type** ![new](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/new-v3.1.png)<br>string **$controller** ![new](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/new-v3.1.png) |
    4856| acf/rest_api/key | string **$key**<br>WP_REST_Request **$request**<br>string **$type** |
    4957| acf/rest_api/item_permissions/get | boolean **$permission**<br>WP_REST_Request **$request**<br>string **$type** |
    5058| acf/rest_api/item_permissions/update | boolean **$permission**<br>WP_REST_Request **$request**<br>string **$type** |
     59| acf/rest_api/**{type}**/prepare_item | mixed ( array, boolean ) **$item**<br>WP_REST_Request **$request** |
     60| acf/rest_api/**{type}**/get_fields | mixed ( array, WP_REST_Request ) **$data**<br>mixed ( WP_REST_Request, NULL ) **$request** |
     61| acf/rest_api/field_settings/show_in_rest ![new](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/new-v3.1.png) | boolean **$show** |
     62| acf/rest_api/field_settings/edit_in_rest ![new](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/new-v3.1.png) | boolean **$edit** |
     63
     64Basic example of how to use the filters, in this case I will set a new permission to get the fields
     65```PHP
     66add_filter( 'acf/rest_api/item_permissions/get', function( $permission ) {
     67  return current_user_can( 'edit_posts' );
     68} );
     69```
     70
     71Deprecated filters
     72====
     73| Filter    | Argument(s) |
     74|-----------|-----------|
     75| acf/rest_api/type | string **$type** |
     76| acf/rest_api/types | array **$types** |
    5177| acf/rest_api/default_rest_base | boolean **$default**<br>string **$type** |
    52 | acf/rest_api/**{type}**/prepare_item | mixed ( array, boolean ) **$item**<br>WP_REST_Request **$request** |
    53 | acf/rest_api/**{type}**/get_fields | mixed ( array, WP_REST_Request ) **$data**<br>mixed ( WP_REST_Request, NULL ) **$request**<br>mixed ( WP_REST_Response, NULL ) **$response**<br>mixed ( WP_Post, WP_Term, WP_User, NULL ) **$object** |
    5478
    55 If you do not want edit/show the fields of posts. So, you must use the filter `acf/rest_api/types`
     79Request API version
     80====
     81See below how to select the Request API Version.
     82
     831. Open the plugins page;
     842. Click the settings link under the pluing name ( `ACF to REST API` );
     853. Select your version in the `ACF to REST API` session;
     864. Click in the button Save changes.
     87
     88![Choose request API version](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/request-api-version-v3.jpg)
     89
     90The other alternative is to define the constant `ACF_TO_REST_API_REQUEST_VERSION` in your `wp-config.php`
    5691
    5792```PHP
    58 add_filter( 'acf/rest_api/types', function( $types ) {
    59     if ( array_key_exists( 'post', $types ) ) {
    60         unset( $types['post'] );
    61     }
     93define( 'ACF_TO_REST_API_REQUEST_VERSION', 2 );
     94```
    6295
    63     return $types;
    64 } );
     96Field Settings
     97====
     98In this version is possible to configure the field options via admin.
     99
     100The options are enabled using the filters below, by default theses options are disabled.
     101
     102```PHP
     103// Enable the option show in rest
     104add_filter( 'acf/rest_api/field_settings/show_in_rest', '__return_true' );
     105
     106// Enable the option edit in rest
     107add_filter( 'acf/rest_api/field_settings/edit_in_rest', '__return_true' );
    65108```
     109
     110After you activate the filters, all your fields should show these options:
     111![Choose request API version](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/field-settings-v3.jpg)
     112
    66113
    67114Editing the fields
     
    69116The fields should be sent into the key `fields`.
    70117
    71 ![Field Name](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/field-name.jpg)
     118![Field Name](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/field-name-v3.jpg)
    72119
    73 **Action:** http://localhost/wp-json/acf/v2/post/1
     120**Action:** http://localhost/wp-json/acf/v3/posts/1
    74121
    75122```HTML
    76 <form action="http://localhost/wp-json/acf/v2/post/1" method="POST">
    77     <?php
    78         // http://v2.wp-api.org/guide/authentication
    79         wp_nonce_field( 'wp_rest' );
    80     ?>
    81     <label>Site: <input type="text" name="fields[site]"></label>
    82     <button type="submit">Save</button>
     123<form action="http://localhost/wp-json/acf/v3/posts/1" method="POST">
     124  <?php
     125    // https://developer.wordpress.org/rest-api/using-the-rest-api/authentication/
     126    wp_nonce_field( 'wp_rest' );
     127  ?>
     128  <label>Site: <input type="text" name="fields[site]"></label>
     129  <button type="submit">Save</button>
    83130</form>
    84131```
     
    88135```HTML
    89136<form action="http://localhost/wp-json/wp/v2/posts/1" method="POST">
    90     <?php
    91         // http://v2.wp-api.org/guide/authentication
    92         wp_nonce_field( 'wp_rest' );
    93     ?>
    94     <label>Title: <input type="text" name="title"></label>
    95     <h3>ACF</h3>
    96     <label>Site: <input type="text" name="fields[site]"></label>
    97     <button type="submit">Save</button>
     137  <?php
     138    // https://developer.wordpress.org/rest-api/using-the-rest-api/authentication/
     139    wp_nonce_field( 'wp_rest' );
     140  ?>
     141  <label>Title: <input type="text" name="title"></label>
     142  <h3>ACF</h3>
     143  <label>Site: <input type="text" name="fields[site]"></label>
     144  <button type="submit">Save</button>
    98145</form>
    99146```
     
    103150```PHP
    104151add_filter( 'acf/rest_api/key', function( $key, $request, $type ) {
    105     return 'acf_fields';
     152  return 'acf_fields';
    106153}, 10, 3 );
    107154```
     
    110157
    111158```HTML
    112 <form action="http://localhost/wp-json/acf/v2/post/1" method="POST">
    113     <?php
    114         // http://v2.wp-api.org/guide/authentication
    115         wp_nonce_field( 'wp_rest' );
    116     ?>
    117     <label>Site: <input type="text" name="acf_fields[site]"></label>
    118     <button type="submit">Save</button>
     159<form action="http://localhost/wp-json/acf/v3/posts/1" method="POST">
     160  <?php
     161    // https://developer.wordpress.org/rest-api/using-the-rest-api/authentication/
     162    wp_nonce_field( 'wp_rest' );
     163  ?>
     164  <label>Site: <input type="text" name="acf_fields[site]"></label>
     165  <button type="submit">Save</button>
    119166</form>
    120167```
    121168
    122 Example
     169Examples
    123170====
    124171Sample theme to edit the ACF Fields.
    125172
    126173https://github.com/airesvsg/acf-to-rest-api-example
     174
     175To-do list ![new](http://airesgoncalves.com.br/screenshot/acf-to-rest-api/readme/new-v3.1.png)
     176
     177https://github.com/airesvsg/to-do-list-acf-to-rest-api
    127178
    128179Cache
  • acf-to-rest-api/trunk/readme.txt

    r1548410 r1752896  
    22Contributors: airesvsg
    33Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=airesvsg%40gmail%2ecom&lc=BR&item_name=Aires%20Goncalves&no_note=0&currency_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
    5 Requires at least: 4.3
    6 Tested up to: 4.7
    7 Stable tag: 2.2.1
     4Tags: acf, api, rest, wp-api, wp-rest-api, json, wp, wordpress, wp-rest-api, wordpress-rest-api
     5Requires at least: 4.6
     6Tested up to: 4.8.2
     7Stable tag: 3.1.0
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
    1010
    11 Exposes Advanced Custom Fields Endpoints in the WP REST API v2
     11Exposes Advanced Custom Fields Endpoints in the WordPress REST API
    1212
    1313== Description ==
    14 Exposes [Advanced Custom Fields](https://wordpress.org/plugins/advanced-custom-fields/) Endpoints in the [WP REST API v2](https://wordpress.org/plugins/rest-api/)
     14Exposes [Advanced Custom Fields](https://wordpress.org/plugins/advanced-custom-fields/) Endpoints in the [WordPress REST API](https://developer.wordpress.org/rest-api/)
    1515
    1616**See details on GitHub:** http://github.com/airesvsg/acf-to-rest-api
     
    2121
    2222== Changelog ==
     23
     24= 3.1.0 =
     25fix indentation
     26removing unnecessary code
     27removing anonymous function
     28
     29= 3.0.2 =
     30stable version
     31
     32= 3.0.2-beta =
     33adding fallback to get_fields
     34changing default value to acf field setting
     35
     36= 3.0.1-beta =
     37fix default params bug
     38
     39= 3.0.0-beta =
     40more readable endpoints ( https://github.com/airesvsg/acf-to-rest-api/issues/46 ) - Thanks to Imaginet
     41change return when acf filed key is empty ( https://github.com/airesvsg/acf-to-rest-api/issues/48 ) - Thanks to Joris Verbogt
     42multiple custom options pages ( https://github.com/airesvsg/acf-to-rest-api/issues/85 ) - Thanks to Alex Patton
     43bugfix ACF key in taxonomy ( https://github.com/airesvsg/acf-to-rest-api/issues/43 ) - Thanks to Cesar Denis
     44depreacted filter acf/rest_api/type
     45depreacted filter acf/rest_api/types
     46depreacted filter acf/rest_api/default_rest_base
    2347
    2448= 2.2.1 =
Note: See TracChangeset for help on using the changeset viewer.