PluginProbe
Elementor Website Builder – more than just a page builder / 3.3.1
Elementor Website Builder – more than just a page builder v3.3.1
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 +55 -327 4.0.83.3.1 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,15 @@
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 24 'a',
30 25 'article',
31 26 'aside',
32 - 'button',
33 - 'form',
34 27 'div',
35 28 'footer',
36 29 'h1',
37 30 'h2',
@@ -46,73 +39,29 @@
46 39 'section',
47 40 'span',
48 41 ];
49 42
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 43 /**
96 - * Variables for free to pro upsale modal promotions
44 + * Is ajax.
45 + *
46 + * Whether the current request is a WordPress ajax request.
47 + *
48 + * @since 1.0.0
49 + * @deprecated 2.6.0 Use `wp_doing_ajax()` instead.
50 + * @access public
51 + * @static
52 + *
53 + * @return bool True if it's a WordPress ajax request, false otherwise.
97 54 */
55 + public static function is_ajax() {
56 + _deprecated_function( __METHOD__, '2.6.0', 'wp_doing_ajax()' );
98 57
99 - const ANIMATED_HEADLINE = 'animated_headline';
58 + return wp_doing_ajax();
59 + }
100 60
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 61 /**
110 - * Whether WordPress CLI mode is enabled or not.
62 + * Is WP CLI.
111 63 *
112 - * @access public
113 - * @static
114 - *
115 64 * @return bool
116 65 */
117 66 public static function is_wp_cli() {
118 67 return defined( 'WP_CLI' ) && WP_CLI;
@@ -118,8 +67,10 @@
118 67 return defined( 'WP_CLI' ) && WP_CLI;
119 68 }
120 69
121 70 /**
71 + * Is script debug.
72 + *
122 73 * Whether script debug is enabled or not.
123 74 *
124 75 * @since 1.0.0
125 76 * @access public
@@ -124,9 +75,9 @@
124 75 * @since 1.0.0
125 76 * @access public
126 77 * @static
127 78 *
128 - * @return bool
79 + * @return bool True if it's a script debug is active, false otherwise.
129 80 */
130 81 public static function is_script_debug() {
131 82 return defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG;
132 83 }
@@ -131,32 +82,8 @@
131 82 return defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG;
132 83 }
133 84
134 85 /**
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 86 * Get pro link.
160 87 *
161 88 * Retrieve the link to Elementor Pro.
162 89 *
@@ -195,54 +122,38 @@
195 122 * @since 2.1.0
196 123 * @static
197 124 * @access public
198 125 *
199 - * @param string $from
200 - * @param string $to
126 + * @param $from
127 + * @param $to
201 128 *
202 129 * @return string
203 - * @throws \Exception If URLs are missing or invalid URLs provided.
130 + * @throws \Exception
204 131 */
205 132 public static function replace_urls( $from, $to ) {
206 133 $from = trim( $from );
207 134 $to = trim( $to );
208 135
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 136 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.' );
137 + throw new \Exception( __( 'The `from` and `to` URL\'s must be different', 'elementor' ) );
219 138 }
220 139
221 140 $is_valid_urls = ( filter_var( $from, FILTER_VALIDATE_URL ) && filter_var( $to, FILTER_VALIDATE_URL ) );
222 -
223 141 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.' );
142 + throw new \Exception( __( 'The `from` and `to` URL\'s must be valid URL\'s', 'elementor' ) );
225 143 }
226 144
227 145 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 146
147 + // @codingStandardsIgnoreStart cannot use `$wpdb->prepare` because it remove's the backslashes
232 148 $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 - );
149 + "UPDATE {$wpdb->postmeta} " .
150 + "SET `meta_value` = REPLACE(`meta_value`, '" . str_replace( '/', '\\\/', $from ) . "', '" . str_replace( '/', '\\\/', $to ) . "') " .
151 + "WHERE `meta_key` = '_elementor_data' AND `meta_value` LIKE '[%' ;" ); // meta_value LIKE '[%' are json formatted
152 + // @codingStandardsIgnoreEnd
242 153
243 154 if ( false === $rows_affected ) {
244 - throw new \Exception( 'An error occurred while replacing URL\'s.' );
155 + throw new \Exception( __( 'An error occurred', 'elementor' ) );
245 156 }
246 157
247 158 // Allow externals to replace-urls, when they have to.
248 159 $rows_affected += (int) apply_filters( 'elementor/tools/replace-urls', 0, $from, $to );
@@ -247,13 +158,12 @@
247 158 // Allow externals to replace-urls, when they have to.
248 159 $rows_affected += (int) apply_filters( 'elementor/tools/replace-urls', 0, $from, $to );
249 160
250 161 Plugin::$instance->files_manager->clear_cache();
251 - Google_Font::clear_cache();
252 162
253 163 return sprintf(
254 - /* translators: %d: Number of rows. */
255 - _n( '%d database row affected.', '%d database rows affected.', $rows_affected, 'elementor' ),
164 + /* translators: %d: Number of rows */
165 + _n( '%d row affected.', '%d rows affected.', $rows_affected, 'elementor' ),
256 166 $rows_affected
257 167 );
258 168 }
259 169
@@ -280,9 +190,9 @@
280 190 *
281 191 * Filters whether the post type supports editing with Elementor.
282 192 *
283 193 * @since 1.0.0
284 - * @deprecated 2.2.0 Use `elementor/utils/is_post_support` hook Instead.
194 + * @deprecated 2.2.0 Use `elementor/utils/is_post_support` Instead
285 195 *
286 196 * @param bool $is_supported Whether the post type supports editing with Elementor.
287 197 * @param int $post_id Post ID.
288 198 * @param string $post_type Post type.
@@ -399,10 +309,10 @@
399 309 if ( ! defined( 'DONOTCDN' ) ) {
400 310 define( 'DONOTCDN', true );
401 311 }
402 312
403 - if ( ! defined( 'DONOTCACHEOBJECT' ) ) {
404 - define( 'DONOTCACHEOBJECT', true );
313 + if ( ! defined( 'DONOTCACHCEOBJECT' ) ) {
314 + define( 'DONOTCACHCEOBJECT', true );
405 315 }
406 316
407 317 // Set the headers to prevent caching for the different browsers.
408 318 nocache_headers();
@@ -441,12 +351,11 @@
441 351 * Retrieve a custom URL for creating a new post/page using Elementor.
442 352 *
443 353 * @since 1.9.0
444 354 * @access public
445 - * @deprecated 3.3.0 Use `Plugin::$instance->documents->get_create_new_post_url()` instead.
446 355 * @static
447 356 *
448 - * @param string $post_type Optional. Post type slug. Default is 'page'.
357 + * @param string $post_type Optional. Post type slug. Default is 'page'.
449 358 * @param string|null $template_type Optional. Query arg 'template_type'. Default is null.
450 359 *
451 360 * @return string A URL for creating new post using Elementor.
452 361 */
@@ -513,14 +422,14 @@
513 422 * @since 2.1.2
514 423 * @access public
515 424 * @static
516 425 */
517 - public static function array_inject( $base_array, $key, $insert ) {
518 - $length = array_search( $key, array_keys( $base_array ), true ) + 1;
426 + public static function array_inject( $array, $key, $insert ) {
427 + $length = array_search( $key, array_keys( $array ), true ) + 1;
519 428
520 - return array_slice( $base_array, 0, $length, true ) +
429 + return array_slice( $array, 0, $length, true ) +
521 430 $insert +
522 - array_slice( $base_array, $length, null, true );
431 + array_slice( $array, $length, null, true );
523 432 }
524 433
525 434 /**
526 435 * Render html attributes
@@ -558,25 +467,18 @@
558 467 }
559 468
560 469 public static function get_meta_viewport( $context = '' ) {
561 470 $meta_tag = '<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />';
562 -
563 471 /**
564 472 * Viewport meta tag.
565 473 *
566 - * Filters the meta tag containing the viewport information.
474 + * Filters the Elementor preview URL.
567 475 *
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 476 * @since 2.5.0
572 477 *
573 478 * @param string $meta_tag Viewport meta tag.
574 - * @param string $context Page context.
575 479 */
576 - $meta_tag = apply_filters( 'elementor/template/viewport_tag', $meta_tag, $context );
577 -
578 - return $meta_tag;
480 + return apply_filters( 'elementor/template/viewport_tag', $meta_tag, $context );
579 481 }
580 482
581 483 /**
582 484 * Add Elementor Config js vars to the relevant script handle,
@@ -581,17 +483,16 @@
581 483 /**
582 484 * Add Elementor Config js vars to the relevant script handle,
583 485 * WP will wrap it with <script> tag.
584 486 * To make sure this script runs thru the `script_loader_tag` hook, use a known handle value.
585 - *
586 487 * @param string $handle
587 488 * @param string $js_var
588 - * @param mixed $config
489 + * @param mixed $config
589 490 */
590 491 public static function print_js_config( $handle, $js_var, $config ) {
591 492 $config = wp_json_encode( $config );
592 493
593 - if ( get_option( self::EDITOR_BREAK_LINES_OPTION_KEY ) ) {
494 + if ( get_option( 'elementor_editor_break_lines' ) ) {
594 495 // Add new lines to avoid memory limits in some hosting servers that handles the buffer output according to new line characters
595 496 $config = str_replace( '}},"', '}},' . PHP_EOL . '"', $config );
596 497 }
597 498
@@ -609,9 +510,9 @@
609 510
610 511 $alias_version_as_float = (float) $alias_version[0];
611 512
612 513 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
514 + _deprecated_file( $item, $version, $replacement );
614 515 }
615 516 }
616 517
617 518 /**
@@ -616,9 +517,9 @@
616 517
617 518 /**
618 519 * Checks a control value for being empty, including a string of '0' not covered by PHP's empty().
619 520 *
620 - * @param mixed $source
521 + * @param mixed $source
621 522 * @param bool|string $key
622 523 *
623 524 * @return bool
624 525 */
@@ -637,30 +538,15 @@
637 538 public static function has_pro() {
638 539 return defined( 'ELEMENTOR_PRO_VERSION' );
639 540 }
640 541
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 542 /**
657 543 * Convert HTMLEntities to UTF-8 characters
658 544 *
659 - * @param string $html_string
545 + * @param $string
660 546 * @return string
661 547 */
662 - public static function urlencode_html_entities( $html_string ) {
548 + public static function urlencode_html_entities( $string ) {
663 549 $entities_dictionary = [
664 550 '&#145;' => "'", // Opening single quote
665 551 '&#146;' => "'", // Closing single quote
666 552 '&#147;' => '"', // Closing double quote
@@ -673,11 +559,11 @@
673 559 '&#8222;' => '"', // Double low quote
674 560 ];
675 561
676 562 // Decode decimal entities
677 - $html_string = str_replace( array_keys( $entities_dictionary ), array_values( $entities_dictionary ), $html_string );
563 + $string = str_replace( array_keys( $entities_dictionary ), array_values( $entities_dictionary ), $string );
678 564
679 - return rawurlencode( html_entity_decode( $html_string, ENT_QUOTES | ENT_HTML5, 'UTF-8' ) );
565 + return rawurlencode( html_entity_decode( $string, ENT_QUOTES | ENT_HTML5, 'UTF-8' ) );
680 566 }
681 567
682 568 /**
683 569 * Parse attributes that come as a string of comma-delimited key|value pairs.
@@ -750,10 +636,10 @@
750 636 * Fired by `admin_menu` action.
751 637 *
752 638 * @since 3.1.0
753 639 *
754 - * @param string $menu_slug
755 - * @param string $new_label
640 + * @param $menu_slug
641 + * @param $new_label
756 642 * @access public
757 643 */
758 644 public static function change_submenu_first_item_label( $menu_slug, $new_label ) {
759 645 global $submenu;
@@ -772,9 +658,9 @@
772 658 *
773 659 * @return string
774 660 */
775 661 public static function validate_html_tag( $tag ) {
776 - return $tag && in_array( strtolower( $tag ), self::ALLOWED_HTML_WRAPPER_TAGS ) ? $tag : 'div';
662 + return in_array( strtolower( $tag ), self::ALLOWED_HTML_WRAPPER_TAGS ) ? $tag : 'div';
777 663 }
778 664
779 665 /**
780 666 * Safe print a validated HTML tag.
@@ -788,10 +674,10 @@
788 674
789 675 /**
790 676 * Print internal content (not user input) without escaping.
791 677 */
792 - public static function print_unescaped_internal_string( $internal_string ) {
793 - echo $internal_string; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
678 + public static function print_unescaped_internal_string( $string ) {
679 + echo $string; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
794 680 }
795 681
796 682 /**
797 683 * Get recently edited posts query.
@@ -804,9 +690,8 @@
804 690 * @return \WP_Query
805 691 */
806 692 public static function get_recently_edited_posts_query( $args = [] ) {
807 693 $args = wp_parse_args( $args, [
808 - 'no_found_rows' => true,
809 694 'post_type' => 'any',
810 695 'post_status' => [ 'publish', 'draft' ],
811 696 'posts_per_page' => '3',
812 697 'meta_key' => '_elementor_edit_mode',
@@ -814,163 +699,6 @@
814 699 'orderby' => 'modified',
815 700 ] );
816 701
817 702 return new \WP_Query( $args );
818 - }
819 -
820 - public static function print_wp_kses_extended( $text, array $tags ) {
821 - $allowed_html = wp_kses_allowed_html( 'post' );
822 -
823 - foreach ( $tags as $tag ) {
824 - if ( isset( self::EXTENDED_ALLOWED_HTML_TAGS[ $tag ] ) ) {
825 - $extended_tags = apply_filters( "elementor/extended_allowed_html_tags/{$tag}", self::EXTENDED_ALLOWED_HTML_TAGS[ $tag ] );
826 - $allowed_html = array_replace_recursive( $allowed_html, $extended_tags );
827 - }
828 - }
829 -
830 - echo wp_kses( $text, $allowed_html );
831 - }
832 -
833 - public static function is_elementor_path( $path ) {
834 - $path = wp_normalize_path( $path );
835 -
836 - /**
837 - * Elementor related paths.
838 - *
839 - * Filters Elementor related paths.
840 - *
841 - * @param string[] $available_paths
842 - */
843 - $available_paths = apply_filters( 'elementor/utils/elementor_related_paths', [ ELEMENTOR_PATH ] );
844 -
845 - return (bool) ( new Collection( $available_paths ) )
846 - ->map( function ( $p ) {
847 - // `untrailingslashit` in order to include other plugins prefixed with elementor.
848 - return untrailingslashit( wp_normalize_path( $p ) );
849 - } )
850 - ->find(function ( $p ) use ( $path ) {
851 - return false !== strpos( $path, $p );
852 - } );
853 - }
854 -
855 - /**
856 - * @param string $file
857 - * @param mixed ...$args
858 - * @return false|string
859 - */
860 - public static function file_get_contents( $file, ...$args ) {
861 - if ( ! is_file( $file ) || ! is_readable( $file ) ) {
862 - return false;
863 - }
864 - return file_get_contents( $file, ...$args );
865 - }
866 -
867 - public static function get_super_global_value( $super_global, $key ) {
868 - if ( ! isset( $super_global[ $key ] ) ) {
869 - return null;
870 - }
871 -
872 - if ( $_FILES === $super_global ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
873 - return isset( $super_global[ $key ]['name'] ) ?
874 - self::sanitize_file_name( $super_global[ $key ] ) :
875 - self::sanitize_multi_upload( $super_global[ $key ] );
876 - }
877 -
878 - return wp_kses_post_deep( wp_unslash( $super_global[ $key ] ) );
879 - }
880 -
881 - private static function sanitize_multi_upload( $fields ) {
882 - return array_map( function( $field ) {
883 - return array_map( 'self::sanitize_file_name', $field );
884 - }, $fields );
885 - }
886 -
887 - private static function sanitize_file_name( $file ) {
888 - $file['name'] = sanitize_file_name( $file['name'] );
889 -
890 - return $file;
891 - }
892 -
893 - /**
894 - * Return specific object property value if exist from array of keys.
895 - *
896 - * @param array $base_array
897 - * @param array $keys
898 - * @return mixed|null
899 - */
900 - public static function get_array_value_by_keys( $base_array, $keys ) {
901 - $keys = (array) $keys;
902 - foreach ( $keys as $key ) {
903 - if ( ! isset( $base_array[ $key ] ) ) {
904 - return null;
905 - }
906 - $base_array = $base_array[ $key ];
907 - }
908 - return $base_array;
909 - }
910 -
911 - public static function get_cached_callback( $callback, $cache_key, $cache_time = 24 * HOUR_IN_SECONDS ) {
912 - $cache = get_site_transient( $cache_key );
913 -
914 - if ( ! $cache ) {
915 - $cache = call_user_func( $callback );
916 -
917 - if ( ! is_wp_error( $cache ) ) {
918 - set_site_transient( $cache_key, $cache, $cache_time );
919 - }
920 - }
921 -
922 - return $cache;
923 - }
924 -
925 - public static function is_sale_time(): bool {
926 - $sale_start_time = gmmktime( 12, 0, 0, 11, 25, 2025 );
927 - $sale_end_time = gmmktime( 3, 59, 0, 12, 3, 2025 );
928 -
929 - $now_time = gmdate( 'U' );
930 -
931 - return $now_time >= $sale_start_time && $now_time <= $sale_end_time;
932 - }
933 -
934 - public static function safe_throw( string $message ) {
935 - if ( ! static::is_elementor_debug() ) {
936 - return;
937 - }
938 -
939 - throw new \Exception( esc_html( $message ) );
940 - }
941 -
942 - public static function has_invalid_post_permissions( $post ): bool {
943 - $is_image_attachment = 'attachment' === $post->post_type && strpos( $post->post_mime_type, 'image/' ) === 0;
944 -
945 - if ( $is_image_attachment ) {
946 - return false;
947 - }
948 -
949 - $is_private = 'private' === $post->post_status
950 - && ! current_user_can( 'read_private_posts', $post->ID );
951 -
952 - $not_allowed = 'publish' !== $post->post_status
953 - && ! current_user_can( 'edit_post', $post->ID );
954 -
955 - $password_required = post_password_required( $post->ID )
956 - && ! current_user_can( 'edit_post', $post->ID );
957 -
958 - return $is_private || $not_allowed || $password_required;
959 - }
960 -
961 - public static function is_custom_kit_applied() {
962 - return (bool) Plugin::$instance->kits_manager->get_previous_id();
963 - }
964 -
965 - public static function decode_string( string $encoded_string, ?string $fallback = '' ) {
966 - try {
967 - return base64_decode( $encoded_string, true ) ?? $fallback;
968 - } catch ( \Exception $e ) {
969 - return $fallback;
970 - }
971 - }
972 -
973 - public static function encode_string( string $decoded_string ): string {
974 - return base64_encode( $decoded_string );
975 703 }
976 704 }