PluginProbe
SureDonation – Donation Forms, Fundraising Campaigns & Donor Management / 1.4.0
SureDonation – Donation Forms, Fundraising Campaigns & Donor Management v1.4.0
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 1.4.0, at inc/rest-api.php

131 lines 2.6 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\Donors_API;
14 use SureDonation\Inc\API\Forms_API;
15 use SureDonation\Inc\API\Import_Export_API;
16 use SureDonation\Inc\API\Import_Givewp_API;
17 use SureDonation\Inc\API\Onboarding_API;
18 use SureDonation\Inc\API\Settings_API;
19 use SureDonation\Inc\Traits\Get_Instance;
20
21 // Exit if accessed directly.
22 if ( ! defined( 'ABSPATH' ) ) {
23 exit;
24 }
25
26 /**
27 * Rest_Api class.
28 *
29 * @since 0.0.1
30 */
31 class Rest_Api {
32 use Get_Instance;
33
34 /**
35 * REST API namespace.
36 *
37 * @var string
38 * @since 0.0.1
39 */
40 private $namespace = 'suredonation';
41
42 /**
43 * REST API version.
44 *
45 * @var string
46 * @since 0.0.1
47 */
48 private $version = 'v1';
49
50 /**
51 * Constructor.
52 *
53 * @since 0.0.1
54 */
55 public function __construct() {
56 add_action( 'rest_api_init', [ $this, 'register_routes' ] );
57 }
58
59 /**
60 * Get REST API namespace with version.
61 *
62 * @return string
63 * @since 0.0.1
64 */
65 public function get_namespace() {
66 return $this->namespace . '/' . $this->version;
67 }
68
69 /**
70 * Register REST API routes.
71 *
72 * @return void
73 * @since 0.0.1
74 */
75 public function register_routes() {
76 $endpoints = $this->get_endpoints();
77
78 foreach ( $endpoints as $endpoint => $args ) {
79 if ( ! is_array( $args ) ) {
80 continue;
81 }
82 register_rest_route(
83 $this->get_namespace(),
84 $endpoint,
85 $args
86 );
87 }
88 }
89
90 /**
91 * Get REST API endpoints.
92 *
93 * @return array<string, mixed>
94 * @since 0.0.1
95 */
96 private function get_endpoints() {
97 $campaigns_api = new Campaigns_API();
98 $donations_api = new Donations_API();
99 $donors_api = new Donors_API();
100 $dashboard_api = new Dashboard_API();
101 $forms_api = new Forms_API();
102 $settings_api = new Settings_API();
103 $import_givewp_api = Import_Givewp_API::get_instance();
104 $import_export_api = new Import_Export_API();
105 $onboarding_api = new Onboarding_API();
106
107 // Merge endpoints from all APIs.
108 $endpoints = array_merge(
109 $campaigns_api->get_endpoints(),
110 $donations_api->get_endpoints(),
111 $donors_api->get_endpoints(),
112 $dashboard_api->get_endpoints(),
113 $forms_api->get_endpoints(),
114 $settings_api->get_endpoints(),
115 $import_givewp_api->get_endpoints(),
116 $import_export_api->get_endpoints(),
117 $onboarding_api->get_endpoints()
118 );
119
120 /**
121 * Filter REST API endpoints.
122 *
123 * @param array $endpoints Array of REST API endpoints.
124 */
125 return apply_filters(
126 'suredonation_rest_api_endpoints',
127 $endpoints
128 );
129 }
130 }
131