PluginProbe
Elementor Website Builder – more than just a page builder / 3.25.4
Elementor Website Builder – more than just a page builder v3.25.4
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 +44 -216 4.3.0-beta23.25.4 View file →
@@ -1,8 +1,7 @@
1 1 <?php
2 2 namespace Elementor;
3 3
4 -use Elementor\Core\Files\Fonts\Google_Font;
5 4 use Elementor\Core\Utils\Collection;
6 5
7 6 if ( ! defined( 'ABSPATH' ) ) {
8 7 exit; // Exit if accessed directly.
@@ -29,9 +28,8 @@
29 28 'a',
30 29 'article',
31 30 'aside',
32 31 'button',
33 - 'form',
34 32 'div',
35 33 'footer',
36 34 'h1',
37 35 'h2',
@@ -46,29 +44,8 @@
46 44 'section',
47 45 'span',
48 46 ];
49 47
50 - /**
51 - * Tags that must never be usable as an HTML wrapper tag, regardless of what
52 - * `elementor/allowed_html_wrapper_tags` filters return. These are the classic
53 - * script-execution / markup-injection vectors (XSS), so they're enforced as a
54 - * hard denylist rather than left to filter authors to avoid re-adding them.
55 - */
56 - const FORBIDDEN_HTML_WRAPPER_TAGS = [
57 - 'script',
58 - 'iframe',
59 - 'object',
60 - 'embed',
61 - 'style',
62 - 'link',
63 - 'meta',
64 - 'base',
65 - 'noscript',
66 - 'template',
67 - 'svg',
68 - 'math',
69 - ];
70 -
71 48 const EXTENDED_ALLOWED_HTML_TAGS = [
72 49 'iframe' => [
73 50 'iframe' => [
74 51 'allow' => true,
@@ -113,27 +90,10 @@
113 90 ],
114 91 ];
115 92
116 93 /**
117 - * Variables for free to pro upsale modal promotions
118 - */
119 -
120 - const ANIMATED_HEADLINE = 'animated_headline';
121 -
122 - const CTA = 'cta';
123 -
124 - const VIDEO_PLAYLIST = 'video_playlist';
125 -
126 - const TESTIMONIAL_WIDGET = 'testimonial_widget';
127 -
128 - const IMAGE_CAROUSEL = 'image_carousel';
129 -
130 - /**
131 - * Whether WordPress CLI mode is enabled or not.
94 + * Is WP CLI.
132 95 *
133 - * @access public
134 - * @static
135 - *
136 96 * @return bool
137 97 */
138 98 public static function is_wp_cli() {
139 99 return defined( 'WP_CLI' ) && WP_CLI;
@@ -139,8 +99,10 @@
139 99 return defined( 'WP_CLI' ) && WP_CLI;
140 100 }
141 101
142 102 /**
103 + * Is script debug.
104 + *
143 105 * Whether script debug is enabled or not.
144 106 *
145 107 * @since 1.0.0
146 108 * @access public
@@ -145,32 +107,21 @@
145 107 * @since 1.0.0
146 108 * @access public
147 109 * @static
148 110 *
149 - * @return bool
111 + * @return bool True if it's a script debug is active, false otherwise.
150 112 */
151 113 public static function is_script_debug() {
152 114 return defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG;
153 115 }
154 116
155 - /**
156 - * Whether Elementor debug is enabled or not.
157 - *
158 - * @access public
159 - * @static
160 - *
161 - * @return bool
162 - */
163 117 public static function is_elementor_debug() {
164 118 return defined( 'ELEMENTOR_DEBUG' ) && ELEMENTOR_DEBUG;
165 119 }
166 120
167 121 /**
168 - * Whether Elementor test mode is enabled or not.
122 + * Whether elementor test mode is enabled or not.
169 123 *
170 - * @access public
171 - * @static
172 - *
173 124 * @return bool
174 125 */
175 126 public static function is_elementor_tests() {
176 127 return defined( 'ELEMENTOR_TESTS' ) && ELEMENTOR_TESTS;
@@ -216,13 +167,13 @@
216 167 * @since 2.1.0
217 168 * @static
218 169 * @access public
219 170 *
220 - * @param string $from
221 - * @param string $to
171 + * @param $from
172 + * @param $to
222 173 *
223 174 * @return string
224 - * @throws \Exception If URLs are missing or invalid URLs provided.
175 + * @throws \Exception
225 176 */
226 177 public static function replace_urls( $from, $to ) {
227 178 $from = trim( $from );
228 179 $to = trim( $to );
@@ -268,9 +219,8 @@
268 219 // Allow externals to replace-urls, when they have to.
269 220 $rows_affected += (int) apply_filters( 'elementor/tools/replace-urls', 0, $from, $to );
270 221
271 222 Plugin::$instance->files_manager->clear_cache();
272 - Google_Font::clear_cache();
273 223
274 224 return sprintf(
275 225 /* translators: %d: Number of rows. */
276 226 _n( '%d database row affected.', '%d database rows affected.', $rows_affected, 'elementor' ),
@@ -465,9 +415,9 @@
465 415 * @access public
466 416 * @deprecated 3.3.0 Use `Plugin::$instance->documents->get_create_new_post_url()` instead.
467 417 * @static
468 418 *
469 - * @param string $post_type Optional. Post type slug. Default is 'page'.
419 + * @param string $post_type Optional. Post type slug. Default is 'page'.
470 420 * @param string|null $template_type Optional. Query arg 'template_type'. Default is null.
471 421 *
472 422 * @return string A URL for creating new post using Elementor.
473 423 */
@@ -534,14 +484,14 @@
534 484 * @since 2.1.2
535 485 * @access public
536 486 * @static
537 487 */
538 - public static function array_inject( $base_array, $key, $insert ) {
539 - $length = array_search( $key, array_keys( $base_array ), true ) + 1;
488 + public static function array_inject( $array, $key, $insert ) {
489 + $length = array_search( $key, array_keys( $array ), true ) + 1;
540 490
541 - return array_slice( $base_array, 0, $length, true ) +
491 + return array_slice( $array, 0, $length, true ) +
542 492 $insert +
543 - array_slice( $base_array, $length, null, true );
493 + array_slice( $array, $length, null, true );
544 494 }
545 495
546 496 /**
547 497 * Render html attributes
@@ -602,12 +552,11 @@
602 552 /**
603 553 * Add Elementor Config js vars to the relevant script handle,
604 554 * WP will wrap it with <script> tag.
605 555 * To make sure this script runs thru the `script_loader_tag` hook, use a known handle value.
606 - *
607 556 * @param string $handle
608 557 * @param string $js_var
609 - * @param mixed $config
558 + * @param mixed $config
610 559 */
611 560 public static function print_js_config( $handle, $js_var, $config ) {
612 561 $config = wp_json_encode( $config );
613 562
@@ -637,9 +586,9 @@
637 586
638 587 /**
639 588 * Checks a control value for being empty, including a string of '0' not covered by PHP's empty().
640 589 *
641 - * @param mixed $source
590 + * @param mixed $source
642 591 * @param bool|string $key
643 592 *
644 593 * @return bool
645 594 */
@@ -658,34 +607,15 @@
658 607 public static function has_pro() {
659 608 return defined( 'ELEMENTOR_PRO_VERSION' );
660 609 }
661 610
662 - public static function is_license_active(): bool {
663 - return class_exists( '\ElementorPro\License\API' ) && \ElementorPro\License\API::is_license_active();
664 - }
665 -
666 - public static function is_pro_installed_and_not_active(): bool {
667 - if ( ! function_exists( 'get_plugins' ) ) {
668 - require_once ABSPATH . 'wp-admin/includes/plugin.php';
669 - }
670 -
671 - $file_path = self::get_elementor_pro_file_path();
672 - $installed_plugins = get_plugins();
673 -
674 - return isset( $installed_plugins[ $file_path ] );
675 - }
676 -
677 - private static function get_elementor_pro_file_path(): string {
678 - return 'elementor-pro/elementor-pro.php';
679 - }
680 -
681 611 /**
682 612 * Convert HTMLEntities to UTF-8 characters
683 613 *
684 - * @param string $html_string
614 + * @param $string
685 615 * @return string
686 616 */
687 - public static function urlencode_html_entities( $html_string ) {
617 + public static function urlencode_html_entities( $string ) {
688 618 $entities_dictionary = [
689 619 '&#145;' => "'", // Opening single quote
690 620 '&#146;' => "'", // Closing single quote
691 621 '&#147;' => '"', // Closing double quote
@@ -698,11 +628,11 @@
698 628 '&#8222;' => '"', // Double low quote
699 629 ];
700 630
701 631 // Decode decimal entities
702 - $html_string = str_replace( array_keys( $entities_dictionary ), array_values( $entities_dictionary ), $html_string );
632 + $string = str_replace( array_keys( $entities_dictionary ), array_values( $entities_dictionary ), $string );
703 633
704 - return rawurlencode( html_entity_decode( $html_string, ENT_QUOTES | ENT_HTML5, 'UTF-8' ) );
634 + return rawurlencode( html_entity_decode( $string, ENT_QUOTES | ENT_HTML5, 'UTF-8' ) );
705 635 }
706 636
707 637 /**
708 638 * Parse attributes that come as a string of comma-delimited key|value pairs.
@@ -754,19 +684,13 @@
754 684 if ( $id === $element['id'] ) {
755 685 return $element;
756 686 }
757 687
758 - $inner_elements = apply_filters(
759 - 'elementor/utils/find_element_recursive/inner_elements',
760 - $element['elements'] ?? [],
761 - $element
762 - );
688 + if ( ! empty( $element['elements'] ) ) {
689 + $element = self::find_element_recursive( $element['elements'], $id );
763 690
764 - if ( ! empty( $inner_elements ) ) {
765 - $found = self::find_element_recursive( $inner_elements, $id );
766 -
767 - if ( $found ) {
768 - return $found;
691 + if ( $element ) {
692 + return $element;
769 693 }
770 694 }
771 695 }
772 696
@@ -781,10 +705,10 @@
781 705 * Fired by `admin_menu` action.
782 706 *
783 707 * @since 3.1.0
784 708 *
785 - * @param string $menu_slug
786 - * @param string $new_label
709 + * @param $menu_slug
710 + * @param $new_label
787 711 * @access public
788 712 */
789 713 public static function change_submenu_first_item_label( $menu_slug, $new_label ) {
790 714 global $submenu;
@@ -796,45 +720,8 @@
796 720 }
797 721 }
798 722
799 723 /**
800 - * @var string[]|null
801 - */
802 - private static $resolved_allowed_html_wrapper_tags;
803 -
804 - /**
805 - * Get allowed HTML wrapper tags.
806 - *
807 - * @since 4.4.0
808 - *
809 - * @return string[]
810 - */
811 - public static function get_allowed_html_wrapper_tags(): array {
812 - if ( null !== self::$resolved_allowed_html_wrapper_tags ) {
813 - return self::$resolved_allowed_html_wrapper_tags;
814 - }
815 -
816 - /**
817 - * Allowed HTML wrapper tags.
818 - *
819 - * Filters the list of allowed HTML tag names used by `validate_html_tag()`.
820 - *
821 - * Note: tags in `Utils::FORBIDDEN_HTML_WRAPPER_TAGS` (e.g. `script`, `iframe`,
822 - * `object`) are always stripped after this filter runs and cannot be re-added,
823 - * to prevent XSS via a wrapper tag that executes script or embeds external content.
824 - *
825 - * @since 4.4.0
826 - *
827 - * @param string[] $tags A list of lowercase HTML tag name strings.
828 - */
829 - $tags = apply_filters( 'elementor/allowed_html_wrapper_tags', self::ALLOWED_HTML_WRAPPER_TAGS );
830 -
831 - self::$resolved_allowed_html_wrapper_tags = self::normalize_allowed_html_wrapper_tags( $tags );
832 -
833 - return self::$resolved_allowed_html_wrapper_tags;
834 - }
835 -
836 - /**
837 724 * Validate an HTML tag against a safe allowed list.
838 725 *
839 726 * @param string $tag
840 727 *
@@ -840,37 +727,12 @@
840 727 *
841 728 * @return string
842 729 */
843 730 public static function validate_html_tag( $tag ) {
844 - return $tag && in_array( strtolower( $tag ), self::get_allowed_html_wrapper_tags(), true ) ? $tag : 'div';
731 + return $tag && in_array( strtolower( $tag ), self::ALLOWED_HTML_WRAPPER_TAGS ) ? $tag : 'div';
845 732 }
846 733
847 734 /**
848 - * @param array $tags
849 - *
850 - * @return string[]
851 - */
852 - private static function normalize_allowed_html_wrapper_tags( array $tags ): array {
853 - $normalized_tags = [];
854 -
855 - foreach ( $tags as $tag ) {
856 - if ( ! is_string( $tag ) ) {
857 - continue;
858 - }
859 -
860 - $tag = strtolower( $tag );
861 -
862 - if ( in_array( $tag, self::FORBIDDEN_HTML_WRAPPER_TAGS, true ) ) {
863 - continue;
864 - }
865 -
866 - $normalized_tags[] = $tag;
867 - }
868 -
869 - return array_values( array_unique( $normalized_tags ) );
870 - }
871 -
872 - /**
873 735 * Safe print a validated HTML tag.
874 736 *
875 737 * @param string $tag
876 738 */
@@ -881,10 +743,10 @@
881 743
882 744 /**
883 745 * Print internal content (not user input) without escaping.
884 746 */
885 - public static function print_unescaped_internal_string( $internal_string ) {
886 - echo $internal_string; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
747 + public static function print_unescaped_internal_string( $string ) {
748 + echo $string; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
887 749 }
888 750
889 751 /**
890 752 * Get recently edited posts query.
@@ -909,9 +771,9 @@
909 771
910 772 return new \WP_Query( $args );
911 773 }
912 774
913 - public static function print_wp_kses_extended( $text, array $tags ) {
775 + public static function print_wp_kses_extended( $string, array $tags ) {
914 776 $allowed_html = wp_kses_allowed_html( 'post' );
915 777
916 778 foreach ( $tags as $tag ) {
917 779 if ( isset( self::EXTENDED_ALLOWED_HTML_TAGS[ $tag ] ) ) {
@@ -919,17 +781,11 @@
919 781 $allowed_html = array_replace_recursive( $allowed_html, $extended_tags );
920 782 }
921 783 }
922 784
923 - echo wp_kses( $text, $allowed_html );
785 + echo wp_kses( $string, $allowed_html );
924 786 }
925 787
926 - public static function kses_post_deep( $data ) {
927 - return map_deep( $data, function ( $value ) {
928 - return is_string( $value ) ? wp_kses_post( $value ) : $value;
929 - } );
930 - }
931 -
932 788 public static function is_elementor_path( $path ) {
933 789 $path = wp_normalize_path( $path );
934 790
935 791 /**
@@ -951,10 +807,10 @@
951 807 } );
952 808 }
953 809
954 810 /**
955 - * @param string $file
956 - * @param mixed ...$args
811 + * @param $file
812 + * @param mixed ...$args
957 813 * @return false|string
958 814 */
959 815 public static function file_get_contents( $file, ...$args ) {
960 816 if ( ! is_file( $file ) || ! is_readable( $file ) ) {
@@ -959,8 +815,9 @@
959 815 public static function file_get_contents( $file, ...$args ) {
960 816 if ( ! is_file( $file ) || ! is_readable( $file ) ) {
961 817 return false;
962 818 }
819 +
963 820 return file_get_contents( $file, ...$args );
964 821 }
965 822
966 823 public static function get_super_global_value( $super_global, $key ) {
@@ -967,9 +824,9 @@
967 824 if ( ! isset( $super_global[ $key ] ) ) {
968 825 return null;
969 826 }
970 827
971 - if ( $_FILES === $super_global ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
828 + if ( $_FILES === $super_global ) {
972 829 return isset( $super_global[ $key ]['name'] ) ?
973 830 self::sanitize_file_name( $super_global[ $key ] ) :
974 831 self::sanitize_multi_upload( $super_global[ $key ] );
975 832 }
@@ -991,21 +848,21 @@
991 848
992 849 /**
993 850 * Return specific object property value if exist from array of keys.
994 851 *
995 - * @param array $base_array
996 - * @param array $keys
997 - * @return mixed|null
852 + * @param $array
853 + * @param $keys
854 + * @return key|false
998 855 */
999 - public static function get_array_value_by_keys( $base_array, $keys ) {
856 + public static function get_array_value_by_keys( $array, $keys ) {
1000 857 $keys = (array) $keys;
1001 858 foreach ( $keys as $key ) {
1002 - if ( ! isset( $base_array[ $key ] ) ) {
859 + if ( ! isset( $array[ $key ] ) ) {
1003 860 return null;
1004 861 }
1005 - $base_array = $base_array[ $key ];
862 + $array = $array[ $key ];
1006 863 }
1007 - return $base_array;
864 + return $array;
1008 865 }
1009 866
1010 867 public static function get_cached_callback( $callback, $cache_key, $cache_time = 24 * HOUR_IN_SECONDS ) {
1011 868 $cache = get_site_transient( $cache_key );
@@ -1021,10 +878,10 @@
1021 878 return $cache;
1022 879 }
1023 880
1024 881 public static function is_sale_time(): bool {
1025 - $sale_start_time = gmmktime( 10, 0, 0, 6, 15, 2026 );
1026 - $sale_end_time = gmmktime( 3, 59, 0, 6, 17, 2026 );
882 + $sale_start_time = gmmktime( 13, 0, 0, 11, 26, 2024 );
883 + $sale_end_time = gmmktime( 9, 59, 0, 12, 4, 2024 );
1027 884
1028 885 $now_time = gmdate( 'U' );
1029 886
1030 887 return $now_time >= $sale_start_time && $now_time <= $sale_end_time;
@@ -1034,9 +891,9 @@
1034 891 if ( ! static::is_elementor_debug() ) {
1035 892 return;
1036 893 }
1037 894
1038 - throw new \Exception( esc_html( $message ) );
895 + throw new \Exception( $message );
1039 896 }
1040 897
1041 898 public static function has_invalid_post_permissions( $post ): bool {
1042 899 $is_image_attachment = 'attachment' === $post->post_type && strpos( $post->post_mime_type, 'image/' ) === 0;
@@ -1054,35 +911,6 @@
1054 911 $password_required = post_password_required( $post->ID )
1055 912 && ! current_user_can( 'edit_post', $post->ID );
1056 913
1057 914 return $is_private || $not_allowed || $password_required;
1058 - }
1059 -
1060 - public static function is_custom_kit_applied() {
1061 - return (bool) Plugin::$instance->kits_manager->get_previous_id();
1062 - }
1063 -
1064 - public static function decode_string( string $encoded_string, ?string $fallback = '' ) {
1065 - try {
1066 - return base64_decode( $encoded_string, true ) ?? $fallback;
1067 - } catch ( \Exception $e ) {
1068 - return $fallback;
1069 - }
1070 - }
1071 -
1072 - public static function encode_string( string $decoded_string ): string {
1073 - return base64_encode( $decoded_string );
1074 - }
1075 -
1076 - public static function html_to_plain_text( string $html ): string {
1077 - if ( empty( $html ) ) {
1078 - return '';
1079 - }
1080 -
1081 - $text = preg_replace( '#<br\s*/?\s*>#i', ' ', $html );
1082 - $text = preg_replace( '#</?[a-z][^>]*>#i', ' ', $text );
1083 - $text = html_entity_decode( $text, ENT_QUOTES, 'UTF-8' );
1084 - $text = str_replace( "\xE2\x80\x8B", '', $text );
1085 -
1086 - return trim( preg_replace( '/\s+/', ' ', $text ) );
1087 915 }
1088 916 }