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 / contact-forms.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
contact-forms.php
89 lines
1 <?php
2
3 use Kubio\Flags;
4
5 add_action(
6 'rest_api_init',
7 function () {
8 $namespace = 'kubio/v1';
9
10 register_rest_route(
11 $namespace,
12 '/prepare_contact_form_plugin',
13 array(
14 'methods' => 'GET',
15 'callback' => 'kubio_api_prepare_contact_form_plugin',
16 'permission_callback' => function () {
17 return current_user_can( 'edit_posts' );
18 },
19
20 )
21 );
22
23 register_rest_route(
24 $namespace,
25 '/get_contact_forms',
26 array(
27 'methods' => 'GET',
28 'callback' => 'kubio_api_get_contact_forms',
29 'permission_callback' => function () {
30 return current_user_can( 'edit_posts' );
31 },
32
33 )
34 );
35 }
36 );
37
38
39 function kubio_api_prepare_contact_form_plugin( WP_REST_Request $request ) {
40 //in case of failures only try init once
41 $already_setup = Flags::getSetting( 'contactFormsInstalled', null );
42 if ( empty( $already_setup ) ) {
43 Flags::setSetting( 'contactFormsInstalled', true );
44 }
45
46 if ( ! kubio_is_recommendation_contact_form_plugin_active() ) {
47 wp_send_json_error( __( 'Contact Form plugin is not active!', 'kubio' ), 400 );
48 }
49
50 $default_form = null;
51
52 if ( $already_setup ) {
53 wp_send_json_success( kubio_get_recommendation_contact_forms() );
54 } else {
55 // Create a default contact form
56 $default_form = kubio_recommendations_create_contact_form();
57 if ( ! $default_form ) {
58 wp_send_json_error( __( 'Failed to create default contact form!', 'kubio' ), 500 );
59 }
60 }
61
62 ob_start();
63 try {
64 $forms = kubio_get_recommendation_contact_forms();
65
66 if ( empty( $forms ) ) {
67 $forms = array();
68 }
69
70 $errors = ob_get_clean();
71 if ( ! empty( $errors ) ) {
72 error_log( $errors );
73 }
74
75 wp_send_json_success( $forms );
76
77 } catch ( Exception $e ) {
78 $errors = ob_get_clean();
79 if ( ! empty( $errors ) ) {
80 error_log( $errors );
81 }
82 wp_send_json_error( $e->getMessage(), 400 );
83 }
84 }
85
86 function kubio_api_get_contact_forms( WP_REST_Request $request ) {
87 wp_send_json_success( kubio_get_recommendation_contact_forms() );
88 }
89