PluginProbe ʕ •ᴥ•ʔ
Hustle – Email Marketing, Lead Generation, Optins, Popups / 7.8.9
Hustle – Email Marketing, Lead Generation, Optins, Popups v7.8.9
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 3 years ago front 9 months ago helpers 9 months ago metas 3 years ago multisite 3 years ago palettes 3 years ago provider 3 years ago providers 9 months ago templates 3 years ago update 3 years ago class-hustle-admin-page-abstract.php 9 months ago class-hustle-black-friday-campaign.php 7 months ago class-hustle-condition-factory.php 6 years ago class-hustle-cross-sell.php 9 months ago class-hustle-dashboard-admin.php 3 years ago class-hustle-data.php 3 years 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 9 months ago class-hustle-module-collection.php 3 years ago class-hustle-module-page-abstract.php 2 years ago class-hustle-notifications.php 3 years ago class-hustle-settings-admin.php 3 years ago class-hustle-tutorials-page.php 4 years ago class-hustle-wp-dashboard-page.php 3 years ago hustle-deletion.php 3 years ago hustle-embedded-admin.php 3 years ago hustle-entries-admin.php 3 years ago hustle-entry-model.php 3 years ago hustle-general-data-protection.php 3 years ago hustle-init.php 7 months ago hustle-mail.php 3 years ago hustle-migration.php 3 years ago hustle-model.php 3 years ago hustle-module-model.php 9 months ago hustle-module-widget-legacy.php 3 years ago hustle-module-widget.php 3 years ago hustle-modules-common-admin-ajax.php 9 months ago hustle-popup-admin.php 3 years ago hustle-providers-admin.php 3 years ago hustle-providers.php 3 years ago hustle-settings-admin-ajax.php 3 years ago hustle-settings-page.php 3 years ago hustle-slidein-admin.php 3 years ago hustle-sshare-admin.php 3 years ago hustle-sshare-model.php 3 years ago hustle-tracking-model.php 3 years ago opt-in-geo.php 9 months ago opt-in-utils.php 3 years ago opt-in-wpmudev-api.php 3 years ago
class-hustle-settings-admin.php
587 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 'published_popup_on_dashboard' => '1',
171 'draft_popup_on_dashboard' => '1',
172 'published_slidein_on_dashboard' => '1',
173 'draft_slidein_on_dashboard' => '1',
174 'published_embedded_on_dashboard' => '1',
175 'draft_embedded_on_dashboard' => '1',
176 'global_tracking_disabled' => '0',
177 'debug_enabled' => '0',
178 // Dashboard settings.
179 'popup_on_dashboard' => 5,
180 'published_popup_on_dashboard' => '1',
181 'draft_popup_on_dashboard' => '1',
182 'slidein_on_dashboard' => 5,
183 'published_slidein_on_dashboard' => '1',
184 'draft_slidein_on_dashboard' => '1',
185 'social_sharing_on_dashboard' => 5,
186 'published_social_sharing_on_dashboard' => '1',
187 'draft_social_sharing_on_dashboard' => '1',
188 'embedded_on_dashboard' => 5,
189 'published_embedded_on_dashboard' => '1',
190 'draft_embedded_on_dashboard' => '1',
191 );
192
193 $general_settings = $default_settings;
194 $saved_settings = self::get_hustle_settings( 'general' );
195
196 // If we have settings already stored in "general".
197 if ( ! empty( $saved_settings ) ) {
198 $saved_settings = array_filter( $saved_settings, 'strlen' );
199
200 /**
201 * Email sender name and address were stored somewhere else before 4.0.3.
202 * Retrieve it from the old location if missing in the new one.
203 */
204 if ( empty( $saved_settings['sender_email_name'] ) || empty( $saved_settings['sender_email_address'] ) ) {
205
206 $old_emails_settings = self::get_hustle_settings( 'emails' );
207
208 if ( empty( $saved_settings['sender_email_name'] ) && ! empty( $old_emails_settings['sender_email_name'] ) ) {
209 $saved_settings['sender_email_name'] = $old_emails_settings['sender_email_name'];
210 }
211
212 if ( empty( $saved_settings['sender_email_address'] ) && ! empty( $old_emails_settings['sender_email_address'] ) ) {
213 $saved_settings['sender_email_address'] = $old_emails_settings['sender_email_address'];
214 }
215 }
216
217 $general_settings = array_merge( $default_settings, $saved_settings );
218
219 } else {
220
221 // When upgrading, we might not have anything in "general" but still have "emails" stored in its old location.
222 $old_emails_settings = self::get_hustle_settings( 'emails' );
223
224 if ( ! empty( $old_emails_settings ) ) {
225
226 $saved_settings = array();
227
228 if ( ! empty( $old_emails_settings['sender_email_name'] ) ) {
229 $saved_settings['sender_email_name'] = $old_emails_settings['sender_email_name'];
230 }
231
232 if ( ! empty( $old_emails_settings['sender_email_address'] ) ) {
233 $saved_settings['sender_email_address'] = $old_emails_settings['sender_email_address'];
234 }
235
236 $general_settings = array_merge( $default_settings, $saved_settings );
237 }
238 }
239
240 self::$settings = apply_filters( 'hustle_get_general_settings', $general_settings );
241
242 return self::$settings;
243 }
244
245 /**
246 * Is global tracking enabled or not
247 *
248 * @return bool
249 */
250 public static function global_tracking() {
251 if ( is_null( self::$global_tracking ) ) {
252 $stored_settings = self::get_general_settings();
253 $global_tracking = '1' !== $stored_settings['global_tracking_disabled'];
254 $global_tracking = apply_filters( 'hustle_global_tracking', $global_tracking );
255 self::$global_tracking = $global_tracking;
256 }
257
258 return self::$global_tracking;
259 }
260
261 /**
262 * Get the 'permissions' settings.
263 *
264 * @since 4.0.4
265 * @return array
266 */
267 public static function get_permissions_settings() {
268
269 $defaults = array(
270 'create' => array(),
271 'edit_integrations' => array(),
272 'access_emails' => array(),
273 'edit_settings' => array(),
274 );
275
276 $settings = self::get_hustle_settings( 'permissions' );
277
278 foreach ( $defaults as $permission => $roles ) {
279 if ( empty( $settings[ $permission ] ) ) {
280 $settings[ $permission ] = Opt_In_Utils::get_admin_roles();
281 }
282 }
283
284 return apply_filters( 'hustle_get_permissions_settings', $settings );
285 }
286
287 /**
288 * Gets the saved or default global reCaptcha settings.
289 *
290 * @since 3.0.5
291 * @return array
292 */
293 public static function get_recaptcha_settings() {
294
295 $default = array(
296 // V2 Checkbox.
297 'v2_checkbox_site_key' => '',
298 'v2_checkbox_secret_key' => '',
299 // V2 Invisible.
300 'v2_invisible_site_key' => '',
301 'v2_invisible_secret_key' => '',
302 // V3 Recaptcha.
303 'v3_recaptcha_site_key' => '',
304 'v3_recaptcha_secret_key' => '',
305 'language' => 'automatic',
306 );
307
308 $recaptcha_settings = $default;
309 $saved_settings = self::get_hustle_settings( 'recaptcha' );
310
311 // Use the standard 4.0.2 recapatcha keys (v2 recaptchas) with the new 4.0.3 keys if not set.
312 if ( ! isset( $saved_settings['v2_checkbox_site_key'] ) && ! empty( $saved_settings['sitekey'] ) ) {
313 $saved_settings['v2_checkbox_site_key'] = $saved_settings['sitekey'];
314 }
315 if ( ! isset( $saved_settings['v2_checkbox_secret_key'] ) && ! empty( $saved_settings['secret'] ) ) {
316 $saved_settings['v2_checkbox_secret_key'] = $saved_settings['secret'];
317 }
318
319 if ( ! empty( $saved_settings ) ) {
320 $recaptcha_settings = array_merge( $default, $saved_settings );
321 }
322
323 return apply_filters( 'hustle_get_recaptcha_settings', $recaptcha_settings );
324 }
325
326 /**
327 * Get the recaptcha versions that are available to be used.
328 *
329 * @since 4.0.3
330 * @return array
331 */
332 public static function get_available_recaptcha_versions() {
333
334 $available_recaptchas = array();
335 $settings = self::get_recaptcha_settings();
336 $recaptcha_versions = array(
337 'v2_checkbox',
338 'v2_invisible',
339 'v3_recaptcha',
340 );
341
342 foreach ( $recaptcha_versions as $version ) {
343
344 // If this versions has the Site key and Secret key stored, it's available to use.
345 if ( ! empty( $settings[ $version . '_site_key' ] ) && ! empty( $settings[ $version . '_secret_key' ] ) ) {
346 $available_recaptchas[] = $version;
347 }
348 }
349
350 return $available_recaptchas;
351 }
352
353 /**
354 * Get the settings of the top metrics.
355 *
356 * @since 4.0.2
357 * @return array
358 */
359 public static function get_top_metrics_settings() {
360
361 $defaults = array( 'average_conversion_rate', 'total_conversions', 'most_conversions' );
362 $stored_settings = self::get_hustle_settings( 'top_metrics' );
363
364 // Use defaults if empty.
365 if ( empty( $stored_settings ) ) {
366 $stored_settings = $defaults;
367 }
368
369 return $stored_settings;
370 }
371
372 /**
373 * Get the stored dashboard analytics settings.
374 *
375 * @since 4.1.0
376 * @return array
377 */
378 public static function get_dashboard_analytics_settings() {
379
380 $defaults = array(
381 'title' => '',
382 'role' => array(),
383 'enabled' => '0',
384 'modules' => array(),
385 );
386
387 $stored_settings = self::get_hustle_settings( 'analytics' );
388
389 // If the stored settings' role is empty, use the default one.
390 if ( empty( $stored_settings['role'] ) ) {
391 $defaults['role'] = Opt_In_Utils::get_admin_roles();
392
393 unset( $stored_settings['role'] );
394 }
395
396 $dashboard_analytics_settings = array_merge( $defaults, $stored_settings );
397
398 return apply_filters( 'hustle_get_dashboard_analytics_settings', $dashboard_analytics_settings );
399 }
400
401 /**
402 * Get privacy settings.
403 *
404 * @since 4.0.2
405 * @return array
406 */
407 public static function get_privacy_settings() {
408 $defaults = array(
409 'ip_tracking' => 'on',
410 'retain_sub_on_erasure' => '1',
411
412 'retain_submission_forever' => '1',
413 'submissions_retention_number' => 30,
414 'submissions_retention_number_unit' => 'days',
415
416 'retain_ip_forever' => '1',
417 'ip_retention_number' => 30,
418 'ip_retention_number_unit' => 'days',
419
420 'retain_tracking_forever' => '1',
421 'tracking_retention_number' => 30,
422 'tracking_retention_number_unit' => 'days',
423 );
424
425 $stored = self::get_hustle_settings( 'privacy' );
426
427 $settings = array_merge( $defaults, $stored );
428
429 return apply_filters( 'hustle_get_privacy_settings', $settings );
430 }
431
432 /**
433 * Get the values of the Data settings.
434 *
435 * @since 4.0.2
436 * @return array
437 */
438 public static function get_data_settings() {
439 $default = array(
440 'reset_settings_uninstall' => '0',
441 );
442
443 $stored = self::get_hustle_settings( 'data' );
444
445 $settings = array_merge( $default, $stored );
446
447 return apply_filters( 'hustle_get_data_settings', $settings );
448 }
449
450 /**
451 * Get settings
452 *
453 * @since 4.0.0
454 *
455 * @param string $key Key from settings, can be null, then whole * settings is returned.
456 */
457 public static function get_hustle_settings( $key = null ) {
458
459 $settings = get_option( self::SETTINGS_OPTION_KEY, array() );
460
461 if ( ! empty( $key ) ) {
462
463 if ( isset( $settings[ $key ] ) ) {
464
465 $specific_setting = $settings[ $key ];
466
467 if ( ! is_array( $specific_setting ) ) {
468 $specific_setting = json_decode( $specific_setting, true );
469 }
470
471 return $specific_setting;
472 }
473
474 return array();
475 }
476
477 return $settings;
478 }
479
480 /**
481 * Update Hustle Settings
482 *
483 * @since 4.0.0
484 * @param mixed $value Value to store.
485 * @param string $key Key from settings, can be null, then whole settings will be saved.
486 */
487 public static function update_hustle_settings( $value, $key = null ) {
488 if ( empty( $key ) ) {
489 return;
490 }
491
492 if ( 'all' === $key ) {
493 update_option( self::SETTINGS_OPTION_KEY, $value, false );
494 return;
495 }
496 $settings = self::get_hustle_settings();
497 $settings[ $key ] = $value;
498 update_option( self::SETTINGS_OPTION_KEY, $settings, false );
499 }
500
501 /**
502 * Delete an existing custom palette.
503 *
504 * @since 4.0.3
505 *
506 * @param string $palette_id ID of the palette to be deleted.
507 */
508 public static function delete_custom_palette( $palette_id ) {
509
510 $name = false;
511 $stored_palettes = self::get_custom_color_palettes();
512
513 if ( isset( $stored_palettes[ $palette_id ] ) ) {
514
515 $name = $stored_palettes[ $palette_id ]['name'];
516 unset( $stored_palettes[ $palette_id ] );
517 update_option( 'hustle_custom_palettes', $stored_palettes, false );
518 }
519
520 return $name;
521 }
522
523 /**
524 * Do the actual saving of a custom palette.
525 * The passed array should be like:
526 * array(
527 * 'slug' => { string }, // Required when updating an existing palette. Omit it when creating a new one.
528 * 'name' => { string }, // The display name. Can be omitted when updating an existing one.
529 * 'palette' => { array() } // The actual palette's colors
530 * )
531 *
532 * @since 4.0.3
533 * @param array $palette_data Data of the palette to be saved.
534 * @return string
535 */
536 public static function save_custom_palette( $palette_data ) {
537
538 $stored_palettes = self::get_custom_color_palettes();
539
540 if ( isset( $palette_data['slug'] ) && isset( $stored_palettes[ $palette_data['slug'] ] ) ) {
541
542 // Update existing palette.
543 $id = $palette_data['slug'];
544 $palette_data = array_merge( $stored_palettes[ $id ], $palette_data );
545
546 } else {
547 // Create new palette.
548 $id = uniqid( '', true );
549
550 // Change the id until it's unique.
551 while ( isset( $stored_palettes[ $id ] ) ) {
552 $id = uniqid( '', true );
553 }
554
555 $palette_data['slug'] = $id;
556 }
557
558 $stored_palettes[ $id ] = $palette_data;
559
560 update_option( 'hustle_custom_palettes', $stored_palettes, false );
561
562 return $id;
563 }
564
565 /**
566 * Get the stored custom color palettes.
567 *
568 * @since 4.0.3
569 *
570 * @return array
571 */
572 public static function get_custom_color_palettes() {
573
574 $custom_palettes = get_option( 'hustle_custom_palettes', array() );
575
576 array_walk_recursive(
577 $custom_palettes,
578 function ( &$val ) {
579 $val = esc_attr( $val );
580 }
581 );
582
583 return apply_filters( 'hustle_get_custom_color_palettes', $custom_palettes );
584 }
585
586 }
587