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 / getresponse / hustle-get-response-form-settings.php
wordpress-popup / inc / providers / getresponse Last commit date
images 7 years ago getresponse.php 5 months ago hustle-get-response-api.php 3 years ago hustle-get-response-form-hooks.php 5 months ago hustle-get-response-form-settings.php 5 months ago hustle-get-response.php 3 years ago
hustle-get-response-form-settings.php
208 lines
1 <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2 /**
3 * Hustle_Get_Response_Form_Settings class
4 *
5 * @package Hustle
6 */
7
8 if ( ! class_exists( 'Hustle_Get_Response_Form_Settings' ) ) :
9
10 /**
11 * Class Hustle_Get_Response_Form_Settings
12 * Form Settings GetResponse Process
13 */
14 class Hustle_Get_Response_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.2.0
20 * @var array
21 */
22 protected $form_completion_options = array( 'selected_global_multi_id', 'list_id', 'list_name' );
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 GetResponse 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
122 // Save only after the step has been validated and there are no errors.
123 if ( $is_submit && ! $has_errors ) {
124 // Save additional data for submission's entry.
125 if ( ! empty( $current_data['list_id'] ) ) {
126 $current_data['list_name'] = ! empty( $this->lists[ $current_data['list_id'] ] )
127 ? $this->lists[ $current_data['list_id'] ] . ' (' . $current_data['list_id'] . ')' : $current_data['list_id'];
128 }
129 $this->save_form_settings_values( $current_data );
130 }
131
132 return $response;
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
147 $campaigns = $api->get_campaigns();
148
149 if ( ! is_wp_error( $campaigns ) ) {
150 $lists = wp_list_pluck( $campaigns, 'name', 'campaignId' );
151 }
152
153 return $lists;
154 }
155
156 /**
157 * Return an array of options used to display the settings of the 1st step.
158 *
159 * @since 4.0
160 *
161 * @param array $submitted_data Submitted data.
162 * @return array
163 */
164 private function get_first_step_options( $submitted_data ) {
165 $lists = $this->get_global_multi_lists();
166 $this->lists = $lists;
167 $selected_list = $this->get_selected_list( $submitted_data );
168
169 $options = array(
170 array(
171 'type' => 'wrapper',
172 'style' => 'margin-bottom: 0;',
173 'elements' => array(
174 'label' => array(
175 'type' => 'label',
176 'for' => 'list_id',
177 'value' => __( 'Email List', 'hustle' ),
178 ),
179 'wrapper' => array(
180 'type' => 'wrapper',
181 'class' => 'hui-select-refresh',
182 'is_not_field_wrapper' => true,
183 'elements' => array(
184 'lists' => array(
185 'type' => 'select',
186 'id' => 'list_id',
187 'name' => 'list_id',
188 'class' => 'sui-select',
189 'value' => $selected_list,
190 'selected' => $selected_list,
191 'options' => $lists,
192 ),
193 'refresh' => array(
194 'type' => 'raw',
195 'value' => Hustle_Provider_Utils::get_provider_button_markup( __( 'Refresh', 'hustle' ), '', 'refresh_list', true ),
196 ),
197 ),
198 ),
199 ),
200 ),
201 );
202
203 return $options;
204 }
205 } // Class end.
206
207 endif;
208