PluginProbe
WANotifier for Forms and Actions / 1.0.3
WANotifier for Forms and Actions v1.0.3
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 1.0.3, at libraries/action-scheduler/classes/ActionScheduler_Compatibility.php

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