| @@ -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 | |
| @@ -22,9 +19,9 @@ | ||
| 22 | 19 | |
| 23 | 20 | const EDITOR_BREAK_LINES_OPTION_KEY = 'elementor_editor_break_lines'; |
| 24 | 21 | |
| 25 | 22 | /** |
| 26 | - * A list of safe tags for `validate_html_tag` method. | |
| 23 | + * A list of safe tage for `validate_html_tag` method. | |
| 27 | 24 | */ |
| 28 | 25 | const ALLOWED_HTML_WRAPPER_TAGS = [ |
| 29 | 26 | 'a', |
| 30 | 27 | 'article', |
| @@ -29,9 +26,8 @@ | ||
| 29 | 26 | 'a', |
| 30 | 27 | 'article', |
| 31 | 28 | 'aside', |
| 32 | 29 | 'button', |
| 33 | - 'form', | |
| 34 | 30 | 'div', |
| 35 | 31 | 'footer', |
| 36 | 32 | 'h1', |
| 37 | 33 | 'h2', |
| @@ -92,27 +88,10 @@ | ||
| 92 | 88 | ], |
| 93 | 89 | ]; |
| 94 | 90 | |
| 95 | 91 | /** |
| 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. | |
| 92 | + * Is WP CLI. | |
| 111 | 93 | * |
| 112 | - * @access public | |
| 113 | - * @static | |
| 114 | - * | |
| 115 | 94 | * @return bool |
| 116 | 95 | */ |
| 117 | 96 | public static function is_wp_cli() { |
| 118 | 97 | return defined( 'WP_CLI' ) && WP_CLI; |
| @@ -118,8 +97,10 @@ | ||
| 118 | 97 | return defined( 'WP_CLI' ) && WP_CLI; |
| 119 | 98 | } |
| 120 | 99 | |
| 121 | 100 | /** |
| 101 | + * Is script debug. | |
| 102 | + * | |
| 122 | 103 | * Whether script debug is enabled or not. |
| 123 | 104 | * |
| 124 | 105 | * @since 1.0.0 |
| 125 | 106 | * @access public |
| @@ -124,9 +105,9 @@ | ||
| 124 | 105 | * @since 1.0.0 |
| 125 | 106 | * @access public |
| 126 | 107 | * @static |
| 127 | 108 | * |
| 128 | - * @return bool | |
| 109 | + * @return bool True if it's a script debug is active, false otherwise. | |
| 129 | 110 | */ |
| 130 | 111 | public static function is_script_debug() { |
| 131 | 112 | return defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG; |
| 132 | 113 | } |
| @@ -131,32 +112,8 @@ | ||
| 131 | 112 | return defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG; |
| 132 | 113 | } |
| 133 | 114 | |
| 134 | 115 | /** |
| 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 | 116 | * Get pro link. |
| 160 | 117 | * |
| 161 | 118 | * Retrieve the link to Elementor Pro. |
| 162 | 119 | * |
| @@ -195,54 +152,38 @@ | ||
| 195 | 152 | * @since 2.1.0 |
| 196 | 153 | * @static |
| 197 | 154 | * @access public |
| 198 | 155 | * |
| 199 | - * @param string $from | |
| 200 | - * @param string $to | |
| 156 | + * @param $from | |
| 157 | + * @param $to | |
| 201 | 158 | * |
| 202 | 159 | * @return string |
| 203 | - * @throws \Exception If URLs are missing or invalid URLs provided. | |
| 160 | + * @throws \Exception | |
| 204 | 161 | */ |
| 205 | 162 | public static function replace_urls( $from, $to ) { |
| 206 | 163 | $from = trim( $from ); |
| 207 | 164 | $to = trim( $to ); |
| 208 | 165 | |
| 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 | 166 | 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.' ); | |
| 167 | + throw new \Exception( esc_html__( 'The `from` and `to` URL\'s must be different', 'elementor' ) ); | |
| 219 | 168 | } |
| 220 | 169 | |
| 221 | 170 | $is_valid_urls = ( filter_var( $from, FILTER_VALIDATE_URL ) && filter_var( $to, FILTER_VALIDATE_URL ) ); |
| 222 | - | |
| 223 | 171 | 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.' ); | |
| 172 | + throw new \Exception( esc_html__( 'The `from` and `to` URL\'s must be valid URL\'s', 'elementor' ) ); | |
| 225 | 173 | } |
| 226 | 174 | |
| 227 | 175 | 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 | 176 | |
| 177 | + // @codingStandardsIgnoreStart cannot use `$wpdb->prepare` because it remove's the backslashes | |
| 232 | 178 | $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 | - ); | |
| 179 | + "UPDATE {$wpdb->postmeta} " . | |
| 180 | + "SET `meta_value` = REPLACE(`meta_value`, '" . str_replace( '/', '\\\/', $from ) . "', '" . str_replace( '/', '\\\/', $to ) . "') " . | |
| 181 | + "WHERE `meta_key` = '_elementor_data' AND `meta_value` LIKE '[%' ;" ); // meta_value LIKE '[%' are json formatted | |
| 182 | + // @codingStandardsIgnoreEnd | |
| 242 | 183 | |
| 243 | 184 | if ( false === $rows_affected ) { |
| 244 | - throw new \Exception( 'An error occurred while replacing URL\'s.' ); | |
| 185 | + throw new \Exception( esc_html__( 'An error occurred', 'elementor' ) ); | |
| 245 | 186 | } |
| 246 | 187 | |
| 247 | 188 | // Allow externals to replace-urls, when they have to. |
| 248 | 189 | $rows_affected += (int) apply_filters( 'elementor/tools/replace-urls', 0, $from, $to ); |
| @@ -247,13 +188,12 @@ | ||
| 247 | 188 | // Allow externals to replace-urls, when they have to. |
| 248 | 189 | $rows_affected += (int) apply_filters( 'elementor/tools/replace-urls', 0, $from, $to ); |
| 249 | 190 | |
| 250 | 191 | Plugin::$instance->files_manager->clear_cache(); |
| 251 | - Google_Font::clear_cache(); | |
| 252 | 192 | |
| 253 | 193 | return sprintf( |
| 254 | 194 | /* translators: %d: Number of rows. */ |
| 255 | - _n( '%d database row affected.', '%d database rows affected.', $rows_affected, 'elementor' ), | |
| 195 | + _n( '%d row affected.', '%d rows affected.', $rows_affected, 'elementor' ), | |
| 256 | 196 | $rows_affected |
| 257 | 197 | ); |
| 258 | 198 | } |
| 259 | 199 | |
| @@ -280,9 +220,9 @@ | ||
| 280 | 220 | * |
| 281 | 221 | * Filters whether the post type supports editing with Elementor. |
| 282 | 222 | * |
| 283 | 223 | * @since 1.0.0 |
| 284 | - * @deprecated 2.2.0 Use `elementor/utils/is_post_support` hook Instead. | |
| 224 | + * @deprecated 2.2.0 Use `elementor/utils/is_post_support` Instead | |
| 285 | 225 | * |
| 286 | 226 | * @param bool $is_supported Whether the post type supports editing with Elementor. |
| 287 | 227 | * @param int $post_id Post ID. |
| 288 | 228 | * @param string $post_type Post type. |
| @@ -399,10 +339,10 @@ | ||
| 399 | 339 | if ( ! defined( 'DONOTCDN' ) ) { |
| 400 | 340 | define( 'DONOTCDN', true ); |
| 401 | 341 | } |
| 402 | 342 | |
| 403 | - if ( ! defined( 'DONOTCACHEOBJECT' ) ) { | |
| 404 | - define( 'DONOTCACHEOBJECT', true ); | |
| 343 | + if ( ! defined( 'DONOTCACHCEOBJECT' ) ) { | |
| 344 | + define( 'DONOTCACHCEOBJECT', true ); | |
| 405 | 345 | } |
| 406 | 346 | |
| 407 | 347 | // Set the headers to prevent caching for the different browsers. |
| 408 | 348 | nocache_headers(); |
| @@ -441,12 +381,12 @@ | ||
| 441 | 381 | * Retrieve a custom URL for creating a new post/page using Elementor. |
| 442 | 382 | * |
| 443 | 383 | * @since 1.9.0 |
| 444 | 384 | * @access public |
| 445 | - * @deprecated 3.3.0 Use `Plugin::$instance->documents->get_create_new_post_url()` instead. | |
| 385 | + * @deprecated 3.3.0 | |
| 446 | 386 | * @static |
| 447 | 387 | * |
| 448 | - * @param string $post_type Optional. Post type slug. Default is 'page'. | |
| 388 | + * @param string $post_type Optional. Post type slug. Default is 'page'. | |
| 449 | 389 | * @param string|null $template_type Optional. Query arg 'template_type'. Default is null. |
| 450 | 390 | * |
| 451 | 391 | * @return string A URL for creating new post using Elementor. |
| 452 | 392 | */ |
| @@ -513,14 +453,14 @@ | ||
| 513 | 453 | * @since 2.1.2 |
| 514 | 454 | * @access public |
| 515 | 455 | * @static |
| 516 | 456 | */ |
| 517 | - public static function array_inject( $base_array, $key, $insert ) { | |
| 518 | - $length = array_search( $key, array_keys( $base_array ), true ) + 1; | |
| 457 | + public static function array_inject( $array, $key, $insert ) { | |
| 458 | + $length = array_search( $key, array_keys( $array ), true ) + 1; | |
| 519 | 459 | |
| 520 | - return array_slice( $base_array, 0, $length, true ) + | |
| 460 | + return array_slice( $array, 0, $length, true ) + | |
| 521 | 461 | $insert + |
| 522 | - array_slice( $base_array, $length, null, true ); | |
| 462 | + array_slice( $array, $length, null, true ); | |
| 523 | 463 | } |
| 524 | 464 | |
| 525 | 465 | /** |
| 526 | 466 | * Render html attributes |
| @@ -564,9 +504,9 @@ | ||
| 564 | 504 | * Viewport meta tag. |
| 565 | 505 | * |
| 566 | 506 | * Filters the meta tag containing the viewport information. |
| 567 | 507 | * |
| 568 | - * This hook can be used to change the initial viewport meta tag set by Elementor | |
| 508 | + * This hook can be used to change the intial viewport meta tag set by Elementor | |
| 569 | 509 | * and replace it with a different viewport tag. |
| 570 | 510 | * |
| 571 | 511 | * @since 2.5.0 |
| 572 | 512 | * |
| @@ -581,12 +521,11 @@ | ||
| 581 | 521 | /** |
| 582 | 522 | * Add Elementor Config js vars to the relevant script handle, |
| 583 | 523 | * WP will wrap it with <script> tag. |
| 584 | 524 | * To make sure this script runs thru the `script_loader_tag` hook, use a known handle value. |
| 585 | - * | |
| 586 | 525 | * @param string $handle |
| 587 | 526 | * @param string $js_var |
| 588 | - * @param mixed $config | |
| 527 | + * @param mixed $config | |
| 589 | 528 | */ |
| 590 | 529 | public static function print_js_config( $handle, $js_var, $config ) { |
| 591 | 530 | $config = wp_json_encode( $config ); |
| 592 | 531 | |
| @@ -616,9 +555,9 @@ | ||
| 616 | 555 | |
| 617 | 556 | /** |
| 618 | 557 | * Checks a control value for being empty, including a string of '0' not covered by PHP's empty(). |
| 619 | 558 | * |
| 620 | - * @param mixed $source | |
| 559 | + * @param mixed $source | |
| 621 | 560 | * @param bool|string $key |
| 622 | 561 | * |
| 623 | 562 | * @return bool |
| 624 | 563 | */ |
| @@ -637,34 +576,15 @@ | ||
| 637 | 576 | public static function has_pro() { |
| 638 | 577 | return defined( 'ELEMENTOR_PRO_VERSION' ); |
| 639 | 578 | } |
| 640 | 579 | |
| 641 | - public static function is_license_active(): bool { | |
| 642 | - return class_exists( '\ElementorPro\License\API' ) && \ElementorPro\License\API::is_license_active(); | |
| 643 | - } | |
| 644 | - | |
| 645 | - public static function is_pro_installed_and_not_active(): bool { | |
| 646 | - if ( ! function_exists( 'get_plugins' ) ) { | |
| 647 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; | |
| 648 | - } | |
| 649 | - | |
| 650 | - $file_path = self::get_elementor_pro_file_path(); | |
| 651 | - $installed_plugins = get_plugins(); | |
| 652 | - | |
| 653 | - return isset( $installed_plugins[ $file_path ] ); | |
| 654 | - } | |
| 655 | - | |
| 656 | - private static function get_elementor_pro_file_path(): string { | |
| 657 | - return 'elementor-pro/elementor-pro.php'; | |
| 658 | - } | |
| 659 | - | |
| 660 | 580 | /** |
| 661 | 581 | * Convert HTMLEntities to UTF-8 characters |
| 662 | 582 | * |
| 663 | - * @param string $html_string | |
| 583 | + * @param $string | |
| 664 | 584 | * @return string |
| 665 | 585 | */ |
| 666 | - public static function urlencode_html_entities( $html_string ) { | |
| 586 | + public static function urlencode_html_entities( $string ) { | |
| 667 | 587 | $entities_dictionary = [ |
| 668 | 588 | '‘' => "'", // Opening single quote |
| 669 | 589 | '’' => "'", // Closing single quote |
| 670 | 590 | '“' => '"', // Closing double quote |
| @@ -677,11 +597,11 @@ | ||
| 677 | 597 | '„' => '"', // Double low quote |
| 678 | 598 | ]; |
| 679 | 599 | |
| 680 | 600 | // Decode decimal entities |
| 681 | - $html_string = str_replace( array_keys( $entities_dictionary ), array_values( $entities_dictionary ), $html_string ); | |
| 601 | + $string = str_replace( array_keys( $entities_dictionary ), array_values( $entities_dictionary ), $string ); | |
| 682 | 602 | |
| 683 | - return rawurlencode( html_entity_decode( $html_string, ENT_QUOTES | ENT_HTML5, 'UTF-8' ) ); | |
| 603 | + return rawurlencode( html_entity_decode( $string, ENT_QUOTES | ENT_HTML5, 'UTF-8' ) ); | |
| 684 | 604 | } |
| 685 | 605 | |
| 686 | 606 | /** |
| 687 | 607 | * Parse attributes that come as a string of comma-delimited key|value pairs. |
| @@ -733,19 +653,13 @@ | ||
| 733 | 653 | if ( $id === $element['id'] ) { |
| 734 | 654 | return $element; |
| 735 | 655 | } |
| 736 | 656 | |
| 737 | - $inner_elements = apply_filters( | |
| 738 | - 'elementor/utils/find_element_recursive/inner_elements', | |
| 739 | - $element['elements'] ?? [], | |
| 740 | - $element | |
| 741 | - ); | |
| 657 | + if ( ! empty( $element['elements'] ) ) { | |
| 658 | + $element = self::find_element_recursive( $element['elements'], $id ); | |
| 742 | 659 | |
| 743 | - if ( ! empty( $inner_elements ) ) { | |
| 744 | - $found = self::find_element_recursive( $inner_elements, $id ); | |
| 745 | - | |
| 746 | - if ( $found ) { | |
| 747 | - return $found; | |
| 660 | + if ( $element ) { | |
| 661 | + return $element; | |
| 748 | 662 | } |
| 749 | 663 | } |
| 750 | 664 | } |
| 751 | 665 | |
| @@ -760,10 +674,10 @@ | ||
| 760 | 674 | * Fired by `admin_menu` action. |
| 761 | 675 | * |
| 762 | 676 | * @since 3.1.0 |
| 763 | 677 | * |
| 764 | - * @param string $menu_slug | |
| 765 | - * @param string $new_label | |
| 678 | + * @param $menu_slug | |
| 679 | + * @param $new_label | |
| 766 | 680 | * @access public |
| 767 | 681 | */ |
| 768 | 682 | public static function change_submenu_first_item_label( $menu_slug, $new_label ) { |
| 769 | 683 | global $submenu; |
| @@ -782,9 +696,9 @@ | ||
| 782 | 696 | * |
| 783 | 697 | * @return string |
| 784 | 698 | */ |
| 785 | 699 | public static function validate_html_tag( $tag ) { |
| 786 | - return $tag && in_array( strtolower( $tag ), self::ALLOWED_HTML_WRAPPER_TAGS ) ? $tag : 'div'; | |
| 700 | + return in_array( strtolower( $tag ), self::ALLOWED_HTML_WRAPPER_TAGS ) ? $tag : 'div'; | |
| 787 | 701 | } |
| 788 | 702 | |
| 789 | 703 | /** |
| 790 | 704 | * Safe print a validated HTML tag. |
| @@ -798,10 +712,10 @@ | ||
| 798 | 712 | |
| 799 | 713 | /** |
| 800 | 714 | * Print internal content (not user input) without escaping. |
| 801 | 715 | */ |
| 802 | - public static function print_unescaped_internal_string( $internal_string ) { | |
| 803 | - echo $internal_string; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 716 | + public static function print_unescaped_internal_string( $string ) { | |
| 717 | + echo $string; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 804 | 718 | } |
| 805 | 719 | |
| 806 | 720 | /** |
| 807 | 721 | * Get recently edited posts query. |
| @@ -826,174 +740,19 @@ | ||
| 826 | 740 | |
| 827 | 741 | return new \WP_Query( $args ); |
| 828 | 742 | } |
| 829 | 743 | |
| 830 | - public static function print_wp_kses_extended( $text, array $tags ) { | |
| 744 | + public static function print_wp_kses_extended( $string, array $tags ) { | |
| 831 | 745 | $allowed_html = wp_kses_allowed_html( 'post' ); |
| 746 | + // Since PHP 5.6 cannot use isset() on the result of an expression. | |
| 747 | + $extended_allowed_html_tags = self::EXTENDED_ALLOWED_HTML_TAGS; | |
| 832 | 748 | |
| 833 | 749 | foreach ( $tags as $tag ) { |
| 834 | - if ( isset( self::EXTENDED_ALLOWED_HTML_TAGS[ $tag ] ) ) { | |
| 750 | + if ( isset( $extended_allowed_html_tags[ $tag ] ) ) { | |
| 835 | 751 | $extended_tags = apply_filters( "elementor/extended_allowed_html_tags/{$tag}", self::EXTENDED_ALLOWED_HTML_TAGS[ $tag ] ); |
| 836 | 752 | $allowed_html = array_replace_recursive( $allowed_html, $extended_tags ); |
| 837 | 753 | } |
| 838 | 754 | } |
| 839 | 755 | |
| 840 | - echo wp_kses( $text, $allowed_html ); | |
| 841 | - } | |
| 842 | - | |
| 843 | - public static function is_elementor_path( $path ) { | |
| 844 | - $path = wp_normalize_path( $path ); | |
| 845 | - | |
| 846 | - /** | |
| 847 | - * Elementor related paths. | |
| 848 | - * | |
| 849 | - * Filters Elementor related paths. | |
| 850 | - * | |
| 851 | - * @param string[] $available_paths | |
| 852 | - */ | |
| 853 | - $available_paths = apply_filters( 'elementor/utils/elementor_related_paths', [ ELEMENTOR_PATH ] ); | |
| 854 | - | |
| 855 | - return (bool) ( new Collection( $available_paths ) ) | |
| 856 | - ->map( function ( $p ) { | |
| 857 | - // `untrailingslashit` in order to include other plugins prefixed with elementor. | |
| 858 | - return untrailingslashit( wp_normalize_path( $p ) ); | |
| 859 | - } ) | |
| 860 | - ->find(function ( $p ) use ( $path ) { | |
| 861 | - return false !== strpos( $path, $p ); | |
| 862 | - } ); | |
| 863 | - } | |
| 864 | - | |
| 865 | - /** | |
| 866 | - * @param string $file | |
| 867 | - * @param mixed ...$args | |
| 868 | - * @return false|string | |
| 869 | - */ | |
| 870 | - public static function file_get_contents( $file, ...$args ) { | |
| 871 | - if ( ! is_file( $file ) || ! is_readable( $file ) ) { | |
| 872 | - return false; | |
| 873 | - } | |
| 874 | - return file_get_contents( $file, ...$args ); | |
| 875 | - } | |
| 876 | - | |
| 877 | - public static function get_super_global_value( $super_global, $key ) { | |
| 878 | - if ( ! isset( $super_global[ $key ] ) ) { | |
| 879 | - return null; | |
| 880 | - } | |
| 881 | - | |
| 882 | - if ( $_FILES === $super_global ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 883 | - return isset( $super_global[ $key ]['name'] ) ? | |
| 884 | - self::sanitize_file_name( $super_global[ $key ] ) : | |
| 885 | - self::sanitize_multi_upload( $super_global[ $key ] ); | |
| 886 | - } | |
| 887 | - | |
| 888 | - return wp_kses_post_deep( wp_unslash( $super_global[ $key ] ) ); | |
| 889 | - } | |
| 890 | - | |
| 891 | - private static function sanitize_multi_upload( $fields ) { | |
| 892 | - return array_map( function( $field ) { | |
| 893 | - return array_map( 'self::sanitize_file_name', $field ); | |
| 894 | - }, $fields ); | |
| 895 | - } | |
| 896 | - | |
| 897 | - private static function sanitize_file_name( $file ) { | |
| 898 | - $file['name'] = sanitize_file_name( $file['name'] ); | |
| 899 | - | |
| 900 | - return $file; | |
| 901 | - } | |
| 902 | - | |
| 903 | - /** | |
| 904 | - * Return specific object property value if exist from array of keys. | |
| 905 | - * | |
| 906 | - * @param array $base_array | |
| 907 | - * @param array $keys | |
| 908 | - * @return mixed|null | |
| 909 | - */ | |
| 910 | - public static function get_array_value_by_keys( $base_array, $keys ) { | |
| 911 | - $keys = (array) $keys; | |
| 912 | - foreach ( $keys as $key ) { | |
| 913 | - if ( ! isset( $base_array[ $key ] ) ) { | |
| 914 | - return null; | |
| 915 | - } | |
| 916 | - $base_array = $base_array[ $key ]; | |
| 917 | - } | |
| 918 | - return $base_array; | |
| 919 | - } | |
| 920 | - | |
| 921 | - public static function get_cached_callback( $callback, $cache_key, $cache_time = 24 * HOUR_IN_SECONDS ) { | |
| 922 | - $cache = get_site_transient( $cache_key ); | |
| 923 | - | |
| 924 | - if ( ! $cache ) { | |
| 925 | - $cache = call_user_func( $callback ); | |
| 926 | - | |
| 927 | - if ( ! is_wp_error( $cache ) ) { | |
| 928 | - set_site_transient( $cache_key, $cache, $cache_time ); | |
| 929 | - } | |
| 930 | - } | |
| 931 | - | |
| 932 | - return $cache; | |
| 933 | - } | |
| 934 | - | |
| 935 | - public static function is_sale_time(): bool { | |
| 936 | - $sale_start_time = gmmktime( 10, 0, 0, 6, 15, 2026 ); | |
| 937 | - $sale_end_time = gmmktime( 3, 59, 0, 6, 17, 2026 ); | |
| 938 | - | |
| 939 | - $now_time = gmdate( 'U' ); | |
| 940 | - | |
| 941 | - return $now_time >= $sale_start_time && $now_time <= $sale_end_time; | |
| 942 | - } | |
| 943 | - | |
| 944 | - public static function safe_throw( string $message ) { | |
| 945 | - if ( ! static::is_elementor_debug() ) { | |
| 946 | - return; | |
| 947 | - } | |
| 948 | - | |
| 949 | - throw new \Exception( esc_html( $message ) ); | |
| 950 | - } | |
| 951 | - | |
| 952 | - public static function has_invalid_post_permissions( $post ): bool { | |
| 953 | - $is_image_attachment = 'attachment' === $post->post_type && strpos( $post->post_mime_type, 'image/' ) === 0; | |
| 954 | - | |
| 955 | - if ( $is_image_attachment ) { | |
| 956 | - return false; | |
| 957 | - } | |
| 958 | - | |
| 959 | - $is_private = 'private' === $post->post_status | |
| 960 | - && ! current_user_can( 'read_private_posts', $post->ID ); | |
| 961 | - | |
| 962 | - $not_allowed = 'publish' !== $post->post_status | |
| 963 | - && ! current_user_can( 'edit_post', $post->ID ); | |
| 964 | - | |
| 965 | - $password_required = post_password_required( $post->ID ) | |
| 966 | - && ! current_user_can( 'edit_post', $post->ID ); | |
| 967 | - | |
| 968 | - return $is_private || $not_allowed || $password_required; | |
| 969 | - } | |
| 970 | - | |
| 971 | - public static function is_custom_kit_applied() { | |
| 972 | - return (bool) Plugin::$instance->kits_manager->get_previous_id(); | |
| 973 | - } | |
| 974 | - | |
| 975 | - public static function decode_string( string $encoded_string, ?string $fallback = '' ) { | |
| 976 | - try { | |
| 977 | - return base64_decode( $encoded_string, true ) ?? $fallback; | |
| 978 | - } catch ( \Exception $e ) { | |
| 979 | - return $fallback; | |
| 980 | - } | |
| 981 | - } | |
| 982 | - | |
| 983 | - public static function encode_string( string $decoded_string ): string { | |
| 984 | - return base64_encode( $decoded_string ); | |
| 985 | - } | |
| 986 | - | |
| 987 | - public static function html_to_plain_text( string $html ): string { | |
| 988 | - if ( empty( $html ) ) { | |
| 989 | - return ''; | |
| 990 | - } | |
| 991 | - | |
| 992 | - $text = preg_replace( '#<br\s*/?\s*>#i', ' ', $html ); | |
| 993 | - $text = preg_replace( '#</?[a-z][^>]*>#i', ' ', $text ); | |
| 994 | - $text = html_entity_decode( $text, ENT_QUOTES, 'UTF-8' ); | |
| 995 | - $text = str_replace( "\xE2\x80\x8B", '', $text ); | |
| 996 | - | |
| 997 | - return trim( preg_replace( '/\s+/', ' ', $text ) ); | |
| 756 | + echo wp_kses( $string, $allowed_html ); | |
| 998 | 757 | } |
| 999 | 758 | } |