PluginProbe ʕ •ᴥ•ʔ
Hustle – Email Marketing, Lead Generation, Optins, Popups / 7.8.14.2
Hustle – Email Marketing, Lead Generation, Optins, Popups v7.8.14.2
7.8.14.2 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 / opt-in-utils.php
wordpress-popup / inc Last commit date
display-conditions 6 days ago front 6 days ago helpers 6 days ago metas 6 days ago multisite 6 days ago palettes 6 days ago provider 6 days ago providers 6 days ago templates 6 days ago update 6 days ago class-hustle-admin-page-abstract.php 6 days ago class-hustle-auth-token.php 6 days ago class-hustle-condition-factory.php 6 days ago class-hustle-cross-sell.php 6 days ago class-hustle-dashboard-admin.php 6 days ago class-hustle-data.php 6 days ago class-hustle-db.php 6 days ago class-hustle-installer.php 6 days ago class-hustle-meta.php 6 days ago class-hustle-module-admin.php 6 days ago class-hustle-module-collection.php 6 days ago class-hustle-module-fields.php 6 days ago class-hustle-module-page-abstract.php 6 days ago class-hustle-module-validator.php 6 days ago class-hustle-notifications.php 6 days ago class-hustle-settings-admin.php 6 days ago class-hustle-wp-dashboard-page.php 6 days ago class-opt-in.php 6 days ago hustle-background-conversion-log.php 6 days ago hustle-deletion.php 6 days ago hustle-embedded-admin.php 6 days ago hustle-entries-admin.php 6 days ago hustle-entry-model.php 6 days ago hustle-general-data-protection.php 6 days ago hustle-init.php 6 days ago hustle-mail.php 6 days ago hustle-migration.php 6 days ago hustle-model.php 6 days ago hustle-module-model.php 6 days ago hustle-module-widget-legacy.php 6 days ago hustle-module-widget.php 6 days ago hustle-modules-common-admin-ajax.php 6 days ago hustle-popup-admin.php 6 days ago hustle-providers-admin.php 6 days ago hustle-providers.php 6 days ago hustle-settings-admin-ajax.php 6 days ago hustle-settings-page.php 6 days ago hustle-slidein-admin.php 6 days ago hustle-sshare-admin.php 6 days ago hustle-sshare-model.php 6 days ago hustle-tracking-model.php 6 days ago interface-hustle-auth-provider.php 6 days ago opt-in-geo.php 6 days ago opt-in-utils.php 6 days ago opt-in-wpmudev-api.php 6 days ago
opt-in-utils.php
1468 lines
1 <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2 /**
3 * Conditions utils
4 *
5 * @package Hustle
6 */
7
8 /**
9 * Class Opt_In_Utils
10 */
11 class Opt_In_Utils {
12
13 /**
14 * CPT
15 *
16 * @var array
17 */
18 private static $post_types;
19
20 /**
21 * Array of administrator roles
22 *
23 * @var array
24 */
25 private static $admin_roles;
26
27 /**
28 * Is static cache enabled
29 *
30 * @var boolean
31 */
32 private static $static_cache;
33
34 /**
35 * Plugin name according White Label option
36 * White Label -> WPMU DEV Plugin Labels
37 *
38 * @var string
39 */
40 private static $plugin_name;
41
42 /**
43 * Returns the referrer.
44 *
45 * @return string
46 */
47 public static function get_referrer() {
48 $referrer = '';
49
50 $po_method = filter_input( INPUT_POST, '_po_method_', FILTER_SANITIZE_SPECIAL_CHARS );
51 $is_ajax = ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ||
52 'raw' === $po_method;
53
54 $http_referer = filter_input( INPUT_SERVER, 'HTTP_REFERER', FILTER_SANITIZE_SPECIAL_CHARS );
55 if ( isset( $_REQUEST['thereferrer'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
56 $referrer = $_REQUEST['thereferrer'];// phpcs:ignore
57 } elseif ( ! $is_ajax && $http_referer ) {
58 // When doing Ajax request we NEVER use the HTTP_REFERER!
59 $referrer = $http_referer;
60 }
61
62 return esc_attr( $referrer );
63 }
64
65 /**
66 * Tests if the current referrer is one of the referers of the list.
67 * Current referrer has to be specified in the URL param "thereferer".
68 *
69 * @param array $source_list List of referers to check.
70 * @return bool
71 */
72 public static function test_referrer( $source_list ) {
73 $response = false;
74 if ( is_string( $source_list ) ) {
75 $source_list = preg_split( '/\r\n|\r|\n/', $source_list );
76 }
77 if ( ! is_array( $source_list ) ) {
78 return true;
79 }
80
81 $referrer = self::get_referrer();
82
83 if ( ! empty( $referrer ) ) {
84 foreach ( $source_list as $item ) {
85 $item = trim( $item );
86 $res = stripos( $referrer, $item ) || fnmatch( $item, $referrer );
87 if ( false !== $res ) {
88 $response = true;
89 break;
90 }
91 }
92 }
93
94 return $response;
95 }
96
97 /**
98 * Get the real page id or false
99 *
100 * @global object $wp_query WP_Query.
101 * @global WP_Post $post Post.
102 * @return int|boolean
103 */
104 public static function get_real_page_id() {
105 global $wp_query, $post;
106
107 $is_wc_shop = class_exists( 'woocommerce' ) && is_shop();
108 $is_posts_page = $wp_query->is_posts_page;
109
110 if ( ! $is_wc_shop && ! $is_posts_page && ( ! isset( $post ) || ! ( $post instanceof WP_Post ) || 'page' !== $post->post_type || ! is_page() ) ) {
111 return false;
112 }
113
114 if ( $is_wc_shop ) {
115 $page_id = wc_get_page_id( 'shop' );
116 } elseif ( $is_posts_page ) {
117 $page_id = get_option( 'page_for_posts' );
118 } else {
119 $page_id = $post->ID;
120 }
121
122 return $page_id;
123 }
124
125 /**
126 * Returns current actual url, the one seen on browser
127 *
128 * @param bool $with_protocol Whether to retrieve the URL with the protocol.
129 * @return string
130 */
131 public static function get_current_actual_url( $with_protocol = false ) {
132
133 if ( ! isset( $_SERVER['HTTP_HOST'] ) || ! isset( $_SERVER['REQUEST_URI'] ) ) {
134 return '';
135 }
136
137 $host = filter_var( wp_unslash( $_SERVER['HTTP_HOST'] ), FILTER_SANITIZE_URL );
138 $uri = filter_var( wp_unslash( $_SERVER['REQUEST_URI'] ), FILTER_SANITIZE_URL );
139
140 $url = $host . $uri;
141
142 if ( ! $with_protocol ) {
143 return $url;
144 }
145
146 return 'http' . ( isset( $_SERVER['HTTPS'] ) ? 's' : '' ) . '://' . $url;
147 }
148
149 /**
150 * Returns current url
151 * should only be called after plugins_loaded hook is fired
152 *
153 * @return string
154 */
155 public static function get_current_url() {
156 if ( ! did_action( 'plugins_loaded' ) ) {
157 new Exception( 'This method should only be called after plugins_loaded hook is fired' ); }
158
159 global $wp;
160 return add_query_arg( $wp->query_string, '', home_url( $wp->request ) );
161 }
162
163 /**
164 * Checks if user is allowed to perform the ajax actions
165 *
166 * @since 4.0
167 * @param array $capability Hustle capability.
168 * @param int $module_id Optional. Module id.
169 */
170 public static function is_user_allowed_ajax( $capability, $module_id = null ) {
171 if ( is_null( $module_id ) ) {
172 $allowed = current_user_can( $capability );
173 } else {
174 $allowed = self::is_user_allowed( $capability, $module_id );
175 }
176
177 if ( ! $allowed ) {
178 wp_send_json_error( esc_html__( 'Invalid request, you are not allowed to make this request', 'hustle' ) );
179 }
180 }
181
182 /**
183 * Check is it admin role or not
184 *
185 * @param string|array $role Role.
186 * @return bool
187 */
188 public static function is_admin_role( $role ) {
189 $admin_roles = array_keys( self::get_admin_roles() );
190
191 if ( ! is_array( $role ) ) {
192 return in_array( $role, $admin_roles, true );
193 }
194
195 return (bool) array_intersect( $role, $admin_roles );
196 }
197
198 /**
199 * Get admin role array
200 *
201 * @since 4.1.0
202 * @return array
203 */
204 public static function get_admin_roles() {
205
206 if ( is_null( self::$admin_roles ) ) {
207 $admins = array();
208 $all_roles = wp_roles();
209
210 if ( $all_roles->is_role( 'administrator' ) ) {
211 $admins['administrator'] = ucfirst( translate_user_role( 'administrator', 'hustle' ) );
212
213 } else {
214 foreach ( $all_roles->roles as $name => $data ) {
215 if ( ! empty( $data['capabilities']['manage_options'] ) && true === $data['capabilities']['manage_options'] ) {
216 $admins[ $name ] = $data['name'];
217 }
218 }
219 }
220
221 self::$admin_roles = apply_filters( 'hustle_get_admin_roles', $admins );
222 }
223
224 return self::$admin_roles;
225 }
226
227 /**
228 * Checks if user has the capability
229 *
230 * @since 4.0
231 * @param array $capability Hustle capability.
232 * @param int $module_id Optional. Module id.
233 * @return bool
234 */
235 public static function is_user_allowed( $capability, $module_id = null ) {
236
237 // Super admins can do everything.
238 if ( current_user_can( 'setup_network' ) ) {
239 return true;
240 }
241
242 $user = wp_get_current_user();
243 $current_user_caps = (array) $user->allcaps;
244 $current_user_roles = (array) $user->roles;
245
246 if ( self::is_admin_role( $current_user_roles ) ) {
247 // If editing a module and the user is godish, allow.
248 return true;
249
250 } elseif ( 'hustle_edit_module' === $capability && ! empty( $current_user_caps['hustle_create'] ) ) {
251 // If the user can create, it also can edit. Allow.
252 return true;
253
254 } elseif ( is_null( $module_id ) ) {
255 // If we're not editing a module, check for the requested capability.
256 return ! empty( $current_user_caps[ $capability ] );
257
258 } else {
259
260 // If editing a module and the user isn't godish...
261 $module = Hustle_Module_Model::new_instance( $module_id );
262
263 // If the module isn't valid, abort.
264 if ( is_wp_error( $module ) ) {
265 return false;
266 }
267
268 // Check for the specific allowed roles.
269 $allowed_roles = $module->get_edit_roles();
270 return (bool) array_intersect( $allowed_roles, $current_user_roles );
271 }
272
273 return false;
274 }
275
276 /**
277 * Get's the status of the membership.
278 *
279 * @since 4.3.3
280 *
281 * @return string
282 */
283 public static function get_membership_status() {
284 // Dashboard is active.
285 if ( class_exists( 'WPMUDEV_Dashboard' ) ) {
286 // Get membership type.
287 if ( method_exists( 'WPMUDEV_Dashboard_Api', 'get_membership_status' ) ) {
288 $status = WPMUDEV_Dashboard::$api->get_membership_status();
289 } else {
290 $status = WPMUDEV_Dashboard::$api->get_membership_type();
291 // Check if API key is available.
292 if ( 'free' === $status && WPMUDEV_Dashboard::$api->has_key() ) {
293 $status = 'expired';
294 }
295 }
296 } else {
297 $status = 'free';
298 }
299 return $status;
300 }
301
302 /**
303 * Checks whether Hustle is included in the membership.
304 *
305 * @since 4.3.3
306 *
307 * @return boolean
308 */
309 public static function is_hustle_included_in_membership() {
310 if ( class_exists( 'WPMUDEV_Dashboard' ) ) {
311 if ( class_exists( 'WPMUDEV_Dashboard' ) && method_exists( \WPMUDEV_Dashboard::$upgrader, 'user_can_install' ) ) {
312 return \WPMUDEV_Dashboard::$upgrader->user_can_install( 1107020, true );
313 }
314 }
315
316 return false;
317 }
318
319 /**
320 * Return URL link for wp.org, wpmudev, support, live chat, docs, installing plugin.
321 *
322 * @since 4.3.4
323 *
324 * @param string $link_for The section to retrieve the link for.
325 * @param string|bool $campaign Utm campaign tag to be used in link.
326 *
327 * @return string
328 */
329 public static function get_link( $link_for, $campaign = false ) {
330 $domain = 'https://wpmudev.com';
331 $wp_org = 'https://wordpress.org';
332 $utm_tags = ! $campaign ? '' : "?utm_source=hustle&utm_medium=plugin&utm_campaign={$campaign}";
333
334 switch ( $link_for ) {
335 case 'chat':
336 $link = "{$domain}/live-support/{$utm_tags}";
337 break;
338 case 'plugin':
339 $link = "{$domain}/project/hustle/{$utm_tags}";
340 break;
341 case 'support':
342 if ( 'full' === self::get_membership_status() ) {
343 $link = "{$domain}/hub/support/{$utm_tags}#get-support";
344 } else {
345 $link = "{$wp_org}/support/plugin/wordpress-popup";
346 }
347 break;
348 case 'docs':
349 $link = "{$domain}/docs/wpmu-dev-plugins/hustle/{$utm_tags}";
350 break;
351 case 'install_plugin':
352 if ( self::is_hustle_included_in_membership() ) {
353 // Return the pro plugin URL.
354 $url = WPMUDEV_Dashboard::$ui->page_urls->plugins_url;
355 $link = $url . '#pid=1107020';
356 } else {
357 // Return the free URL.
358 $link = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=wordpress-popup' ), 'install-plugin_wordpress-popup' );
359 }
360 break;
361 case 'roadmap':
362 $link = "{$domain}/roadmap/{$utm_tags}";
363 break;
364 case 'wpmudev':
365 $link = "{$domain}/{$utm_tags}";
366 break;
367 case 'blog':
368 $link = "{$domain}/blog/{$utm_tags}";
369 break;
370 default:
371 $link = '';
372 break;
373 }
374
375 return $link;
376 }
377
378 /**
379 * Checks if the ajax
380 *
381 * @since 1.0
382 * @param string $action ajax call action name.
383 */
384 public static function validate_ajax_call( $action ) {
385 if ( ! check_ajax_referer( $action, false, false ) ) {
386 wp_send_json_error( esc_html__( 'Invalid request, you are not allowed to make this request', 'hustle' ) ); }
387 }
388
389 /**
390 * Verify if current version is FREE
391 **/
392 public static function is_free() {
393 $is_free = ! file_exists( Opt_In::$plugin_path . 'lib/wpmudev-dashboard/wpmudev-dash-notification.php' );
394
395 return $is_free;
396 }
397
398 /**
399 * Get the user roles options.
400 *
401 * @since 4.0
402 *
403 * @return array
404 */
405 public static function get_user_roles() {
406
407 global $wp_roles;
408 $roles = $wp_roles->get_names();
409
410 return apply_filters( 'hustle_get_module_permissions_roles', $roles );
411 }
412
413 // ====================================
414 // INTEGRATIONS
415 // ====================================
416
417 /**
418 * Used for sanitizing form submissions.
419 * This method will do a simple sanitation of $post_data. It applies sanitize_text_field() to the keys and values of the first level array.
420 * The keys from second level arrays are converted to numbers, and their values are sanitized with sanitize_text_field() as well.
421 * This method doesn’t do an exhaustive sanitation, so you should handled special cases if your integration requires something different.
422 * The names passed on $required_fields are searched into $post_data array keys. If the key is not set, an array with the key “errors” is returned.
423 *
424 * @since 3.0.5
425 * @param array $post_data The data to be sanitized and validated.
426 * @param array $required_fields Fields that must exist on $post_data so the validation doesn't fail.
427 * @return array
428 */
429 public static function validate_and_sanitize_fields( $post_data, $required_fields = array() ) {
430 // for serialized data or form.
431 if ( ! is_array( $post_data ) && is_string( $post_data ) ) {
432 $post_string = $post_data;
433 $post_data = array();
434 wp_parse_str( $post_string, $post_data );
435 }
436
437 $errors = array();
438 foreach ( $required_fields as $key => $required_field ) {
439 if ( ! isset( $post_data[ $required_field ] ) || ( empty( trim( $post_data[ $required_field ] ) ) && '0' !== $post_data[ $required_field ] ) ) {
440 /* translators: required field name */
441 $errors[ $required_field ] = sprintf( __( 'Field %s is required.', 'hustle' ), $required_field );
442 continue;
443 }
444 }
445
446 if ( ! empty( $errors ) ) {
447 return array( 'errors' => $errors );
448 }
449
450 $sanitized_data = array();
451 foreach ( $post_data as $key => $post_datum ) {
452 /**
453 * Sanitize here every request so we dont need to sanitize it again on other methods,
454 * unless special treatment is required.
455 */
456 $sanitized_data[ sanitize_text_field( $key ) ] = self::sanitize_text_input_deep( $post_datum );
457 }
458
459 return $sanitized_data;
460 }
461
462 /**
463 * Sanitizes the values of a multi-dimensional array.
464 * The keys of the sub-arrays are converted to numerical arrays.
465 * Sub-arrays are expected to have numerical indexes.
466 *
467 * @since 3.0.5
468 * @param array|string $value Value.
469 * @return string
470 */
471 public static function sanitize_text_input_deep( $value ) {
472 if ( is_array( $value ) ) {
473 array_walk_recursive(
474 $value,
475 function ( &$val ) {
476 $val = sanitize_textarea_field( $val );
477 }
478 );
479 } else {
480 $value = sanitize_textarea_field( $value );
481 }
482
483 return $value;
484 }
485
486 /**
487 * Encode square brackets so a value cannot form a live shortcode.
488 *
489 * @param mixed $value Raw user-supplied value.
490 * @return mixed
491 */
492 public static function encode_shortcode_brackets( $value ) {
493 if ( is_array( $value ) ) {
494 array_walk_recursive(
495 $value,
496 function ( &$item ) {
497 if ( is_string( $item ) ) {
498 $item = str_replace( array( '[', ']' ), array( '&#91;', '&#93;' ), $item );
499 }
500 }
501 );
502
503 return $value;
504 }
505
506 if ( ! is_string( $value ) ) {
507 return $value;
508 }
509
510 return str_replace( array( '[', ']' ), array( '&#91;', '&#93;' ), $value );
511 }
512
513 /**
514 * Restore encoded shortcode brackets for exported values.
515 *
516 * @param mixed $value Value to decode.
517 *
518 * @return mixed
519 */
520 public static function decode_shortcode_brackets( $value ) {
521 if ( ! is_string( $value ) ) {
522 return $value;
523 }
524
525 return str_replace( array( '&#91;', '&#93;' ), array( '[', ']' ), $value );
526 }
527
528 /**
529 * Adds an entry to debug log
530 *
531 * By default it will check `WP_DEBUG` and HUSTLE_DEBUG to decide whether to add the log,
532 * then will check `filters`.
533 *
534 * @since 3.0.5
535 * @since 4.0 also checks HUSTLE_DEBUG
536 */
537 public static function maybe_log() {
538
539 $wp_debug_enabled = ( defined( 'WP_DEBUG' ) && WP_DEBUG );
540
541 $enabled = ( defined( 'HUSTLE_DEBUG' ) && HUSTLE_DEBUG );
542
543 $stored_settings = Hustle_Settings_Admin::get_general_settings();
544 $debug_setting_enabled = '1' === $stored_settings['debug_enabled'];
545
546 $enabled = ( $wp_debug_enabled && ( $debug_setting_enabled || $enabled ) );
547
548 /**
549 * Filter to enable or disable log for Hustle
550 *
551 * By default it will check `WP_DEBUG`
552 *
553 * @since 3.0.5
554 *
555 * @param bool $enabled current enabled status
556 */
557 $enabled = apply_filters( 'hustle_enable_log', $enabled );
558
559 if ( $enabled ) {
560 $args = func_get_args();
561 $message = wp_json_encode( $args );
562 if ( false !== $message ) {
563 error_log( '[Hustle] ' . $message );// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
564 }
565 }
566 }
567
568 // ====================================
569 // MISC?
570 // ====================================
571
572 /**
573 * Returns list of optin providers based on their declared classes that implement Opt_In_Provider_Interface
574 *
575 * @return array
576 */
577 public static function get_post_types() {
578 if ( empty( self::$post_types ) ) {
579 /**
580 * Add all custom post types
581 */
582 $post_types = array();
583 $cpts = get_post_types(
584 array(
585 'public' => true,
586 '_builtin' => false,
587 ),
588 'objects'
589 );
590 foreach ( $cpts as $cpt ) {
591
592 // skip ms_invoice.
593 if ( 'ms_invoice' === $cpt->name ) {
594 continue;
595 }
596
597 $cpt_array['name'] = $cpt->name;
598 $cpt_array['label'] = $cpt->label;
599 $cpt_array['data'] = array();
600
601 $post_types[ $cpt->name ] = $cpt_array;
602 }
603 self::$post_types = $post_types;
604 }
605 return self::$post_types;
606 }
607
608
609 /**
610 * Get usable object for select2
611 *
612 * @param string $post_type post type.
613 * @param array $include_ids Include IDs.
614 * @return array
615 */
616 public static function get_select2_data( $post_type, $include_ids = null ) {
617 $data = array();
618
619 if ( array() === $include_ids ) {
620 return $data;
621 }
622
623 $args = array(
624 'numberposts' => -1,
625 'post_type' => $post_type,
626 'post_status' => 'publish',
627 'order' => 'ASC',
628 );
629
630 if ( ! empty( $include_ids ) ) {
631 $args['post__in'] = $include_ids;
632 }
633
634 $posts = get_posts( $args );
635 foreach ( $posts as $post ) {
636 $data[] = (object) array(
637 'id' => $post->ID,
638 'text' => $post->post_title,
639 );
640 }
641
642 return $data;
643 }
644
645 /**
646 * Return reCAPTCHA languages
647 *
648 * @since 4.0
649 * @return array
650 */
651 public static function get_captcha_languages() {
652 return apply_filters(
653 'hustle_captcha_languages',
654 array(
655 'ar' => esc_html__( 'Arabic', 'hustle' ),
656 'af' => esc_html__( 'Afrikaans', 'hustle' ),
657 'am' => esc_html__( 'Amharic', 'hustle' ),
658 'hy' => esc_html__( 'Armenian', 'hustle' ),
659 'az' => esc_html__( 'Azerbaijani', 'hustle' ),
660 'eu' => esc_html__( 'Basque', 'hustle' ),
661 'bn' => esc_html__( 'Bengali', 'hustle' ),
662 'bg' => esc_html__( 'Bulgarian', 'hustle' ),
663 'ca' => esc_html__( 'Catalan', 'hustle' ),
664 'zh-HK' => esc_html__( 'Chinese (Hong Kong)', 'hustle' ),
665 'zh-CN' => esc_html__( 'Chinese (Simplified)', 'hustle' ),
666 'zh-TW' => esc_html__( 'Chinese (Traditional)', 'hustle' ),
667 'hr' => esc_html__( 'Croatian', 'hustle' ),
668 'cs' => esc_html__( 'Czech', 'hustle' ),
669 'da' => esc_html__( 'Danish', 'hustle' ),
670 'nl' => esc_html__( 'Dutch', 'hustle' ),
671 'en-GB' => esc_html__( 'English (UK)', 'hustle' ),
672 'en' => esc_html__( 'English (US)', 'hustle' ),
673 'et' => esc_html__( 'Estonian', 'hustle' ),
674 'fil' => esc_html__( 'Filipino', 'hustle' ),
675 'fi' => esc_html__( 'Finnish', 'hustle' ),
676 'fr' => esc_html__( 'French', 'hustle' ),
677 'fr-CA' => esc_html__( 'French (Canadian)', 'hustle' ),
678 'gl' => esc_html__( 'Galician', 'hustle' ),
679 'ka' => esc_html__( 'Georgian', 'hustle' ),
680 'de' => esc_html__( 'German', 'hustle' ),
681 'de-AT' => esc_html__( 'German (Austria)', 'hustle' ),
682 'de-CH' => esc_html__( 'German (Switzerland)', 'hustle' ),
683 'el' => esc_html__( 'Greek', 'hustle' ),
684 'gu' => esc_html__( 'Gujarati', 'hustle' ),
685 'iw' => esc_html__( 'Hebrew', 'hustle' ),
686 'hi' => esc_html__( 'Hindi', 'hustle' ),
687 'hu' => esc_html__( 'Hungarain', 'hustle' ),
688 'is' => esc_html__( 'Icelandic', 'hustle' ),
689 'id' => esc_html__( 'Indonesian', 'hustle' ),
690 'it' => esc_html__( 'Italian', 'hustle' ),
691 'ja' => esc_html__( 'Japanese', 'hustle' ),
692 'kn' => esc_html__( 'Kannada', 'hustle' ),
693 'ko' => esc_html__( 'Korean', 'hustle' ),
694 'lo' => esc_html__( 'Laothian', 'hustle' ),
695 'lv' => esc_html__( 'Latvian', 'hustle' ),
696 'lt' => esc_html__( 'Lithuanian', 'hustle' ),
697 'ms' => esc_html__( 'Malay', 'hustle' ),
698 'ml' => esc_html__( 'Malayalam', 'hustle' ),
699 'mr' => esc_html__( 'Marathi', 'hustle' ),
700 'mn' => esc_html__( 'Mongolian', 'hustle' ),
701 'no' => esc_html__( 'Norwegian', 'hustle' ),
702 'fa' => esc_html__( 'Persian', 'hustle' ),
703 'pl' => esc_html__( 'Polish', 'hustle' ),
704 'pt' => esc_html__( 'Portuguese', 'hustle' ),
705 'pt-BR' => esc_html__( 'Portuguese (Brazil)', 'hustle' ),
706 'pt-PT' => esc_html__( 'Portuguese (Portugal)', 'hustle' ),
707 'ro' => esc_html__( 'Romanian', 'hustle' ),
708 'ru' => esc_html__( 'Russian', 'hustle' ),
709 'sr' => esc_html__( 'Serbian', 'hustle' ),
710 'si' => esc_html__( 'Sinhalese', 'hustle' ),
711 'sk' => esc_html__( 'Slovak', 'hustle' ),
712 'sl' => esc_html__( 'Slovenian', 'hustle' ),
713 'es' => esc_html__( 'Spanish', 'hustle' ),
714 'es-419' => esc_html__( 'Spanish (Latin America)', 'hustle' ),
715 'sw' => esc_html__( 'Swahili', 'hustle' ),
716 'sv' => esc_html__( 'Swedish', 'hustle' ),
717 'ta' => esc_html__( 'Tamil', 'hustle' ),
718 'te' => esc_html__( 'Telugu', 'hustle' ),
719 'th' => esc_html__( 'Thai', 'hustle' ),
720 'tr' => esc_html__( 'Turkish', 'hustle' ),
721 'uk' => esc_html__( 'Ukrainian', 'hustle' ),
722 'ur' => esc_html__( 'Urdu', 'hustle' ),
723 'vi' => esc_html__( 'Vietnamese', 'hustle' ),
724 'zu' => esc_html__( 'Zulu', 'hustle' ),
725 )
726 );
727 }
728
729 /**
730 * Gets post property
731 *
732 * @since 4.0.4
733 * @param string $property Requested post property.
734 * @param string $default_value Fallback value.
735 * @return string
736 */
737 public static function get_post_data( $property, $default_value = '' ) {
738 global $post;
739
740 if ( ! $post ) {
741 // fallback on wp_ajax, `global $post` not available.
742 $wp_referer = wp_get_referer();
743 if ( $wp_referer ) {
744 $post_id = ! function_exists( 'wpcom_vip_url_to_postid' ) ? url_to_postid( $wp_referer ) : wpcom_vip_url_to_postid( $wp_referer );
745 if ( $post_id ) {
746 $post_object = get_post( $post_id );
747 // make sure it's wp_post.
748 if ( $post_object instanceof WP_Post ) {
749 // set global $post as $post_object retrieved from `get_post` for next usage.
750 $post = $post_object;// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
751 }
752 }
753 }
754 }
755
756 $post_data = (array) $post;
757 if ( isset( $post_data[ $property ] ) ) {
758 return $post_data[ $property ];
759 }
760
761 return $default_value;
762 }
763
764 // ====================================
765 // MODULES HELPERS
766 // ====================================
767
768 /**
769 * Get current post id
770 *
771 * @since 4.0
772 *
773 * @return int|string
774 */
775 public static function get_post_id() {
776 return get_post() ? get_the_ID() : '0';
777 }
778
779 /**
780 * Gets the a current user's property.
781 *
782 * @since 4.0.4
783 * @param string $property The user's property to be retrieved.
784 * @return string
785 */
786 public static function get_user_data( $property ) {
787 $current_user = wp_get_current_user();
788
789 if ( $current_user && $current_user->exists() ) {
790 return $current_user->get( $property );
791 }
792 return '';
793 }
794
795 /**
796 * Replace a key in an array without changing its order.
797 *
798 * @since 4.0
799 *
800 * @param string $old_key Old key.
801 * @param string $new_key New key.
802 * @param array $source_array Array.
803 * @return array
804 */
805 public static function replace_array_key( $old_key, $new_key, $source_array ) {
806
807 // Replace the name without changing the array's order.
808 $keys_array = array_keys( $source_array );
809 $index = array_search( $old_key, $keys_array, true );
810
811 if ( false === $index ) {
812 return $source_array;
813 }
814
815 $keys_array[ $index ] = $new_key;
816
817 $new_array = array_combine( $keys_array, array_values( $source_array ) );
818
819 return $new_array;
820 }
821
822 /**
823 * Get the display name of a module type.
824 *
825 * @since 4.0
826 *
827 * @param string $module_type Module type.
828 * @param boolean $plural Plural.
829 * @param boolean $capitalized Capitalized.
830 * @return string
831 */
832 public static function get_module_type_display_name( $module_type, $plural = false, $capitalized = false ) {
833
834 $display_name = '';
835
836 if ( Hustle_Module_Model::POPUP_MODULE === $module_type ) {
837 if ( ! $plural ) {
838 $display_name = __( 'pop-up', 'hustle' );
839 } else {
840 $display_name = __( 'pop-ups', 'hustle' );
841 }
842 } elseif ( Hustle_Module_Model::SLIDEIN_MODULE === $module_type ) {
843 if ( ! $plural ) {
844 $display_name = __( 'slide-in', 'hustle' );
845 } else {
846 $display_name = __( 'slide-ins', 'hustle' );
847 }
848 } elseif ( Hustle_Module_Model::EMBEDDED_MODULE === $module_type ) {
849 if ( ! $plural ) {
850 $display_name = __( 'embed', 'hustle' );
851 } else {
852 $display_name = __( 'embeds', 'hustle' );
853 }
854 } elseif ( Hustle_Module_Model::SOCIAL_SHARING_MODULE === $module_type ) {
855 if ( ! $plural ) {
856 $display_name = __( 'social sharing', 'hustle' );
857 } else {
858 $display_name = __( 'social shares', 'hustle' );
859 }
860 }
861
862 if ( $capitalized ) {
863 $display_name = ucwords( $display_name );
864 }
865
866 return esc_html( $display_name );
867 }
868
869 /**
870 * Get page templates
871 *
872 * @since 4.0.3
873 */
874 public static function hustle_get_page_templates() {
875 $templates = get_page_templates();
876 $page_templates = array();
877 foreach ( $templates as $template_name => $template_filename ) {
878 $page_templates[ $template_filename ] = $template_name;
879 }
880 return $page_templates;
881 }
882
883 /**
884 * Add special scripts for IE if it's detected
885 *
886 * @global bool $is_IE
887 * @global bool $is_edge
888 */
889 public static function maybe_add_scripts_for_ie() {
890 global $is_IE, $is_edge;
891
892 if ( $is_IE || $is_edge ) {
893 wp_enqueue_script(
894 'optin_admin_fitie',
895 Opt_In::$plugin_url . 'assets/js/vendor/fitie/fitie.js',
896 array(),
897 Opt_In::VERSION,
898 true
899 );
900 }
901 }
902
903 /**
904 * Check if WooCommerce is active or not
905 *
906 * @return bool
907 */
908 public static function is_woocommerce_active() {
909 return is_plugin_active( 'woocommerce/woocommerce.php' );
910 }
911
912 /**
913 * Check if Forminator is installed or not.
914 *
915 * @return bool
916 */
917 public static function is_forminator_installed() {
918 return file_exists( WP_PLUGIN_DIR . '/forminator/forminator.php' );
919 }
920
921 /**
922 * Gets the first key of an array.
923 *
924 * @since 4.0.0
925 *
926 * @param array $source_array Array.
927 * @return mixed
928 */
929 public static function array_key_first( array $source_array ) {
930 return $source_array ? array_keys( $source_array )[0] : null;
931 }
932
933 /**
934 * Get the global placeholders for display.
935 * The array's key has the placeholder value, that's what's inserted between
936 * brackets and then replaced by self::replace_global_placeholders().
937 * The array's value has the display name for the placeholder.
938 *
939 * @since 4.0.3
940 * @see Opt_In_Utils::replace_global_placeholders()
941 * @return array
942 */
943 public static function get_global_placeholders() {
944
945 $placeholders = array(
946 'site_url' => __( 'Site URL', 'hustle' ),
947 'site_name' => __( 'Site name', 'hustle' ),
948 'post_url' => __( 'Post/page URL', 'hustle' ),
949 'post_title' => __( 'Post/page title', 'hustle' ),
950 );
951
952 /**
953 * Filter the available global placeholders.
954 * These are used in some text fields, to be replaced by
955 * self::replace_global_placeholders().
956 *
957 * @since 4.0.3
958 * @see Opt_In_Utils::replace_global_placeholders()
959 * @return array
960 */
961 return apply_filters( 'hustle_get_global_placeholders', $placeholders );
962 }
963
964 /**
965 * Replace the global placeholders from a string.
966 * These are added to some text fields by the admin.
967 * The available ones are returned by self::get_global_placeholders().
968 *
969 * @since 4.0.3
970 * @see Opt_In_Utils::replace_global_placeholders()
971 * @param string $source_text String with placeholders to be replaced.
972 * @return string
973 */
974 public static function replace_global_placeholders( $source_text ) {
975
976 preg_match_all( '/\{[^}]*\}/', $source_text, $matches );
977
978 if ( ! empty( $matches[0] ) && is_array( $matches[0] ) ) {
979
980 $defined_placeholders = array(
981 '{site_url}' => site_url(),
982 '{site_name}' => get_bloginfo( 'name' ),
983 '{post_url}' => get_permalink(),
984 '{post_title}' => esc_html( get_the_title() ),
985 );
986
987 /**
988 * Filter the placeholders and their values.
989 * The keys of the array belong to the placeholder to be replaced.
990 * The values of the array belong to the value to use as replacement.
991 * Eg: [ '{post_url}' => get_permalink() ]
992 *
993 * @since 4.0.3
994 * @return array
995 */
996 $defined_placeholders = apply_filters( 'hustle_global_placeholders_to_replace', $defined_placeholders );
997
998 foreach ( $matches[0] as $placeholder ) {
999
1000 if ( key_exists( $placeholder, $defined_placeholders ) ) {
1001 $replacement = $defined_placeholders[ $placeholder ];
1002
1003 if ( $replacement !== $placeholder ) {
1004 // Replace if we found something.
1005 $source_text = str_replace( $placeholder, $replacement, $source_text );
1006 }
1007 }
1008 }
1009 }
1010
1011 return $source_text;
1012 }
1013
1014 // Static stuff below.
1015
1016 /**
1017 * Returns array of browsers
1018 *
1019 * @since 4.1
1020 * @return array|mixed|null|void
1021 */
1022 public static function get_browsers() {
1023
1024 $browsers = array(
1025 'chrome' => __( 'Chrome', 'hustle' ),
1026 'firefox' => __( 'Firefox', 'hustle' ),
1027 'safari' => __( 'Safari', 'hustle' ),
1028 'edge' => __( 'Edge', 'hustle' ),
1029 'MSIE' => __( 'Internet Explorer', 'hustle' ),
1030 'opera' => __( 'Opera', 'hustle' ),
1031 );
1032
1033 /**
1034 * Filter the list of browsers
1035 * Must return an associative array where the key is the browser's slug
1036 * and the value is its display name.
1037 *
1038 * @since 4.1
1039 */
1040 return apply_filters( 'hustle_get_browsers_list', $browsers );
1041 }
1042
1043 /**
1044 * Returns array of countries
1045 *
1046 * @return array|mixed|null|void
1047 */
1048 public static function get_countries() {
1049
1050 $countries = array(
1051 'AU' => __( 'Australia', 'hustle' ),
1052 'AF' => __( 'Afghanistan', 'hustle' ),
1053 'AL' => __( 'Albania', 'hustle' ),
1054 'DZ' => __( 'Algeria', 'hustle' ),
1055 'AS' => __( 'American Samoa', 'hustle' ),
1056 'AD' => __( 'Andorra', 'hustle' ),
1057 'AO' => __( 'Angola', 'hustle' ),
1058 'AI' => __( 'Anguilla', 'hustle' ),
1059 'AQ' => __( 'Antarctica', 'hustle' ),
1060 'AG' => __( 'Antigua and Barbuda', 'hustle' ),
1061 'AR' => __( 'Argentina', 'hustle' ),
1062 'AM' => __( 'Armenia', 'hustle' ),
1063 'AW' => __( 'Aruba', 'hustle' ),
1064 'AT' => __( 'Austria', 'hustle' ),
1065 'AZ' => __( 'Azerbaijan', 'hustle' ),
1066 'BS' => __( 'Bahamas', 'hustle' ),
1067 'BH' => __( 'Bahrain', 'hustle' ),
1068 'BD' => __( 'Bangladesh', 'hustle' ),
1069 'BB' => __( 'Barbados', 'hustle' ),
1070 'BY' => __( 'Belarus', 'hustle' ),
1071 'BE' => __( 'Belgium', 'hustle' ),
1072 'BZ' => __( 'Belize', 'hustle' ),
1073 'BJ' => __( 'Benin', 'hustle' ),
1074 'BM' => __( 'Bermuda', 'hustle' ),
1075 'BT' => __( 'Bhutan', 'hustle' ),
1076 'BO' => __( 'Bolivia', 'hustle' ),
1077 'BA' => __( 'Bosnia and Herzegovina', 'hustle' ),
1078 'BW' => __( 'Botswana', 'hustle' ),
1079 'BV' => __( 'Bouvet Island', 'hustle' ),
1080 'BR' => __( 'Brazil', 'hustle' ),
1081 'IO' => __( 'British Indian Ocean Territory', 'hustle' ),
1082 'BN' => __( 'Brunei', 'hustle' ),
1083 'BG' => __( 'Bulgaria', 'hustle' ),
1084 'BF' => __( 'Burkina Faso', 'hustle' ),
1085 'BI' => __( 'Burundi', 'hustle' ),
1086 'KH' => __( 'Cambodia', 'hustle' ),
1087 'CM' => __( 'Cameroon', 'hustle' ),
1088 'CA' => __( 'Canada', 'hustle' ),
1089 'CV' => __( 'Cape Verde', 'hustle' ),
1090 'KY' => __( 'Cayman Islands', 'hustle' ),
1091 'CF' => __( 'Central African Republic', 'hustle' ),
1092 'TD' => __( 'Chad', 'hustle' ),
1093 'CL' => __( 'Chile', 'hustle' ),
1094 'CN' => __( 'China, People\'s Republic of', 'hustle' ),
1095 'CX' => __( 'Christmas Island', 'hustle' ),
1096 'CC' => __( 'Cocos Islands', 'hustle' ),
1097 'CO' => __( 'Colombia', 'hustle' ),
1098 'KM' => __( 'Comoros', 'hustle' ),
1099 'CD' => __( 'Congo, Democratic Republic of the', 'hustle' ),
1100 'CG' => __( 'Congo, Republic of the', 'hustle' ),
1101 'CK' => __( 'Cook Islands', 'hustle' ),
1102 'CR' => __( 'Costa Rica', 'hustle' ),
1103 'CI' => __( 'Côte d\'Ivoire', 'hustle' ),
1104 'HR' => __( 'Croatia', 'hustle' ),
1105 'CU' => __( 'Cuba', 'hustle' ),
1106 'CW' => __( 'Curaçao', 'hustle' ),
1107 'CY' => __( 'Cyprus', 'hustle' ),
1108 'CZ' => __( 'Czech Republic', 'hustle' ),
1109 'DK' => __( 'Denmark', 'hustle' ),
1110 'DJ' => __( 'Djibouti', 'hustle' ),
1111 'DM' => __( 'Dominica', 'hustle' ),
1112 'DO' => __( 'Dominican Republic', 'hustle' ),
1113 'TL' => __( 'East Timor', 'hustle' ),
1114 'EC' => __( 'Ecuador', 'hustle' ),
1115 'EG' => __( 'Egypt', 'hustle' ),
1116 'SV' => __( 'El Salvador', 'hustle' ),
1117 'GQ' => __( 'Equatorial Guinea', 'hustle' ),
1118 'ER' => __( 'Eritrea', 'hustle' ),
1119 'EE' => __( 'Estonia', 'hustle' ),
1120 'ET' => __( 'Ethiopia', 'hustle' ),
1121 'FK' => __( 'Falkland Islands', 'hustle' ),
1122 'FO' => __( 'Faroe Islands', 'hustle' ),
1123 'FJ' => __( 'Fiji', 'hustle' ),
1124 'FI' => __( 'Finland', 'hustle' ),
1125 'FR' => __( 'France', 'hustle' ),
1126 'FX' => __( 'France, Metropolitan', 'hustle' ),
1127 'GF' => __( 'French Guiana', 'hustle' ),
1128 'PF' => __( 'French Polynesia', 'hustle' ),
1129 'TF' => __( 'French South Territories', 'hustle' ),
1130 'GA' => __( 'Gabon', 'hustle' ),
1131 'GM' => __( 'Gambia', 'hustle' ),
1132 'GE' => __( 'Georgia', 'hustle' ),
1133 'DE' => __( 'Germany', 'hustle' ),
1134 'GH' => __( 'Ghana', 'hustle' ),
1135 'GI' => __( 'Gibraltar', 'hustle' ),
1136 'GR' => __( 'Greece', 'hustle' ),
1137 'GL' => __( 'Greenland', 'hustle' ),
1138 'GD' => __( 'Grenada', 'hustle' ),
1139 'GP' => __( 'Guadeloupe', 'hustle' ),
1140 'GU' => __( 'Guam', 'hustle' ),
1141 'GT' => __( 'Guatemala', 'hustle' ),
1142 'GN' => __( 'Guinea', 'hustle' ),
1143 'GW' => __( 'Guinea-Bissau', 'hustle' ),
1144 'GY' => __( 'Guyana', 'hustle' ),
1145 'HT' => __( 'Haiti', 'hustle' ),
1146 'HM' => __( 'Heard Island And Mcdonald Island', 'hustle' ),
1147 'HN' => __( 'Honduras', 'hustle' ),
1148 'HK' => __( 'Hong Kong', 'hustle' ),
1149 'HU' => __( 'Hungary', 'hustle' ),
1150 'IS' => __( 'Iceland', 'hustle' ),
1151 'IN' => __( 'India', 'hustle' ),
1152 'ID' => __( 'Indonesia', 'hustle' ),
1153 'IR' => __( 'Iran', 'hustle' ),
1154 'IQ' => __( 'Iraq', 'hustle' ),
1155 'IE' => __( 'Ireland', 'hustle' ),
1156 'IL' => __( 'Israel', 'hustle' ),
1157 'IT' => __( 'Italy', 'hustle' ),
1158 'JM' => __( 'Jamaica', 'hustle' ),
1159 'JP' => __( 'Japan', 'hustle' ),
1160 'JT' => __( 'Johnston Island', 'hustle' ),
1161 'JO' => __( 'Jordan', 'hustle' ),
1162 'KZ' => __( 'Kazakhstan', 'hustle' ),
1163 'KE' => __( 'Kenya', 'hustle' ),
1164 'XK' => __( 'Kosovo', 'hustle' ),
1165 'KI' => __( 'Kiribati', 'hustle' ),
1166 'KP' => __( 'Korea, Democratic People\'s Republic of', 'hustle' ),
1167 'KR' => __( 'Korea, Republic of', 'hustle' ),
1168 'KW' => __( 'Kuwait', 'hustle' ),
1169 'KG' => __( 'Kyrgyzstan', 'hustle' ),
1170 'LA' => __( 'Lao People\'s Democratic Republic', 'hustle' ),
1171 'LV' => __( 'Latvia', 'hustle' ),
1172 'LB' => __( 'Lebanon', 'hustle' ),
1173 'LS' => __( 'Lesotho', 'hustle' ),
1174 'LR' => __( 'Liberia', 'hustle' ),
1175 'LY' => __( 'Libya', 'hustle' ),
1176 'LI' => __( 'Liechtenstein', 'hustle' ),
1177 'LT' => __( 'Lithuania', 'hustle' ),
1178 'LU' => __( 'Luxembourg', 'hustle' ),
1179 'MO' => __( 'Macau', 'hustle' ),
1180 'MK' => __( 'Macedonia', 'hustle' ),
1181 'MG' => __( 'Madagascar', 'hustle' ),
1182 'MW' => __( 'Malawi', 'hustle' ),
1183 'MY' => __( 'Malaysia', 'hustle' ),
1184 'MV' => __( 'Maldives', 'hustle' ),
1185 'ML' => __( 'Mali', 'hustle' ),
1186 'MT' => __( 'Malta', 'hustle' ),
1187 'MH' => __( 'Marshall Islands', 'hustle' ),
1188 'MQ' => __( 'Martinique', 'hustle' ),
1189 'MR' => __( 'Mauritania', 'hustle' ),
1190 'MU' => __( 'Mauritius', 'hustle' ),
1191 'YT' => __( 'Mayotte', 'hustle' ),
1192 'MX' => __( 'Mexico', 'hustle' ),
1193 'FM' => __( 'Micronesia', 'hustle' ),
1194 'MD' => __( 'Moldova', 'hustle' ),
1195 'MC' => __( 'Monaco', 'hustle' ),
1196 'MN' => __( 'Mongolia', 'hustle' ),
1197 'ME' => __( 'Montenegro', 'hustle' ),
1198 'MS' => __( 'Montserrat', 'hustle' ),
1199 'MA' => __( 'Morocco', 'hustle' ),
1200 'MZ' => __( 'Mozambique', 'hustle' ),
1201 'MM' => __( 'Myanmar', 'hustle' ),
1202 'NA' => __( 'Namibia', 'hustle' ),
1203 'NR' => __( 'Nauru', 'hustle' ),
1204 'NP' => __( 'Nepal', 'hustle' ),
1205 'NL' => __( 'Netherlands', 'hustle' ),
1206 'AN' => __( 'Netherlands Antilles', 'hustle' ),
1207 'NC' => __( 'New Caledonia', 'hustle' ),
1208 'NZ' => __( 'New Zealand', 'hustle' ),
1209 'NI' => __( 'Nicaragua', 'hustle' ),
1210 'NE' => __( 'Niger', 'hustle' ),
1211 'NG' => __( 'Nigeria', 'hustle' ),
1212 'NU' => __( 'Niue', 'hustle' ),
1213 'NF' => __( 'Norfolk Island', 'hustle' ),
1214 'MNP' => __( 'Northern Mariana Islands', 'hustle' ),
1215 'MP' => __( 'Mariana Islands, Northern', 'hustle' ),
1216 'NO' => __( 'Norway', 'hustle' ),
1217 'OM' => __( 'Oman', 'hustle' ),
1218 'PK' => __( 'Pakistan', 'hustle' ),
1219 'PW' => __( 'Palau', 'hustle' ),
1220 'PS' => __( 'Palestine, State of', 'hustle' ),
1221 'PA' => __( 'Panama', 'hustle' ),
1222 'PG' => __( 'Papua New Guinea', 'hustle' ),
1223 'PY' => __( 'Paraguay', 'hustle' ),
1224 'PE' => __( 'Peru', 'hustle' ),
1225 'PH' => __( 'Philippines', 'hustle' ),
1226 'PN' => __( 'Pitcairn Islands', 'hustle' ),
1227 'PL' => __( 'Poland', 'hustle' ),
1228 'PT' => __( 'Portugal', 'hustle' ),
1229 'PR' => __( 'Puerto Rico', 'hustle' ),
1230 'QA' => __( 'Qatar', 'hustle' ),
1231 'RE' => __( 'Réunion', 'hustle' ),
1232 'RO' => __( 'Romania', 'hustle' ),
1233 'RU' => __( 'Russia', 'hustle' ),
1234 'RW' => __( 'Rwanda', 'hustle' ),
1235 'SH' => __( 'Saint Helena', 'hustle' ),
1236 'KN' => __( 'Saint Kitts and Nevis', 'hustle' ),
1237 'LC' => __( 'Saint Lucia', 'hustle' ),
1238 'PM' => __( 'Saint Pierre and Miquelon', 'hustle' ),
1239 'VC' => __( 'Saint Vincent and the Grenadines', 'hustle' ),
1240 'WS' => __( 'Samoa', 'hustle' ),
1241 'SM' => __( 'San Marino', 'hustle' ),
1242 'ST' => __( 'Sao Tome and Principe', 'hustle' ),
1243 'SA' => __( 'Saudi Arabia', 'hustle' ),
1244 'SN' => __( 'Senegal', 'hustle' ),
1245 'CS' => __( 'Serbia', 'hustle' ),
1246 'SC' => __( 'Seychelles', 'hustle' ),
1247 'SL' => __( 'Sierra Leone', 'hustle' ),
1248 'SG' => __( 'Singapore', 'hustle' ),
1249 'MF' => __( 'Sint Maarten', 'hustle' ),
1250 'SK' => __( 'Slovakia', 'hustle' ),
1251 'SI' => __( 'Slovenia', 'hustle' ),
1252 'SB' => __( 'Solomon Islands', 'hustle' ),
1253 'SO' => __( 'Somalia', 'hustle' ),
1254 'ZA' => __( 'South Africa', 'hustle' ),
1255 'GS' => __( 'South Georgia and the South Sandwich Islands', 'hustle' ),
1256 'ES' => __( 'Spain', 'hustle' ),
1257 'LK' => __( 'Sri Lanka', 'hustle' ),
1258 'XX' => __( 'Stateless Persons', 'hustle' ),
1259 'SD' => __( 'Sudan', 'hustle' ),
1260 'SS' => __( 'South Sudan', 'hustle' ),
1261 'SR' => __( 'Suriname', 'hustle' ),
1262 'SJ' => __( 'Svalbard and Jan Mayen', 'hustle' ),
1263 'SZ' => __( 'Swaziland', 'hustle' ),
1264 'SE' => __( 'Sweden', 'hustle' ),
1265 'CH' => __( 'Switzerland', 'hustle' ),
1266 'SY' => __( 'Syria', 'hustle' ),
1267 'TW' => __( 'Taiwan, Republic of China', 'hustle' ),
1268 'TJ' => __( 'Tajikistan', 'hustle' ),
1269 'TZ' => __( 'Tanzania', 'hustle' ),
1270 'TH' => __( 'Thailand', 'hustle' ),
1271 'TG' => __( 'Togo', 'hustle' ),
1272 'TK' => __( 'Tokelau', 'hustle' ),
1273 'TO' => __( 'Tonga', 'hustle' ),
1274 'TT' => __( 'Trinidad and Tobago', 'hustle' ),
1275 'TN' => __( 'Tunisia', 'hustle' ),
1276 'TR' => __( 'Turkey', 'hustle' ),
1277 'TM' => __( 'Turkmenistan', 'hustle' ),
1278 'TC' => __( 'Turks and Caicos Islands', 'hustle' ),
1279 'TV' => __( 'Tuvalu', 'hustle' ),
1280 'UG' => __( 'Uganda', 'hustle' ),
1281 'UA' => __( 'Ukraine', 'hustle' ),
1282 'AE' => __( 'United Arab Emirates', 'hustle' ),
1283 'GB' => __( 'United Kingdom', 'hustle' ),
1284 'US' => __( 'United States of America (USA)', 'hustle' ),
1285 'UM' => __( 'US Minor Outlying Islands', 'hustle' ),
1286 'UY' => __( 'Uruguay', 'hustle' ),
1287 'UZ' => __( 'Uzbekistan', 'hustle' ),
1288 'VU' => __( 'Vanuatu', 'hustle' ),
1289 'VA' => __( 'Vatican City', 'hustle' ),
1290 'VE' => __( 'Venezuela', 'hustle' ),
1291 'VN' => __( 'Vietnam', 'hustle' ),
1292 'VG' => __( 'Virgin Islands, British', 'hustle' ),
1293 'VI' => __( 'Virgin Islands, U.S.', 'hustle' ),
1294 'WF' => __( 'Wallis And Futuna', 'hustle' ),
1295 'EH' => __( 'Western Sahara', 'hustle' ),
1296 'YE' => __( 'Yemen', 'hustle' ),
1297 'ZM' => __( 'Zambia', 'hustle' ),
1298 'ZW' => __( 'Zimbabwe', 'hustle' ),
1299 );
1300
1301 // Deprecated.
1302 $countries = apply_filters_deprecated( 'opt_in-country-list', array( $countries ), '4.6.0', 'opt_in_country_list' );
1303 /**
1304 * Returns a list with countries
1305 * Must be an associative array where the key is the country code
1306 * and its value is its display name.
1307 */
1308 return apply_filters( 'opt_in_country_list', $countries );
1309 }
1310
1311 /**
1312 * Get HTML for notice about using cookies
1313 */
1314 public static function get_cookie_saving_notice() {
1315 ?>
1316 <div class="sui-notice">
1317 <div class="sui-notice-content">
1318 <div class="sui-notice-message">
1319
1320 <span class="sui-notice-icon sui-icon-info sui-md" aria-hidden="true"></span>
1321 <p style="margin-top: 0;"><?php esc_html_e( 'Note: When enabled, this will set a tracking cookie in your visitor’s web browser.', 'hustle' ); ?></p>
1322
1323 </div>
1324 </div>
1325 </div>
1326 <?php
1327 }
1328
1329 /**
1330 * Check if static cache is enabled
1331 *
1332 * @return boolean
1333 */
1334 public static function is_static_cache_enabled() {
1335 if ( ! is_null( self::$static_cache ) ) {
1336 return self::$static_cache;
1337 }
1338
1339 if ( defined( 'HUSTLE_STATIC_CACHE_ENABLED' ) ) {
1340 self::$static_cache = HUSTLE_STATIC_CACHE_ENABLED;
1341 } elseif ( apply_filters( 'wp_hummingbird_is_active_module_page_cache', false ) ) {
1342 self::$static_cache = true;
1343 } else {
1344 self::$static_cache = self::is_hub_cache();
1345 }
1346
1347 return self::$static_cache;
1348 }
1349
1350 /**
1351 * Is Static Server Cache enabled on HUB or not
1352 *
1353 * @return boolean
1354 */
1355 private static function is_hub_cache() {
1356 $key_option = 'hustle_hub_cache_enabled';
1357 $cache = get_site_transient( $key_option );
1358
1359 if ( false === $cache ) {
1360 $cache = self::is_hub_cache_enabled();
1361 set_site_transient( $key_option, (int) $cache, DAY_IN_SECONDS );
1362 }
1363
1364 return (bool) $cache;
1365 }
1366
1367 /**
1368 * Check if Static Server Cache is enabled on HUB
1369 *
1370 * @return boolean
1371 */
1372 private static function is_hub_cache_enabled() {
1373 return (bool) self::get_hosting_feature( 'static_cache' );
1374 }
1375
1376 /**
1377 * Get list of hosting features and their status
1378 *
1379 * @param string $name The name of the hosting feature to check.
1380 * @return mixed The status of the hosting feature, or an empty string if not found.
1381 */
1382 private static function get_hosting_feature( $name ) {
1383 if ( function_exists( 'wpmudev_hosting_features' ) ) {
1384 $states = wpmudev_hosting_features();
1385 return isset( $states[ $name ] ) ? $states[ $name ] : '';
1386 }
1387
1388 return '';
1389 }
1390
1391 /**
1392 * Get branded plugin name
1393 *
1394 * @return string
1395 */
1396 public static function get_plugin_name() {
1397 if ( is_null( self::$plugin_name ) ) {
1398 $branding_plugin_name = self::get_branding_plugin_name();
1399 if ( $branding_plugin_name ) {
1400 $plugin_name = $branding_plugin_name;
1401 } elseif ( self::is_free() ) {
1402 $plugin_name = __( 'Hustle', 'hustle' );
1403 } else {
1404 $plugin_name = __( 'Hustle Pro', 'hustle' );
1405 }
1406
1407 self::$plugin_name = $plugin_name;
1408 }
1409
1410 return self::$plugin_name;
1411 }
1412
1413 /**
1414 * Get branding plugin name
1415 *
1416 * @return null|string
1417 */
1418 private static function get_branding_plugin_name() {
1419 if ( ! class_exists( 'WPMUDEV_Dashboard' )
1420 || empty( WPMUDEV_Dashboard::$whitelabel )
1421 || ! method_exists( WPMUDEV_Dashboard::$whitelabel, 'get_settings' ) ) {
1422 return;
1423 }
1424 $settings = WPMUDEV_Dashboard::$whitelabel->get_settings();
1425 if ( empty( $settings['enabled'] ) || true !== $settings['enabled']
1426 || empty( $settings['labels_config'][1107020]['name'] ) ) {
1427 return;
1428 }
1429
1430 return $settings['labels_config'][1107020]['name'];
1431 }
1432
1433 /**
1434 * Build notification response
1435 *
1436 * @param string $type The type of notification (success, error, etc.).
1437 * @param string $message The notification message.
1438 * @return array The notification response.
1439 */
1440 public static function build_notification( $type, $message ) {
1441 return array(
1442 'action' => 'notification',
1443 'status' => $type,
1444 'message' => $message,
1445 );
1446 }
1447
1448 /**
1449 * Get HUB API key
1450 *
1451 * @return string
1452 */
1453 public static function get_hub_api_key() {
1454 if ( ! class_exists( 'WPMUDEV_Dashboard' ) ) {
1455 return '';
1456 }
1457
1458 if (
1459 WPMUDEV_Dashboard::$api &&
1460 WPMUDEV_Dashboard::$api->has_key()
1461 ) {
1462 return WPMUDEV_Dashboard::$api->get_key();
1463 }
1464
1465 return '';
1466 }
1467 }
1468