PluginProbe
Elementor Website Builder – more than just a page builder / 3.25.0-dev3
Elementor Website Builder – more than just a page builder v3.25.0-dev3
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 +43 -128 4.1.0-dev23.25.0-dev3 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',
@@ -92,27 +90,10 @@
92 90 ],
93 91 ];
94 92
95 93 /**
96 - * Variables for free to pro upsale modal promotions
97 - */
98 -
99 - const ANIMATED_HEADLINE = 'animated_headline';
100 -
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 - /**
110 - * Whether WordPress CLI mode is enabled or not.
94 + * Is WP CLI.
111 95 *
112 - * @access public
113 - * @static
114 - *
115 96 * @return bool
116 97 */
117 98 public static function is_wp_cli() {
118 99 return defined( 'WP_CLI' ) && WP_CLI;
@@ -118,8 +99,10 @@
118 99 return defined( 'WP_CLI' ) && WP_CLI;
119 100 }
120 101
121 102 /**
103 + * Is script debug.
104 + *
122 105 * Whether script debug is enabled or not.
123 106 *
124 107 * @since 1.0.0
125 108 * @access public
@@ -124,32 +107,21 @@
124 107 * @since 1.0.0
125 108 * @access public
126 109 * @static
127 110 *
128 - * @return bool
111 + * @return bool True if it's a script debug is active, false otherwise.
129 112 */
130 113 public static function is_script_debug() {
131 114 return defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG;
132 115 }
133 116
134 - /**
135 - * Whether Elementor debug is enabled or not.
136 - *
137 - * @access public
138 - * @static
139 - *
140 - * @return bool
141 - */
142 117 public static function is_elementor_debug() {
143 118 return defined( 'ELEMENTOR_DEBUG' ) && ELEMENTOR_DEBUG;
144 119 }
145 120
146 121 /**
147 - * Whether Elementor test mode is enabled or not.
122 + * Whether elementor test mode is enabled or not.
148 123 *
149 - * @access public
150 - * @static
151 - *
152 124 * @return bool
153 125 */
154 126 public static function is_elementor_tests() {
155 127 return defined( 'ELEMENTOR_TESTS' ) && ELEMENTOR_TESTS;
@@ -195,13 +167,13 @@
195 167 * @since 2.1.0
196 168 * @static
197 169 * @access public
198 170 *
199 - * @param string $from
200 - * @param string $to
171 + * @param $from
172 + * @param $to
201 173 *
202 174 * @return string
203 - * @throws \Exception If URLs are missing or invalid URLs provided.
175 + * @throws \Exception
204 176 */
205 177 public static function replace_urls( $from, $to ) {
206 178 $from = trim( $from );
207 179 $to = trim( $to );
@@ -247,9 +219,8 @@
247 219 // Allow externals to replace-urls, when they have to.
248 220 $rows_affected += (int) apply_filters( 'elementor/tools/replace-urls', 0, $from, $to );
249 221
250 222 Plugin::$instance->files_manager->clear_cache();
251 - Google_Font::clear_cache();
252 223
253 224 return sprintf(
254 225 /* translators: %d: Number of rows. */
255 226 _n( '%d database row affected.', '%d database rows affected.', $rows_affected, 'elementor' ),
@@ -444,9 +415,9 @@
444 415 * @access public
445 416 * @deprecated 3.3.0 Use `Plugin::$instance->documents->get_create_new_post_url()` instead.
446 417 * @static
447 418 *
448 - * @param string $post_type Optional. Post type slug. Default is 'page'.
419 + * @param string $post_type Optional. Post type slug. Default is 'page'.
449 420 * @param string|null $template_type Optional. Query arg 'template_type'. Default is null.
450 421 *
451 422 * @return string A URL for creating new post using Elementor.
452 423 */
@@ -513,14 +484,14 @@
513 484 * @since 2.1.2
514 485 * @access public
515 486 * @static
516 487 */
517 - public static function array_inject( $base_array, $key, $insert ) {
518 - $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;
519 490
520 - return array_slice( $base_array, 0, $length, true ) +
491 + return array_slice( $array, 0, $length, true ) +
521 492 $insert +
522 - array_slice( $base_array, $length, null, true );
493 + array_slice( $array, $length, null, true );
523 494 }
524 495
525 496 /**
526 497 * Render html attributes
@@ -581,12 +552,11 @@
581 552 /**
582 553 * Add Elementor Config js vars to the relevant script handle,
583 554 * WP will wrap it with <script> tag.
584 555 * To make sure this script runs thru the `script_loader_tag` hook, use a known handle value.
585 - *
586 556 * @param string $handle
587 557 * @param string $js_var
588 - * @param mixed $config
558 + * @param mixed $config
589 559 */
590 560 public static function print_js_config( $handle, $js_var, $config ) {
591 561 $config = wp_json_encode( $config );
592 562
@@ -616,9 +586,9 @@
616 586
617 587 /**
618 588 * Checks a control value for being empty, including a string of '0' not covered by PHP's empty().
619 589 *
620 - * @param mixed $source
590 + * @param mixed $source
621 591 * @param bool|string $key
622 592 *
623 593 * @return bool
624 594 */
@@ -637,30 +607,15 @@
637 607 public static function has_pro() {
638 608 return defined( 'ELEMENTOR_PRO_VERSION' );
639 609 }
640 610
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 611 /**
657 612 * Convert HTMLEntities to UTF-8 characters
658 613 *
659 - * @param string $html_string
614 + * @param $string
660 615 * @return string
661 616 */
662 - public static function urlencode_html_entities( $html_string ) {
617 + public static function urlencode_html_entities( $string ) {
663 618 $entities_dictionary = [
664 619 '&#145;' => "'", // Opening single quote
665 620 '&#146;' => "'", // Closing single quote
666 621 '&#147;' => '"', // Closing double quote
@@ -673,11 +628,11 @@
673 628 '&#8222;' => '"', // Double low quote
674 629 ];
675 630
676 631 // Decode decimal entities
677 - $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 );
678 633
679 - 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' ) );
680 635 }
681 636
682 637 /**
683 638 * Parse attributes that come as a string of comma-delimited key|value pairs.
@@ -729,19 +684,13 @@
729 684 if ( $id === $element['id'] ) {
730 685 return $element;
731 686 }
732 687
733 - $inner_elements = apply_filters(
734 - 'elementor/utils/find_element_recursive/inner_elements',
735 - $element['elements'] ?? [],
736 - $element
737 - );
688 + if ( ! empty( $element['elements'] ) ) {
689 + $element = self::find_element_recursive( $element['elements'], $id );
738 690
739 - if ( ! empty( $inner_elements ) ) {
740 - $found = self::find_element_recursive( $inner_elements, $id );
741 -
742 - if ( $found ) {
743 - return $found;
691 + if ( $element ) {
692 + return $element;
744 693 }
745 694 }
746 695 }
747 696
@@ -756,10 +705,10 @@
756 705 * Fired by `admin_menu` action.
757 706 *
758 707 * @since 3.1.0
759 708 *
760 - * @param string $menu_slug
761 - * @param string $new_label
709 + * @param $menu_slug
710 + * @param $new_label
762 711 * @access public
763 712 */
764 713 public static function change_submenu_first_item_label( $menu_slug, $new_label ) {
765 714 global $submenu;
@@ -794,10 +743,10 @@
794 743
795 744 /**
796 745 * Print internal content (not user input) without escaping.
797 746 */
798 - public static function print_unescaped_internal_string( $internal_string ) {
799 - 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
800 749 }
801 750
802 751 /**
803 752 * Get recently edited posts query.
@@ -822,9 +771,9 @@
822 771
823 772 return new \WP_Query( $args );
824 773 }
825 774
826 - public static function print_wp_kses_extended( $text, array $tags ) {
775 + public static function print_wp_kses_extended( $string, array $tags ) {
827 776 $allowed_html = wp_kses_allowed_html( 'post' );
828 777
829 778 foreach ( $tags as $tag ) {
830 779 if ( isset( self::EXTENDED_ALLOWED_HTML_TAGS[ $tag ] ) ) {
@@ -832,9 +781,9 @@
832 781 $allowed_html = array_replace_recursive( $allowed_html, $extended_tags );
833 782 }
834 783 }
835 784
836 - echo wp_kses( $text, $allowed_html );
785 + echo wp_kses( $string, $allowed_html );
837 786 }
838 787
839 788 public static function is_elementor_path( $path ) {
840 789 $path = wp_normalize_path( $path );
@@ -858,10 +807,10 @@
858 807 } );
859 808 }
860 809
861 810 /**
862 - * @param string $file
863 - * @param mixed ...$args
811 + * @param $file
812 + * @param mixed ...$args
864 813 * @return false|string
865 814 */
866 815 public static function file_get_contents( $file, ...$args ) {
867 816 if ( ! is_file( $file ) || ! is_readable( $file ) ) {
@@ -866,8 +815,9 @@
866 815 public static function file_get_contents( $file, ...$args ) {
867 816 if ( ! is_file( $file ) || ! is_readable( $file ) ) {
868 817 return false;
869 818 }
819 +
870 820 return file_get_contents( $file, ...$args );
871 821 }
872 822
873 823 public static function get_super_global_value( $super_global, $key ) {
@@ -874,9 +824,9 @@
874 824 if ( ! isset( $super_global[ $key ] ) ) {
875 825 return null;
876 826 }
877 827
878 - if ( $_FILES === $super_global ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
828 + if ( $_FILES === $super_global ) {
879 829 return isset( $super_global[ $key ]['name'] ) ?
880 830 self::sanitize_file_name( $super_global[ $key ] ) :
881 831 self::sanitize_multi_upload( $super_global[ $key ] );
882 832 }
@@ -898,21 +848,21 @@
898 848
899 849 /**
900 850 * Return specific object property value if exist from array of keys.
901 851 *
902 - * @param array $base_array
903 - * @param array $keys
904 - * @return mixed|null
852 + * @param $array
853 + * @param $keys
854 + * @return key|false
905 855 */
906 - public static function get_array_value_by_keys( $base_array, $keys ) {
856 + public static function get_array_value_by_keys( $array, $keys ) {
907 857 $keys = (array) $keys;
908 858 foreach ( $keys as $key ) {
909 - if ( ! isset( $base_array[ $key ] ) ) {
859 + if ( ! isset( $array[ $key ] ) ) {
910 860 return null;
911 861 }
912 - $base_array = $base_array[ $key ];
862 + $array = $array[ $key ];
913 863 }
914 - return $base_array;
864 + return $array;
915 865 }
916 866
917 867 public static function get_cached_callback( $callback, $cache_key, $cache_time = 24 * HOUR_IN_SECONDS ) {
918 868 $cache = get_site_transient( $cache_key );
@@ -928,10 +878,10 @@
928 878 return $cache;
929 879 }
930 880
931 881 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 );
882 + $sale_start_time = gmmktime( 12, 0, 0, 5, 28, 2024 );
883 + $sale_end_time = gmmktime( 4, 59, 0, 6, 4, 2024 );
934 884
935 885 $now_time = gmdate( 'U' );
936 886
937 887 return $now_time >= $sale_start_time && $now_time <= $sale_end_time;
@@ -941,18 +891,12 @@
941 891 if ( ! static::is_elementor_debug() ) {
942 892 return;
943 893 }
944 894
945 - throw new \Exception( esc_html( $message ) );
895 + throw new \Exception( $message );
946 896 }
947 897
948 898 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 899 $is_private = 'private' === $post->post_status
956 900 && ! current_user_can( 'read_private_posts', $post->ID );
957 901
958 902 $not_allowed = 'publish' !== $post->post_status
@@ -961,35 +905,6 @@
961 905 $password_required = post_password_required( $post->ID )
962 906 && ! current_user_can( 'edit_post', $post->ID );
963 907
964 908 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 ) );
994 909 }
995 910 }