PluginProbe
Elementor Website Builder – more than just a page builder / 3.1.3
Elementor Website Builder – more than just a page builder v3.1.3
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
← All changes | includes/utils.php +70 -406 4.1.0-dev33.1.3 View file →
@@ -1,10 +1,7 @@
1 1 <?php
2 2 namespace Elementor;
3 3
4 -use Elementor\Core\Files\Fonts\Google_Font;
5 -use Elementor\Core\Utils\Collection;
6 -
7 4 if ( ! defined( 'ABSPATH' ) ) {
8 5 exit; // Exit if accessed directly.
9 6 }
10 7
@@ -19,19 +16,14 @@
19 16 class Utils {
20 17
21 18 const DEPRECATION_RANGE = 0.4;
22 19
23 - const EDITOR_BREAK_LINES_OPTION_KEY = 'elementor_editor_break_lines';
24 -
25 20 /**
26 - * A list of safe tags for `validate_html_tag` method.
21 + * A list of safe tage for `validate_html_tag` method.
27 22 */
28 23 const ALLOWED_HTML_WRAPPER_TAGS = [
29 - 'a',
30 24 'article',
31 25 'aside',
32 - 'button',
33 - 'form',
34 26 'div',
35 27 'footer',
36 28 'h1',
37 29 'h2',
@@ -46,73 +38,29 @@
46 38 'section',
47 39 'span',
48 40 ];
49 41
50 - const EXTENDED_ALLOWED_HTML_TAGS = [
51 - 'iframe' => [
52 - 'iframe' => [
53 - 'allow' => true,
54 - 'allowfullscreen' => true,
55 - 'frameborder' => true,
56 - 'height' => true,
57 - 'loading' => true,
58 - 'name' => true,
59 - 'referrerpolicy' => true,
60 - 'sandbox' => true,
61 - 'src' => true,
62 - 'width' => true,
63 - ],
64 - ],
65 - 'svg' => [
66 - 'svg' => [
67 - 'aria-hidden' => true,
68 - 'aria-labelledby' => true,
69 - 'class' => true,
70 - 'height' => true,
71 - 'role' => true,
72 - 'viewbox' => true,
73 - 'width' => true,
74 - 'xmlns' => true,
75 - ],
76 - 'g' => [
77 - 'fill' => true,
78 - ],
79 - 'title' => [
80 - 'title' => true,
81 - ],
82 - 'path' => [
83 - 'd' => true,
84 - 'fill' => true,
85 - ],
86 - ],
87 - 'image' => [
88 - 'img' => [
89 - 'srcset' => true,
90 - 'sizes' => true,
91 - ],
92 - ],
93 - ];
94 -
95 42 /**
96 - * Variables for free to pro upsale modal promotions
43 + * Is ajax.
44 + *
45 + * Whether the current request is a WordPress ajax request.
46 + *
47 + * @since 1.0.0
48 + * @deprecated 2.6.0 Use `wp_doing_ajax()` instead.
49 + * @access public
50 + * @static
51 + *
52 + * @return bool True if it's a WordPress ajax request, false otherwise.
97 53 */
54 + public static function is_ajax() {
55 + _deprecated_function( __METHOD__, '2.6.0', 'wp_doing_ajax()' );
98 56
99 - const ANIMATED_HEADLINE = 'animated_headline';
57 + return wp_doing_ajax();
58 + }
100 59
101 - const CTA = 'cta';
102 -
103 - const VIDEO_PLAYLIST = 'video_playlist';
104 -
105 - const TESTIMONIAL_WIDGET = 'testimonial_widget';
106 -
107 - const IMAGE_CAROUSEL = 'image_carousel';
108 -
109 60 /**
110 - * Whether WordPress CLI mode is enabled or not.
61 + * Is WP CLI.
111 62 *
112 - * @access public
113 - * @static
114 - *
115 63 * @return bool
116 64 */
117 65 public static function is_wp_cli() {
118 66 return defined( 'WP_CLI' ) && WP_CLI;
@@ -118,8 +66,10 @@
118 66 return defined( 'WP_CLI' ) && WP_CLI;
119 67 }
120 68
121 69 /**
70 + * Is script debug.
71 + *
122 72 * Whether script debug is enabled or not.
123 73 *
124 74 * @since 1.0.0
125 75 * @access public
@@ -124,9 +74,9 @@
124 74 * @since 1.0.0
125 75 * @access public
126 76 * @static
127 77 *
128 - * @return bool
78 + * @return bool True if it's a script debug is active, false otherwise.
129 79 */
130 80 public static function is_script_debug() {
131 81 return defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG;
132 82 }
@@ -131,32 +81,8 @@
131 81 return defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG;
132 82 }
133 83
134 84 /**
135 - * Whether Elementor debug is enabled or not.
136 - *
137 - * @access public
138 - * @static
139 - *
140 - * @return bool
141 - */
142 - public static function is_elementor_debug() {
143 - return defined( 'ELEMENTOR_DEBUG' ) && ELEMENTOR_DEBUG;
144 - }
145 -
146 - /**
147 - * Whether Elementor test mode is enabled or not.
148 - *
149 - * @access public
150 - * @static
151 - *
152 - * @return bool
153 - */
154 - public static function is_elementor_tests() {
155 - return defined( 'ELEMENTOR_TESTS' ) && ELEMENTOR_TESTS;
156 - }
157 -
158 - /**
159 85 * Get pro link.
160 86 *
161 87 * Retrieve the link to Elementor Pro.
162 88 *
@@ -195,65 +121,45 @@
195 121 * @since 2.1.0
196 122 * @static
197 123 * @access public
198 124 *
199 - * @param string $from
200 - * @param string $to
125 + * @param $from
126 + * @param $to
201 127 *
202 128 * @return string
203 - * @throws \Exception If URLs are missing or invalid URLs provided.
129 + * @throws \Exception
204 130 */
205 131 public static function replace_urls( $from, $to ) {
206 132 $from = trim( $from );
207 133 $to = trim( $to );
208 134
209 - if ( empty( $from ) ) {
210 - throw new \Exception( 'Couldn’t replace your address because the old URL was not provided. Try again by entering the old URL.' );
211 - }
212 -
213 - if ( empty( $to ) ) {
214 - throw new \Exception( 'Couldn’t replace your address because the new URL was not provided. Try again by entering the new URL.' );
215 - }
216 -
217 135 if ( $from === $to ) {
218 - throw new \Exception( 'Couldn’t replace your address because both of the URLs provided are identical. Try again by entering different URLs.' );
136 + throw new \Exception( __( 'The `from` and `to` URL\'s must be different', 'elementor' ) );
219 137 }
220 138
221 139 $is_valid_urls = ( filter_var( $from, FILTER_VALIDATE_URL ) && filter_var( $to, FILTER_VALIDATE_URL ) );
222 -
223 140 if ( ! $is_valid_urls ) {
224 - throw new \Exception( 'Couldn’t replace your address because at least one of the URLs provided are invalid. Try again by entering valid URLs.' );
141 + throw new \Exception( __( 'The `from` and `to` URL\'s must be valid URL\'s', 'elementor' ) );
225 142 }
226 143
227 144 global $wpdb;
228 - $escaped_from = str_replace( '/', '\\/', $from );
229 - $escaped_to = str_replace( '/', '\\/', $to );
230 - $meta_value_like = '[%'; // meta_value LIKE '[%' are json formatted
231 145
146 + // @codingStandardsIgnoreStart cannot use `$wpdb->prepare` because it remove's the backslashes
232 147 $rows_affected = $wpdb->query(
233 - $wpdb->prepare(
234 - "UPDATE {$wpdb->postmeta} " .
235 - 'SET `meta_value` = REPLACE(`meta_value`, %s, %s) ' .
236 - "WHERE `meta_key` = '_elementor_data' AND `meta_value` LIKE %s;",
237 - $escaped_from,
238 - $escaped_to,
239 - $meta_value_like
240 - )
241 - );
148 + "UPDATE {$wpdb->postmeta} " .
149 + "SET `meta_value` = REPLACE(`meta_value`, '" . str_replace( '/', '\\\/', $from ) . "', '" . str_replace( '/', '\\\/', $to ) . "') " .
150 + "WHERE `meta_key` = '_elementor_data' AND `meta_value` LIKE '[%' ;" ); // meta_value LIKE '[%' are json formatted
151 + // @codingStandardsIgnoreEnd
242 152
243 153 if ( false === $rows_affected ) {
244 - throw new \Exception( 'An error occurred while replacing URL\'s.' );
154 + throw new \Exception( __( 'An error occurred', 'elementor' ) );
245 155 }
246 156
247 - // Allow externals to replace-urls, when they have to.
248 - $rows_affected += (int) apply_filters( 'elementor/tools/replace-urls', 0, $from, $to );
249 -
250 157 Plugin::$instance->files_manager->clear_cache();
251 - Google_Font::clear_cache();
252 158
253 159 return sprintf(
254 - /* translators: %d: Number of rows. */
255 - _n( '%d database row affected.', '%d database rows affected.', $rows_affected, 'elementor' ),
160 + /* translators: %d: Number of rows */
161 + _n( '%d row affected.', '%d rows affected.', $rows_affected, 'elementor' ),
256 162 $rows_affected
257 163 );
258 164 }
259 165
@@ -280,9 +186,9 @@
280 186 *
281 187 * Filters whether the post type supports editing with Elementor.
282 188 *
283 189 * @since 1.0.0
284 - * @deprecated 2.2.0 Use `elementor/utils/is_post_support` hook Instead.
190 + * @deprecated 2.2.0 Use `elementor/utils/is_post_support` Instead
285 191 *
286 192 * @param bool $is_supported Whether the post type supports editing with Elementor.
287 193 * @param int $post_id Post ID.
288 194 * @param string $post_type Post type.
@@ -399,10 +305,10 @@
399 305 if ( ! defined( 'DONOTCDN' ) ) {
400 306 define( 'DONOTCDN', true );
401 307 }
402 308
403 - if ( ! defined( 'DONOTCACHEOBJECT' ) ) {
404 - define( 'DONOTCACHEOBJECT', true );
309 + if ( ! defined( 'DONOTCACHCEOBJECT' ) ) {
310 + define( 'DONOTCACHCEOBJECT', true );
405 311 }
406 312
407 313 // Set the headers to prevent caching for the different browsers.
408 314 nocache_headers();
@@ -441,20 +347,30 @@
441 347 * Retrieve a custom URL for creating a new post/page using Elementor.
442 348 *
443 349 * @since 1.9.0
444 350 * @access public
445 - * @deprecated 3.3.0 Use `Plugin::$instance->documents->get_create_new_post_url()` instead.
446 351 * @static
447 352 *
448 - * @param string $post_type Optional. Post type slug. Default is 'page'.
353 + * @param string $post_type Optional. Post type slug. Default is 'page'.
449 354 * @param string|null $template_type Optional. Query arg 'template_type'. Default is null.
450 355 *
451 356 * @return string A URL for creating new post using Elementor.
452 357 */
453 358 public static function get_create_new_post_url( $post_type = 'page', $template_type = null ) {
454 - Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __FUNCTION__, '3.3.0', 'Plugin::$instance->documents->get_create_new_post_url()' );
359 + $query_args = [
360 + 'action' => 'elementor_new_post',
361 + 'post_type' => $post_type,
362 + ];
455 363
456 - return Plugin::$instance->documents->get_create_new_post_url( $post_type, $template_type );
364 + if ( $template_type ) {
365 + $query_args['template_type'] = $template_type;
366 + }
367 +
368 + $new_post_url = add_query_arg( $query_args, admin_url( 'edit.php' ) );
369 +
370 + $new_post_url = add_query_arg( '_wpnonce', wp_create_nonce( 'elementor_action_new_post' ), $new_post_url );
371 +
372 + return $new_post_url;
457 373 }
458 374
459 375 /**
460 376 * Get post autosave.
@@ -513,14 +429,14 @@
513 429 * @since 2.1.2
514 430 * @access public
515 431 * @static
516 432 */
517 - public static function array_inject( $base_array, $key, $insert ) {
518 - $length = array_search( $key, array_keys( $base_array ), true ) + 1;
433 + public static function array_inject( $array, $key, $insert ) {
434 + $length = array_search( $key, array_keys( $array ), true ) + 1;
519 435
520 - return array_slice( $base_array, 0, $length, true ) +
436 + return array_slice( $array, 0, $length, true ) +
521 437 $insert +
522 - array_slice( $base_array, $length, null, true );
438 + array_slice( $array, $length, null, true );
523 439 }
524 440
525 441 /**
526 442 * Render html attributes
@@ -544,39 +460,20 @@
544 460
545 461 return implode( ' ', $rendered_attributes );
546 462 }
547 463
548 - /**
549 - * Safe print html attributes
550 - *
551 - * @access public
552 - * @static
553 - * @param array $attributes
554 - */
555 - public static function print_html_attributes( array $attributes ) {
556 - // PHPCS - the method render_html_attributes is safe.
557 - echo self::render_html_attributes( $attributes ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
558 - }
559 -
560 464 public static function get_meta_viewport( $context = '' ) {
561 465 $meta_tag = '<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />';
562 -
563 466 /**
564 467 * Viewport meta tag.
565 468 *
566 - * Filters the meta tag containing the viewport information.
469 + * Filters the Elementor preview URL.
567 470 *
568 - * This hook can be used to change the initial viewport meta tag set by Elementor
569 - * and replace it with a different viewport tag.
570 - *
571 471 * @since 2.5.0
572 472 *
573 473 * @param string $meta_tag Viewport meta tag.
574 - * @param string $context Page context.
575 474 */
576 - $meta_tag = apply_filters( 'elementor/template/viewport_tag', $meta_tag, $context );
577 -
578 - return $meta_tag;
475 + return apply_filters( 'elementor/template/viewport_tag', $meta_tag, $context );
579 476 }
580 477
581 478 /**
582 479 * Add Elementor Config js vars to the relevant script handle,
@@ -581,17 +478,16 @@
581 478 /**
582 479 * Add Elementor Config js vars to the relevant script handle,
583 480 * WP will wrap it with <script> tag.
584 481 * To make sure this script runs thru the `script_loader_tag` hook, use a known handle value.
585 - *
586 482 * @param string $handle
587 483 * @param string $js_var
588 - * @param mixed $config
484 + * @param mixed $config
589 485 */
590 486 public static function print_js_config( $handle, $js_var, $config ) {
591 487 $config = wp_json_encode( $config );
592 488
593 - if ( get_option( self::EDITOR_BREAK_LINES_OPTION_KEY ) ) {
489 + if ( get_option( 'elementor_editor_break_lines' ) ) {
594 490 // Add new lines to avoid memory limits in some hosting servers that handles the buffer output according to new line characters
595 491 $config = str_replace( '}},"', '}},' . PHP_EOL . '"', $config );
596 492 }
597 493
@@ -609,9 +505,9 @@
609 505
610 506 $alias_version_as_float = (float) $alias_version[0];
611 507
612 508 if ( round( $current_version_as_float - $alias_version_as_float, 1 ) >= self::DEPRECATION_RANGE ) {
613 - _deprecated_file( $item, $version, $replacement ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
509 + _deprecated_file( $item, $version, $replacement );
614 510 }
615 511 }
616 512
617 513 /**
@@ -616,9 +512,9 @@
616 512
617 513 /**
618 514 * Checks a control value for being empty, including a string of '0' not covered by PHP's empty().
619 515 *
620 - * @param mixed $source
516 + * @param mixed $source
621 517 * @param bool|string $key
622 518 *
623 519 * @return bool
624 520 */
@@ -637,30 +533,15 @@
637 533 public static function has_pro() {
638 534 return defined( 'ELEMENTOR_PRO_VERSION' );
639 535 }
640 536
641 - public static function is_pro_installed_and_not_active(): bool {
642 - if ( ! function_exists( 'get_plugins' ) ) {
643 - require_once ABSPATH . 'wp-admin/includes/plugin.php';
644 - }
645 -
646 - $file_path = self::get_elementor_pro_file_path();
647 - $installed_plugins = get_plugins();
648 -
649 - return isset( $installed_plugins[ $file_path ] );
650 - }
651 -
652 - private static function get_elementor_pro_file_path(): string {
653 - return 'elementor-pro/elementor-pro.php';
654 - }
655 -
656 537 /**
657 538 * Convert HTMLEntities to UTF-8 characters
658 539 *
659 - * @param string $html_string
540 + * @param $string
660 541 * @return string
661 542 */
662 - public static function urlencode_html_entities( $html_string ) {
543 + public static function urlencode_html_entities( $string ) {
663 544 $entities_dictionary = [
664 545 '&#145;' => "'", // Opening single quote
665 546 '&#146;' => "'", // Closing single quote
666 547 '&#147;' => '"', // Closing double quote
@@ -673,11 +554,11 @@
673 554 '&#8222;' => '"', // Double low quote
674 555 ];
675 556
676 557 // Decode decimal entities
677 - $html_string = str_replace( array_keys( $entities_dictionary ), array_values( $entities_dictionary ), $html_string );
558 + $string = str_replace( array_keys( $entities_dictionary ), array_values( $entities_dictionary ), $string );
678 559
679 - return rawurlencode( html_entity_decode( $html_string, ENT_QUOTES | ENT_HTML5, 'UTF-8' ) );
560 + return rawurlencode( html_entity_decode( $string, ENT_QUOTES | ENT_HTML5, 'UTF-8' ) );
680 561 }
681 562
682 563 /**
683 564 * Parse attributes that come as a string of comma-delimited key|value pairs.
@@ -729,19 +610,13 @@
729 610 if ( $id === $element['id'] ) {
730 611 return $element;
731 612 }
732 613
733 - $inner_elements = apply_filters(
734 - 'elementor/utils/find_element_recursive/inner_elements',
735 - $element['elements'] ?? [],
736 - $element
737 - );
614 + if ( ! empty( $element['elements'] ) ) {
615 + $element = self::find_element_recursive( $element['elements'], $id );
738 616
739 - if ( ! empty( $inner_elements ) ) {
740 - $found = self::find_element_recursive( $inner_elements, $id );
741 -
742 - if ( $found ) {
743 - return $found;
617 + if ( $element ) {
618 + return $element;
744 619 }
745 620 }
746 621 }
747 622
@@ -756,10 +631,10 @@
756 631 * Fired by `admin_menu` action.
757 632 *
758 633 * @since 3.1.0
759 634 *
760 - * @param string $menu_slug
761 - * @param string $new_label
635 + * @param $menu_slug
636 + * @param $new_label
762 637 * @access public
763 638 */
764 639 public static function change_submenu_first_item_label( $menu_slug, $new_label ) {
765 640 global $submenu;
@@ -778,218 +653,7 @@
778 653 *
779 654 * @return string
780 655 */
781 656 public static function validate_html_tag( $tag ) {
782 - return $tag && in_array( strtolower( $tag ), self::ALLOWED_HTML_WRAPPER_TAGS ) ? $tag : 'div';
783 - }
784 -
785 - /**
786 - * Safe print a validated HTML tag.
787 - *
788 - * @param string $tag
789 - */
790 - public static function print_validated_html_tag( $tag ) {
791 - // PHPCS - the method validate_html_tag is safe.
792 - echo self::validate_html_tag( $tag ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
793 - }
794 -
795 - /**
796 - * Print internal content (not user input) without escaping.
797 - */
798 - public static function print_unescaped_internal_string( $internal_string ) {
799 - echo $internal_string; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
800 - }
801 -
802 - /**
803 - * Get recently edited posts query.
804 - *
805 - * Returns `WP_Query` of the recent edited posts.
806 - * By default max posts ( $args['posts_per_page'] ) is 3.
807 - *
808 - * @param array $args
809 - *
810 - * @return \WP_Query
811 - */
812 - public static function get_recently_edited_posts_query( $args = [] ) {
813 - $args = wp_parse_args( $args, [
814 - 'no_found_rows' => true,
815 - 'post_type' => 'any',
816 - 'post_status' => [ 'publish', 'draft' ],
817 - 'posts_per_page' => '3',
818 - 'meta_key' => '_elementor_edit_mode',
819 - 'meta_value' => 'builder',
820 - 'orderby' => 'modified',
821 - ] );
822 -
823 - return new \WP_Query( $args );
824 - }
825 -
826 - public static function print_wp_kses_extended( $text, array $tags ) {
827 - $allowed_html = wp_kses_allowed_html( 'post' );
828 -
829 - foreach ( $tags as $tag ) {
830 - if ( isset( self::EXTENDED_ALLOWED_HTML_TAGS[ $tag ] ) ) {
831 - $extended_tags = apply_filters( "elementor/extended_allowed_html_tags/{$tag}", self::EXTENDED_ALLOWED_HTML_TAGS[ $tag ] );
832 - $allowed_html = array_replace_recursive( $allowed_html, $extended_tags );
833 - }
834 - }
835 -
836 - echo wp_kses( $text, $allowed_html );
837 - }
838 -
839 - public static function is_elementor_path( $path ) {
840 - $path = wp_normalize_path( $path );
841 -
842 - /**
843 - * Elementor related paths.
844 - *
845 - * Filters Elementor related paths.
846 - *
847 - * @param string[] $available_paths
848 - */
849 - $available_paths = apply_filters( 'elementor/utils/elementor_related_paths', [ ELEMENTOR_PATH ] );
850 -
851 - return (bool) ( new Collection( $available_paths ) )
852 - ->map( function ( $p ) {
853 - // `untrailingslashit` in order to include other plugins prefixed with elementor.
854 - return untrailingslashit( wp_normalize_path( $p ) );
855 - } )
856 - ->find(function ( $p ) use ( $path ) {
857 - return false !== strpos( $path, $p );
858 - } );
859 - }
860 -
861 - /**
862 - * @param string $file
863 - * @param mixed ...$args
864 - * @return false|string
865 - */
866 - public static function file_get_contents( $file, ...$args ) {
867 - if ( ! is_file( $file ) || ! is_readable( $file ) ) {
868 - return false;
869 - }
870 - return file_get_contents( $file, ...$args );
871 - }
872 -
873 - public static function get_super_global_value( $super_global, $key ) {
874 - if ( ! isset( $super_global[ $key ] ) ) {
875 - return null;
876 - }
877 -
878 - if ( $_FILES === $super_global ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
879 - return isset( $super_global[ $key ]['name'] ) ?
880 - self::sanitize_file_name( $super_global[ $key ] ) :
881 - self::sanitize_multi_upload( $super_global[ $key ] );
882 - }
883 -
884 - return wp_kses_post_deep( wp_unslash( $super_global[ $key ] ) );
885 - }
886 -
887 - private static function sanitize_multi_upload( $fields ) {
888 - return array_map( function( $field ) {
889 - return array_map( 'self::sanitize_file_name', $field );
890 - }, $fields );
891 - }
892 -
893 - private static function sanitize_file_name( $file ) {
894 - $file['name'] = sanitize_file_name( $file['name'] );
895 -
896 - return $file;
897 - }
898 -
899 - /**
900 - * Return specific object property value if exist from array of keys.
901 - *
902 - * @param array $base_array
903 - * @param array $keys
904 - * @return mixed|null
905 - */
906 - public static function get_array_value_by_keys( $base_array, $keys ) {
907 - $keys = (array) $keys;
908 - foreach ( $keys as $key ) {
909 - if ( ! isset( $base_array[ $key ] ) ) {
910 - return null;
911 - }
912 - $base_array = $base_array[ $key ];
913 - }
914 - return $base_array;
915 - }
916 -
917 - public static function get_cached_callback( $callback, $cache_key, $cache_time = 24 * HOUR_IN_SECONDS ) {
918 - $cache = get_site_transient( $cache_key );
919 -
920 - if ( ! $cache ) {
921 - $cache = call_user_func( $callback );
922 -
923 - if ( ! is_wp_error( $cache ) ) {
924 - set_site_transient( $cache_key, $cache, $cache_time );
925 - }
926 - }
927 -
928 - return $cache;
929 - }
930 -
931 - public static function is_sale_time(): bool {
932 - $sale_start_time = gmmktime( 12, 0, 0, 11, 25, 2025 );
933 - $sale_end_time = gmmktime( 3, 59, 0, 12, 3, 2025 );
934 -
935 - $now_time = gmdate( 'U' );
936 -
937 - return $now_time >= $sale_start_time && $now_time <= $sale_end_time;
938 - }
939 -
940 - public static function safe_throw( string $message ) {
941 - if ( ! static::is_elementor_debug() ) {
942 - return;
943 - }
944 -
945 - throw new \Exception( esc_html( $message ) );
946 - }
947 -
948 - public static function has_invalid_post_permissions( $post ): bool {
949 - $is_image_attachment = 'attachment' === $post->post_type && strpos( $post->post_mime_type, 'image/' ) === 0;
950 -
951 - if ( $is_image_attachment ) {
952 - return false;
953 - }
954 -
955 - $is_private = 'private' === $post->post_status
956 - && ! current_user_can( 'read_private_posts', $post->ID );
957 -
958 - $not_allowed = 'publish' !== $post->post_status
959 - && ! current_user_can( 'edit_post', $post->ID );
960 -
961 - $password_required = post_password_required( $post->ID )
962 - && ! current_user_can( 'edit_post', $post->ID );
963 -
964 - return $is_private || $not_allowed || $password_required;
965 - }
966 -
967 - public static function is_custom_kit_applied() {
968 - return (bool) Plugin::$instance->kits_manager->get_previous_id();
969 - }
970 -
971 - public static function decode_string( string $encoded_string, ?string $fallback = '' ) {
972 - try {
973 - return base64_decode( $encoded_string, true ) ?? $fallback;
974 - } catch ( \Exception $e ) {
975 - return $fallback;
976 - }
977 - }
978 -
979 - public static function encode_string( string $decoded_string ): string {
980 - return base64_encode( $decoded_string );
981 - }
982 -
983 - public static function html_to_plain_text( string $html ): string {
984 - if ( empty( $html ) ) {
985 - return '';
986 - }
987 -
988 - $text = preg_replace( '#<br\s*/?\s*>#i', ' ', $html );
989 - $text = preg_replace( '#</?[a-z][^>]*>#i', ' ', $text );
990 - $text = html_entity_decode( $text, ENT_QUOTES, 'UTF-8' );
991 - $text = str_replace( "\xE2\x80\x8B", '', $text );
992 -
993 - return trim( preg_replace( '/\s+/', ' ', $text ) );
657 + return in_array( strtolower( $tag ), self::ALLOWED_HTML_WRAPPER_TAGS ) ? $tag : 'div';
994 658 }
995 659 }