PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.2.7
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.2.7
3.7.5 3.7.4 3.7.3 3.7.2 1-final 3.7.1 3.7.0 3.6.8 3.6.7 3.6.6 3.6.5 3.6.4 3.6.3 3.6.2 3.6.1 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.10 All 111 releases
← All changes | includes/Utils/Helper.php +105 -36 3.1.13.2.7 View file →
@@ -1,7 +1,8 @@
1 1 <?php
2 2 namespace Templately\Utils;
3 3
4 +use Elementor\Plugin;
4 5 use WP_Error;
5 6 use WP_REST_Response;
6 7 use function get_plugins;
7 8 use function is_plugin_active;
@@ -12,31 +13,36 @@
12 13 *
13 14 * @since 1.0.0
14 15 */
15 16 class Helper extends Base {
16 - /**
17 - * Get installed WordPress Plugin List
18 - * @return array
19 - */
20 - public static function get_plugins(){
21 - if( ! function_exists( 'get_plugins' ) ) {
22 - require_once ABSPATH . 'wp-admin/includes/plugin.php';
23 - }
24 - return get_plugins();
25 - }
17 + /**
18 + * Get installed WordPress Plugin List
19 + * @return array
20 + */
21 + public static function get_plugins(){
22 + if( ! function_exists( 'get_plugins' ) ) {
23 + require_once ABSPATH . 'wp-admin/includes/plugin.php';
24 + }
25 + return get_plugins();
26 + }
27 + public static function is_plugins_installed($plugin_file){
28 + $_plugins = self::get_plugins();
29 + $is_installed = isset( $_plugins[ $plugin_file ] );
30 + return $is_installed;
31 + }
26 32
27 - /**
28 - * Get installed WordPress Plugin List
29 - * @return boolean
30 - */
31 - public static function is_plugin_active( $plugin ){
32 - if( ! function_exists( 'is_plugin_active' ) ) {
33 - require_once ABSPATH . 'wp-admin/includes/plugin.php';
34 - }
35 - return is_plugin_active( $plugin );
36 - }
33 + /**
34 + * Get installed WordPress Plugin List
35 + * @return boolean
36 + */
37 + public static function is_plugin_active( $plugin ){
38 + if( ! function_exists( 'is_plugin_active' ) ) {
39 + require_once ABSPATH . 'wp-admin/includes/plugin.php';
40 + }
41 + return is_plugin_active( $plugin );
42 + }
37 43
38 - /**
44 + /**
39 45 * Collect IP from request.
40 46 *
41 47 * @return string
42 48 */
@@ -52,24 +58,24 @@
52 58
53 59 return sanitize_text_field( $ip );
54 60 }
55 61
56 - /**
57 - * Get views for front-end display
58 - *
59 - * @param string $name it will be file name only from the view's folder.
60 - * @param array $data
61 - * @return void
62 - */
63 - public static function views( $name, $data = [] ){
62 + /**
63 + * Get views for front-end display
64 + *
65 + * @param string $name it will be file name only from the view's folder.
66 + * @param array $data
67 + * @return void
68 + */
69 + public static function views( $name, $data = [] ){
64 70 extract( $data );
65 - $helper = self::class;
66 - $file = TEMPLATELY_PATH . 'views/' . $name . '.php';
71 + $helper = self::class;
72 + $file = TEMPLATELY_PATH . 'views/' . $name . '.php';
67 73
68 - if( is_readable( $file ) ) {
69 - include_once $file;
70 - }
71 - }
74 + if( is_readable( $file ) ) {
75 + include_once $file;
76 + }
77 + }
72 78
73 79 /**
74 80 * Sanitize Helper
75 81 *
@@ -187,9 +193,9 @@
187 193 * @param mixed $log
188 194 * @return void
189 195 */
190 196 public static function log( $log ){
191 - if ( defined('WP_DEBUG_LOG') && WP_DEBUG_LOG === true ) {
197 + if ( defined('WP_DEBUG_LOG') && WP_DEBUG_LOG ) {
192 198 if ( is_array( $log ) || is_object( $log ) ) {
193 199 error_log( print_r( $log, true ) );
194 200 } else {
195 201 error_log( $log ?: '' );
@@ -197,8 +203,11 @@
197 203 }
198 204 }
199 205
200 206 public static function should_flush(){
207 + if(isset($_GET['is_lightspeed']) && $_GET['is_lightspeed'] === 'true'){
208 + return false;
209 + }
201 210 return (!defined('TEMPLATELY_IGNORE_FLUSH_ALL') || !TEMPLATELY_IGNORE_FLUSH_ALL) && strpos($_SERVER['SERVER_SOFTWARE'], 'LiteSpeed') === false;
202 211 }
203 212
204 213 public static function get_block_by_name($blocks, $search) {
@@ -277,7 +286,67 @@
277 286 }
278 287 }
279 288
280 289 return true;
290 + }
291 +
292 + /**
293 + * Calculates the elapsed time and checks if it is close to the maximum execution time.
294 + * Returns true if the script should exit to avoid exceeding the limit.
295 + *
296 + * @return bool True if the script should exit, false otherwise.
297 + */
298 + public static function fsi_should_exit() {
299 + if (defined('TEMPLATELY_START_TIME') && ini_get('max_execution_time')) {
300 + $max_time = ini_get('max_execution_time');
301 + $elapsed = microtime(true) - TEMPLATELY_START_TIME;
302 + $delay = max(5, $max_time * 20 / 100);
303 +
304 + // Check if elapsed time is close to max execution time
305 + if ($max_time - $elapsed <= $delay) {
306 + return ['max_time' => $max_time, 'elapsed' => $elapsed, 'delay' => $delay];
307 + }
308 + }
309 + return false;
310 + }
311 +
312 + /**
313 + * Enable Elementor Container
314 + * This function will enable the Elementor Container feature.
315 + * Without this feature, some of the templates may not work properly.
316 + *
317 + * @return boolean
318 + */
319 + public static function enable_elementor_container(){
320 + if(class_exists('Elementor\Plugin')) {
321 + $control_name = Plugin::instance()->experiments->get_feature_option_key( 'container' );
322 + if(get_option( $control_name ) === 'inactive') {
323 + update_option( $control_name, 'active' );
324 + return true;
325 + }
326 + }
327 + return false;
328 + }
329 +
330 + /**
331 + * Undocumented function
332 + *
333 + * @param [type] $args
334 + * @param [type] $defaults
335 + * @return array
336 + */
337 + public static function recursive_wp_parse_args( $args, $defaults ) {
338 + $args = (array) $args;
339 + $defaults = (array) $defaults;
340 + $r = $defaults;
341 + foreach ( $args as $key => $value ) {
342 + if ( is_array( $value ) && isset( $r[ $key ] ) ) {
343 + $r[ $key ] = self::recursive_wp_parse_args( $value, $r[ $key ] );
344 + }
345 + else {
346 + $r[$key] = $value;
347 + }
348 + }
349 + return $r;
281 350 }
282 351
283 352 }