PluginProbe
SureDonation – Donation Forms, Fundraising Campaigns & Donor Management / 0.0.1
SureDonation – Donation Forms, Fundraising Campaigns & Donor Management v0.0.1
1.6.0 1.5.1 1.5.0 1.4.0 1.3.0 trunk 0.0.1 1.0.0 1.1.0 1.1.1 1.1.2 1.2.0
suredonation / inc / rest-api.php

rest-api.php in SureDonation – Donation Forms, Fundraising Campaigns & Donor Management 0.0.1, at inc/rest-api.php

119 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * REST API Endpoints
4 *
5 * @package SureDonation
6 */
7
8 namespace SureDonation\Inc;
9
10 use SureDonation\Inc\API\Campaigns_API;
11 use SureDonation\Inc\API\Dashboard_API;
12 use SureDonation\Inc\API\Donations_API;
13 use SureDonation\Inc\API\Forms_API;
14 use SureDonation\Inc\API\Settings_API;
15 use SureDonation\Inc\Traits\Get_Instance;
16
17 // Exit if accessed directly.
18 if ( ! defined( 'ABSPATH' ) ) {
19 exit;
20 }
21
22 /**
23 * Rest_Api class.
24 *
25 * @since 0.0.1
26 */
27 class Rest_Api {
28 use Get_Instance;
29
30 /**
31 * REST API namespace.
32 *
33 * @var string
34 * @since 0.0.1
35 */
36 private $namespace = 'suredonation';
37
38 /**
39 * REST API version.
40 *
41 * @var string
42 * @since 0.0.1
43 */
44 private $version = 'v1';
45
46 /**
47 * Constructor.
48 *
49 * @since 0.0.1
50 */
51 public function __construct() {
52 add_action( 'rest_api_init', [ $this, 'register_routes' ] );
53 }
54
55 /**
56 * Get REST API namespace with version.
57 *
58 * @return string
59 * @since 0.0.1
60 */
61 public function get_namespace() {
62 return $this->namespace . '/' . $this->version;
63 }
64
65 /**
66 * Register REST API routes.
67 *
68 * @return void
69 * @since 0.0.1
70 */
71 public function register_routes() {
72 $endpoints = $this->get_endpoints();
73
74 foreach ( $endpoints as $endpoint => $args ) {
75 if ( ! is_array( $args ) ) {
76 continue;
77 }
78 register_rest_route(
79 $this->get_namespace(),
80 $endpoint,
81 $args
82 );
83 }
84 }
85
86 /**
87 * Get REST API endpoints.
88 *
89 * @return array<string, mixed>
90 * @since 0.0.1
91 */
92 private function get_endpoints() {
93 $campaigns_api = new Campaigns_API();
94 $donations_api = new Donations_API();
95 $dashboard_api = new Dashboard_API();
96 $forms_api = new Forms_API();
97 $settings_api = new Settings_API();
98
99 // Merge endpoints from all APIs.
100 $endpoints = array_merge(
101 $campaigns_api->get_endpoints(),
102 $donations_api->get_endpoints(),
103 $dashboard_api->get_endpoints(),
104 $forms_api->get_endpoints(),
105 $settings_api->get_endpoints()
106 );
107
108 /**
109 * Filter REST API endpoints.
110 *
111 * @param array $endpoints Array of REST API endpoints.
112 */
113 return apply_filters(
114 'suredonation_rest_api_endpoints',
115 $endpoints
116 );
117 }
118 }
119