ACF_To_REST_API_Controller::get_fields PHP Метод

get_fields() защищенный Метод

protected get_fields ( $request, $response = null, $object = null )
        protected function get_fields($request, $response = null, $object = null)
        {
            $data = array();
            $field = null;
            $swap = $response instanceof WP_REST_Response;
            if ($request instanceof WP_REST_Request) {
                $field = $request->get_param('field');
            }
            if ($swap) {
                $data = $response->get_data();
            }
            if (empty($object)) {
                if (!empty($request)) {
                    $object = $request;
                } elseif (!empty($data)) {
                    $object = $response;
                }
            }
            $this->format_id($object);
            if ($this->id) {
                if ($field) {
                    $data = array($field => get_field($field, $this->id));
                } else {
                    $data['acf'] = get_fields($this->id);
                }
            } else {
                $data['acf'] = array();
            }
            if ($swap) {
                $response->data = $data;
                $data = $response;
            }
            return apply_filters('acf/rest_api/' . $this->type . '/get_fields', $data, $request, $response, $object);
        }

Usage Example

 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);
 }