PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 2.8.16
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v2.8.16
3.13.3 3.13.2 3.13.1 3.13.0 3.12.13 3.12.12 3.12.11 3.12.10 3.12.9 3.12.8 3.12.7 3.12.6 3.12.5 3.12.4 3.12.3 3.12.1 3.12.2 3.12.0 3.11.1 3.11.0 3.10.9 3.10.8 3.10.7 3.10.6 2.8.16 All 261 releases
wpfunnels / includes / core / rest-api / class-server.php

class-server.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 2.8.16, at includes/core/rest-api/class-server.php

105 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Server
4 *
5 * @package
6 */
7 namespace WPFunnels\Rest;
8
9 class Server
10 {
11
12 /**
13 * The single instance of the class.
14 *
15 * @var object
16 */
17 protected static $instance = null;
18
19 /**
20 * REST API namespaces and endpoints.
21 *
22 * @var array
23 */
24 protected $controllers = [];
25
26 /**
27 * Get class instance.
28 *
29 * @return object Instance.
30 */
31 final public static function instance()
32 {
33 if (null === static::$instance) {
34 static::$instance = new static();
35 }
36 return static::$instance;
37 }
38
39 /**
40 * Hook into WordPress ready to init the REST API as needed.
41 */
42 public function init()
43 {
44 add_action('rest_api_init', [ $this, 'register_rest_routes' ], 10);
45 }
46
47 /**
48 * Register REST API routes.
49 */
50 public function register_rest_routes()
51 {
52
53 foreach ($this->get_rest_namespaces() as $namespace => $controllers) {
54 foreach ($controllers as $controller_name => $controller_class) {
55 $controller_class_name = "WPFunnels\\Rest\\Controllers\\".$controller_class;
56 $this->controllers[ $namespace ][ $controller_name ] = new $controller_class_name();
57 $this->controllers[ $namespace ][ $controller_name ]->register_routes();
58 }
59 }
60 }
61
62
63 /**
64 * Get API namespaces - new namespaces should be registered here.
65 *
66 * @return array List of Namespaces and Main controller classes.
67 */
68 protected function get_rest_namespaces()
69 {
70 return [
71 'wpfunnels/v1' => $this->get_controllers(),
72 ];
73 }
74
75 /**
76 * List of controllers in the wc/v1 namespace.
77 *
78 * @return array
79 */
80 protected function get_controllers()
81 {
82 return apply_filters( 'wpfunnels/rest_api_controllers', array(
83 'settings' => 'SettingsController',
84 'templates_library' => 'TemplateLibraryController',
85 'order_bump' => 'OrderBumpController',
86 'funnel_control' => 'FunnelController',
87 'step_control' => 'StepController',
88 'remote_funnel' => 'RemoteFunnelsController',
89 'products' => 'ProductsController',
90 'gutenberg' => 'GutenbergCSSController',
91 'checkout' => 'CheckoutController'
92 ));
93 }
94
95 /**
96 * Return the path to the package.
97 *
98 * @return string
99 */
100 public static function get_path()
101 {
102 return dirname(__DIR__);
103 }
104 }
105