All Projects → airesvsg → Acf To Rest Api

airesvsg / Acf To Rest Api

Exposes Advanced Custom Fields Endpoints in the WordPress REST API

Projects that are alternatives of or similar to Acf To Rest Api

Pop
Monorepo of the PoP project, including: a server-side component model in PHP, a GraphQL server, a GraphQL API plugin for WordPress, and a website builder
Stars: ✭ 160 (-86.11%)
Mutual labels:  api, rest-api, wordpress, wordpress-plugin
Co Cart
🛒 CoCart is a flexible, open-source solution to enabling the shopping cart via the REST API for WooCommerce.
Stars: ✭ 198 (-82.81%)
Mutual labels:  api, rest-api, wordpress, wordpress-plugin
Wp Rest Api Cache
Enable caching for WordPress REST API and increase speed of your application
Stars: ✭ 239 (-79.25%)
Mutual labels:  api, rest-api, rest, wordpress
Rest Hapi
🚀 A RESTful API generator for Node.js
Stars: ✭ 1,102 (-4.34%)
Mutual labels:  api, rest-api, rest
Cookiecutter Django Rest
Build best practiced apis fast with Python3
Stars: ✭ 1,108 (-3.82%)
Mutual labels:  api, rest-api, rest
Rest Api Nodejs Mongodb
A boilerplate for REST API Development with Node.js, Express, and MongoDB
Stars: ✭ 672 (-41.67%)
Mutual labels:  api, rest-api, rest
Javacord
An easy to use multithreaded library for creating Discord bots in Java.
Stars: ✭ 368 (-68.06%)
Mutual labels:  api, rest-api, rest
Axios Rest
A simple axios wrapper to make rest api call delightful
Stars: ✭ 41 (-96.44%)
Mutual labels:  api, rest-api, rest
Ngx Restangular
Restangular for Angular 2 and higher versions
Stars: ✭ 787 (-31.68%)
Mutual labels:  api, rest-api, rest
Wp Rest Api Log
WordPress plugin for logging REST API requests and responses
Stars: ✭ 58 (-94.97%)
Mutual labels:  rest-api, wordpress, wordpress-plugin
Json Api Dart
JSON:API client for Dart/Flutter
Stars: ✭ 53 (-95.4%)
Mutual labels:  api, rest-api, rest
Spyke
Interact with REST services in an ActiveRecord-like manner
Stars: ✭ 591 (-48.7%)
Mutual labels:  api, rest-api, rest
Networking
⚡️ Elegantly connect to a REST JSON Api. URLSession + Combine + Decodable + Generics = <3
Stars: ✭ 499 (-56.68%)
Mutual labels:  api, rest-api, rest
Apidoc
RESTful API 文档生成工具,支持 Go、Java、Swift、JavaScript、Rust、PHP、Python、Typescript、Kotlin 和 Ruby 等大部分语言。
Stars: ✭ 785 (-31.86%)
Mutual labels:  api, rest-api, rest
Awesome Wp Developer Tools
A collection of plugins, starter themes and tools to make WordPress development easier.
Stars: ✭ 388 (-66.32%)
Mutual labels:  rest-api, wordpress, wordpress-plugin
Discord4j
Discord4J is a fast, powerful, unopinionated, reactive library to enable quick and easy development of Discord bots for Java, Kotlin, and other JVM languages using the official Discord Bot API.
Stars: ✭ 973 (-15.54%)
Mutual labels:  api, rest-api, rest
Rest Control
Framework for testing and validation REST services
Stars: ✭ 51 (-95.57%)
Mutual labels:  api, rest-api, rest
Githubapi
Swift implementation of Github REST API v3
Stars: ✭ 55 (-95.23%)
Mutual labels:  api, rest-api, rest
Better Rest Endpoints
A WordPress plugin that serves up slimmer WP Rest API endpoints.
Stars: ✭ 56 (-95.14%)
Mutual labels:  api, wordpress, wordpress-plugin
Kanary
A minimalist web framework for building REST APIs in Kotlin/Java.
Stars: ✭ 319 (-72.31%)
Mutual labels:  api, rest-api, rest

ACF to REST API

Exposes Advanced Custom Fields Endpoints in the WordPress REST API

https://wordpress.org/plugins/acf-to-rest-api/

Installation

  1. Copy the acf-to-rest-api folder into your wp-content/plugins folder
  2. Activate the ACF to REST API plugin via the plugin admin page

Endpoints

