PluginProbe
The Innovative Form Builder – IvyForms / 1.1
The Innovative Form Builder – IvyForms v1.1
1.5.1 1.5 1.4.1 1.4 trunk 0.1.2 0.2 0.2.1 0.3 0.3.1 0.4 0.5 0.6 0.6.1 0.6.1-backup 0.6.1.1 0.7 0.8 0.8.1 0.8.2 0.9 0.9.1 1.0 1.1 1.1.1 All 27 releases
ivyforms / backend / src / Routes / Template / Template.php

Template.php in The Innovative Form Builder – IvyForms 1.1, at backend/src/Routes/Template/Template.php

61 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace IvyForms\Routes\Template;
4
5 use IvyForms\Vendor\DI\Container;
6 use IvyForms\Vendor\DI\DependencyException;
7 use IvyForms\Vendor\DI\NotFoundException;
8 use IvyForms\Controllers\Form\AddFormController;
9 use IvyForms\Controllers\Template\GetTemplatesController;
10 use IvyForms\Controllers\Template\GetTemplateController;
11 use WP_REST_Server;
12
13 class Template
14 {
15 /**
16 * @throws DependencyException
17 * @throws NotFoundException
18 */
19 public static function registerRoutes(Container $container, string $routeNamespace): void
20 {
21 // Get all templates
22 register_rest_route(
23 $routeNamespace,
24 '/templates',
25 [
26 'methods' => WP_REST_Server::READABLE,
27 'callback' => $container->get(GetTemplatesController::class),
28 'permission_callback' => function () {
29 return current_user_can('manage_options');
30 }
31 ]
32 );
33
34 // Get specific template by ID
35 register_rest_route(
36 $routeNamespace,
37 '/template/(?P<id>[a-zA-Z0-9_-]+)',
38 [
39 'methods' => WP_REST_Server::READABLE,
40 'callback' => $container->get(GetTemplateController::class),
41 'permission_callback' => function () {
42 return current_user_can('manage_options');
43 }
44 ]
45 );
46
47 // Create form from template
48 register_rest_route(
49 $routeNamespace,
50 '/template/create',
51 [
52 'methods' => WP_REST_Server::CREATABLE,
53 'callback' => $container->get(AddFormController::class),
54 'permission_callback' => function () {
55 return current_user_can('manage_options');
56 }
57 ]
58 );
59 }
60 }
61