@@ -33,8 +33,8 @@ discard block |
||
| 33 | 33 | * @param Worker $worker |
| 34 | 34 | * @param int $interval |
| 35 | 35 | */ |
| 36 | - public function __construct( $id, $worker, $interval ) { |
|
| 37 | - $this->id = strtolower( str_replace( '\\', '_', $id ) ); |
|
| 36 | + public function __construct($id, $worker, $interval) { |
|
| 37 | + $this->id = strtolower(str_replace('\\', '_', $id)); |
|
| 38 | 38 | $this->worker = $worker; |
| 39 | 39 | $this->interval = $interval; |
| 40 | 40 | } |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | * @return bool |
| 46 | 46 | */ |
| 47 | 47 | protected function is_enabled() { |
| 48 | - if ( defined( 'DISABLE_WP_QUEUE_CRON' ) && DISABLE_WP_QUEUE_CRON ) { |
|
| 48 | + if (defined('DISABLE_WP_QUEUE_CRON') && DISABLE_WP_QUEUE_CRON) { |
|
| 49 | 49 | return false; |
| 50 | 50 | } |
| 51 | 51 | |
@@ -58,16 +58,16 @@ discard block |
||
| 58 | 58 | * @return bool |
| 59 | 59 | */ |
| 60 | 60 | public function init() { |
| 61 | - if ( ! $this->is_enabled() ) { |
|
| 61 | + if ( ! $this->is_enabled()) { |
|
| 62 | 62 | return false; |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - add_filter( 'cron_schedules', array( $this, 'schedule_cron' ) ); |
|
| 66 | - add_action( $this->id, array( $this, 'cron_worker' ) ); |
|
| 65 | + add_filter('cron_schedules', array($this, 'schedule_cron')); |
|
| 66 | + add_action($this->id, array($this, 'cron_worker')); |
|
| 67 | 67 | |
| 68 | - if ( ! wp_next_scheduled( $this->id ) ) { |
|
| 68 | + if ( ! wp_next_scheduled($this->id)) { |
|
| 69 | 69 | // Schedule health check |
| 70 | - wp_schedule_event( time(), $this->id, $this->id ); |
|
| 70 | + wp_schedule_event(time(), $this->id, $this->id); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | return true; |
@@ -80,10 +80,10 @@ discard block |
||
| 80 | 80 | * |
| 81 | 81 | * @return array |
| 82 | 82 | */ |
| 83 | - public function schedule_cron( $schedules ) { |
|
| 84 | - $schedules[ $this->id ] = array( |
|
| 83 | + public function schedule_cron($schedules) { |
|
| 84 | + $schedules[$this->id] = array( |
|
| 85 | 85 | 'interval' => MINUTE_IN_SECONDS * $this->interval, |
| 86 | - 'display' => sprintf( __( 'Every %d Minutes' ), $this->interval ), |
|
| 86 | + 'display' => sprintf(__('Every %d Minutes'), $this->interval), |
|
| 87 | 87 | ); |
| 88 | 88 | |
| 89 | 89 | return $schedules; |
@@ -95,8 +95,8 @@ discard block |
||
| 95 | 95 | public function cron_worker() { |
| 96 | 96 | $this->start_time = time(); |
| 97 | 97 | |
| 98 | - while ( ! $this->time_exceeded() && ! $this->memory_exceeded() ) { |
|
| 99 | - if ( ! $this->worker->process() ) { |
|
| 98 | + while ( ! $this->time_exceeded() && ! $this->memory_exceeded()) { |
|
| 99 | + if ( ! $this->worker->process()) { |
|
| 100 | 100 | break; |
| 101 | 101 | } |
| 102 | 102 | } |
@@ -112,14 +112,14 @@ discard block |
||
| 112 | 112 | */ |
| 113 | 113 | protected function memory_exceeded() { |
| 114 | 114 | $memory_limit = $this->get_memory_limit() * 0.8; // 80% of max memory |
| 115 | - $current_memory = memory_get_usage( true ); |
|
| 115 | + $current_memory = memory_get_usage(true); |
|
| 116 | 116 | $return = false; |
| 117 | 117 | |
| 118 | - if ( $current_memory >= $memory_limit ) { |
|
| 118 | + if ($current_memory >= $memory_limit) { |
|
| 119 | 119 | $return = true; |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | - return apply_filters( 'wp_queue_cron_memory_exceeded', $return ); |
|
| 122 | + return apply_filters('wp_queue_cron_memory_exceeded', $return); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | /** |
@@ -128,18 +128,18 @@ discard block |
||
| 128 | 128 | * @return int |
| 129 | 129 | */ |
| 130 | 130 | protected function get_memory_limit() { |
| 131 | - if ( function_exists( 'ini_get' ) ) { |
|
| 132 | - $memory_limit = ini_get( 'memory_limit' ); |
|
| 131 | + if (function_exists('ini_get')) { |
|
| 132 | + $memory_limit = ini_get('memory_limit'); |
|
| 133 | 133 | } else { |
| 134 | 134 | $memory_limit = '256M'; |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - if ( ! $memory_limit || - 1 == $memory_limit ) { |
|
| 137 | + if ( ! $memory_limit || - 1 == $memory_limit) { |
|
| 138 | 138 | // Unlimited, set to 1GB |
| 139 | 139 | $memory_limit = '1000M'; |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | - return intval( $memory_limit ) * 1024 * 1024; |
|
| 142 | + return intval($memory_limit) * 1024 * 1024; |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | /** |
@@ -151,13 +151,13 @@ discard block |
||
| 151 | 151 | * @return bool |
| 152 | 152 | */ |
| 153 | 153 | protected function time_exceeded() { |
| 154 | - $finish = $this->start_time + apply_filters( 'wp_queue_cron_time_limit', 20 ); // 20 seconds |
|
| 154 | + $finish = $this->start_time + apply_filters('wp_queue_cron_time_limit', 20); // 20 seconds |
|
| 155 | 155 | $return = false; |
| 156 | 156 | |
| 157 | - if ( time() >= $finish ) { |
|
| 157 | + if (time() >= $finish) { |
|
| 158 | 158 | $return = true; |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | - return apply_filters( 'wp_queue_cron_time_exceeded', $return ); |
|
| 161 | + return apply_filters('wp_queue_cron_time_exceeded', $return); |
|
| 162 | 162 | } |
| 163 | 163 | } |
| 164 | 164 | \ No newline at end of file |