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