PluginProbe ʕ •ᴥ•ʔ
Hustle – Email Marketing, Lead Generation, Optins, Popups / 7.3.7
Hustle – Email Marketing, Lead Generation, Optins, Popups v7.3.7
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 / class-hustle-settings-admin.php
wordpress-popup / inc Last commit date
display-conditions 5 years ago front 5 years ago helpers 5 years ago metas 5 years ago palettes 5 years ago provider 5 years ago providers 5 years ago templates 5 years ago update 5 years ago class-hustle-admin-page-abstract.php 5 years ago class-hustle-condition-factory.php 6 years ago class-hustle-dashboard-admin.php 5 years ago class-hustle-data.php 5 years ago class-hustle-db.php 6 years ago class-hustle-module-admin.php 5 years ago class-hustle-module-collection.php 5 years ago class-hustle-module-decorator.php 5 years ago class-hustle-module-page-abstract.php 5 years ago class-hustle-notifications.php 5 years ago class-hustle-settings-admin.php 5 years ago class-hustle-upsell-page.php 5 years ago class-hustle-wp-dashboard-page.php 5 years ago hustle-collection.php 6 years ago hustle-deletion.php 5 years ago hustle-embedded-admin.php 6 years ago hustle-entries-admin.php 5 years ago hustle-entry-model.php 5 years ago hustle-general-data-protection.php 6 years ago hustle-init.php 5 years ago hustle-mail.php 5 years ago hustle-meta.php 5 years ago hustle-migration.php 5 years ago hustle-model.php 5 years ago hustle-module-model.php 5 years ago hustle-module-widget-legacy.php 5 years ago hustle-module-widget.php 5 years ago hustle-modules-common-admin-ajax.php 5 years ago hustle-popup-admin.php 6 years ago hustle-providers-admin.php 5 years ago hustle-providers.php 6 years ago hustle-settings-admin-ajax.php 5 years ago hustle-settings-page.php 5 years ago hustle-slidein-admin.php 6 years ago hustle-sshare-admin.php 5 years ago hustle-sshare-model.php 5 years ago hustle-tracking-model.php 5 years ago opt-in-geo.php 5 years ago opt-in-utils.php 5 years ago opt-in-wpmudev-api.php 6 years ago
class-hustle-settings-admin.php
532 lines
1 <?php
2 /**
3 * File for Hustle_Settings_Admin class.
4 *
5 * @package Hustle
6 * @since unknown
7 */
8
9 /**
10 * Class Hustle_Settings_Admin.
11 * Handles saving and retrieving Hustle's global settings.
12 */
13 class Hustle_Settings_Admin {
14
15 /**
16 * Key of the Hustle's settings in wp_options.
17 *
18 * @since 4.0.0
19 */
20 const SETTINGS_OPTION_KEY = 'hustle_settings';
21
22 /**
23 * Gets the saved or default global unsubscription messages.
24 *
25 * @since 3.0.5
26 * @return array
27 */
28 public static function get_unsubscribe_messages() {
29
30 $settings = self::get_hustle_settings( 'unsubscribe' );
31
32 // Default unsubscription messages.
33 $default = array(
34 'enabled' => '0',
35 'get_lists_button_text' => __( 'Get Lists', 'hustle' ),
36 'submit_button_text' => __( 'Unsubscribe!', 'hustle' ),
37 'invalid_email' => __( 'Please enter a valid email address.', 'hustle' ),
38 'email_not_found' => __( "Looks like you're not in our list!", 'hustle' ),
39 'invalid_data' => __( "The unsubscription data doesn't seem to be correct.", 'hustle' ),
40 'email_submitted' => __( 'Please check your email to confirm your unsubscription.', 'hustle' ),
41 'successful_unsubscription' => __( "You've been successfully unsubscribed.", 'hustle' ),
42 'email_not_processed' => __( 'Something went wrong submitting the email. Please make sure a list is selected, and your install is able to send emails.', 'hustle' ),
43 );
44
45 $messages = $default;
46
47 // Use customized unsubscribe messages if they're set, and if it's enabled (for frontend), or is_admin() (for settings page).
48 if ( ! empty( $settings['messages'] ) ) {
49
50 $saved_messages = $settings['messages'];
51 if ( is_string( $saved_messages ) ) {
52 $saved_messages = json_decode( $saved_messages );
53 }
54
55 if ( is_admin() || '0' !== (string) $saved_messages['enabled'] ) {
56 $messages = stripslashes_deep( array_merge( $default, $saved_messages ) );
57 }
58 }
59
60 return apply_filters( 'hustle_get_unsubscribe_messages', $messages );
61 }
62
63 /**
64 * Gets the saved or default global unsubscription email settings.
65 *
66 * @since 3.0.5
67 * @return array
68 */
69 public static function get_unsubscribe_email_settings() {
70
71 $default_email_body = sprintf(
72 /* translators: 1: opening 'p' tag, 2: closing 'p' tag, 3: 'br' tag, 4: link to the unsubscribe url */
73 esc_html__(
74 '%1$sHi%2$s
75 %1$sWe\'re sorry to see you go!%2$s
76 %1$sClick on the link below to unsubscribe:%3$s
77 %4$s%2$s',
78 'hustle'
79 ),
80 '<p>',
81 '</p>',
82 '<br />',
83 '<a href="{hustle_unsubscribe_link}" target="_blank">{hustle_unsubscribe_link}</a>'
84 );
85
86 $default_email_settings = array(
87 'enabled' => '0',
88 'email_subject' => __( 'Unsubscribe', 'hustle' ),
89 'email_body' => $default_email_body,
90 );
91
92 $settings = self::get_hustle_settings( 'unsubscribe' );
93
94 // Use customized unsubscribe email messages if they're set, and if it's enabled (for frontend), or is_admin() (for settings page).
95 $saved_settings = isset( $settings['email'] ) && ( ( isset( $settings['email']['enabled'] ) && '0' !== (string) $settings['email']['enabled'] ) || is_admin() ) ?
96 $settings['email'] : array();
97
98 $stored_email_settings = array();
99 if ( ! empty( $saved_settings ) ) {
100 $saved_settings['email_body'] = isset( $saved_settings['email_body'] ) ? json_decode( $saved_settings['email_body'] ) : '';
101 $stored_email_settings = stripslashes_deep( $saved_settings );
102 }
103
104 $email_settings = array_merge( $default_email_settings, $stored_email_settings );
105
106 return apply_filters( 'hustle_get_unsubscribe_email', $email_settings );
107 }
108
109 /**
110 * Get pagination limit
111 *
112 * @since 4.0.3
113 *
114 * @param string $type module|submission Pagination limit type.
115 * @return int
116 */
117 public static function get_per_page( $type ) {
118 $general_settings = self::get_general_settings();
119 $limit = isset( $general_settings[ $type . '_pagination' ] ) ? (int) $general_settings[ $type . '_pagination' ] : 0;
120 if ( 1 > $limit ) {
121 $limit = 1;
122 }
123
124 return $limit;
125 }
126
127 /**
128 * Gets the saved or default global general settings.
129 *
130 * @since 4.0.3
131 * @return array
132 */
133 public static function get_general_settings() {
134
135 $default_settings = array(
136 'module_pagination' => 10,
137 'submission_pagination' => 10,
138 'sender_email_name' => get_bloginfo( 'name' ),
139 'sender_email_address' => get_option( 'admin_email', '' ),
140 'mobile_breakpoint' => 782,
141 'published_popup_on_dashboard' => '1',
142 'draft_popup_on_dashboard' => '1',
143 'published_slidein_on_dashboard' => '1',
144 'draft_slidein_on_dashboard' => '1',
145 'published_embedded_on_dashboard' => '1',
146 'draft_embedded_on_dashboard' => '1',
147 'debug_enabled' => '0',
148 // Dashboard settings.
149 'popup_on_dashboard' => 5,
150 'published_popup_on_dashboard' => '1',
151 'draft_popup_on_dashboard' => '1',
152 'slidein_on_dashboard' => 5,
153 'published_slidein_on_dashboard' => '1',
154 'draft_slidein_on_dashboard' => '1',
155 'social_sharing_on_dashboard' => 5,
156 'published_social_sharing_on_dashboard' => '1',
157 'draft_social_sharing_on_dashboard' => '1',
158 'embedded_on_dashboard' => 5,
159 'published_embedded_on_dashboard' => '1',
160 'draft_embedded_on_dashboard' => '1',
161 );
162
163 $general_settings = $default_settings;
164 $saved_settings = self::get_hustle_settings( 'general' );
165
166 // If we have settings already stored in "general".
167 if ( ! empty( $saved_settings ) ) {
168 $saved_settings = array_filter( $saved_settings, 'strlen' );
169
170 /**
171 * Email sender name and address were stored somewhere else before 4.0.3.
172 * Retrieve it from the old location if missing in the new one.
173 */
174 if ( empty( $saved_settings['sender_email_name'] ) || empty( $saved_settings['sender_email_address'] ) ) {
175
176 $old_emails_settings = self::get_hustle_settings( 'emails' );
177
178 if ( empty( $saved_settings['sender_email_name'] ) && ! empty( $old_emails_settings['sender_email_name'] ) ) {
179 $saved_settings['sender_email_name'] = $old_emails_settings['sender_email_name'];
180 }
181
182 if ( empty( $saved_settings['sender_email_address'] ) && ! empty( $old_emails_settings['sender_email_address'] ) ) {
183 $saved_settings['sender_email_address'] = $old_emails_settings['sender_email_address'];
184 }
185 }
186
187 $general_settings = array_merge( $default_settings, $saved_settings );
188
189 } else {
190
191 // When upgrading, we might not have anything in "general" but still have "emails" stored in its old location.
192 $old_emails_settings = self::get_hustle_settings( 'emails' );
193
194 if ( ! empty( $old_emails_settings ) ) {
195
196 $saved_settings = array();
197
198 if ( ! empty( $old_emails_settings['sender_email_name'] ) ) {
199 $saved_settings['sender_email_name'] = $old_emails_settings['sender_email_name'];
200 }
201
202 if ( ! empty( $old_emails_settings['sender_email_address'] ) ) {
203 $saved_settings['sender_email_address'] = $old_emails_settings['sender_email_address'];
204 }
205
206 $general_settings = array_merge( $default_settings, $saved_settings );
207 }
208 }
209
210 return apply_filters( 'hustle_get_general_settings', $general_settings );
211 }
212
213 /**
214 * Get the 'permissions' settings.
215 *
216 * @since 4.0.4
217 * @return array
218 */
219 public static function get_permissions_settings() {
220
221 $defaults = array(
222 'create' => array(),
223 'edit_integrations' => array(),
224 'access_emails' => array(),
225 'edit_settings' => array(),
226 );
227
228 $settings = self::get_hustle_settings( 'permissions' );
229
230 foreach ( $defaults as $permission => $roles ) {
231 if ( empty( $settings[ $permission ] ) ) {
232 $settings[ $permission ] = Opt_In_Utils::get_admin_roles();
233 }
234 }
235
236 return apply_filters( 'hustle_get_permissions_settings', $settings );
237 }
238
239 /**
240 * Gets the saved or default global reCaptcha settings.
241 *
242 * @since 3.0.5
243 * @return array
244 */
245 public static function get_recaptcha_settings() {
246
247 $default = array(
248 // V2 Checkbox.
249 'v2_checkbox_site_key' => '',
250 'v2_checkbox_secret_key' => '',
251 // V2 Invisible.
252 'v2_invisible_site_key' => '',
253 'v2_invisible_secret_key' => '',
254 // V3 Recaptcha.
255 'v3_recaptcha_site_key' => '',
256 'v3_recaptcha_secret_key' => '',
257 'language' => 'automatic',
258 );
259
260 $recaptcha_settings = $default;
261 $saved_settings = self::get_hustle_settings( 'recaptcha' );
262
263 // Use the standard 4.0.2 recapatcha keys (v2 recaptchas) with the new 4.0.3 keys if not set.
264 if ( ! isset( $saved_settings['v2_checkbox_site_key'] ) && ! empty( $saved_settings['sitekey'] ) ) {
265 $saved_settings['v2_checkbox_site_key'] = $saved_settings['sitekey'];
266 }
267 if ( ! isset( $saved_settings['v2_checkbox_secret_key'] ) && ! empty( $saved_settings['secret'] ) ) {
268 $saved_settings['v2_checkbox_secret_key'] = $saved_settings['secret'];
269 }
270
271 if ( ! empty( $saved_settings ) ) {
272 $recaptcha_settings = array_merge( $default, $saved_settings );
273 }
274
275 return apply_filters( 'hustle_get_recaptcha_settings', $recaptcha_settings );
276 }
277
278 /**
279 * Get the recaptcha versions that are available to be used.
280 *
281 * @since 4.0.3
282 * @return array
283 */
284 public static function get_available_recaptcha_versions() {
285
286 $available_recaptchas = array();
287 $settings = self::get_recaptcha_settings();
288 $recaptcha_versions = array(
289 'v2_checkbox',
290 'v2_invisible',
291 'v3_recaptcha',
292 );
293
294 foreach ( $recaptcha_versions as $version ) {
295
296 // If this versions has the Site key and Secret key stored, it's available to use.
297 if ( ! empty( $settings[ $version . '_site_key' ] ) && ! empty( $settings[ $version . '_secret_key' ] ) ) {
298 $available_recaptchas[] = $version;
299 }
300 }
301
302 return $available_recaptchas;
303 }
304
305 /**
306 * Get the settings of the top metrics.
307 *
308 * @since 4.0.2
309 * @return array
310 */
311 public static function get_top_metrics_settings() {
312
313 $defaults = array( 'average_conversion_rate', 'total_conversions', 'most_conversions' );
314 $stored_settings = self::get_hustle_settings( 'top_metrics' );
315
316 // Use defaults if empty.
317 if ( empty( $stored_settings ) ) {
318 $stored_settings = $defaults;
319 }
320
321 return $stored_settings;
322 }
323
324 /**
325 * Get the stored dashboard analytics settings.
326 *
327 * @since 4.1.0
328 * @return array
329 */
330 public static function get_dashboard_analytics_settings() {
331
332 $defaults = array(
333 'title' => '',
334 'role' => array(),
335 'enabled' => '0',
336 'modules' => array(),
337 );
338
339 $stored_settings = self::get_hustle_settings( 'analytics' );
340
341 // If the stored settings' role is empty, use the default one.
342 if ( empty( $stored_settings['role'] ) ) {
343 $defaults['role'] = Opt_In_Utils::get_admin_roles();
344
345 unset( $stored_settings['role'] );
346 }
347
348 $dashboard_analytics_settings = array_merge( $defaults, $stored_settings );
349
350 return apply_filters( 'hustle_get_dashboard_analytics_settings', $dashboard_analytics_settings );
351 }
352
353 /**
354 * Get privacy settings.
355 *
356 * @since 4.0.2
357 * @return array
358 */
359 public static function get_privacy_settings() {
360 $defaults = array(
361 'ip_tracking' => 'on',
362 'retain_sub_on_erasure' => '1',
363
364 'retain_submission_forever' => '1',
365 'submissions_retention_number' => 30,
366 'submissions_retention_number_unit' => 'days',
367
368 'retain_ip_forever' => '1',
369 'ip_retention_number' => 30,
370 'ip_retention_number_unit' => 'days',
371
372 'retain_tracking_forever' => '1',
373 'tracking_retention_number' => 30,
374 'tracking_retention_number_unit' => 'days',
375 );
376
377 $stored = self::get_hustle_settings( 'privacy' );
378
379 $settings = array_merge( $defaults, $stored );
380
381 return apply_filters( 'hustle_get_privacy_settings', $settings );
382 }
383
384 /**
385 * Get the values of the Data settings.
386 *
387 * @since 4.0.2
388 * @return array
389 */
390 public static function get_data_settings() {
391 $default = array(
392 'reset_settings_uninstall' => '0',
393 );
394
395 $stored = self::get_hustle_settings( 'data' );
396
397 $settings = array_merge( $default, $stored );
398
399 return apply_filters( 'hustle_get_data_settings', $settings );
400 }
401
402 /**
403 * Get settings
404 *
405 * @since 4.0.0
406 *
407 * @param string $key Key from settings, can be null, then whole * settings is returned.
408 */
409 public static function get_hustle_settings( $key = null ) {
410
411 $settings = get_option( self::SETTINGS_OPTION_KEY, array() );
412
413 if ( ! empty( $key ) ) {
414
415 if ( isset( $settings[ $key ] ) ) {
416
417 $specific_setting = $settings[ $key ];
418
419 if ( ! is_array( $specific_setting ) ) {
420 $specific_setting = json_decode( $specific_setting, true );
421 }
422
423 return $specific_setting;
424 }
425
426 return array();
427 }
428
429 return $settings;
430 }
431
432 /**
433 * Update Hustle Settings
434 *
435 * @since 4.0.0
436 * @param mixed $value Value to store.
437 * @param string $key Key from settings, can be null, then whole settings will be saved.
438 */
439 public static function update_hustle_settings( $value, $key = null ) {
440 if ( empty( $key ) ) {
441 return;
442 }
443
444 if ( 'all' === $key ) {
445 update_option( self::SETTINGS_OPTION_KEY, $value );
446 return;
447 }
448 $settings = self::get_hustle_settings();
449 $settings[ $key ] = $value;
450 update_option( self::SETTINGS_OPTION_KEY, $settings );
451 }
452
453 /**
454 * Delete an existing custom palette.
455 *
456 * @since 4.0.3
457 *
458 * @param string $palette_id ID of the palette to be deleted.
459 */
460 public static function delete_custom_palette( $palette_id ) {
461
462 $name = false;
463 $stored_palettes = self::get_custom_color_palettes();
464
465 if ( isset( $stored_palettes[ $palette_id ] ) ) {
466
467 $name = $stored_palettes[ $palette_id ]['name'];
468 unset( $stored_palettes[ $palette_id ] );
469 update_option( 'hustle_custom_palettes', $stored_palettes );
470 }
471
472 return $name;
473 }
474
475 /**
476 * Do the actual saving of a custom palette.
477 * The passed array should be like:
478 * array(
479 * 'slug' => { string }, // Required when updating an existing palette. Omit it when creating a new one.
480 * 'name' => { string }, // The display name. Can be omitted when updating an existing one.
481 * 'palette' => { array() } // The actual palette's colors
482 * )
483 *
484 * @since 4.0.3
485 * @param array $palette_data Data of the palette to be saved.
486 * @return string
487 */
488 public static function save_custom_palette( $palette_data ) {
489
490 $stored_palettes = self::get_custom_color_palettes();
491
492 if ( isset( $palette_data['slug'] ) && isset( $stored_palettes[ $palette_data['slug'] ] ) ) {
493
494 // Update existing palette.
495 $id = $palette_data['slug'];
496 $palette_data = array_merge( $stored_palettes[ $id ], $palette_data );
497
498 } else {
499 // Create new palette.
500 $id = uniqid( '', true );
501
502 // Change the id until it's unique.
503 while ( isset( $stored_palettes[ $id ] ) ) {
504 $id = uniqid( '', true );
505 }
506
507 $palette_data['slug'] = $id;
508 }
509
510 $stored_palettes[ $id ] = $palette_data;
511
512 update_option( 'hustle_custom_palettes', $stored_palettes );
513
514 return $id;
515 }
516
517 /**
518 * Get the stored custom color palettes.
519 *
520 * @since 4.0.3
521 *
522 * @return array
523 */
524 public static function get_custom_color_palettes() {
525
526 $custom_palettes = get_option( 'hustle_custom_palettes', array() );
527
528 return apply_filters( 'hustle_get_custom_color_palettes', $custom_palettes );
529 }
530
531 }
532