PluginProbe ʕ •ᴥ•ʔ
Kubio AI Page Builder / 2.8.3
Kubio AI Page Builder v2.8.3
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 / iconvert-email-marketer.php
kubio / lib / api / recommendations Last commit date
newsletter 3 months ago contact-forms.php 3 months ago fluent-booking.php 3 months ago iconvert-email-marketer.php 1 week ago index.php 1 week ago siteleads.php 3 months ago
iconvert-email-marketer.php
95 lines
1 <?php
2
3 use Kubio\Core\Utils;
4
5 add_action(
6 'rest_api_init',
7 function () {
8 $namespace = 'kubio/v1';
9
10 register_rest_route(
11 $namespace,
12 '/prepare_iconvert_email_marketer_plugin',
13 array(
14 'methods' => 'POST',
15 'callback' => 'kubio_api_prepare_iconvert_email_marketer_plugin',
16 'permission_callback' => function () {
17 return current_user_can( 'edit_posts' );
18 },
19
20 )
21 );
22 }
23 );
24
25
26
27 function kubio_api_prepare_iconvert_email_marketer_plugin( WP_REST_Request $request ) {
28
29 if ( ! Utils::getIsIconvertEmailMarketerActive() ) {
30 wp_send_json_error( __( 'Required plugin is missing', 'kubio' ), 400 );
31 }
32
33 $form_id = sanitize_text_field( $request->get_param( 'form_id' ) );
34 $form_id = intval( $form_id );
35 if ( empty( $form_id ) || is_nan( $form_id ) ) {
36 wp_send_json_error( __( 'Invalid form id', 'kubio' ), 400 );
37 }
38
39 //in case of failures only try init once
40 $already_setup = get_option( 'iconvertEmailMarketerThirdPartyInited', null );
41
42 if ( $already_setup ) {
43 // wp_send_json_success();
44 }
45 update_option( 'iconvertEmailMarketerThirdPartyInited', true );
46 try {
47
48 kubio_iconvert_email_marketer_create_default_template( $form_id );
49 wp_send_json_success();
50
51 } catch ( Exception $e ) {
52 wp_send_json_error( $e->getMessage(), 400 );
53
54 }
55 }
56 function kubio_iconvert_email_marketer_create_default_template( $form_id ) {
57 if ( empty( $form_id ) ) {
58 return;
59 }
60 $request = new WP_REST_Request(
61 'POST',
62 '/iconvertem/v1/create-template'
63 );
64
65 // get contact form title
66 $cf_title = get_post_field( 'post_title', $form_id );
67 $title = sprintf( __( '%s - Confirmation Email', 'kubio' ), $cf_title );
68
69 $request->set_body_params(
70 array(
71 'title' => $title,
72 'email_type' => 'icem-mail-tpl-taxonomy-type-transactional',
73 'sending_event_form_id' => $form_id,
74 'sending_event_type' => 'afterContactForm7Submission',
75 'template_id' => '227',
76 'email_subject' => __( 'Thanks for contacting us', 'kubio' ),
77 )
78 );
79
80 $response = rest_do_request( $request );
81
82 $data = $response->get_data();
83 if(is_array($data) && isset($data['success'])) {
84
85 $template_id = $data['data']['id'] ?? null;
86 if ( ! empty( $template_id ) ) {
87 $originally_disabled = get_post_meta( $template_id, '_iconvertem_email_disabled', true );
88 update_post_meta( $template_id, '_iconvertem_email_disabled', '1', $originally_disabled );
89 }
90
91 return $data['success'];
92 }
93 return false;
94 }
95