PluginProbe
WANotifier for Forms and Actions / 2.7.5
WANotifier for Forms and Actions v2.7.5
3.1.1 3.1.0 3.0.4 2.7.10 2.7.11 2.7.12 2.7.13 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 3.0.0 3.0.1 3.0.2 3.0.3 trunk 0.1.0 0.1.1 1.0.0 1.0.1 1.0.2 All 67 releases
notifier / libraries / action-scheduler / classes / ActionScheduler_Compatibility.php

ActionScheduler_Compatibility.php in WANotifier for Forms and Actions 2.7.5, at libraries/action-scheduler/classes/ActionScheduler_Compatibility.php

106 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Class ActionScheduler_Compatibility
5 */
6 class ActionScheduler_Compatibility {
7 /**
8 * Converts a shorthand byte value to an integer byte value.
9 *
10 * Wrapper for wp_convert_hr_to_bytes(), moved to load.php in WordPress 4.6 from media.php
11 *
12 * @link https://secure.php.net/manual/en/function.ini-get.php
13 * @link https://secure.php.net/manual/en/faq.using.php#faq.using.shorthandbytes
14 *
15 * @param string $value A (PHP ini) byte value, either shorthand or ordinary.
16 * @return int An integer byte value.
17 */
18 public static function convert_hr_to_bytes( $value ) {
19 if ( function_exists( 'wp_convert_hr_to_bytes' ) ) {
20 return wp_convert_hr_to_bytes( $value );
21 }
22
23 $value = strtolower( trim( $value ) );
24 $bytes = (int) $value;
25
26 if ( false !== strpos( $value, 'g' ) ) {
27 $bytes *= GB_IN_BYTES;
28 } elseif ( false !== strpos( $value, 'm' ) ) {
29 $bytes *= MB_IN_BYTES;
30 } elseif ( false !== strpos( $value, 'k' ) ) {
31 $bytes *= KB_IN_BYTES;
32 }
33
34 // Deal with large (float) values which run into the maximum integer size.
35 return min( $bytes, PHP_INT_MAX );
36 }
37
38 /**
39 * Attempts to raise the PHP memory limit for memory intensive processes.
40 *
41 * Only allows raising the existing limit and prevents lowering it.
42 *
43 * Wrapper for wp_raise_memory_limit(), added in WordPress v4.6.0
44 *
45 * @return bool|int|string The limit that was set or false on failure.
46 */
47 public static function raise_memory_limit() {
48 if ( function_exists( 'wp_raise_memory_limit' ) ) {
49 return wp_raise_memory_limit( 'admin' );
50 }
51
52 $current_limit = @ini_get( 'memory_limit' );
53 $current_limit_int = self::convert_hr_to_bytes( $current_limit );
54
55 if ( -1 === $current_limit_int ) {
56 return false;
57 }
58
59 $wp_max_limit = WP_MAX_MEMORY_LIMIT;
60 $wp_max_limit_int = self::convert_hr_to_bytes( $wp_max_limit );
61 $filtered_limit = apply_filters( 'admin_memory_limit', $wp_max_limit );
62 $filtered_limit_int = self::convert_hr_to_bytes( $filtered_limit );
63
64 if ( -1 === $filtered_limit_int || ( $filtered_limit_int > $wp_max_limit_int && $filtered_limit_int > $current_limit_int ) ) {
65 if ( false !== @ini_set( 'memory_limit', $filtered_limit ) ) {
66 return $filtered_limit;
67 } else {
68 return false;
69 }
70 } elseif ( -1 === $wp_max_limit_int || $wp_max_limit_int > $current_limit_int ) {
71 if ( false !== @ini_set( 'memory_limit', $wp_max_limit ) ) {
72 return $wp_max_limit;
73 } else {
74 return false;
75 }
76 }
77 return false;
78 }
79
80 /**
81 * Attempts to raise the PHP timeout for time intensive processes.
82 *
83 * Only allows raising the existing limit and prevents lowering it. Wrapper for wc_set_time_limit(), when available.
84 *
85 * @param int $limit The time limit in seconds.
86 */
87 public static function raise_time_limit( $limit = 0 ) {
88 $limit = (int) $limit;
89 $max_execution_time = (int) ini_get( 'max_execution_time' );
90
91 // If the max execution time is already set to zero (unlimited), there is no reason to make a further change.
92 if ( 0 === $max_execution_time ) {
93 return;
94 }
95
96 // Whichever of $max_execution_time or $limit is higher is the amount by which we raise the time limit.
97 $raise_by = 0 === $limit || $limit > $max_execution_time ? $limit : $max_execution_time;
98
99 if ( function_exists( 'wc_set_time_limit' ) ) {
100 wc_set_time_limit( $raise_by );
101 } elseif ( function_exists( 'set_time_limit' ) && false === strpos( ini_get( 'disable_functions' ), 'set_time_limit' ) && ! ini_get( 'safe_mode' ) ) { // phpcs:ignore PHPCompatibility.IniDirectives.RemovedIniDirectives.safe_modeDeprecatedRemoved
102 @set_time_limit( $raise_by ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
103 }
104 }
105 }
106