PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 3.13.2
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v3.13.2
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 3.13.2, at includes/core/rest-api/class-server.php

133 lines 4.0 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 // The React settings screen (?page=wpfunnels#/settings).
91 'settings_page' => 'SettingsPageController',
92 'templates_library' => 'TemplateLibraryController',
93 'order_bump' => 'OrderBumpController',
94 'funnel_control' => 'FunnelController',
95 // Funnel listing screen (?page=wpfunnels#/funnels).
96 'funnel_list' => 'FunnelListController',
97 'offer' => 'OfferController',
98 'step_control' => 'StepController',
99 'remote_funnel' => 'RemoteFunnelsController',
100 'products' => 'ProductsController',
101 'gutenberg' => 'GutenbergCSSController',
102 'checkout' => 'CheckoutController',
103 'importexport' => 'ImportExportController',
104 'report' => 'DashboardController',
105 'plugin_installer' => 'PluginInstallerController',
106 'setup_wizard' => 'SetupWizardController',
107 'store_checkout' => 'StoreCheckoutController',
108 /*
109 * Two different controllers answer to automations, and WPFunnels Pro
110 * overwrites the 'automation' key with its own CRM controller (see
111 * wpfunnels_add_analytics_controller in wpfnl-pro.php). Keeping this
112 * one under its own key means both register instead of the Pro one
113 * silently replacing it — which is what left the wpfnl/v1 namespace
114 * with no routes at all whenever Pro was active.
115 */
116 'automation' => 'WpfnlAutomationController',
117 'automation_canvas_crud' => 'WpfnlAutomationController',
118 'ai_chat' => 'AiChatController',
119 'ai_generate' => 'SingleShotAiController',
120 ));
121 }
122
123 /**
124 * Return the path to the package.
125 *
126 * @return string
127 */
128 public static function get_path()
129 {
130 return dirname(__DIR__);
131 }
132 }
133