PluginProbe ʕ •ᴥ•ʔ
Kubio AI Page Builder / 2.6.3
Kubio AI Page Builder v2.6.3
2.8.3 2.8.2 2.8.1 trunk 1.0.0 1.0.1 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.9.0 2.0.0 2.1.1 2.1.2 2.1.3 2.2.0 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.5 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.6.1 2.6.2 2.6.3 2.6.5 2.6.6 2.6.7 2.7.0 2.7.1 2.7.2 2.7.3 2.8.0
kubio / lib / api / recommendations / bubble-chat.php
kubio / lib / api / recommendations Last commit date
newsletter 11 months ago bubble-chat.php 11 months ago contact-forms.php 11 months ago fluent-booking.php 11 months ago index.php 11 months ago
bubble-chat.php
164 lines
1 <?php
2
3 use IlluminateAgnostic\Arr\Support\Arr;
4 use \Kubio\Flags;
5 use Kubio\Core\LodashBasic;
6
7 add_action(
8 'rest_api_init',
9 function () {
10 $namespace = 'kubio/v1';
11
12 register_rest_route(
13 $namespace,
14 '/prepare_bubble_chat_plugin',
15 array(
16 'methods' => 'GET',
17 'callback' => 'kubio_api_prepare_bubble_chat_plugin',
18 'permission_callback' => function () {
19 return current_user_can( 'edit_posts' );
20 },
21
22 )
23 );
24
25 register_rest_route(
26 $namespace,
27 '/get_bubble_chat_widgets',
28 array(
29 'methods' => 'GET',
30 'callback' => 'kubio_api_get_bubble_chat_widgets',
31 'permission_callback' => function () {
32 return current_user_can( 'edit_posts' );
33 },
34
35 )
36 );
37
38 register_rest_route(
39 $namespace,
40 '/update_bubble_chat_widget_data',
41 array(
42 'methods' => 'POST',
43 'callback' => 'kubio_api_update_bubble_chat_widget_data',
44 'permission_callback' => function () {
45 return current_user_can( 'edit_posts' );
46 },
47
48 )
49 );
50 }
51 );
52
53
54
55 function kubio_api_prepare_bubble_chat_plugin( WP_REST_Request $request ) {
56
57 //in case of failures only try init once
58 $already_setup = Flags::getSetting( 'bubbleChatInstalled', null );
59 if(empty($already_setup)) {
60 Flags::setSetting( "bubbleChatInstalled", true );
61 }
62
63 if(!kubio_is_bubble_chat_plugin_active()) {
64 wp_send_json_error(__('Required plugin is missing', 'kubio'), 400);
65 }
66
67
68 if ( ! class_exists( '\FloatingContact\Features\Widgets\FCWidget' )
69 || ! method_exists( '\FloatingContact\Features\Widgets\FCWidget', 'createFromTemplate' )) {
70 wp_send_json_error(__('Required class or functions are missing', 'kubio'), 400);
71 }
72
73 if ( $already_setup ) {
74 wp_send_json_success(kubio_get_bubble_chat_widgets());
75 }
76
77 ob_start();
78
79
80 try {
81 $widgets = kubio_get_bubble_chat_widgets();
82
83 //in case the widgets are already created
84 if(!empty($widgets)) {
85
86 $errors = ob_get_clean();
87 if(!empty($errors)) {
88 error_log($errors);
89 }
90
91 return $widgets;
92 }
93
94 \FloatingContact\Features\Widgets\FCWidget::createFromTemplate([
95 'name' => __('Kubio Widget', 'kubio')
96 ]);
97
98 $result = kubio_get_bubble_chat_widgets();
99
100 $errors = ob_get_clean();
101 if(!empty($errors)) {
102 error_log($errors);
103 }
104
105 wp_send_json_success($result);
106
107 } catch ( Exception $e ) {
108 $errors = ob_get_clean();
109 if(!empty($errors)) {
110 error_log($errors);
111 }
112 wp_send_json_error($e->getMessage(), 400);
113 }
114 }
115
116
117 function kubio_api_get_bubble_chat_widgets( WP_REST_Request $request ) {
118 wp_send_json_success(kubio_get_bubble_chat_widgets());
119 }
120 function kubio_api_update_bubble_chat_widget_data( WP_REST_Request $request ) {
121 if(!kubio_is_bubble_chat_plugin_active()) {
122 wp_send_json_error(__('Required plugin is missing', 'kubio'), 400);
123 }
124 if ( ! class_exists( '\FloatingContact\Features\Widgets\FCWidget' ) ||
125 ! method_exists( '\FloatingContact\Features\Widgets\FCWidget', 'findById' ) ||
126 ! method_exists( '\FloatingContact\Features\Widgets\FCWidget', 'updateParams' )
127 ) {
128 wp_send_json_error(__('Required class or functions are missing', 'kubio'), 400);
129 }
130
131 try {
132 $id = $request->get_param( 'widgetId' );
133 $params = $request->get_param( 'params' );
134 $phoneNr = LodashBasic::get($params, 'phone.phoneNr');
135 $whatsappNr = LodashBasic::get($params, 'whatsapp.phoneNr');
136 $widgetParams = [
137 'phone' => [
138 'phoneNr' => $phoneNr
139 ],
140 'whatsapp' => [
141 'phoneNr' => $whatsappNr
142 ]
143 ];
144 ob_start();
145 try {
146 $widget = \FloatingContact\Features\Widgets\FCWidget::findById($id);
147
148 if(!$widget) {
149 wp_send_json_error(__('Widget not found'), 404);
150 }
151 $widget->updateParams($widgetParams);
152
153 wp_send_json_success();
154 } catch(\Exception $e) {
155 wp_send_json_error($e->getMessage(), 400);
156 }
157
158
159
160 } catch ( Exception $e ) {
161 wp_send_json_error($e->getMessage(), 400);
162 }
163 }
164