PluginProbe ʕ •ᴥ•ʔ
Hustle – Email Marketing, Lead Generation, Optins, Popups / 7.8.9
Hustle – Email Marketing, Lead Generation, Optins, Popups v7.8.9
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 / mailster / class-hustle-mailster.php
wordpress-popup / inc / providers / mailster Last commit date
images 5 years ago class-hustle-mailster-form-hooks.php 3 years ago class-hustle-mailster-form-settings.php 3 years ago class-hustle-mailster.php 3 years ago mailster.php 5 years ago
class-hustle-mailster.php
282 lines
1 <?php
2 /**
3 * Hustle_Mailster class.
4 *
5 * @package hustle
6 *
7 * @since 4.4.0
8 */
9
10 /**
11 * Class Hustle_Mailster.
12 *
13 * @since 4.4.0
14 */
15 class Hustle_Mailster extends Hustle_Provider_Abstract {
16
17 /**
18 * Provider Instance
19 *
20 * @since 4.4.0
21 *
22 * @var self|null
23 */
24 protected static $instance;
25
26 /**
27 * Provider slug.
28 *
29 * @since 4.4.0
30 *
31 * @var string
32 */
33 protected $slug = 'mailster';
34
35 /**
36 * Provider version.
37 *
38 * @var string
39 */
40 protected $version = '1.0.0';
41
42 /**
43 * Provider's name class name.
44 *
45 * @since 4.4.0
46 *
47 * @var string
48 */
49 protected $class = __CLASS__;
50
51 /**
52 * Provider's title.
53 *
54 * @since 4.4.0
55 *
56 * @var string
57 */
58 protected $title = 'Mailster';
59
60 /**
61 * Whether there can be multiple global instances.
62 *
63 * @since 4.4.0
64 *
65 * @var string
66 */
67 protected $is_multi_on_global = false;
68
69 /**
70 * Set of options that must be set in order to be connected.
71 *
72 * @since 4.4.0
73 *
74 * @var array
75 */
76 protected $completion_options = array( 'active' );
77
78 /**
79 * Class name of form settings.
80 *
81 * @since 4.4.0
82 *
83 * @var string
84 */
85 protected $form_settings = 'Hustle_Mailster_Form_Settings';
86
87 /**
88 * Class name of form hooks
89 *
90 * @since 4.4.0
91 * @var string
92 */
93 protected $form_hooks = 'Hustle_Mailster_Form_Hooks';
94
95 /**
96 * Get Instance
97 *
98 * @return self|null
99 */
100 public static function get_instance() {
101 if ( is_null( self::$instance ) ) {
102 self::$instance = new self();
103 }
104
105 return self::$instance;
106 }
107
108 /**
109 * Provider constructor.
110 */
111 public function __construct() {
112 $this->icon_2x = plugin_dir_url( __FILE__ ) . 'images/icon.png';
113 $this->logo_2x = plugin_dir_url( __FILE__ ) . 'images/logo.png';
114 }
115
116 /**
117 * Checks whether Mailster is active.
118 *
119 * @since 4.4.0
120 *
121 * @return boolean
122 */
123 private function is_plugin_active() {
124 return function_exists( 'mailster' );
125 }
126
127 /**
128 * Checks if the settings are completed.
129 *
130 * @since 4.4.0
131 *
132 * @param string $multi_id Multi-integration ID, if any.
133 * @return boolean
134 */
135 protected function settings_are_completed( $multi_id = '' ) {
136 return $this->is_plugin_active();
137 }
138
139 /**
140 * Get the wizard callbacks for the global settings.
141 *
142 * @since 4.4.0
143 *
144 * @return array
145 */
146 public function settings_wizards() {
147 return array(
148 array(
149 'callback' => array( $this, 'configure' ),
150 'is_completed' => array( $this, 'settings_are_completed' ),
151 ),
152 );
153 }
154
155 /**
156 * Configure the API key settings. Global settings.
157 *
158 * @since 4.4.0
159 *
160 * @param array $submitted_data The data submitted.
161 * @param bool $is_submit Whether the current request is a submission.
162 *
163 * @return array
164 */
165 public function configure( $submitted_data, $is_submit ) {
166 $has_errors = false;
167 $active = $this->is_connected();
168
169 if ( $is_submit ) {
170
171 $active = ! empty( $submitted_data['active'] );
172 // If not active, activate it.
173 if ( ! Hustle_Provider_Utils::is_provider_active( $this->slug ) ) {
174
175 // TODO: Wrap this in a friendlier method.
176 $activated = Hustle_Providers::get_instance()->activate_addon( $this->slug );
177 if ( ! $activated ) {
178 $error_message = esc_html( $this->provider_connection_falied() );
179 $has_errors = true;
180 } else {
181 $this->save_settings_values( array( 'active' => $active ) );
182 }
183 } else {
184 $this->save_settings_values( array( 'active' => $active ) );
185 }
186
187 if ( ! $has_errors ) {
188
189 return array(
190 'html' => Hustle_Provider_Utils::get_integration_modal_title_markup( __( 'Mailster Added', 'hustle' ), __( 'You can now go to your pop-ups, slide-ins and embeds and assign them to this integration', 'hustle' ) ),
191 'buttons' => array(
192 'close' => array(
193 'markup' => Hustle_Provider_Utils::get_provider_button_markup( __( 'Close', 'hustle' ), 'sui-button-ghost sui-button-center', 'close' ),
194 ),
195 ),
196 'redirect' => false,
197 'has_errors' => false,
198 'notification' => array(
199 'type' => 'success',
200 'text' => '<strong>' . $this->get_title() . '</strong> ' . esc_html__( 'successfully connected', 'hustle' ),
201 ),
202 );
203
204 }
205 }
206
207 $options = array(
208 array(
209 'type' => 'hidden',
210 'name' => 'active',
211 'value' => 1,
212 ),
213 );
214
215 $step_html = Hustle_Provider_Utils::get_integration_modal_title_markup(
216 __( 'Connect Mailster', 'hustle' ),
217 __( 'Mailster lets you create, manage, and send email newsletter campaings from within your WordPress site.', 'hustle' )
218 );
219
220 if ( ! $this->is_plugin_active() ) {
221 $has_errors = true;
222 $error_message = sprintf(
223 /* translators: 1. opening 'a' tag to the Mailster's wp page, 2. closing 'a' tag, 3. opening 'b' tag, 4. closing 'b' tag */
224 esc_html__( 'This integration requires the %1$sMailster Newsletter Plugin%2$s, %3$sversion 2.2%4$s or newer. Install and activate it and try again.', 'hustle' ),
225 '<a href="https://mailster.co/" target="_blank">',
226 '</a>',
227 '<b>',
228 '</b>'
229 );
230
231 $error_notice = array(
232 'type' => 'notice',
233 'icon' => 'info',
234 'class' => 'sui-notice-error',
235 'value' => $error_message,
236 );
237 array_unshift( $options, $error_notice );
238 }
239
240 $step_html .= Hustle_Provider_Utils::get_html_for_options( $options );
241
242 if ( ! $this->is_plugin_active() ) {
243 $buttons = array(
244 'close' => array(
245 'markup' => Hustle_Provider_Utils::get_provider_button_markup( __( 'Close', 'hustle' ), 'sui-button-ghost sui-button-center', 'close' ),
246 ),
247 );
248 } elseif ( $this->is_connected() ) {
249 $buttons = array(
250 'disconnect' => array(
251 'markup' => Hustle_Provider_Utils::get_provider_button_markup(
252 __( 'Disconnect', 'hustle' ),
253 'sui-button-ghost sui-button-center',
254 'disconnect',
255 true
256 ),
257 ),
258 );
259 } else {
260 $buttons = array(
261 'connect' => array(
262 'markup' => Hustle_Provider_Utils::get_provider_button_markup(
263 __( 'Activate', 'hustle' ),
264 'sui-button-center',
265 'connect',
266 true
267 ),
268 ),
269 );
270
271 }
272
273 $response = array(
274 'html' => $step_html,
275 'buttons' => $buttons,
276 'has_errors' => $has_errors,
277 );
278
279 return $response;
280 }
281 }
282