PluginProbe ʕ •ᴥ•ʔ
Kubio AI Page Builder / 2.8.0
Kubio AI Page Builder v2.8.0
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 / recommendations / contact-forms.php
kubio / lib / recommendations Last commit date
contact-forms 11 months ago contact-forms.php 11 months ago fluent-booking.php 9 months ago index.php 1 month ago newsletters.php 11 months ago recommendation-page-post-type.php 11 months ago recommendations-trait.php 3 months ago siteleads.php 3 months ago
contact-forms.php
120 lines
1 <?php
2
3 use Kubio\Core\LodashBasic;
4
5
6 function kubio_is_recommendation_contact_form_plugin_active() {
7 return class_exists( '\WPCF7_ContactForm' );
8 }
9
10 function kubio_get_recommendation_contact_forms( $top_forms_ids = array() ) {
11 if ( ! kubio_is_recommendation_contact_form_plugin_active() ) {
12 return array();
13 }
14
15 if ( ! class_exists( '\WPCF7_ContactForm' ) || ! method_exists( '\WPCF7_ContactForm', 'find' ) ) {
16 return array();
17 }
18
19 // Get all the forms registered with Contact Form 7
20 $contact_forms = \WPCF7_ContactForm::find();
21
22 if ( ! is_array( $contact_forms ) || empty( $contact_forms ) ) {
23 return array();
24 }
25
26 $sample_form = LodashBasic::get( $contact_forms, '0' );
27
28 if ( ! is_callable( array( $sample_form, 'title' ) ) || ! is_callable( array( $sample_form, 'id' ) ) ) {
29 return array();
30 }
31
32 $forms = array();
33
34 foreach ( $contact_forms as $form ) {
35 $next_form = array(
36 'label' => $form->title(),
37 'value' => intval( $form->id() ),
38 );
39
40 $label = LodashBasic::get($next_form, 'label');
41 $default_contact_form_title = kubio_recommendation_get_default_contact_form_title();
42 if ( $label === $default_contact_form_title) {
43 // If this form is in the top forms, we add it at the beginning of the array
44 array_unshift( $forms, $next_form );
45 } else {
46 // Otherwise we add it at the end of the array
47 $forms[] = $next_form;
48 }
49 }
50
51 //We make sure we have the data we require
52 $forms = array_filter(
53 $forms,
54 function ( $item ) {
55 return LodashBasic::get( $item, 'value' ) !== null && LodashBasic::get( $item, 'label' ) !== null;
56 }
57 );
58
59 return $forms;
60 }
61 function kubio_recommendation_get_default_contact_form_title() {
62 return __( 'Contact / Quotation Form 1', 'kubio' );
63 }
64
65 function kubio_recommendations_create_contact_form() {
66 if ( ! kubio_is_recommendation_contact_form_plugin_active() ) {
67 return false;
68 }
69
70 if ( ! class_exists( '\WPCF7_ContactForm' ) ) {
71 return false;
72 }
73 if ( ! method_exists( '\WPCF7_ContactForm', 'get_template' ) ||
74 ! method_exists( '\WPCF7_ContactForm', 'set_properties' ) ||
75 ! method_exists( '\WPCF7_ContactForm', 'save' ) ||
76 ! method_exists( '\WPCF7_ContactForm', 'id' ) ||
77 ! method_exists( '\WPCF7', 'update_option' )
78
79 ) {
80 wp_send_json_error( __( 'At least one of required functions is missing', 'kubio' ), 400 );
81 }
82 $contact_form = \WPCF7_ContactForm::get_template(
83 array(
84 'title' => kubio_recommendation_get_default_contact_form_title(),
85 )
86 );
87
88 $default_template = '';
89
90 ob_start();
91 require __DIR__ . '/contact-forms/default-template.php';
92 $default_template = ob_get_clean();
93
94 if ( $default_template ) {
95 $contact_form->set_properties(
96 array(
97 'form' => $default_template,
98 )
99 );
100 }
101
102 $contact_form->save();
103
104 \WPCF7::update_option(
105 'bulk_validate',
106 array(
107 'timestamp' => time(),
108 'version' => WPCF7_VERSION,
109 'count_valid' => 1,
110 'count_invalid' => 0,
111 )
112 );
113
114 if ( is_wp_error( $contact_form ) ) {
115 return false;
116 }
117
118 return $contact_form->id();
119 }
120