PluginProbe
The Innovative Form Builder – IvyForms / 0.9
The Innovative Form Builder – IvyForms v0.9
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 0.9, at backend/src/Routes/Template/Template.php

66 lines 1.9 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 // phpcs:disable PSR1.Files.SideEffects
6 if (!defined('ABSPATH')) {
7 exit; // Exit if accessed directly
8 }
9
10 use IvyForms\Vendor\DI\Container;
11 use IvyForms\Vendor\DI\DependencyException;
12 use IvyForms\Vendor\DI\NotFoundException;
13 use IvyForms\Controllers\Form\AddFormController;
14 use IvyForms\Controllers\Template\GetTemplatesController;
15 use IvyForms\Controllers\Template\GetTemplateController;
16 use WP_REST_Server;
17
18 class Template
19 {
20 /**
21 * @throws DependencyException
22 * @throws NotFoundException
23 */
24 public static function registerRoutes(Container $container, string $routeNamespace): void
25 {
26 // Get all templates
27 register_rest_route(
28 $routeNamespace,
29 '/templates',
30 [
31 'methods' => WP_REST_Server::READABLE,
32 'callback' => $container->get(GetTemplatesController::class),
33 'permission_callback' => function () {
34 return current_user_can('manage_options');
35 }
36 ]
37 );
38
39 // Get specific template by ID
40 register_rest_route(
41 $routeNamespace,
42 '/template/(?P<id>[a-zA-Z0-9_-]+)',
43 [
44 'methods' => WP_REST_Server::READABLE,
45 'callback' => $container->get(GetTemplateController::class),
46 'permission_callback' => function () {
47 return current_user_can('manage_options');
48 }
49 ]
50 );
51
52 // Create form from template
53 register_rest_route(
54 $routeNamespace,
55 '/template/create',
56 [
57 'methods' => WP_REST_Server::CREATABLE,
58 'callback' => $container->get(AddFormController::class),
59 'permission_callback' => function () {
60 return current_user_can('manage_options');
61 }
62 ]
63 );
64 }
65 }
66