PluginProbe
Ultimate Post Kit – Elementor Post Grid, Post Carousel, Post Slider & Blog Layout Widgets / 4.5.4
Ultimate Post Kit – Elementor Post Grid, Post Carousel, Post Slider & Blog Layout Widgets v4.5.4
4.5.4 4.2.1 4.2.2 4.2.3 4.5.0 4.5.2 4.5.3 4.2.0 4.1.18 4.1.17 4.1.16 4.1.15 4.1.14 4.1.13 4.1.12 4.1.11 4.1.10 4.1.9 4.1.8 4.0.9 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 All 146 releases
ultimate-post-kit / includes / utils.php

utils.php in Ultimate Post Kit – Elementor Post Grid, Post Carousel, Post Slider & Blog Layout Widgets 4.5.4, at includes/utils.php

191 lines 5.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace UltimatePostKit;
3
4 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
5
6 class Utils {
7
8 /**
9 * A list of safe tage for `get_valid_html_tag` method.
10 */
11 const ALLOWED_HTML_WRAPPER_TAGS = [
12 'article',
13 'aside',
14 'div',
15 'footer',
16 'h1',
17 'h2',
18 'h3',
19 'h4',
20 'h5',
21 'h6',
22 'header',
23 'main',
24 'nav',
25 'p',
26 'section',
27 'span',
28 ];
29
30 public static function get_site_domain() {
31 return str_ireplace( 'www.', '', wp_parse_url( home_url(), PHP_URL_HOST ) );
32 }
33
34 public static function readable_num( $size ) {
35 $l = substr( $size, -1 );
36 $ret = substr( $size, 0, -1 );
37 $byte = 1024;
38
39 switch ( strtoupper( $l ) ) {
40 case 'P':
41 $ret *= 1024;
42 case 'T':
43 $ret *= 1024;
44 case 'G':
45 $ret *= 1024;
46 case 'M':
47 $ret *= 1024;
48 case 'K':
49 $ret *= 1024;
50 }
51 return $ret;
52 }
53
54 /**
55 * Validate an HTML tag against a safe allowed list.
56 * @param string $tag
57 * @return string
58 */
59 public static function get_valid_html_tag( $tag ) {
60 if ( ! is_scalar( $tag ) ) {
61 return 'div';
62 }
63
64 return in_array( strtolower( (string) $tag ), self::ALLOWED_HTML_WRAPPER_TAGS ) ? $tag : 'div';
65 }
66
67 public static function print_valid_html_tag( $tag ) {
68 echo esc_attr( self::get_valid_html_tag( $tag ) );
69 }
70
71 /**
72 * Get placeholder image source.
73 * Retrieve the source of the placeholder image.
74 * @since 5.7.6
75 * @access public
76 * @static
77 * @return string The source of the default placeholder image used by Elementor.
78 */
79 public static function get_placeholder_image_src() {
80 $placeholder_image = ELEMENTOR_ASSETS_URL . 'images/placeholder.png';
81
82 return $placeholder_image;
83 }
84
85 /**
86 * For get wp environment for element pack
87 * @return [type] [description]
88 */
89 public static function get_environment_info(){
90
91 // Figure out cURL version, if installed.
92 $curl_version = '';
93 if ( function_exists( 'curl_version' ) ) {
94 $curl_version = curl_version();
95 $curl_version = $curl_version['version'] . ', ' . $curl_version['ssl_version'];
96 }
97
98
99 // WP memory limit.
100 $wp_memory_limit = self::readable_num(WP_MEMORY_LIMIT);
101 if ( function_exists( 'memory_get_usage' ) ) {
102 $wp_memory_limit = max( $wp_memory_limit, self::readable_num( @ini_get( 'memory_limit' ) ) );
103 }
104
105
106 return array(
107 'home_url' => get_option( 'home' ),
108 'site_url' => get_option( 'siteurl' ),
109 'version' => BDTUPK_VER,
110 'wp_version' => get_bloginfo( 'version' ),
111 'wp_multisite' => is_multisite(),
112 'wp_memory_limit' => $wp_memory_limit,
113 'wp_debug_mode' => ( defined( 'WP_DEBUG' ) && WP_DEBUG ),
114 'wp_cron' => ! ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ),
115 'language' => get_locale(),
116 'external_object_cache' => wp_using_ext_object_cache(),
117 'php_version' => phpversion(),
118 'php_post_max_size' => self::readable_num( ini_get( 'post_max_size' ) ),
119 'php_max_execution_time' => ini_get( 'max_execution_time' ),
120 'php_max_input_vars' => ini_get( 'max_input_vars' ),
121 'curl_version' => $curl_version,
122 'suhosin_installed' => extension_loaded( 'suhosin' ),
123 'max_upload_size' => wp_max_upload_size(),
124 'default_timezone' => date_default_timezone_get(),
125 'fsockopen_or_curl_enabled' => ( function_exists( 'fsockopen' ) || function_exists( 'curl_init' ) ),
126 'soapclient_enabled' => class_exists( 'SoapClient' ),
127 'domdocument_enabled' => class_exists( 'DOMDocument' ),
128 'gzip_enabled' => is_callable( 'gzopen' ),
129 'mbstring_enabled' => extension_loaded( 'mbstring' ),
130 );
131
132 }
133
134 /**
135 * Get timezone string.
136 *
137 * Retrieve timezone string from the WordPress database.
138 *
139 * @since 1.0.0
140 * @access public
141 * @static
142 *
143 * @return string Timezone string.
144 */
145 public static function get_timezone_string() {
146 $current_offset = (float) get_option( 'gmt_offset' );
147 $timezone_string = get_option( 'timezone_string' );
148
149 // Create a UTC+- zone if no timezone string exists.
150 if ( empty( $timezone_string ) ) {
151 if ( $current_offset < 0 ) {
152 $timezone_string = 'UTC' . $current_offset;
153 } else {
154 $timezone_string = 'UTC+' . $current_offset;
155 }
156 }
157
158 return $timezone_string;
159 }
160
161 /**
162 * Build a localized comment count string for front-end display.
163 *
164 * Single translatable pattern so locales can reorder words (e.g. "Comments: %s").
165 * Always escape with esc_html() (or esc_attr() for attributes) when outputting.
166 *
167 * @param int $post_id Post ID. Use 0 for the current post in The Loop.
168 * @return string Unescaped translated string.
169 */
170 public static function get_formatted_comments_count( $post_id = 0 ) {
171 $comment_count = (int) get_comments_number( $post_id );
172
173 return sprintf(
174 /* translators: %s: number of comments */
175 _n( '%s comment', '%s comments', $comment_count, 'ultimate-post-kit' ),
176 number_format_i18n( $comment_count )
177 );
178 }
179
180 /**
181 * Localized numeric comment count only (no word label). For icon-only meta.
182 *
183 * @param int $post_id Post ID. Use 0 for the current post in The Loop.
184 * @return string
185 */
186 public static function get_localized_comment_count( $post_id = 0 ) {
187 return number_format_i18n( (int) get_comments_number( $post_id ) );
188 }
189
190 }
191