PluginProbe
Elementor Website Builder – more than just a page builder / 3.24.4
Elementor Website Builder – more than just a page builder v3.24.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 +42 -152 4.1.33.24.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',
@@ -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,9 +107,9 @@
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 }
@@ -131,27 +114,12 @@
131 114 return defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG;
132 115 }
133 116
134 117 /**
135 - * Whether Elementor debug is enabled or not.
118 + * Whether elementor test mode is enabled or not.
136 119 *
137 - * @access public
138 - * @static
139 - *
140 120 * @return bool
141 121 */
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 122 public static function is_elementor_tests() {
155 123 return defined( 'ELEMENTOR_TESTS' ) && ELEMENTOR_TESTS;
156 124 }
157 125
@@ -195,13 +163,13 @@
195 163 * @since 2.1.0
196 164 * @static
197 165 * @access public
198 166 *
199 - * @param string $from
200 - * @param string $to
167 + * @param $from
168 + * @param $to
201 169 *
202 170 * @return string
203 - * @throws \Exception If URLs are missing or invalid URLs provided.
171 + * @throws \Exception
204 172 */
205 173 public static function replace_urls( $from, $to ) {
206 174 $from = trim( $from );
207 175 $to = trim( $to );
@@ -247,9 +215,8 @@
247 215 // Allow externals to replace-urls, when they have to.
248 216 $rows_affected += (int) apply_filters( 'elementor/tools/replace-urls', 0, $from, $to );
249 217
250 218 Plugin::$instance->files_manager->clear_cache();
251 - Google_Font::clear_cache();
252 219
253 220 return sprintf(
254 221 /* translators: %d: Number of rows. */
255 222 _n( '%d database row affected.', '%d database rows affected.', $rows_affected, 'elementor' ),
@@ -444,9 +411,9 @@
444 411 * @access public
445 412 * @deprecated 3.3.0 Use `Plugin::$instance->documents->get_create_new_post_url()` instead.
446 413 * @static
447 414 *
448 - * @param string $post_type Optional. Post type slug. Default is 'page'.
415 + * @param string $post_type Optional. Post type slug. Default is 'page'.
449 416 * @param string|null $template_type Optional. Query arg 'template_type'. Default is null.
450 417 *
451 418 * @return string A URL for creating new post using Elementor.
452 419 */
@@ -513,14 +480,14 @@
513 480 * @since 2.1.2
514 481 * @access public
515 482 * @static
516 483 */
517 - public static function array_inject( $base_array, $key, $insert ) {
518 - $length = array_search( $key, array_keys( $base_array ), true ) + 1;
484 + public static function array_inject( $array, $key, $insert ) {
485 + $length = array_search( $key, array_keys( $array ), true ) + 1;
519 486
520 - return array_slice( $base_array, 0, $length, true ) +
487 + return array_slice( $array, 0, $length, true ) +
521 488 $insert +
522 - array_slice( $base_array, $length, null, true );
489 + array_slice( $array, $length, null, true );
523 490 }
524 491
525 492 /**
526 493 * Render html attributes
@@ -581,12 +548,11 @@
581 548 /**
582 549 * Add Elementor Config js vars to the relevant script handle,
583 550 * WP will wrap it with <script> tag.
584 551 * To make sure this script runs thru the `script_loader_tag` hook, use a known handle value.
585 - *
586 552 * @param string $handle
587 553 * @param string $js_var
588 - * @param mixed $config
554 + * @param mixed $config
589 555 */
590 556 public static function print_js_config( $handle, $js_var, $config ) {
591 557 $config = wp_json_encode( $config );
592 558
@@ -616,9 +582,9 @@
616 582
617 583 /**
618 584 * Checks a control value for being empty, including a string of '0' not covered by PHP's empty().
619 585 *
620 - * @param mixed $source
586 + * @param mixed $source
621 587 * @param bool|string $key
622 588 *
623 589 * @return bool
624 590 */
@@ -637,30 +603,15 @@
637 603 public static function has_pro() {
638 604 return defined( 'ELEMENTOR_PRO_VERSION' );
639 605 }
640 606
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 607 /**
657 608 * Convert HTMLEntities to UTF-8 characters
658 609 *
659 - * @param string $html_string
610 + * @param $string
660 611 * @return string
661 612 */
662 - public static function urlencode_html_entities( $html_string ) {
613 + public static function urlencode_html_entities( $string ) {
663 614 $entities_dictionary = [
664 615 '&#145;' => "'", // Opening single quote
665 616 '&#146;' => "'", // Closing single quote
666 617 '&#147;' => '"', // Closing double quote
@@ -673,11 +624,11 @@
673 624 '&#8222;' => '"', // Double low quote
674 625 ];
675 626
676 627 // Decode decimal entities
677 - $html_string = str_replace( array_keys( $entities_dictionary ), array_values( $entities_dictionary ), $html_string );
628 + $string = str_replace( array_keys( $entities_dictionary ), array_values( $entities_dictionary ), $string );
678 629
679 - return rawurlencode( html_entity_decode( $html_string, ENT_QUOTES | ENT_HTML5, 'UTF-8' ) );
630 + return rawurlencode( html_entity_decode( $string, ENT_QUOTES | ENT_HTML5, 'UTF-8' ) );
680 631 }
681 632
682 633 /**
683 634 * Parse attributes that come as a string of comma-delimited key|value pairs.
@@ -729,19 +680,13 @@
729 680 if ( $id === $element['id'] ) {
730 681 return $element;
731 682 }
732 683
733 - $inner_elements = apply_filters(
734 - 'elementor/utils/find_element_recursive/inner_elements',
735 - $element['elements'] ?? [],
736 - $element
737 - );
684 + if ( ! empty( $element['elements'] ) ) {
685 + $element = self::find_element_recursive( $element['elements'], $id );
738 686
739 - if ( ! empty( $inner_elements ) ) {
740 - $found = self::find_element_recursive( $inner_elements, $id );
741 -
742 - if ( $found ) {
743 - return $found;
687 + if ( $element ) {
688 + return $element;
744 689 }
745 690 }
746 691 }
747 692
@@ -756,10 +701,10 @@
756 701 * Fired by `admin_menu` action.
757 702 *
758 703 * @since 3.1.0
759 704 *
760 - * @param string $menu_slug
761 - * @param string $new_label
705 + * @param $menu_slug
706 + * @param $new_label
762 707 * @access public
763 708 */
764 709 public static function change_submenu_first_item_label( $menu_slug, $new_label ) {
765 710 global $submenu;
@@ -794,10 +739,10 @@
794 739
795 740 /**
796 741 * Print internal content (not user input) without escaping.
797 742 */
798 - public static function print_unescaped_internal_string( $internal_string ) {
799 - echo $internal_string; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
743 + public static function print_unescaped_internal_string( $string ) {
744 + echo $string; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
800 745 }
801 746
802 747 /**
803 748 * Get recently edited posts query.
@@ -822,9 +767,9 @@
822 767
823 768 return new \WP_Query( $args );
824 769 }
825 770
826 - public static function print_wp_kses_extended( $text, array $tags ) {
771 + public static function print_wp_kses_extended( $string, array $tags ) {
827 772 $allowed_html = wp_kses_allowed_html( 'post' );
828 773
829 774 foreach ( $tags as $tag ) {
830 775 if ( isset( self::EXTENDED_ALLOWED_HTML_TAGS[ $tag ] ) ) {
@@ -832,9 +777,9 @@
832 777 $allowed_html = array_replace_recursive( $allowed_html, $extended_tags );
833 778 }
834 779 }
835 780
836 - echo wp_kses( $text, $allowed_html );
781 + echo wp_kses( $string, $allowed_html );
837 782 }
838 783
839 784 public static function is_elementor_path( $path ) {
840 785 $path = wp_normalize_path( $path );
@@ -858,10 +803,10 @@
858 803 } );
859 804 }
860 805
861 806 /**
862 - * @param string $file
863 - * @param mixed ...$args
807 + * @param $file
808 + * @param mixed ...$args
864 809 * @return false|string
865 810 */
866 811 public static function file_get_contents( $file, ...$args ) {
867 812 if ( ! is_file( $file ) || ! is_readable( $file ) ) {
@@ -866,8 +811,9 @@
866 811 public static function file_get_contents( $file, ...$args ) {
867 812 if ( ! is_file( $file ) || ! is_readable( $file ) ) {
868 813 return false;
869 814 }
815 +
870 816 return file_get_contents( $file, ...$args );
871 817 }
872 818
873 819 public static function get_super_global_value( $super_global, $key ) {
@@ -874,9 +820,9 @@
874 820 if ( ! isset( $super_global[ $key ] ) ) {
875 821 return null;
876 822 }
877 823
878 - if ( $_FILES === $super_global ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
824 + if ( $_FILES === $super_global ) {
879 825 return isset( $super_global[ $key ]['name'] ) ?
880 826 self::sanitize_file_name( $super_global[ $key ] ) :
881 827 self::sanitize_multi_upload( $super_global[ $key ] );
882 828 }
@@ -898,21 +844,21 @@
898 844
899 845 /**
900 846 * Return specific object property value if exist from array of keys.
901 847 *
902 - * @param array $base_array
903 - * @param array $keys
904 - * @return mixed|null
848 + * @param $array
849 + * @param $keys
850 + * @return key|false
905 851 */
906 - public static function get_array_value_by_keys( $base_array, $keys ) {
852 + public static function get_array_value_by_keys( $array, $keys ) {
907 853 $keys = (array) $keys;
908 854 foreach ( $keys as $key ) {
909 - if ( ! isset( $base_array[ $key ] ) ) {
855 + if ( ! isset( $array[ $key ] ) ) {
910 856 return null;
911 857 }
912 - $base_array = $base_array[ $key ];
858 + $array = $array[ $key ];
913 859 }
914 - return $base_array;
860 + return $array;
915 861 }
916 862
917 863 public static function get_cached_callback( $callback, $cache_key, $cache_time = 24 * HOUR_IN_SECONDS ) {
918 864 $cache = get_site_transient( $cache_key );
@@ -928,68 +874,12 @@
928 874 return $cache;
929 875 }
930 876
931 877 public static function is_sale_time(): bool {
932 - $sale_start_time = gmmktime( 10, 0, 0, 6, 15, 2026 );
933 - $sale_end_time = gmmktime( 3, 59, 0, 6, 17, 2026 );
878 + $sale_start_time = gmmktime( 12, 0, 0, 5, 28, 2024 );
879 + $sale_end_time = gmmktime( 4, 59, 0, 6, 4, 2024 );
934 880
935 881 $now_time = gmdate( 'U' );
936 882
937 883 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 ) );
994 884 }
995 885 }