PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 3.13.1
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v3.13.1
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 2.8.17 2.8.18 All 259 releases
wpfunnels / includes / core / rest-api / class-server.php

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

120 lines 3.2 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
57 if ( ! class_exists( $controller_class_name ) ) {
58 continue;
59 }
60
61 $this->controllers[ $namespace ][ $controller_name ] = new $controller_class_name();
62 $this->controllers[ $namespace ][ $controller_name ]->register_routes();
63 }
64 }
65 }
66
67
68 /**
69 * Get API namespaces - new namespaces should be registered here.
70 *
71 * @return array List of Namespaces and Main controller classes.
72 */
73 protected function get_rest_namespaces()
74 {
75 return [
76 'wpfunnels/v1' => $this->get_controllers(),
77 ];
78 }
79
80 /**
81 * List of controllers in the wc/v1 namespace.
82 *
83 * @return array
84 */
85 protected function get_controllers()
86 {
87 return apply_filters( 'wpfunnels/rest_api_controllers', array(
88 'mcp_settings' => 'McpSettingsController',
89 'settings' => 'SettingsController',
90 'templates_library' => 'TemplateLibraryController',
91 'order_bump' => 'OrderBumpController',
92 'funnel_control' => 'FunnelController',
93 'offer' => 'OfferController',
94 'step_control' => 'StepController',
95 'remote_funnel' => 'RemoteFunnelsController',
96 'products' => 'ProductsController',
97 'gutenberg' => 'GutenbergCSSController',
98 'checkout' => 'CheckoutController',
99 'importexport' => 'ImportExportController',
100 'report' => 'DashboardController',
101 'plugin_installer' => 'PluginInstallerController',
102 'setup_wizard' => 'SetupWizardController',
103 'store_checkout' => 'StoreCheckoutController',
104 'automation' => 'WpfnlAutomationController',
105 'ai_chat' => 'AiChatController',
106 'ai_generate' => 'SingleShotAiController',
107 ));
108 }
109
110 /**
111 * Return the path to the package.
112 *
113 * @return string
114 */
115 public static function get_path()
116 {
117 return dirname(__DIR__);
118 }
119 }
120