# bit-form/1.2/includes/API/Route/Routes.php

Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator &amp; Custom Form Builder, version 1.2. 160 lines.

- Page: https://pluginprobe.com/plugins/bit-form/1.2/code/includes/API/Route/Routes.php
- Raw: https://pluginprobe.com/plugins/bit-form/1.2/raw/includes/API/Route/Routes.php
- Modified: 2021-02-06T08:25:28+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/bit-form/1.2/code/includes/API/Route/Routes.php#L10-L20`.

```php
<?php

namespace BitCode\BitForm\API\Route;

use WP_REST_Controller;
use WP_REST_Server;
use BitCode\BitForm\API\Controller\EntryController;
use BitCode\BitForm\API\Controller\NoteController;


class Routes extends WP_REST_Controller
{
  function __construct()
  {
    $this->namespace = 'bitform';
    $this->rest_base = 'v1';
    $this->entryController = new EntryController();
    $this->noteController  = new NoteController();
  }

  public function register_routes()
  {
    /* form routes */
    register_rest_route(
      $this->namespace,
      $this->rest_base . '/forms/',
      [
        [
          'methods'             => WP_REST_Server::READABLE,
          'callback'            => [$this->entryController, 'get_forms'],
          'permission_callback' => array($this, 'get_items_permissions_check'),
        ],
        'schema' => [$this, 'get_item_schema']
      ]
    );
    register_rest_route(
      $this->namespace,
      $this->rest_base . '/fields/(?P<form_id>[\d]+)',
      [
        [
          'methods'             => WP_REST_Server::READABLE,
          'callback'            => [$this->entryController, 'get_fields'],
          'permission_callback' => [$this, 'get_items_permissions_check']
        ]
      ]
    );
    /* form routes*/

    /* entry routes*/
    register_rest_route(
      $this->namespace,
      $this->rest_base . '/entry/(?P<form_id>[\d]+)',
      [
        [
          'methods'             => WP_REST_Server::CREATABLE,
          'callback'            => [$this->entryController, 'entry_store'],
          'permission_callback' => [$this, 'get_items_permissions_check']
        ]
      ]
    );
    register_rest_route(
      $this->namespace,
      $this->rest_base . '/form/response/(?P<id>[\d]+)',
      [
        [
          'methods'             => WP_REST_Server::READABLE,
          'callback'            => [$this->entryController, 'getEntryResponse'],
          'permission_callback' => [$this, 'get_items_permissions_check']
        ]
      ]
    );
    register_rest_route(
      $this->namespace,
      $this->rest_base . '/entry/(?P<entry_id>[\d]+)',
      [
        [
          'methods'             => WP_REST_Server::READABLE,
          'callback'            => [$this->entryController, 'entry_view'],
          'permission_callback' => [$this, 'get_items_permissions_check']

        ],
        [
          'methods'             => WP_REST_Server::DELETABLE,
          'callback'            => [$this->entryController, 'entry_delete'],
          'permission_callback' => [$this, 'get_items_permissions_check']
        ]
      ]
    );

    register_rest_route(
      $this->namespace,
      $this->rest_base . '/entry_update/(?P<entry_id>[\d]+)/',
      [
        [
          'methods'             => WP_REST_Server::EDITABLE,
          'callback'            => [$this->entryController, 'entry_update'],
          'permission_callback' => '__return_true'
        ]
      ]
    );
    /* entry routes*/

    /* note routes*/
    register_rest_route(
      $this->namespace,
      $this->rest_base . '/notes/',
      [
        [
          'methods'             => WP_REST_Server::READABLE,
          'callback'            => [$this->noteController, 'get_notes'],
          'permission_callback' => [$this, 'get_items_permissions_check']
        ]
      ]
    );
    register_rest_route(
      $this->namespace,
      $this->rest_base . '/create-note/',
      [
        [
          'methods'             => WP_REST_Server::CREATABLE,
          'callback'            => [$this->noteController, 'create_note'],
          'permission_callback' => [$this, 'get_items_permissions_check']
        ]
      ]
    );
    register_rest_route(
      $this->namespace,
      $this->rest_base . '/note/(?P<id>[\d]+)',
      [
        [
          'methods'             => WP_REST_Server::READABLE,
          'callback'            => [$this->noteController, 'note_edit'],
          'permission_callback' => [$this, 'get_items_permissions_check'],
          'args'                => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE),
        ],
        [
          'methods'             => WP_REST_Server::EDITABLE,
          'callback'            => [$this->noteController, 'note_update'],
          'permission_callback' => [$this, 'get_items_permissions_check']
        ],
        [
          'methods'             => WP_REST_Server::DELETABLE,
          'callback'            => [$this->noteController, 'note_delete'],
          'permission_callback' => [$this, 'get_items_permissions_check']
        ]
      ]
    );
    /* note routes*/
  }
  public function get_items_permissions_check($request)
  {
    $api_key =  get_option('bitform_secret_api_key');
    if ($request->get_header('Bitform-Api-Key') != $api_key || $api_key == null) {
      $error = ['message' => 'Api Key is required to access this resource'];
      return wp_send_json_error($error, 401);
    }
    return true;
  }
}

```
