PluginProbe
Ultimate Post Kit / 4.2.2
Ultimate Post Kit v4.2.2
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 4.1.5 All 145 releases
ultimate-post-kit / includes / utils.php

utils.php in Ultimate Post Kit 4.2.2, at includes/utils.php

187 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 return in_array( strtolower( $tag ), self::ALLOWED_HTML_WRAPPER_TAGS ) ? $tag : 'div';
61 }
62
63 public static function print_valid_html_tag( $tag ) {
64 echo esc_attr( in_array( strtolower( $tag ), self::ALLOWED_HTML_WRAPPER_TAGS ) ? $tag : 'div' );
65 }
66
67 /**
68 * Get placeholder image source.
69 * Retrieve the source of the placeholder image.
70 * @since 5.7.6
71 * @access public
72 * @static
73 * @return string The source of the default placeholder image used by Elementor.
74 */
75 public static function get_placeholder_image_src() {
76 $placeholder_image = ELEMENTOR_ASSETS_URL . 'images/placeholder.png';
77
78 return $placeholder_image;
79 }
80
81 /**
82 * For get wp environment for element pack
83 * @return [type] [description]
84 */
85 public static function get_environment_info(){
86
87 // Figure out cURL version, if installed.
88 $curl_version = '';
89 if ( function_exists( 'curl_version' ) ) {
90 $curl_version = curl_version();
91 $curl_version = $curl_version['version'] . ', ' . $curl_version['ssl_version'];
92 }
93
94
95 // WP memory limit.
96 $wp_memory_limit = self::readable_num(WP_MEMORY_LIMIT);
97 if ( function_exists( 'memory_get_usage' ) ) {
98 $wp_memory_limit = max( $wp_memory_limit, self::readable_num( @ini_get( 'memory_limit' ) ) );
99 }
100
101
102 return array(
103 'home_url' => get_option( 'home' ),
104 'site_url' => get_option( 'siteurl' ),
105 'version' => BDTUPK_VER,
106 'wp_version' => get_bloginfo( 'version' ),
107 'wp_multisite' => is_multisite(),
108 'wp_memory_limit' => $wp_memory_limit,
109 'wp_debug_mode' => ( defined( 'WP_DEBUG' ) && WP_DEBUG ),
110 'wp_cron' => ! ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ),
111 'language' => get_locale(),
112 'external_object_cache' => wp_using_ext_object_cache(),
113 'php_version' => phpversion(),
114 'php_post_max_size' => self::readable_num( ini_get( 'post_max_size' ) ),
115 'php_max_execution_time' => ini_get( 'max_execution_time' ),
116 'php_max_input_vars' => ini_get( 'max_input_vars' ),
117 'curl_version' => $curl_version,
118 'suhosin_installed' => extension_loaded( 'suhosin' ),
119 'max_upload_size' => wp_max_upload_size(),
120 'default_timezone' => date_default_timezone_get(),
121 'fsockopen_or_curl_enabled' => ( function_exists( 'fsockopen' ) || function_exists( 'curl_init' ) ),
122 'soapclient_enabled' => class_exists( 'SoapClient' ),
123 'domdocument_enabled' => class_exists( 'DOMDocument' ),
124 'gzip_enabled' => is_callable( 'gzopen' ),
125 'mbstring_enabled' => extension_loaded( 'mbstring' ),
126 );
127
128 }
129
130 /**
131 * Get timezone string.
132 *
133 * Retrieve timezone string from the WordPress database.
134 *
135 * @since 1.0.0
136 * @access public
137 * @static
138 *
139 * @return string Timezone string.
140 */
141 public static function get_timezone_string() {
142 $current_offset = (float) get_option( 'gmt_offset' );
143 $timezone_string = get_option( 'timezone_string' );
144
145 // Create a UTC+- zone if no timezone string exists.
146 if ( empty( $timezone_string ) ) {
147 if ( $current_offset < 0 ) {
148 $timezone_string = 'UTC' . $current_offset;
149 } else {
150 $timezone_string = 'UTC+' . $current_offset;
151 }
152 }
153
154 return $timezone_string;
155 }
156
157 /**
158 * Build a localized comment count string for front-end display.
159 *
160 * Single translatable pattern so locales can reorder words (e.g. "Comments: %s").
161 * Always escape with esc_html() (or esc_attr() for attributes) when outputting.
162 *
163 * @param int $post_id Post ID. Use 0 for the current post in The Loop.
164 * @return string Unescaped translated string.
165 */
166 public static function get_formatted_comments_count( $post_id = 0 ) {
167 $comment_count = (int) get_comments_number( $post_id );
168
169 return sprintf(
170 /* translators: %s: number of comments */
171 _n( '%s comment', '%s comments', $comment_count, 'ultimate-post-kit' ),
172 number_format_i18n( $comment_count )
173 );
174 }
175
176 /**
177 * Localized numeric comment count only (no word label). For icon-only meta.
178 *
179 * @param int $post_id Post ID. Use 0 for the current post in The Loop.
180 * @return string
181 */
182 public static function get_localized_comment_count( $post_id = 0 ) {
183 return number_format_i18n( (int) get_comments_number( $post_id ) );
184 }
185
186 }
187