WP_CLI
1 year ago
abstracts
1 year ago
actions
1 year ago
data-stores
1 year ago
migration
1 year ago
schedules
1 year ago
schema
1 year ago
ActionScheduler_ActionClaim.php
1 year ago
ActionScheduler_ActionFactory.php
1 year ago
ActionScheduler_AdminView.php
1 year ago
ActionScheduler_AsyncRequest_QueueRunner.php
1 year ago
ActionScheduler_Compatibility.php
1 year ago
ActionScheduler_DataController.php
1 year ago
ActionScheduler_DateTime.php
1 year ago
ActionScheduler_Exception.php
4 years ago
ActionScheduler_FatalErrorMonitor.php
1 year ago
ActionScheduler_InvalidActionException.php
1 year ago
ActionScheduler_ListTable.php
1 year ago
ActionScheduler_LogEntry.php
1 year ago
ActionScheduler_NullLogEntry.php
1 year ago
ActionScheduler_OptionLock.php
2 years ago
ActionScheduler_QueueCleaner.php
1 year ago
ActionScheduler_QueueRunner.php
1 year ago
ActionScheduler_SystemInformation.php
1 year ago
ActionScheduler_Versions.php
1 year ago
ActionScheduler_WPCommentCleaner.php
1 year ago
ActionScheduler_wcSystemStatus.php
4 years ago
index.php
3 years ago
ActionScheduler_Compatibility.php
67 lines
| 1 | <?php |
| 2 | if (!defined('ABSPATH')) exit; |
| 3 | class ActionScheduler_Compatibility { |
| 4 | public static function convert_hr_to_bytes( $value ) { |
| 5 | if ( function_exists( 'wp_convert_hr_to_bytes' ) ) { |
| 6 | return wp_convert_hr_to_bytes( $value ); |
| 7 | } |
| 8 | $value = strtolower( trim( $value ) ); |
| 9 | $bytes = (int) $value; |
| 10 | if ( false !== strpos( $value, 'g' ) ) { |
| 11 | $bytes *= GB_IN_BYTES; |
| 12 | } elseif ( false !== strpos( $value, 'm' ) ) { |
| 13 | $bytes *= MB_IN_BYTES; |
| 14 | } elseif ( false !== strpos( $value, 'k' ) ) { |
| 15 | $bytes *= KB_IN_BYTES; |
| 16 | } |
| 17 | // Deal with large (float) values which run into the maximum integer size. |
| 18 | return min( $bytes, PHP_INT_MAX ); |
| 19 | } |
| 20 | public static function raise_memory_limit() { |
| 21 | if ( function_exists( 'wp_raise_memory_limit' ) ) { |
| 22 | return wp_raise_memory_limit( 'admin' ); |
| 23 | } |
| 24 | $current_limit = @ini_get( 'memory_limit' ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
| 25 | $current_limit_int = self::convert_hr_to_bytes( $current_limit ); |
| 26 | if ( -1 === $current_limit_int ) { |
| 27 | return false; |
| 28 | } |
| 29 | $wp_max_limit = WP_MAX_MEMORY_LIMIT; |
| 30 | $wp_max_limit_int = self::convert_hr_to_bytes( $wp_max_limit ); |
| 31 | $filtered_limit = apply_filters( 'admin_memory_limit', $wp_max_limit ); |
| 32 | $filtered_limit_int = self::convert_hr_to_bytes( $filtered_limit ); |
| 33 | // phpcs:disable WordPress.PHP.IniSet.memory_limit_Blacklisted |
| 34 | // phpcs:disable WordPress.PHP.NoSilencedErrors.Discouraged |
| 35 | if ( -1 === $filtered_limit_int || ( $filtered_limit_int > $wp_max_limit_int && $filtered_limit_int > $current_limit_int ) ) { |
| 36 | if ( false !== @ini_set( 'memory_limit', $filtered_limit ) ) { |
| 37 | return $filtered_limit; |
| 38 | } else { |
| 39 | return false; |
| 40 | } |
| 41 | } elseif ( -1 === $wp_max_limit_int || $wp_max_limit_int > $current_limit_int ) { |
| 42 | if ( false !== @ini_set( 'memory_limit', $wp_max_limit ) ) { |
| 43 | return $wp_max_limit; |
| 44 | } else { |
| 45 | return false; |
| 46 | } |
| 47 | } |
| 48 | // phpcs:enable |
| 49 | return false; |
| 50 | } |
| 51 | public static function raise_time_limit( $limit = 0 ) { |
| 52 | $limit = (int) $limit; |
| 53 | $max_execution_time = (int) ini_get( 'max_execution_time' ); |
| 54 | // If the max execution time is already set to zero (unlimited), there is no reason to make a further change. |
| 55 | if ( 0 === $max_execution_time ) { |
| 56 | return; |
| 57 | } |
| 58 | // Whichever of $max_execution_time or $limit is higher is the amount by which we raise the time limit. |
| 59 | $raise_by = 0 === $limit || $limit > $max_execution_time ? $limit : $max_execution_time; |
| 60 | if ( function_exists( 'wc_set_time_limit' ) ) { |
| 61 | wc_set_time_limit( $raise_by ); |
| 62 | } 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 |
| 63 | @set_time_limit( $raise_by ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 |