PluginProbe
Elementor Website Builder – more than just a page builder / 3.2.2
Elementor Website Builder – more than just a page builder v3.2.2
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 +80 -382 4.2.0-dev23.2.2 View file →
@@ -1,9 +1,8 @@
1 1 <?php
2 2 namespace Elementor;
3 3
4 -use Elementor\Core\Files\Fonts\Google_Font;
5 -use Elementor\Core\Utils\Collection;
4 +use Elementor\Core\Settings\Page\Manager;
6 5
7 6 if ( ! defined( 'ABSPATH' ) ) {
8 7 exit; // Exit if accessed directly.
9 8 }
@@ -19,19 +18,14 @@
19 18 class Utils {
20 19
21 20 const DEPRECATION_RANGE = 0.4;
22 21
23 - const EDITOR_BREAK_LINES_OPTION_KEY = 'elementor_editor_break_lines';
24 -
25 22 /**
26 - * A list of safe tags for `validate_html_tag` method.
23 + * A list of safe tage for `validate_html_tag` method.
27 24 */
28 25 const ALLOWED_HTML_WRAPPER_TAGS = [
29 - 'a',
30 26 'article',
31 27 'aside',
32 - 'button',
33 - 'form',
34 28 'div',
35 29 'footer',
36 30 'h1',
37 31 'h2',
@@ -46,73 +40,29 @@
46 40 'section',
47 41 'span',
48 42 ];
49 43
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 44 /**
96 - * Variables for free to pro upsale modal promotions
45 + * Is ajax.
46 + *
47 + * Whether the current request is a WordPress ajax request.
48 + *
49 + * @since 1.0.0
50 + * @deprecated 2.6.0 Use `wp_doing_ajax()` instead.
51 + * @access public
52 + * @static
53 + *
54 + * @return bool True if it's a WordPress ajax request, false otherwise.
97 55 */
56 + public static function is_ajax() {
57 + _deprecated_function( __METHOD__, '2.6.0', 'wp_doing_ajax()' );
98 58
99 - const ANIMATED_HEADLINE = 'animated_headline';
59 + return wp_doing_ajax();
60 + }
100 61
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 62 /**
110 - * Whether WordPress CLI mode is enabled or not.
63 + * Is WP CLI.
111 64 *
112 - * @access public
113 - * @static
114 - *
115 65 * @return bool
116 66 */
117 67 public static function is_wp_cli() {
118 68 return defined( 'WP_CLI' ) && WP_CLI;
@@ -118,8 +68,10 @@
118 68 return defined( 'WP_CLI' ) && WP_CLI;
119 69 }
120 70
121 71 /**
72 + * Is script debug.
73 + *
122 74 * Whether script debug is enabled or not.
123 75 *
124 76 * @since 1.0.0
125 77 * @access public
@@ -124,9 +76,9 @@
124 76 * @since 1.0.0
125 77 * @access public
126 78 * @static
127 79 *
128 - * @return bool
80 + * @return bool True if it's a script debug is active, false otherwise.
129 81 */
130 82 public static function is_script_debug() {
131 83 return defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG;
132 84 }
@@ -131,32 +83,8 @@
131 83 return defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG;
132 84 }
133 85
134 86 /**
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 87 * Get pro link.
160 88 *
161 89 * Retrieve the link to Elementor Pro.
162 90 *
@@ -195,54 +123,48 @@
195 123 * @since 2.1.0
196 124 * @static
197 125 * @access public
198 126 *
199 - * @param string $from
200 - * @param string $to
127 + * @param $from
128 + * @param $to
201 129 *
202 130 * @return string
203 - * @throws \Exception If URLs are missing or invalid URLs provided.
131 + * @throws \Exception
204 132 */
205 133 public static function replace_urls( $from, $to ) {
206 134 $from = trim( $from );
207 135 $to = trim( $to );
208 136
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 137 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.' );
138 + throw new \Exception( __( 'The `from` and `to` URL\'s must be different', 'elementor' ) );
219 139 }
220 140
221 141 $is_valid_urls = ( filter_var( $from, FILTER_VALIDATE_URL ) && filter_var( $to, FILTER_VALIDATE_URL ) );
222 -
223 142 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.' );
143 + throw new \Exception( __( 'The `from` and `to` URL\'s must be valid URL\'s', 'elementor' ) );
225 144 }
226 145
227 146 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 147
148 + // @codingStandardsIgnoreStart cannot use `$wpdb->prepare` because it remove's the backslashes
232 149 $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 - )
150 + "UPDATE {$wpdb->postmeta} " .
151 + "SET `meta_value` = REPLACE(`meta_value`, '" . str_replace( '/', '\\\/', $from ) . "', '" . str_replace( '/', '\\\/', $to ) . "') " .
152 + "WHERE `meta_key` = '_elementor_data' AND `meta_value` LIKE '[%' ;" ); // meta_value LIKE '[%' are json formatted
153 + // @codingStandardsIgnoreEnd
154 +
155 + $second_rows_affected = $wpdb->query(
156 + "UPDATE {$wpdb->postmeta} " .
157 + $wpdb->prepare( 'SET `meta_value` = REPLACE(`meta_value`, %s, %s) ', $from, $to ) .
158 + 'WHERE `meta_key` = \'' . Manager::META_KEY . '\''
241 159 );
242 160
161 + if ( $second_rows_affected ) {
162 + $rows_affected += $second_rows_affected;
163 + }
164 +
243 165 if ( false === $rows_affected ) {
244 - throw new \Exception( 'An error occurred while replacing URL\'s.' );
166 + throw new \Exception( __( 'An error occurred', 'elementor' ) );
245 167 }
246 168
247 169 // Allow externals to replace-urls, when they have to.
248 170 $rows_affected += (int) apply_filters( 'elementor/tools/replace-urls', 0, $from, $to );
@@ -247,13 +169,12 @@
247 169 // Allow externals to replace-urls, when they have to.
248 170 $rows_affected += (int) apply_filters( 'elementor/tools/replace-urls', 0, $from, $to );
249 171
250 172 Plugin::$instance->files_manager->clear_cache();
251 - Google_Font::clear_cache();
252 173
253 174 return sprintf(
254 - /* translators: %d: Number of rows. */
255 - _n( '%d database row affected.', '%d database rows affected.', $rows_affected, 'elementor' ),
175 + /* translators: %d: Number of rows */
176 + _n( '%d row affected.', '%d rows affected.', $rows_affected, 'elementor' ),
256 177 $rows_affected
257 178 );
258 179 }
259 180
@@ -280,9 +201,9 @@
280 201 *
281 202 * Filters whether the post type supports editing with Elementor.
282 203 *
283 204 * @since 1.0.0
284 - * @deprecated 2.2.0 Use `elementor/utils/is_post_support` hook Instead.
205 + * @deprecated 2.2.0 Use `elementor/utils/is_post_support` Instead
285 206 *
286 207 * @param bool $is_supported Whether the post type supports editing with Elementor.
287 208 * @param int $post_id Post ID.
288 209 * @param string $post_type Post type.
@@ -399,10 +320,10 @@
399 320 if ( ! defined( 'DONOTCDN' ) ) {
400 321 define( 'DONOTCDN', true );
401 322 }
402 323
403 - if ( ! defined( 'DONOTCACHEOBJECT' ) ) {
404 - define( 'DONOTCACHEOBJECT', true );
324 + if ( ! defined( 'DONOTCACHCEOBJECT' ) ) {
325 + define( 'DONOTCACHCEOBJECT', true );
405 326 }
406 327
407 328 // Set the headers to prevent caching for the different browsers.
408 329 nocache_headers();
@@ -441,20 +362,30 @@
441 362 * Retrieve a custom URL for creating a new post/page using Elementor.
442 363 *
443 364 * @since 1.9.0
444 365 * @access public
445 - * @deprecated 3.3.0 Use `Plugin::$instance->documents->get_create_new_post_url()` instead.
446 366 * @static
447 367 *
448 - * @param string $post_type Optional. Post type slug. Default is 'page'.
368 + * @param string $post_type Optional. Post type slug. Default is 'page'.
449 369 * @param string|null $template_type Optional. Query arg 'template_type'. Default is null.
450 370 *
451 371 * @return string A URL for creating new post using Elementor.
452 372 */
453 373 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()' );
374 + $query_args = [
375 + 'action' => 'elementor_new_post',
376 + 'post_type' => $post_type,
377 + ];
455 378
456 - return Plugin::$instance->documents->get_create_new_post_url( $post_type, $template_type );
379 + if ( $template_type ) {
380 + $query_args['template_type'] = $template_type;
381 + }
382 +
383 + $new_post_url = add_query_arg( $query_args, admin_url( 'edit.php' ) );
384 +
385 + $new_post_url = add_query_arg( '_wpnonce', wp_create_nonce( 'elementor_action_new_post' ), $new_post_url );
386 +
387 + return $new_post_url;
457 388 }
458 389
459 390 /**
460 391 * Get post autosave.
@@ -513,14 +444,14 @@
513 444 * @since 2.1.2
514 445 * @access public
515 446 * @static
516 447 */
517 - public static function array_inject( $base_array, $key, $insert ) {
518 - $length = array_search( $key, array_keys( $base_array ), true ) + 1;
448 + public static function array_inject( $array, $key, $insert ) {
449 + $length = array_search( $key, array_keys( $array ), true ) + 1;
519 450
520 - return array_slice( $base_array, 0, $length, true ) +
451 + return array_slice( $array, 0, $length, true ) +
521 452 $insert +
522 - array_slice( $base_array, $length, null, true );
453 + array_slice( $array, $length, null, true );
523 454 }
524 455
525 456 /**
526 457 * Render html attributes
@@ -544,39 +475,20 @@
544 475
545 476 return implode( ' ', $rendered_attributes );
546 477 }
547 478
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 479 public static function get_meta_viewport( $context = '' ) {
561 480 $meta_tag = '<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />';
562 -
563 481 /**
564 482 * Viewport meta tag.
565 483 *
566 - * Filters the meta tag containing the viewport information.
484 + * Filters the Elementor preview URL.
567 485 *
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 486 * @since 2.5.0
572 487 *
573 488 * @param string $meta_tag Viewport meta tag.
574 - * @param string $context Page context.
575 489 */
576 - $meta_tag = apply_filters( 'elementor/template/viewport_tag', $meta_tag, $context );
577 -
578 - return $meta_tag;
490 + return apply_filters( 'elementor/template/viewport_tag', $meta_tag, $context );
579 491 }
580 492
581 493 /**
582 494 * Add Elementor Config js vars to the relevant script handle,
@@ -581,17 +493,16 @@
581 493 /**
582 494 * Add Elementor Config js vars to the relevant script handle,
583 495 * WP will wrap it with <script> tag.
584 496 * To make sure this script runs thru the `script_loader_tag` hook, use a known handle value.
585 - *
586 497 * @param string $handle
587 498 * @param string $js_var
588 - * @param mixed $config
499 + * @param mixed $config
589 500 */
590 501 public static function print_js_config( $handle, $js_var, $config ) {
591 502 $config = wp_json_encode( $config );
592 503
593 - if ( get_option( self::EDITOR_BREAK_LINES_OPTION_KEY ) ) {
504 + if ( get_option( 'elementor_editor_break_lines' ) ) {
594 505 // Add new lines to avoid memory limits in some hosting servers that handles the buffer output according to new line characters
595 506 $config = str_replace( '}},"', '}},' . PHP_EOL . '"', $config );
596 507 }
597 508
@@ -609,9 +520,9 @@
609 520
610 521 $alias_version_as_float = (float) $alias_version[0];
611 522
612 523 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
524 + _deprecated_file( $item, $version, $replacement );
614 525 }
615 526 }
616 527
617 528 /**
@@ -616,9 +527,9 @@
616 527
617 528 /**
618 529 * Checks a control value for being empty, including a string of '0' not covered by PHP's empty().
619 530 *
620 - * @param mixed $source
531 + * @param mixed $source
621 532 * @param bool|string $key
622 533 *
623 534 * @return bool
624 535 */
@@ -637,34 +548,15 @@
637 548 public static function has_pro() {
638 549 return defined( 'ELEMENTOR_PRO_VERSION' );
639 550 }
640 551
641 - public static function is_license_active(): bool {
642 - return class_exists( '\ElementorPro\License\API' ) && \ElementorPro\License\API::is_license_active();
643 - }
644 -
645 - public static function is_pro_installed_and_not_active(): bool {
646 - if ( ! function_exists( 'get_plugins' ) ) {
647 - require_once ABSPATH . 'wp-admin/includes/plugin.php';
648 - }
649 -
650 - $file_path = self::get_elementor_pro_file_path();
651 - $installed_plugins = get_plugins();
652 -
653 - return isset( $installed_plugins[ $file_path ] );
654 - }
655 -
656 - private static function get_elementor_pro_file_path(): string {
657 - return 'elementor-pro/elementor-pro.php';
658 - }
659 -
660 552 /**
661 553 * Convert HTMLEntities to UTF-8 characters
662 554 *
663 - * @param string $html_string
555 + * @param $string
664 556 * @return string
665 557 */
666 - public static function urlencode_html_entities( $html_string ) {
558 + public static function urlencode_html_entities( $string ) {
667 559 $entities_dictionary = [
668 560 '&#145;' => "'", // Opening single quote
669 561 '&#146;' => "'", // Closing single quote
670 562 '&#147;' => '"', // Closing double quote
@@ -677,11 +569,11 @@
677 569 '&#8222;' => '"', // Double low quote
678 570 ];
679 571
680 572 // Decode decimal entities
681 - $html_string = str_replace( array_keys( $entities_dictionary ), array_values( $entities_dictionary ), $html_string );
573 + $string = str_replace( array_keys( $entities_dictionary ), array_values( $entities_dictionary ), $string );
682 574
683 - return rawurlencode( html_entity_decode( $html_string, ENT_QUOTES | ENT_HTML5, 'UTF-8' ) );
575 + return rawurlencode( html_entity_decode( $string, ENT_QUOTES | ENT_HTML5, 'UTF-8' ) );
684 576 }
685 577
686 578 /**
687 579 * Parse attributes that come as a string of comma-delimited key|value pairs.
@@ -733,19 +625,13 @@
733 625 if ( $id === $element['id'] ) {
734 626 return $element;
735 627 }
736 628
737 - $inner_elements = apply_filters(
738 - 'elementor/utils/find_element_recursive/inner_elements',
739 - $element['elements'] ?? [],
740 - $element
741 - );
629 + if ( ! empty( $element['elements'] ) ) {
630 + $element = self::find_element_recursive( $element['elements'], $id );
742 631
743 - if ( ! empty( $inner_elements ) ) {
744 - $found = self::find_element_recursive( $inner_elements, $id );
745 -
746 - if ( $found ) {
747 - return $found;
632 + if ( $element ) {
633 + return $element;
748 634 }
749 635 }
750 636 }
751 637
@@ -760,10 +646,10 @@
760 646 * Fired by `admin_menu` action.
761 647 *
762 648 * @since 3.1.0
763 649 *
764 - * @param string $menu_slug
765 - * @param string $new_label
650 + * @param $menu_slug
651 + * @param $new_label
766 652 * @access public
767 653 */
768 654 public static function change_submenu_first_item_label( $menu_slug, $new_label ) {
769 655 global $submenu;
@@ -782,29 +668,12 @@
782 668 *
783 669 * @return string
784 670 */
785 671 public static function validate_html_tag( $tag ) {
786 - return $tag && in_array( strtolower( $tag ), self::ALLOWED_HTML_WRAPPER_TAGS ) ? $tag : 'div';
672 + return in_array( strtolower( $tag ), self::ALLOWED_HTML_WRAPPER_TAGS ) ? $tag : 'div';
787 673 }
788 674
789 675 /**
790 - * Safe print a validated HTML tag.
791 - *
792 - * @param string $tag
793 - */
794 - public static function print_validated_html_tag( $tag ) {
795 - // PHPCS - the method validate_html_tag is safe.
796 - echo self::validate_html_tag( $tag ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
797 - }
798 -
799 - /**
800 - * Print internal content (not user input) without escaping.
801 - */
802 - public static function print_unescaped_internal_string( $internal_string ) {
803 - echo $internal_string; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
804 - }
805 -
806 - /**
807 676 * Get recently edited posts query.
808 677 *
809 678 * Returns `WP_Query` of the recent edited posts.
810 679 * By default max posts ( $args['posts_per_page'] ) is 3.
@@ -814,9 +683,8 @@
814 683 * @return \WP_Query
815 684 */
816 685 public static function get_recently_edited_posts_query( $args = [] ) {
817 686 $args = wp_parse_args( $args, [
818 - 'no_found_rows' => true,
819 687 'post_type' => 'any',
820 688 'post_status' => [ 'publish', 'draft' ],
821 689 'posts_per_page' => '3',
822 690 'meta_key' => '_elementor_edit_mode',
@@ -824,176 +692,6 @@
824 692 'orderby' => 'modified',
825 693 ] );
826 694
827 695 return new \WP_Query( $args );
828 - }
829 -
830 - public static function print_wp_kses_extended( $text, array $tags ) {
831 - $allowed_html = wp_kses_allowed_html( 'post' );
832 -
833 - foreach ( $tags as $tag ) {
834 - if ( isset( self::EXTENDED_ALLOWED_HTML_TAGS[ $tag ] ) ) {
835 - $extended_tags = apply_filters( "elementor/extended_allowed_html_tags/{$tag}", self::EXTENDED_ALLOWED_HTML_TAGS[ $tag ] );
836 - $allowed_html = array_replace_recursive( $allowed_html, $extended_tags );
837 - }
838 - }
839 -
840 - echo wp_kses( $text, $allowed_html );
841 - }
842 -
843 - public static function is_elementor_path( $path ) {
844 - $path = wp_normalize_path( $path );
845 -
846 - /**
847 - * Elementor related paths.
848 - *
849 - * Filters Elementor related paths.
850 - *
851 - * @param string[] $available_paths
852 - */
853 - $available_paths = apply_filters( 'elementor/utils/elementor_related_paths', [ ELEMENTOR_PATH ] );
854 -
855 - return (bool) ( new Collection( $available_paths ) )
856 - ->map( function ( $p ) {
857 - // `untrailingslashit` in order to include other plugins prefixed with elementor.
858 - return untrailingslashit( wp_normalize_path( $p ) );
859 - } )
860 - ->find(function ( $p ) use ( $path ) {
861 - return false !== strpos( $path, $p );
862 - } );
863 - }
864 -
865 - /**
866 - * @param string $file
867 - * @param mixed ...$args
868 - * @return false|string
869 - */
870 - public static function file_get_contents( $file, ...$args ) {
871 - if ( ! is_file( $file ) || ! is_readable( $file ) ) {
872 - return false;
873 - }
874 - return file_get_contents( $file, ...$args );
875 - }
876 -
877 - public static function get_super_global_value( $super_global, $key ) {
878 - if ( ! isset( $super_global[ $key ] ) ) {
879 - return null;
880 - }
881 -
882 - if ( $_FILES === $super_global ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
883 - return isset( $super_global[ $key ]['name'] ) ?
884 - self::sanitize_file_name( $super_global[ $key ] ) :
885 - self::sanitize_multi_upload( $super_global[ $key ] );
886 - }
887 -
888 - return wp_kses_post_deep( wp_unslash( $super_global[ $key ] ) );
889 - }
890 -
891 - private static function sanitize_multi_upload( $fields ) {
892 - return array_map( function( $field ) {
893 - return array_map( 'self::sanitize_file_name', $field );
894 - }, $fields );
895 - }
896 -
897 - private static function sanitize_file_name( $file ) {
898 - $file['name'] = sanitize_file_name( $file['name'] );
899 -
900 - return $file;
901 - }
902 -
903 - /**
904 - * Return specific object property value if exist from array of keys.
905 - *
906 - * @param array $base_array
907 - * @param array $keys
908 - * @return mixed|null
909 - */
910 - public static function get_array_value_by_keys( $base_array, $keys ) {
911 - $keys = (array) $keys;
912 - foreach ( $keys as $key ) {
913 - if ( ! isset( $base_array[ $key ] ) ) {
914 - return null;
915 - }
916 - $base_array = $base_array[ $key ];
917 - }
918 - return $base_array;
919 - }
920 -
921 - public static function get_cached_callback( $callback, $cache_key, $cache_time = 24 * HOUR_IN_SECONDS ) {
922 - $cache = get_site_transient( $cache_key );
923 -
924 - if ( ! $cache ) {
925 - $cache = call_user_func( $callback );
926 -
927 - if ( ! is_wp_error( $cache ) ) {
928 - set_site_transient( $cache_key, $cache, $cache_time );
929 - }
930 - }
931 -
932 - return $cache;
933 - }
934 -
935 - public static function is_sale_time(): bool {
936 - $sale_start_time = gmmktime( 10, 0, 0, 6, 15, 2026 );
937 - $sale_end_time = gmmktime( 3, 59, 0, 6, 17, 2026 );
938 -
939 - $now_time = gmdate( 'U' );
940 -
941 - return $now_time >= $sale_start_time && $now_time <= $sale_end_time;
942 - }
943 -
944 - public static function safe_throw( string $message ) {
945 - if ( ! static::is_elementor_debug() ) {
946 - return;
947 - }
948 -
949 - throw new \Exception( esc_html( $message ) );
950 - }
951 -
952 - public static function has_invalid_post_permissions( $post ): bool {
953 - $is_image_attachment = 'attachment' === $post->post_type && strpos( $post->post_mime_type, 'image/' ) === 0;
954 -
955 - if ( $is_image_attachment ) {
956 - return false;
957 - }
958 -
959 - $is_private = 'private' === $post->post_status
960 - && ! current_user_can( 'read_private_posts', $post->ID );
961 -
962 - $not_allowed = 'publish' !== $post->post_status
963 - && ! current_user_can( 'edit_post', $post->ID );
964 -
965 - $password_required = post_password_required( $post->ID )
966 - && ! current_user_can( 'edit_post', $post->ID );
967 -
968 - return $is_private || $not_allowed || $password_required;
969 - }
970 -
971 - public static function is_custom_kit_applied() {
972 - return (bool) Plugin::$instance->kits_manager->get_previous_id();
973 - }
974 -
975 - public static function decode_string( string $encoded_string, ?string $fallback = '' ) {
976 - try {
977 - return base64_decode( $encoded_string, true ) ?? $fallback;
978 - } catch ( \Exception $e ) {
979 - return $fallback;
980 - }
981 - }
982 -
983 - public static function encode_string( string $decoded_string ): string {
984 - return base64_encode( $decoded_string );
985 - }
986 -
987 - public static function html_to_plain_text( string $html ): string {
988 - if ( empty( $html ) ) {
989 - return '';
990 - }
991 -
992 - $text = preg_replace( '#<br\s*/?\s*>#i', ' ', $html );
993 - $text = preg_replace( '#</?[a-z][^>]*>#i', ' ', $text );
994 - $text = html_entity_decode( $text, ENT_QUOTES, 'UTF-8' );
995 - $text = str_replace( "\xE2\x80\x8B", '', $text );
996 -
997 - return trim( preg_replace( '/\s+/', ' ', $text ) );
998 696 }
999 697 }