PluginProbe ʕ •ᴥ•ʔ
Kubio AI Page Builder / 2.6.6
Kubio AI Page Builder v2.6.6
2.9.1 2.9.0 2.8.6 2.8.5 2.8.4 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 10 months ago bubble-chat.php 11 months ago contact-forms.php 11 months ago fluent-booking.php 1 year ago index.php 1 year ago
bubble-chat.php
158 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
88
89 return $widgets;
90 }
91
92 \FloatingContact\Features\Widgets\FCWidget::createFromTemplate([
93 'name' => __('Kubio Widget', 'kubio')
94 ]);
95
96 $result = kubio_get_bubble_chat_widgets();
97
98 $errors = ob_get_clean();
99
100
101 wp_send_json_success($result);
102
103 } catch ( Exception $e ) {
104 $errors = ob_get_clean();
105
106 wp_send_json_error($e->getMessage(), 400);
107 }
108 }
109
110
111 function kubio_api_get_bubble_chat_widgets( WP_REST_Request $request ) {
112 wp_send_json_success(kubio_get_bubble_chat_widgets());
113 }
114 function kubio_api_update_bubble_chat_widget_data( WP_REST_Request $request ) {
115 if(!kubio_is_bubble_chat_plugin_active()) {
116 wp_send_json_error(__('Required plugin is missing', 'kubio'), 400);
117 }
118 if ( ! class_exists( '\FloatingContact\Features\Widgets\FCWidget' ) ||
119 ! method_exists( '\FloatingContact\Features\Widgets\FCWidget', 'findById' ) ||
120 ! method_exists( '\FloatingContact\Features\Widgets\FCWidget', 'updateParams' )
121 ) {
122 wp_send_json_error(__('Required class or functions are missing', 'kubio'), 400);
123 }
124
125 try {
126 $id = $request->get_param( 'widgetId' );
127 $params = $request->get_param( 'params' );
128 $phoneNr = LodashBasic::get($params, 'phone.phoneNr');
129 $whatsappNr = LodashBasic::get($params, 'whatsapp.phoneNr');
130 $widgetParams = [
131 'phone' => [
132 'phoneNr' => $phoneNr
133 ],
134 'whatsapp' => [
135 'phoneNr' => $whatsappNr
136 ]
137 ];
138 ob_start();
139 try {
140 $widget = \FloatingContact\Features\Widgets\FCWidget::findById($id);
141
142 if(!$widget) {
143 wp_send_json_error(__('Widget not found', 'kubio'), 404);
144 }
145 $widget->updateParams($widgetParams);
146
147 wp_send_json_success();
148 } catch(\Exception $e) {
149 wp_send_json_error($e->getMessage(), 400);
150 }
151
152
153
154 } catch ( Exception $e ) {
155 wp_send_json_error($e->getMessage(), 400);
156 }
157 }
158