Endpoint READABLE EDITABLE
/wp-json/acf/v3/posts new yes no
/wp-json/acf/v3/posts/{id} yes yes
/wp-json/acf/v3/posts/{id}/{field-name} yes yes
/wp-json/acf/v3/pages new yes no
/wp-json/acf/v3/pages/{id} yes yes
/wp-json/acf/v3/pages/{id}/{field-name} yes yes
/wp-json/acf/v3/users new yes no
/wp-json/acf/v3/users/{id} yes yes
/wp-json/acf/v3/users/{id}/{field-name} yes yes
/wp-json/acf/v3/{taxonomy} new yes no
/wp-json/acf/v3/{taxonomy}/{id} new yes yes
/wp-json/acf/v3/{taxonomy}/{id}/{field-name} new yes yes
/wp-json/acf/v3/comments new yes no
/wp-json/acf/v3/comments/{id} yes yes
/wp-json/acf/v3/comments/{id}/{field-name} yes yes
/wp-json/acf/v3/media new yes no
/wp-json/acf/v3/media/{id} yes yes
/wp-json/acf/v3/media/{id}/{field-name} yes yes
/wp-json/acf/v3/{post-type} new yes no
/wp-json/acf/v3/{post-type}/{id} new yes yes
/wp-json/acf/v3/{post-type}/{id}/{field-name} new yes yes
/wp-json/acf/v3/options/{id} new yes yes
/wp-json/acf/v3/options/{id}/{field-name} new yes yes

Filters

Filter Argument(s)
acf/rest_api/id mixed ( string, integer, boolean ) $id
string $type new
string $controller new
acf/rest_api/key string $key
WP_REST_Request $request
string $type
acf/rest_api/item_permissions/get boolean $permission
WP_REST_Request $request
string $type
acf/rest_api/item_permissions/update boolean $permission
WP_REST_Request $request
string $type
acf/rest_api/{type}/prepare_item mixed ( array, boolean ) $item
WP_REST_Request $request
acf/rest_api/{type}/get_fields mixed ( array, WP_REST_Request ) $data
mixed ( WP_REST_Request, NULL ) $request
acf/rest_api/field_settings/show_in_rest new boolean $show
acf/rest_api/field_settings/edit_in_rest new boolean $edit

Basic example of how to use the filters, in this case I will set a new permission to get the fields

add_filter( 'acf/rest_api/item_permissions/get', function( $permission ) {
  return current_user_can( 'edit_posts' );
} );

Deprecated filters

Filter Argument(s)
acf/rest_api/type string $type
acf/rest_api/types array $types
acf/rest_api/default_rest_base boolean $default
string $type

Request API version

See below how to select the Request API Version.

  1. Open the plugins page;
  2. Click the settings link under the pluing name ( ACF to REST API );
  3. Select your version in the ACF to REST API session;
  4. Click in the button Save changes.

Choose request API version

The other alternative is to define the constant ACF_TO_REST_API_REQUEST_VERSION in your wp-config.php

define( 'ACF_TO_REST_API_REQUEST_VERSION', 2 );

Field Settings

In this version is possible to configure the field options via admin.

The options are enabled using the filters below, by default theses options are disabled.

// Enable the option show in rest
add_filter( 'acf/rest_api/field_settings/show_in_rest', '__return_true' );

// Enable the option edit in rest
add_filter( 'acf/rest_api/field_settings/edit_in_rest', '__return_true' );

After you activate the filters, all your fields should show these options: Choose request API version

Editing the fields

The fields should be sent into the key fields.

Field Name

Action: http://localhost/wp-json/acf/v3/posts/1

<form action="http://localhost/wp-json/acf/v3/posts/1" method="POST">
  <?php 
    // https://developer.wordpress.org/rest-api/using-the-rest-api/authentication/
    wp_nonce_field( 'wp_rest' ); 
  ?>
  <label>Site: <input type="text" name="fields[site]"></label>
  <button type="submit">Save</button>
</form>

Action: http://localhost/wp-json/wp/v2/posts/1

<form action="http://localhost/wp-json/wp/v2/posts/1" method="POST">
  <?php 
    // https://developer.wordpress.org/rest-api/using-the-rest-api/authentication/
    wp_nonce_field( 'wp_rest' ); 
  ?>
  <label>Title: <input type="text" name="title"></label>
  <h3>ACF</h3>
  <label>Site: <input type="text" name="fields[site]"></label>
  <button type="submit">Save</button>
</form>

Use the filter acf/rest_api/key to change the key fields.

add_filter( 'acf/rest_api/key', function( $key, $request, $type ) {
  return 'acf_fields';
}, 10, 3 );

Now, the fields should be sent into the key acf_fields

<form action="http://localhost/wp-json/acf/v3/posts/1" method="POST">
  <?php 
    // https://developer.wordpress.org/rest-api/using-the-rest-api/authentication/
    wp_nonce_field( 'wp_rest' ); 
  ?>
  <label>Site: <input type="text" name="acf_fields[site]"></label>
  <button type="submit">Save</button>
</form>

Examples

Sample theme to edit the ACF Fields.

https://github.com/airesvsg/acf-to-rest-api-example

To-do list new

https://github.com/airesvsg/to-do-list-acf-to-rest-api

Get ACF Fields Recursivelynew

https://github.com/airesvsg/acf-to-rest-api-recursive

More details:

Cache

Enable caching for WordPress REST API and increase speed of your application.

https://github.com/airesvsg/wp-rest-api-cache

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].