public function register_hooks() { if ($this->type) { add_filter('rest_prepare_' . $this->type, array($this, 'rest_prepare'), 10, 3); add_action('rest_insert_' . $this->type, array($this, 'rest_insert'), 10, 3); } }
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(); } } }