PluginProbe
Elementor Website Builder – more than just a page builder / 3.11.5
Elementor Website Builder – more than just a page builder v3.11.5
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
elementor / includes / utils.php

utils.php in Elementor Website Builder – more than just a page builder 3.11.5, at includes/utils.php

843 lines 20.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor;
3
4 use Elementor\Core\Utils\Collection;
5
6 if ( ! defined( 'ABSPATH' ) ) {
7 exit; // Exit if accessed directly.
8 }
9
10 /**
11 * Elementor utils.
12 *
13 * Elementor utils handler class is responsible for different utility methods
14 * used by Elementor.
15 *
16 * @since 1.0.0
17 */
18 class Utils {
19
20 const DEPRECATION_RANGE = 0.4;
21
22 const EDITOR_BREAK_LINES_OPTION_KEY = 'elementor_editor_break_lines';
23
24 /**
25 * A list of safe tage for `validate_html_tag` method.
26 */
27 const ALLOWED_HTML_WRAPPER_TAGS = [
28 'a',
29 'article',
30 'aside',
31 'button',
32 'div',
33 'footer',
34 'h1',
35 'h2',
36 'h3',
37 'h4',
38 'h5',
39 'h6',
40 'header',
41 'main',
42 'nav',
43 'p',
44 'section',
45 'span',
46 ];
47
48 const EXTENDED_ALLOWED_HTML_TAGS = [
49 'iframe' => [
50 'iframe' => [
51 'allow' => true,
52 'allowfullscreen' => true,
53 'frameborder' => true,
54 'height' => true,
55 'loading' => true,
56 'name' => true,
57 'referrerpolicy' => true,
58 'sandbox' => true,
59 'src' => true,
60 'width' => true,
61 ],
62 ],
63 'svg' => [
64 'svg' => [
65 'aria-hidden' => true,
66 'aria-labelledby' => true,
67 'class' => true,
68 'height' => true,
69 'role' => true,
70 'viewbox' => true,
71 'width' => true,
72 'xmlns' => true,
73 ],
74 'g' => [
75 'fill' => true,
76 ],
77 'title' => [
78 'title' => true,
79 ],
80 'path' => [
81 'd' => true,
82 'fill' => true,
83 ],
84 ],
85 'image' => [
86 'img' => [
87 'srcset' => true,
88 'sizes' => true,
89 ],
90 ],
91 ];
92
93 /**
94 * Is WP CLI.
95 *
96 * @return bool
97 */
98 public static function is_wp_cli() {
99 return defined( 'WP_CLI' ) && WP_CLI;
100 }
101
102 /**
103 * Is script debug.
104 *
105 * Whether script debug is enabled or not.
106 *
107 * @since 1.0.0
108 * @access public
109 * @static
110 *
111 * @return bool True if it's a script debug is active, false otherwise.
112 */
113 public static function is_script_debug() {
114 return defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG;
115 }
116
117 /**
118 * Whether elementor test mode is enabled or not.
119 *
120 * @return bool
121 */
122 public static function is_elementor_tests() {
123 return defined( 'ELEMENTOR_TESTS' ) && ELEMENTOR_TESTS;
124 }
125
126 /**
127 * Get pro link.
128 *
129 * Retrieve the link to Elementor Pro.
130 *
131 * @since 1.7.0
132 * @access public
133 * @static
134 *
135 * @param string $link URL to Elementor pro.
136 *
137 * @return string Elementor pro link.
138 */
139 public static function get_pro_link( $link ) {
140 static $theme_name = false;
141
142 if ( ! $theme_name ) {
143 $theme_obj = wp_get_theme();
144 if ( $theme_obj->parent() ) {
145 $theme_name = $theme_obj->parent()->get( 'Name' );
146 } else {
147 $theme_name = $theme_obj->get( 'Name' );
148 }
149
150 $theme_name = sanitize_key( $theme_name );
151 }
152
153 $link = add_query_arg( 'utm_term', $theme_name, $link );
154
155 return $link;
156 }
157
158 /**
159 * Replace URLs.
160 *
161 * Replace old URLs to new URLs. This method also updates all the Elementor data.
162 *
163 * @since 2.1.0
164 * @static
165 * @access public
166 *
167 * @param $from
168 * @param $to
169 *
170 * @return string
171 * @throws \Exception
172 */
173 public static function replace_urls( $from, $to ) {
174 $from = trim( $from );
175 $to = trim( $to );
176
177 if ( empty( $from ) ) {
178 throw new \Exception( 'Couldn’t replace your address because the old URL was not provided. Try again by entering the old URL.' );
179 }
180
181 if ( empty( $to ) ) {
182 throw new \Exception( 'Couldn’t replace your address because the new URL was not provided. Try again by entering the new URL.' );
183 }
184
185 if ( $from === $to ) {
186 throw new \Exception( 'Couldn’t replace your address because both of the URLs provided are identical. Try again by entering different URLs.' );
187 }
188
189 $is_valid_urls = ( filter_var( $from, FILTER_VALIDATE_URL ) && filter_var( $to, FILTER_VALIDATE_URL ) );
190 if ( ! $is_valid_urls ) {
191 throw new \Exception( 'Couldn’t replace your address because at least one of the URLs provided are invalid. Try again by entering valid URLs.' );
192 }
193
194 global $wpdb;
195
196 // @codingStandardsIgnoreStart cannot use `$wpdb->prepare` because it remove's the backslashes
197 $rows_affected = $wpdb->query(
198 "UPDATE {$wpdb->postmeta} " .
199 "SET `meta_value` = REPLACE(`meta_value`, '" . str_replace( '/', '\\\/', $from ) . "', '" . str_replace( '/', '\\\/', $to ) . "') " .
200 "WHERE `meta_key` = '_elementor_data' AND `meta_value` LIKE '[%' ;" ); // meta_value LIKE '[%' are json formatted
201 // @codingStandardsIgnoreEnd
202
203 if ( false === $rows_affected ) {
204 throw new \Exception( 'An error occurred while replacing URL\'s.' );
205 }
206
207 // Allow externals to replace-urls, when they have to.
208 $rows_affected += (int) apply_filters( 'elementor/tools/replace-urls', 0, $from, $to );
209
210 Plugin::$instance->files_manager->clear_cache();
211
212 return sprintf(
213 /* translators: %d: Number of rows. */
214 _n( '%d database row affected.', '%d database rows affected.', $rows_affected, 'elementor' ),
215 $rows_affected
216 );
217 }
218
219 /**
220 * Is post supports Elementor.
221 *
222 * Whether the post supports editing with Elementor.
223 *
224 * @since 1.0.0
225 * @access public
226 * @static
227 *
228 * @param int $post_id Optional. Post ID. Default is `0`.
229 *
230 * @return string True if post supports editing with Elementor, false otherwise.
231 */
232 public static function is_post_support( $post_id = 0 ) {
233 $post_type = get_post_type( $post_id );
234
235 $is_supported = self::is_post_type_support( $post_type );
236
237 /**
238 * Is post type support.
239 *
240 * Filters whether the post type supports editing with Elementor.
241 *
242 * @since 1.0.0
243 * @deprecated 2.2.0 Use `elementor/utils/is_post_support` Instead
244 *
245 * @param bool $is_supported Whether the post type supports editing with Elementor.
246 * @param int $post_id Post ID.
247 * @param string $post_type Post type.
248 */
249 $is_supported = apply_filters( 'elementor/utils/is_post_type_support', $is_supported, $post_id, $post_type );
250
251 /**
252 * Is post support.
253 *
254 * Filters whether the post supports editing with Elementor.
255 *
256 * @since 2.2.0
257 *
258 * @param bool $is_supported Whether the post type supports editing with Elementor.
259 * @param int $post_id Post ID.
260 * @param string $post_type Post type.
261 */
262 $is_supported = apply_filters( 'elementor/utils/is_post_support', $is_supported, $post_id, $post_type );
263
264 return $is_supported;
265 }
266
267
268 /**
269 * Is post type supports Elementor.
270 *
271 * Whether the post type supports editing with Elementor.
272 *
273 * @since 2.2.0
274 * @access public
275 * @static
276 *
277 * @param string $post_type Post Type.
278 *
279 * @return string True if post type supports editing with Elementor, false otherwise.
280 */
281 public static function is_post_type_support( $post_type ) {
282 if ( ! post_type_exists( $post_type ) ) {
283 return false;
284 }
285
286 if ( ! post_type_supports( $post_type, 'elementor' ) ) {
287 return false;
288 }
289
290 return true;
291 }
292
293 /**
294 * Get placeholder image source.
295 *
296 * Retrieve the source of the placeholder image.
297 *
298 * @since 1.0.0
299 * @access public
300 * @static
301 *
302 * @return string The source of the default placeholder image used by Elementor.
303 */
304 public static function get_placeholder_image_src() {
305 $placeholder_image = ELEMENTOR_ASSETS_URL . 'images/placeholder.png';
306
307 /**
308 * Get placeholder image source.
309 *
310 * Filters the source of the default placeholder image used by Elementor.
311 *
312 * @since 1.0.0
313 *
314 * @param string $placeholder_image The source of the default placeholder image.
315 */
316 $placeholder_image = apply_filters( 'elementor/utils/get_placeholder_image_src', $placeholder_image );
317
318 return $placeholder_image;
319 }
320
321 /**
322 * Generate random string.
323 *
324 * Returns a string containing a hexadecimal representation of random number.
325 *
326 * @since 1.0.0
327 * @access public
328 * @static
329 *
330 * @return string Random string.
331 */
332 public static function generate_random_string() {
333 return dechex( rand() );
334 }
335
336 /**
337 * Do not cache.
338 *
339 * Tell WordPress cache plugins not to cache this request.
340 *
341 * @since 1.0.0
342 * @access public
343 * @static
344 */
345 public static function do_not_cache() {
346 if ( ! defined( 'DONOTCACHEPAGE' ) ) {
347 define( 'DONOTCACHEPAGE', true );
348 }
349
350 if ( ! defined( 'DONOTCACHEDB' ) ) {
351 define( 'DONOTCACHEDB', true );
352 }
353
354 if ( ! defined( 'DONOTMINIFY' ) ) {
355 define( 'DONOTMINIFY', true );
356 }
357
358 if ( ! defined( 'DONOTCDN' ) ) {
359 define( 'DONOTCDN', true );
360 }
361
362 if ( ! defined( 'DONOTCACHCEOBJECT' ) ) {
363 define( 'DONOTCACHCEOBJECT', true );
364 }
365
366 // Set the headers to prevent caching for the different browsers.
367 nocache_headers();
368 }
369
370 /**
371 * Get timezone string.
372 *
373 * Retrieve timezone string from the WordPress database.
374 *
375 * @since 1.0.0
376 * @access public
377 * @static
378 *
379 * @return string Timezone string.
380 */
381 public static function get_timezone_string() {
382 $current_offset = (float) get_option( 'gmt_offset' );
383 $timezone_string = get_option( 'timezone_string' );
384
385 // Create a UTC+- zone if no timezone string exists.
386 if ( empty( $timezone_string ) ) {
387 if ( $current_offset < 0 ) {
388 $timezone_string = 'UTC' . $current_offset;
389 } else {
390 $timezone_string = 'UTC+' . $current_offset;
391 }
392 }
393
394 return $timezone_string;
395 }
396
397 /**
398 * Get create new post URL.
399 *
400 * Retrieve a custom URL for creating a new post/page using Elementor.
401 *
402 * @since 1.9.0
403 * @access public
404 * @deprecated 3.3.0
405 * @static
406 *
407 * @param string $post_type Optional. Post type slug. Default is 'page'.
408 * @param string|null $template_type Optional. Query arg 'template_type'. Default is null.
409 *
410 * @return string A URL for creating new post using Elementor.
411 */
412 public static function get_create_new_post_url( $post_type = 'page', $template_type = null ) {
413 Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __FUNCTION__, '3.3.0', 'Plugin::$instance->documents->get_create_new_post_url()' );
414
415 return Plugin::$instance->documents->get_create_new_post_url( $post_type, $template_type );
416 }
417
418 /**
419 * Get post autosave.
420 *
421 * Retrieve an autosave for any given post.
422 *
423 * @since 1.9.2
424 * @access public
425 * @static
426 *
427 * @param int $post_id Post ID.
428 * @param int $user_id Optional. User ID. Default is `0`.
429 *
430 * @return \WP_Post|false Post autosave or false.
431 */
432 public static function get_post_autosave( $post_id, $user_id = 0 ) {
433 global $wpdb;
434
435 $post = get_post( $post_id );
436
437 $where = $wpdb->prepare( 'post_parent = %d AND post_name LIKE %s AND post_modified_gmt > %s', [ $post_id, "{$post_id}-autosave%", $post->post_modified_gmt ] );
438
439 if ( $user_id ) {
440 $where .= $wpdb->prepare( ' AND post_author = %d', $user_id );
441 }
442
443 $revision = $wpdb->get_row( "SELECT * FROM $wpdb->posts WHERE $where AND post_type = 'revision'" ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
444
445 if ( $revision ) {
446 $revision = new \WP_Post( $revision );
447 } else {
448 $revision = false;
449 }
450
451 return $revision;
452 }
453
454 /**
455 * Is CPT supports custom templates.
456 *
457 * Whether the Custom Post Type supports templates.
458 *
459 * @since 2.0.0
460 * @access public
461 * @static
462 *
463 * @return bool True is templates are supported, False otherwise.
464 */
465 public static function is_cpt_custom_templates_supported() {
466 require_once ABSPATH . '/wp-admin/includes/theme.php';
467
468 return method_exists( wp_get_theme(), 'get_post_templates' );
469 }
470
471 /**
472 * @since 2.1.2
473 * @access public
474 * @static
475 */
476 public static function array_inject( $array, $key, $insert ) {
477 $length = array_search( $key, array_keys( $array ), true ) + 1;
478
479 return array_slice( $array, 0, $length, true ) +
480 $insert +
481 array_slice( $array, $length, null, true );
482 }
483
484 /**
485 * Render html attributes
486 *
487 * @access public
488 * @static
489 * @param array $attributes
490 *
491 * @return string
492 */
493 public static function render_html_attributes( array $attributes ) {
494 $rendered_attributes = [];
495
496 foreach ( $attributes as $attribute_key => $attribute_values ) {
497 if ( is_array( $attribute_values ) ) {
498 $attribute_values = implode( ' ', $attribute_values );
499 }
500
501 $rendered_attributes[] = sprintf( '%1$s="%2$s"', $attribute_key, esc_attr( $attribute_values ) );
502 }
503
504 return implode( ' ', $rendered_attributes );
505 }
506
507 /**
508 * Safe print html attributes
509 *
510 * @access public
511 * @static
512 * @param array $attributes
513 */
514 public static function print_html_attributes( array $attributes ) {
515 // PHPCS - the method render_html_attributes is safe.
516 echo self::render_html_attributes( $attributes ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
517 }
518
519 public static function get_meta_viewport( $context = '' ) {
520 $meta_tag = '<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />';
521
522 /**
523 * Viewport meta tag.
524 *
525 * Filters the meta tag containing the viewport information.
526 *
527 * This hook can be used to change the intial viewport meta tag set by Elementor
528 * and replace it with a different viewport tag.
529 *
530 * @since 2.5.0
531 *
532 * @param string $meta_tag Viewport meta tag.
533 * @param string $context Page context.
534 */
535 $meta_tag = apply_filters( 'elementor/template/viewport_tag', $meta_tag, $context );
536
537 return $meta_tag;
538 }
539
540 /**
541 * Add Elementor Config js vars to the relevant script handle,
542 * WP will wrap it with <script> tag.
543 * To make sure this script runs thru the `script_loader_tag` hook, use a known handle value.
544 * @param string $handle
545 * @param string $js_var
546 * @param mixed $config
547 */
548 public static function print_js_config( $handle, $js_var, $config ) {
549 $config = wp_json_encode( $config );
550
551 if ( get_option( self::EDITOR_BREAK_LINES_OPTION_KEY ) ) {
552 // Add new lines to avoid memory limits in some hosting servers that handles the buffer output according to new line characters
553 $config = str_replace( '}},"', '}},' . PHP_EOL . '"', $config );
554 }
555
556 $script_data = 'var ' . $js_var . ' = ' . $config . ';';
557
558 wp_add_inline_script( $handle, $script_data, 'before' );
559 }
560
561 public static function handle_deprecation( $item, $version, $replacement = null ) {
562 preg_match( '/^[0-9]+\.[0-9]+/', ELEMENTOR_VERSION, $current_version );
563
564 $current_version_as_float = (float) $current_version[0];
565
566 preg_match( '/^[0-9]+\.[0-9]+/', $version, $alias_version );
567
568 $alias_version_as_float = (float) $alias_version[0];
569
570 if ( round( $current_version_as_float - $alias_version_as_float, 1 ) >= self::DEPRECATION_RANGE ) {
571 _deprecated_file( $item, $version, $replacement ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
572 }
573 }
574
575 /**
576 * Checks a control value for being empty, including a string of '0' not covered by PHP's empty().
577 *
578 * @param mixed $source
579 * @param bool|string $key
580 *
581 * @return bool
582 */
583 public static function is_empty( $source, $key = false ) {
584 if ( is_array( $source ) ) {
585 if ( ! isset( $source[ $key ] ) ) {
586 return true;
587 }
588
589 $source = $source[ $key ];
590 }
591
592 return '0' !== $source && empty( $source );
593 }
594
595 public static function has_pro() {
596 return defined( 'ELEMENTOR_PRO_VERSION' );
597 }
598
599 /**
600 * Convert HTMLEntities to UTF-8 characters
601 *
602 * @param $string
603 * @return string
604 */
605 public static function urlencode_html_entities( $string ) {
606 $entities_dictionary = [
607 '&#145;' => "'", // Opening single quote
608 '&#146;' => "'", // Closing single quote
609 '&#147;' => '"', // Closing double quote
610 '&#148;' => '"', // Opening double quote
611 '&#8216;' => "'", // Closing single quote
612 '&#8217;' => "'", // Opening single quote
613 '&#8218;' => "'", // Single low quote
614 '&#8220;' => '"', // Closing double quote
615 '&#8221;' => '"', // Opening double quote
616 '&#8222;' => '"', // Double low quote
617 ];
618
619 // Decode decimal entities
620 $string = str_replace( array_keys( $entities_dictionary ), array_values( $entities_dictionary ), $string );
621
622 return rawurlencode( html_entity_decode( $string, ENT_QUOTES | ENT_HTML5, 'UTF-8' ) );
623 }
624
625 /**
626 * Parse attributes that come as a string of comma-delimited key|value pairs.
627 * Removes Javascript events and unescaped `href` attributes.
628 *
629 * @param string $attributes_string
630 *
631 * @param string $delimiter Default comma `,`.
632 *
633 * @return array
634 */
635 public static function parse_custom_attributes( $attributes_string, $delimiter = ',' ) {
636 $attributes = explode( $delimiter, $attributes_string );
637 $result = [];
638
639 foreach ( $attributes as $attribute ) {
640 $attr_key_value = explode( '|', $attribute );
641
642 $attr_key = mb_strtolower( $attr_key_value[0] );
643
644 // Remove any not allowed characters.
645 preg_match( '/[-_a-z0-9]+/', $attr_key, $attr_key_matches );
646
647 if ( empty( $attr_key_matches[0] ) ) {
648 continue;
649 }
650
651 $attr_key = $attr_key_matches[0];
652
653 // Avoid Javascript events and unescaped href.
654 if ( 'href' === $attr_key || 'on' === substr( $attr_key, 0, 2 ) ) {
655 continue;
656 }
657
658 if ( isset( $attr_key_value[1] ) ) {
659 $attr_value = trim( $attr_key_value[1] );
660 } else {
661 $attr_value = '';
662 }
663
664 $result[ $attr_key ] = $attr_value;
665 }
666
667 return $result;
668 }
669
670 public static function find_element_recursive( $elements, $id ) {
671 foreach ( $elements as $element ) {
672 if ( $id === $element['id'] ) {
673 return $element;
674 }
675
676 if ( ! empty( $element['elements'] ) ) {
677 $element = self::find_element_recursive( $element['elements'], $id );
678
679 if ( $element ) {
680 return $element;
681 }
682 }
683 }
684
685 return false;
686 }
687
688 /**
689 * Change Submenu First Item Label
690 *
691 * Overwrite the label of the first submenu item of an admin menu item.
692 *
693 * Fired by `admin_menu` action.
694 *
695 * @since 3.1.0
696 *
697 * @param $menu_slug
698 * @param $new_label
699 * @access public
700 */
701 public static function change_submenu_first_item_label( $menu_slug, $new_label ) {
702 global $submenu;
703
704 if ( isset( $submenu[ $menu_slug ] ) ) {
705 // @codingStandardsIgnoreStart
706 $submenu[ $menu_slug ][0][0] = $new_label;
707 // @codingStandardsIgnoreEnd
708 }
709 }
710
711 /**
712 * Validate an HTML tag against a safe allowed list.
713 *
714 * @param string $tag
715 *
716 * @return string
717 */
718 public static function validate_html_tag( $tag ) {
719 return in_array( strtolower( $tag ), self::ALLOWED_HTML_WRAPPER_TAGS ) ? $tag : 'div';
720 }
721
722 /**
723 * Safe print a validated HTML tag.
724 *
725 * @param string $tag
726 */
727 public static function print_validated_html_tag( $tag ) {
728 // PHPCS - the method validate_html_tag is safe.
729 echo self::validate_html_tag( $tag ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
730 }
731
732 /**
733 * Print internal content (not user input) without escaping.
734 */
735 public static function print_unescaped_internal_string( $string ) {
736 echo $string; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
737 }
738
739 /**
740 * Get recently edited posts query.
741 *
742 * Returns `WP_Query` of the recent edited posts.
743 * By default max posts ( $args['posts_per_page'] ) is 3.
744 *
745 * @param array $args
746 *
747 * @return \WP_Query
748 */
749 public static function get_recently_edited_posts_query( $args = [] ) {
750 $args = wp_parse_args( $args, [
751 'no_found_rows' => true,
752 'post_type' => 'any',
753 'post_status' => [ 'publish', 'draft' ],
754 'posts_per_page' => '3',
755 'meta_key' => '_elementor_edit_mode',
756 'meta_value' => 'builder',
757 'orderby' => 'modified',
758 ] );
759
760 return new \WP_Query( $args );
761 }
762
763 public static function print_wp_kses_extended( $string, array $tags ) {
764 $allowed_html = wp_kses_allowed_html( 'post' );
765
766 foreach ( $tags as $tag ) {
767 if ( isset( self::EXTENDED_ALLOWED_HTML_TAGS[ $tag ] ) ) {
768 $extended_tags = apply_filters( "elementor/extended_allowed_html_tags/{$tag}", self::EXTENDED_ALLOWED_HTML_TAGS[ $tag ] );
769 $allowed_html = array_replace_recursive( $allowed_html, $extended_tags );
770 }
771 }
772
773 echo wp_kses( $string, $allowed_html );
774 }
775
776 public static function is_elementor_path( $path ) {
777 $path = wp_normalize_path( $path );
778
779 /**
780 * Elementor related paths.
781 *
782 * Filters Elementor related paths.
783 *
784 * @param string[] $available_paths
785 */
786 $available_paths = apply_filters( 'elementor/utils/elementor_related_paths', [ ELEMENTOR_PATH ] );
787
788 return (bool) ( new Collection( $available_paths ) )
789 ->map( function ( $p ) {
790 // `untrailingslashit` in order to include other plugins prefixed with elementor.
791 return untrailingslashit( wp_normalize_path( $p ) );
792 } )
793 ->find(function ( $p ) use ( $path ) {
794 return false !== strpos( $path, $p );
795 } );
796 }
797
798 /**
799 * @param $file
800 * @param mixed ...$args
801 * @return false|string
802 */
803 public static function file_get_contents( $file, ...$args ) {
804 if ( ! is_file( $file ) || ! is_readable( $file ) ) {
805 return false;
806 }
807
808 return file_get_contents( $file, ...$args );
809 }
810
811 public static function get_super_global_value( $super_global, $key ) {
812 if ( ! isset( $super_global[ $key ] ) ) {
813 return null;
814 }
815
816 if ( $_FILES === $super_global ) {
817 $super_global[ $key ]['name'] = sanitize_file_name( $super_global[ $key ]['name'] );
818
819 return $super_global[ $key ];
820 }
821
822 return wp_kses_post_deep( wp_unslash( $super_global[ $key ] ) );
823 }
824
825 /**
826 * Return specific object property value if exist from array of keys.
827 *
828 * @param $array
829 * @param $keys
830 * @return key|false
831 */
832 public static function get_array_value_by_keys( $array, $keys ) {
833 $keys = (array) $keys;
834 foreach ( $keys as $key ) {
835 if ( ! isset( $array[ $key ] ) ) {
836 return null;
837 }
838 $array = $array[ $key ];
839 }
840 return $array;
841 }
842 }
843