public static function create_rest_routes() { $default = array('user', 'comment', 'term', 'option'); $types = get_post_types(array('show_in_rest' => true)); if ($types && isset($types['attachment'])) { unset($types['attachment']); $default[] = 'media'; } $types = apply_filters('acf/rest_api/types', array_merge($types, array_combine($default, $default))); if (is_array($types) && count($types) > 0) { foreach ($types as $type) { if ('term' == $type) { $controller = new ACF_To_REST_API_Term_Controller($type); } elseif ('media' == $type) { $controller = new ACF_To_REST_API_Attachment_Controller($type); } elseif ('option' == $type) { $controller = new ACF_To_REST_API_Option_Controller($type); } else { $controller = new ACF_To_REST_API_Controller($type); } $controller->register_routes(); $controller->register_hooks(); } } }
public function get_item($request) { if (self::show($request)) { return parent::get_item($request); } return new WP_Error('rest_no_route', __('No route was found matching the URL and request method', 'acf-to-rest-api'), array('status' => 404)); }
public function get_fields($request, $response = null, $object = null) { if ($request instanceof WP_REST_Request) { $name = $request->get_param('name'); if ($name) { $value = get_field($name, $this->type); $data = array($name => $value); return apply_filters("acf/rest_api/{$this->type}/get_fields", $data, $request, $response, $object); } } return parent::get_fields($request, $response, $object); }
public function __construct($type) { parent::__construct($type); $this->rest_base = 'options'; }
public function register_hooks() { $this->type = 'attachment'; parent::register_hooks(); }