PluginProbe ʕ •ᴥ•ʔ
Hustle – Email Marketing, Lead Generation, Optins, Popups / 7.8.14
Hustle – Email Marketing, Lead Generation, Optins, Popups v7.8.14
7.8.14 7.8.14.1 7.8.13 7.8.13.1 trunk 3.0 3.1 3.1.1 3.1.2 3.1.3 3.1.4 4.3.2 4.4.4 4.4.5 4.4.5.1 4.4.5.4 4.6 4.6.1.1 4.6.1.4 4.7.0.2 4.7.0.3 4.7.0.7 4.7.0.9 4.7.1.0 4.7.1.1 4.8.0.0 5.0.0 5.0.1 5.0.1.1 5.0.1.2 5.1 5.1.1 5.1.2 5.1.3 5.1.3.1 5.1.3.2 5.1.4 5.1.5 6.0 6.0.1 6.0.2 6.0.3 6.0.4.2 6.0.5 6.0.6.1 6.0.7 6.0.8.1 6.0.9 7.0.0.1 7.0.2 7.0.3 7.0.4 7.1.0 7.1.1 7.2.0 7.2.1 7.3.0 7.3.1 7.3.3 7.3.5 7.3.6 7.3.7 7.4.0 7.4.1 7.4.11 7.4.13 7.4.13.1 7.4.2 7.4.3 7.4.4 7.4.5 7.4.5.1 7.4.5.2 7.4.6 7.4.7 7.5.0 7.6.0 7.6.1 7.6.3 7.6.4 7.6.6 7.7.0 7.7.1 7.8.0 7.8.1 7.8.10 7.8.10.1 7.8.10.2 7.8.11 7.8.12 7.8.12.1 7.8.2 7.8.3 7.8.4 7.8.5 7.8.6 7.8.7 7.8.8 7.8.9 7.8.9.1 7.8.9.2 7.8.9.3
wordpress-popup / inc / providers / convertkit / hustle-convertkit-form-settings.php
wordpress-popup / inc / providers / convertkit Last commit date
images 4 months ago convertkit.php 4 months ago hustle-convertkit-api-intefrace.php 4 months ago hustle-convertkit-api-v2.php 4 months ago hustle-convertkit-api.php 4 months ago hustle-convertkit-form-hooks.php 4 months ago hustle-convertkit-form-settings.php 5 months ago hustle-convertkit-v2.php 4 months ago hustle-convertkit.php 4 months ago
hustle-convertkit-form-settings.php
207 lines
1 <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2 /**
3 * Hustle_ConvertKit_Form_Settings class
4 *
5 * @package Hustle
6 */
7
8 if ( ! class_exists( 'Hustle_ConvertKit_Form_Settings' ) ) :
9
10 /**
11 * Class Hustle_ConvertKit_Form_Settings
12 * Form Settings ConvertKit Process
13 */
14 class Hustle_ConvertKit_Form_Settings extends Hustle_Provider_Form_Settings_Abstract {
15
16 /**
17 * Options that must be set in order to consider the integration as "connected" to the form.
18 *
19 * @since 4.3.1
20 * @var array
21 */
22 protected $form_completion_options = array( 'selected_global_multi_id', 'list_id' );
23
24 /**
25 * For settings Wizard steps
26 *
27 * @since 3.0.5
28 * @return array
29 */
30 public function form_settings_wizards() {
31 // already filtered on Abstract
32 // numerical array steps.
33 return array(
34 // 0
35 array(
36 'callback' => array( $this, 'first_step_callback' ),
37 'is_completed' => array( $this, 'first_step_is_completed' ),
38 ),
39 );
40 }
41
42 /**
43 * Check if step is completed
44 *
45 * @since 3.0.5
46 * @return bool
47 */
48 public function first_step_is_completed() {
49 $this->addon_form_settings = $this->get_form_settings_values();
50 if ( ! isset( $this->addon_form_settings['list_id'] ) ) {
51 // preliminary value.
52 $this->addon_form_settings['list_id'] = 0;
53
54 return false;
55 }
56
57 if ( empty( $this->addon_form_settings['list_id'] ) ) {
58 return false;
59 }
60
61 return true;
62 }
63
64 /**
65 * Returns all settings and conditions for 1st step of ConvertKit settings
66 *
67 * @since 3.0.5
68 * @since 4.0 param $validate removed.
69 *
70 * @param array $submitted_data Submitted data.
71 * @return array
72 */
73 public function first_step_callback( $submitted_data ) {
74 $this->addon_form_settings = $this->get_form_settings_values();
75 $current_data = array(
76 'list_id' => '',
77 );
78 $current_data = $this->get_current_data( $current_data, $submitted_data );
79 $is_submit = ! empty( $submitted_data['hustle_is_submit'] );
80
81 if ( $is_submit && ( empty( $submitted_data['list_id'] ) ) ) {
82 $error_message = __( 'The email list is required.', 'hustle' );
83 }
84
85 $options = $this->get_first_step_options( $current_data );
86
87 $step_html = Hustle_Provider_Utils::get_integration_modal_title_markup( __( 'Choose your list', 'hustle' ), __( 'Choose the list you want to send form data to.', 'hustle' ) );
88 $step_html .= Hustle_Provider_Utils::get_html_for_options( $options );
89
90 if ( ! isset( $error_message ) ) {
91 $has_errors = false;
92 } else {
93 $step_html .= '<span class="sui-error-message">' . esc_html( $error_message ) . '</span>';
94 $has_errors = true;
95 }
96
97 $buttons = array(
98 'disconnect' => array(
99 'markup' => Hustle_Provider_Utils::get_provider_button_markup(
100 __( 'Disconnect', 'hustle' ),
101 'sui-button-ghost',
102 'disconnect_form',
103 true
104 ),
105 ),
106 'save' => array(
107 'markup' => Hustle_Provider_Utils::get_provider_button_markup(
108 __( 'Save', 'hustle' ),
109 '',
110 'next',
111 true
112 ),
113 ),
114 );
115
116 $response = array(
117 'html' => $step_html,
118 'buttons' => $buttons,
119 'has_errors' => $has_errors,
120 );
121 // Save only after the step has been validated and there are no errors.
122 if ( $is_submit && ! $has_errors ) {
123 // Save additional data for submission's entry.
124 if ( ! empty( $current_data['list_id'] ) ) {
125 $current_data['list_name'] = ! empty( $this->lists[ $current_data['list_id'] ] )
126 ? $this->lists[ $current_data['list_id'] ] . ' (' . $current_data['list_id'] . ')' : $current_data['list_id'];
127 }
128 $this->save_form_settings_values( $current_data );
129 }
130
131 return $response;
132 }
133
134 /**
135 * Refresh list array via API
136 *
137 * @param object $provider Provider.
138 * @param string $global_multi_id Global multi ID.
139 * @return array
140 */
141 public function refresh_global_multi_lists( $provider, $global_multi_id ) {
142 $api_key = $provider->get_setting( 'api_key', '', $global_multi_id );
143 $api = $provider::api( $api_key );
144
145 $lists = array();
146 $forms = $api->get_forms();
147
148 if ( ! is_wp_error( $forms ) ) {
149 $lists = wp_list_pluck( $forms, 'name', 'id' );
150 }
151
152 return $lists;
153 }
154
155 /**
156 * Return an array of options used to display the settings of the 1st step.
157 *
158 * @since 4.0
159 *
160 * @param array $submitted_data Submitted data.
161 * @return array
162 */
163 private function get_first_step_options( $submitted_data ) {
164 $lists = $this->get_global_multi_lists();
165 $this->lists = $lists;
166 $selected_list = $this->get_selected_list( $submitted_data );
167
168 $options = array(
169 array(
170 'type' => 'wrapper',
171 'style' => 'margin-bottom: 0;',
172 'elements' => array(
173 'label' => array(
174 'type' => 'label',
175 'for' => 'list_id',
176 'value' => __( 'Email List', 'hustle' ),
177 ),
178 'wrapper' => array(
179 'type' => 'wrapper',
180 'class' => 'hui-select-refresh',
181 'is_not_field_wrapper' => true,
182 'elements' => array(
183 'lists' => array(
184 'type' => 'select',
185 'id' => 'list_id',
186 'name' => 'list_id',
187 'class' => 'sui-select',
188 'value' => $selected_list,
189 'selected' => $selected_list,
190 'options' => $lists,
191 ),
192 'refresh' => array(
193 'type' => 'raw',
194 'value' => Hustle_Provider_Utils::get_provider_button_markup( __( 'Refresh', 'hustle' ), '', 'refresh_list', true ),
195 ),
196 ),
197 ),
198 ),
199 ),
200 );
201
202 return $options;
203 }
204 } // Class end.
205
206 endif;
207