Completed
Push — feature/code-quality ( 458ff8...d5dbe9 )
by Juliette
03:37
created
class-debug-bar-cron.php 1 patch
Spacing   +99 added lines, -99 removed lines patch added patch discarded remove patch
@@ -10,16 +10,16 @@  discard block
 block discarded – undo
10 10
  */
11 11
 
12 12
 // Avoid direct calls to this file.
13
-if ( ! function_exists( 'add_action' ) ) {
14
-	header( 'Status: 403 Forbidden' );
15
-	header( 'HTTP/1.1 403 Forbidden' );
13
+if ( ! function_exists('add_action')) {
14
+	header('Status: 403 Forbidden');
15
+	header('HTTP/1.1 403 Forbidden');
16 16
 	exit();
17 17
 }
18 18
 
19 19
 /**
20 20
  * The class in this file extends the functionality provided by the parent plugin "Debug Bar".
21 21
  */
22
-if ( ! class_exists( 'ZT_Debug_Bar_Cron' ) && class_exists( 'Debug_Bar_Panel' ) ) {
22
+if ( ! class_exists('ZT_Debug_Bar_Cron') && class_exists('Debug_Bar_Panel')) {
23 23
 
24 24
 	/**
25 25
 	 * Add a new Debug Bar Panel.
@@ -72,10 +72,10 @@  discard block
 block discarded – undo
72 72
 		 * @return void
73 73
 		 */
74 74
 		public function init() {
75
-			load_plugin_textdomain( 'zt-debug-bar-cron', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
76
-			$this->title( __( 'Cron', 'zt-debug-bar-cron' ) );
77
-			add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts_styles' ) );
78
-			add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts_styles' ) );
75
+			load_plugin_textdomain('zt-debug-bar-cron', false, dirname(plugin_basename(__FILE__)).'/languages/');
76
+			$this->title(__('Cron', 'zt-debug-bar-cron'));
77
+			add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts_styles'));
78
+			add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts_styles'));
79 79
 		}
80 80
 
81 81
 
@@ -85,12 +85,12 @@  discard block
 block discarded – undo
85 85
 		 * @return void
86 86
 		 */
87 87
 		public function enqueue_scripts_styles() {
88
-			$suffix = ( ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min' );
88
+			$suffix = ((defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '' : '.min');
89 89
 
90 90
 			wp_enqueue_style(
91 91
 				self::DBCRON_NAME,
92
-				plugins_url( 'css/' . self::DBCRON_NAME . $suffix . '.css', __FILE__ ),
93
-				array( 'debug-bar' ),
92
+				plugins_url('css/'.self::DBCRON_NAME.$suffix.'.css', __FILE__),
93
+				array('debug-bar'),
94 94
 				self::DBCRON_STYLES_VERSION
95 95
 			);
96 96
 		}
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 		 * @return void
103 103
 		 */
104 104
 		public function prerender() {
105
-			$this->set_visible( true );
105
+			$this->set_visible(true);
106 106
 		}
107 107
 
108 108
 
@@ -114,53 +114,53 @@  discard block
 block discarded – undo
114 114
 		public function render() {
115 115
 			$this->get_crons();
116 116
 
117
-			$this->_doing_cron = get_transient( 'doing_cron' ) ? __( 'Yes', 'zt-debug-bar-cron' ) : __( 'No', 'zt-debug-bar-cron' );
117
+			$this->_doing_cron = get_transient('doing_cron') ? __('Yes', 'zt-debug-bar-cron') : __('No', 'zt-debug-bar-cron');
118 118
 
119 119
 			// Get the time of the next event.
120
-			$cron_times          = ( is_array( $this->_crons ) ? array_keys( $this->_crons ) : array() );
120
+			$cron_times          = (is_array($this->_crons) ? array_keys($this->_crons) : array());
121 121
 			$unix_time_next_cron = $cron_times[0];
122
-			$time_next_cron      = date( 'Y-m-d H:i:s', $unix_time_next_cron );
122
+			$time_next_cron      = date('Y-m-d H:i:s', $unix_time_next_cron);
123 123
 
124
-			$human_time_next_cron = human_time_diff( $unix_time_next_cron );
124
+			$human_time_next_cron = human_time_diff($unix_time_next_cron);
125 125
 
126 126
 			// Add a class if past current time and doing cron is not running.
127
-			$times_class = ( time() > $unix_time_next_cron && 'No' === $this->_doing_cron ) ? ' past' : '';
127
+			$times_class = (time() > $unix_time_next_cron && 'No' === $this->_doing_cron) ? ' past' : '';
128 128
 
129 129
 			echo '
130 130
 			<div class="debug-bar-cron">
131
-				<h2><span>', esc_html__( 'Total Events', 'zt-debug-bar-cron' ), ':</span>', intval( $this->_total_crons ), '</h2>
132
-				<h2><span>', esc_html__( 'Doing Cron', 'zt-debug-bar-cron' ), ':</span>', esc_html( $this->_doing_cron ), '</h2>
133
-				<h2 class="times', esc_attr( $times_class ), '"><span>', esc_html__( 'Next Event', 'zt-debug-bar-cron' ), ':</span>
134
-					', esc_html( $time_next_cron ), '<br />
135
-					', intval( $unix_time_next_cron ), '<br />
136
-					', esc_html( $this->display_past_time( $human_time_next_cron, $unix_time_next_cron ) ), '
131
+				<h2><span>', esc_html__('Total Events', 'zt-debug-bar-cron'), ':</span>', intval($this->_total_crons), '</h2>
132
+				<h2><span>', esc_html__('Doing Cron', 'zt-debug-bar-cron'), ':</span>', esc_html($this->_doing_cron), '</h2>
133
+				<h2 class="times', esc_attr($times_class), '"><span>', esc_html__('Next Event', 'zt-debug-bar-cron'), ':</span>
134
+					', esc_html($time_next_cron), '<br />
135
+					', intval($unix_time_next_cron), '<br />
136
+					', esc_html($this->display_past_time($human_time_next_cron, $unix_time_next_cron)), '
137 137
 				</h2>
138
-				<h2><span>', esc_html__( 'Current Time', 'zt-debug-bar-cron' ), ':</span>', esc_html( date( 'H:i:s' ) ), '</h2>
138
+				<h2><span>', esc_html__('Current Time', 'zt-debug-bar-cron'), ':</span>', esc_html(date('H:i:s')), '</h2>
139 139
 
140 140
 				<div class="clear"></div>
141 141
 
142
-				<h3>', esc_html__( 'Custom Events', 'zt-debug-bar-cron' ), '</h3>';
142
+				<h3>', esc_html__('Custom Events', 'zt-debug-bar-cron'), '</h3>';
143 143
 
144
-			if ( ! is_null( $this->_user_crons ) ) {
145
-				$this->display_events( $this->_user_crons );
144
+			if ( ! is_null($this->_user_crons)) {
145
+				$this->display_events($this->_user_crons);
146 146
 			} else {
147 147
 				echo '
148
-				<p>', esc_html__( 'No Custom Events scheduled.', 'zt-debug-bar-cron' ), '</p>';
148
+				<p>', esc_html__('No Custom Events scheduled.', 'zt-debug-bar-cron'), '</p>';
149 149
 			}
150 150
 
151 151
 			echo '
152
-				<h3>', esc_html__( 'Schedules', 'zt-debug-bar-cron' ), '</h3>';
152
+				<h3>', esc_html__('Schedules', 'zt-debug-bar-cron'), '</h3>';
153 153
 
154 154
 			$this->display_schedules();
155 155
 
156 156
 			echo '
157
-				<h3>', esc_html__( 'Core Events', 'zt-debug-bar-cron' ), '</h3>';
157
+				<h3>', esc_html__('Core Events', 'zt-debug-bar-cron'), '</h3>';
158 158
 
159
-			if ( ! is_null( $this->_core_crons ) ) {
160
-				$this->display_events( $this->_core_crons );
159
+			if ( ! is_null($this->_core_crons)) {
160
+				$this->display_events($this->_core_crons);
161 161
 			} else {
162 162
 				echo '
163
-				<p>', esc_html__( 'No Core Events scheduled.', 'zt-debug-bar-cron' ), '</p>';
163
+				<p>', esc_html__('No Core Events scheduled.', 'zt-debug-bar-cron'), '</p>';
164 164
 			}
165 165
 
166 166
 			echo '
@@ -177,11 +177,11 @@  discard block
 block discarded – undo
177 177
 		 * @return array Array of crons.
178 178
 		 */
179 179
 		private function get_crons() {
180
-			if ( ! is_null( $this->_crons ) ) {
180
+			if ( ! is_null($this->_crons)) {
181 181
 				return $this->_crons;
182 182
 			}
183 183
 
184
-			if ( ! $crons = _get_cron_array() ) {
184
+			if ( ! $crons = _get_cron_array()) {
185 185
 				return $this->_crons;
186 186
 			}
187 187
 
@@ -191,28 +191,28 @@  discard block
 block discarded – undo
191 191
 			// @internal To find all, search WP trunk for `wp_schedule_(single_)?event`.
192 192
 			$core_cron_hooks = array(
193 193
 				'do_pings',
194
-				'importer_scheduled_cleanup',     // WP 3.1+.
194
+				'importer_scheduled_cleanup', // WP 3.1+.
195 195
 				'publish_future_post',
196
-				'update_network_counts',          // WP 3.1+.
197
-				'upgrader_scheduled_cleanup',     // WP 3.3+.
198
-				'wp_maybe_auto_update',           // WP 3.7+.
196
+				'update_network_counts', // WP 3.1+.
197
+				'upgrader_scheduled_cleanup', // WP 3.3+.
198
+				'wp_maybe_auto_update', // WP 3.7+.
199 199
 				'wp_scheduled_auto_draft_delete', // WP 3.4+.
200
-				'wp_scheduled_delete',            // WP 2.9+.
201
-				'wp_split_shared_term_batch',     // WP 4.3+.
200
+				'wp_scheduled_delete', // WP 2.9+.
201
+				'wp_split_shared_term_batch', // WP 4.3+.
202 202
 				'wp_update_plugins',
203 203
 				'wp_update_themes',
204 204
 				'wp_version_check',
205 205
 			);
206 206
 
207 207
 			// Sort and count crons.
208
-			foreach ( $this->_crons as $time => $time_cron_array ) {
209
-				foreach ( $time_cron_array as $hook => $data ) {
208
+			foreach ($this->_crons as $time => $time_cron_array) {
209
+				foreach ($time_cron_array as $hook => $data) {
210 210
 					$this->_total_crons++;
211 211
 
212
-					if ( in_array( $hook, $core_cron_hooks, true ) ) {
213
-						$this->_core_crons[ $time ][ $hook ] = $data;
212
+					if (in_array($hook, $core_cron_hooks, true)) {
213
+						$this->_core_crons[$time][$hook] = $data;
214 214
 					} else {
215
-						$this->_user_crons[ $time ][ $hook ] = $data;
215
+						$this->_user_crons[$time][$hook] = $data;
216 216
 					}
217 217
 				}
218 218
 			}
@@ -228,77 +228,77 @@  discard block
 block discarded – undo
228 228
 		 *
229 229
 		 * @return void|string Void on failure; table display of events on success.
230 230
 		 */
231
-		private function display_events( $events ) {
232
-			if ( is_null( $events ) || empty( $events ) ) {
231
+		private function display_events($events) {
232
+			if (is_null($events) || empty($events)) {
233 233
 				return;
234 234
 			}
235 235
 
236 236
 			echo '
237 237
 				<table class="zt-debug-bar-cron-event-table">
238 238
 					<thead><tr>
239
-						<th class="col1">', esc_html__( 'Next Execution', 'zt-debug-bar-cron' ), '</th>
240
-						<th class="col2">', esc_html__( 'Hook', 'zt-debug-bar-cron' ), '</th>
241
-						<th class="col3">', esc_html__( 'Interval Hook', 'zt-debug-bar-cron' ), '</th>
242
-						<th class="col4">', esc_html__( 'Interval Value', 'zt-debug-bar-cron' ), '</th>
243
-						<th class="col5">', esc_html__( 'Args', 'zt-debug-bar-cron' ), '</th>
239
+						<th class="col1">', esc_html__('Next Execution', 'zt-debug-bar-cron'), '</th>
240
+						<th class="col2">', esc_html__('Hook', 'zt-debug-bar-cron'), '</th>
241
+						<th class="col3">', esc_html__('Interval Hook', 'zt-debug-bar-cron'), '</th>
242
+						<th class="col4">', esc_html__('Interval Value', 'zt-debug-bar-cron'), '</th>
243
+						<th class="col5">', esc_html__('Args', 'zt-debug-bar-cron'), '</th>
244 244
 					</tr></thead>
245 245
 					<tbody>';
246 246
 
247
-			foreach ( $events as $time => $time_cron_array ) {
248
-				foreach ( $time_cron_array as $hook => $data ) {
247
+			foreach ($events as $time => $time_cron_array) {
248
+				foreach ($time_cron_array as $hook => $data) {
249 249
 					echo '
250 250
 						<tr>
251 251
 							<td';
252 252
 
253 253
 					// Add a class if past current time.
254
-					if ( time() > $time && 'No' === $this->_doing_cron ) {
254
+					if (time() > $time && 'No' === $this->_doing_cron) {
255 255
 						echo ' class="past"';
256 256
 					}
257 257
 
258 258
 					echo '>
259
-								', esc_html( date( 'Y-m-d H:i:s', $time ) ), '<br />
260
-								', intval( $time ), '<br />
261
-								', esc_html( $this->display_past_time( human_time_diff( $time ), $time ) ), '
259
+								', esc_html(date('Y-m-d H:i:s', $time)), '<br />
260
+								', intval($time), '<br />
261
+								', esc_html($this->display_past_time(human_time_diff($time), $time)), '
262 262
 							</td>
263
-							<td>', esc_html( $hook ), '</td>';
263
+							<td>', esc_html($hook), '</td>';
264 264
 
265
-					foreach ( $data as $hash => $info ) {
265
+					foreach ($data as $hash => $info) {
266 266
 						// Report the schedule.
267 267
 						echo '
268 268
 							<td>';
269
-						if ( $info['schedule'] ) {
270
-							echo esc_html( $info['schedule'] );
269
+						if ($info['schedule']) {
270
+							echo esc_html($info['schedule']);
271 271
 						} else {
272
-							echo esc_html__( 'Single Event', 'zt-debug-bar-cron' );
272
+							echo esc_html__('Single Event', 'zt-debug-bar-cron');
273 273
 						}
274 274
 						echo '</td>';
275 275
 
276 276
 						// Report the interval.
277 277
 						echo '
278 278
 							<td>';
279
-						if ( isset( $info['interval'] ) ) {
279
+						if (isset($info['interval'])) {
280 280
 							/* TRANSLATORS: %s is number of seconds. */
281
-							printf( esc_html__( '%ss', 'zt-debug-bar-cron' ) . '<br />', intval( wp_strip_all_tags( $info['interval'] ) ) );
281
+							printf(esc_html__('%ss', 'zt-debug-bar-cron').'<br />', intval(wp_strip_all_tags($info['interval'])));
282 282
 							/* TRANSLATORS: %s is number of minutes. */
283
-							printf( esc_html__( '%sm', 'zt-debug-bar-cron' ) . '<br />', intval( wp_strip_all_tags( $info['interval'] ) / 60 ) );
283
+							printf(esc_html__('%sm', 'zt-debug-bar-cron').'<br />', intval(wp_strip_all_tags($info['interval']) / 60));
284 284
 							/* TRANSLATORS: %s is number of hours. */
285
-							printf( esc_html__( '%sh', 'zt-debug-bar-cron' ), intval( wp_strip_all_tags( $info['interval'] ) / ( 60 * 60 ) ) );
285
+							printf(esc_html__('%sh', 'zt-debug-bar-cron'), intval(wp_strip_all_tags($info['interval']) / (60 * 60)));
286 286
 						} else {
287
-							echo esc_html__( 'Single Event', 'zt-debug-bar-cron' );
287
+							echo esc_html__('Single Event', 'zt-debug-bar-cron');
288 288
 						}
289 289
 						echo '</td>';
290 290
 
291 291
 						// Report the args.
292 292
 						echo '
293 293
 							<td>';
294
-						if ( is_array( $info['args'] ) && ! empty( $info['args'] ) ) {
295
-							foreach ( $info['args'] as $key => $value ) {
296
-								$this->display_cron_arguments( $key, $value );
294
+						if (is_array($info['args']) && ! empty($info['args'])) {
295
+							foreach ($info['args'] as $key => $value) {
296
+								$this->display_cron_arguments($key, $value);
297 297
 							}
298
-						} else if ( is_string( $info['args'] ) && '' !== $info['args'] ) {
299
-							echo esc_html( $info['args'] );
298
+						} else if (is_string($info['args']) && '' !== $info['args']) {
299
+							echo esc_html($info['args']);
300 300
 						} else {
301
-							echo esc_html__( 'No Args', 'zt-debug-bar-cron' );
301
+							echo esc_html__('No Args', 'zt-debug-bar-cron');
302 302
 						}
303 303
 						echo '</td>';
304 304
 					}
@@ -323,19 +323,19 @@  discard block
 block discarded – undo
323 323
 		 *
324 324
 		 * @return void
325 325
 		 */
326
-		function display_cron_arguments( $key, $value, $depth = 0 ) {
327
-			if ( is_string( $value ) || is_int( $value ) ) {
328
-				echo str_repeat( '&nbsp;', ( $depth * 2 ) ) . wp_strip_all_tags( $key ) . ' => ' . esc_html( $value ) . '<br />';
329
-			} else if ( is_array( $value ) ) {
330
-				if ( count( $value ) > 0 ) {
331
-					echo str_repeat( '&nbsp;', ( $depth * 2 ) ) . wp_strip_all_tags( $key ) . ' => array(<br />';
326
+		function display_cron_arguments($key, $value, $depth = 0) {
327
+			if (is_string($value) || is_int($value)) {
328
+				echo str_repeat('&nbsp;', ($depth * 2)).wp_strip_all_tags($key).' => '.esc_html($value).'<br />';
329
+			} else if (is_array($value)) {
330
+				if (count($value) > 0) {
331
+					echo str_repeat('&nbsp;', ($depth * 2)).wp_strip_all_tags($key).' => array(<br />';
332 332
 					$depth++;
333
-					foreach ( $value as $k => $v ) {
334
-						$this->display_cron_arguments( $k, $v, $depth );
333
+					foreach ($value as $k => $v) {
334
+						$this->display_cron_arguments($k, $v, $depth);
335 335
 					}
336
-					echo str_repeat( '&nbsp;', ( ( $depth - 1 ) * 2 ) ) . ')';
336
+					echo str_repeat('&nbsp;', (($depth - 1) * 2)).')';
337 337
 				} else {
338
-					echo esc_html( 'Empty Array', 'zt-debug-bar-cron' );
338
+					echo esc_html('Empty Array', 'zt-debug-bar-cron');
339 339
 				}
340 340
 			}
341 341
 		}
@@ -350,24 +350,24 @@  discard block
 block discarded – undo
350 350
 			echo '
351 351
 				<table class="zt-debug-bar-cron-event-table">
352 352
 					<thead><tr>
353
-						<th class="col1">', esc_html__( 'Interval Hook', 'zt-debug-bar-cron' ), '</th>
354
-						<th class="col2">', esc_html__( 'Interval (S)', 'zt-debug-bar-cron' ), '</th>
355
-						<th class="col3">', esc_html__( 'Interval (M)', 'zt-debug-bar-cron' ), '</th>
356
-						<th class="col4">', esc_html__( 'Interval (H)', 'zt-debug-bar-cron' ), '</th>
357
-						<th class="col5">', esc_html__( 'Display Name', 'zt-debug-bar-cron' ), '</th>
353
+						<th class="col1">', esc_html__('Interval Hook', 'zt-debug-bar-cron'), '</th>
354
+						<th class="col2">', esc_html__('Interval (S)', 'zt-debug-bar-cron'), '</th>
355
+						<th class="col3">', esc_html__('Interval (M)', 'zt-debug-bar-cron'), '</th>
356
+						<th class="col4">', esc_html__('Interval (H)', 'zt-debug-bar-cron'), '</th>
357
+						<th class="col5">', esc_html__('Display Name', 'zt-debug-bar-cron'), '</th>
358 358
 					</tr></thead>
359 359
 					<tbody>';
360 360
 
361 361
 
362 362
 			$schedules = wp_get_schedules();
363
-			foreach ( $schedules as $interval_hook => $data ) {
363
+			foreach ($schedules as $interval_hook => $data) {
364 364
 				echo '
365 365
 						<tr>
366
-							<td>', esc_html( $interval_hook ), '</td>
367
-							<td>', intval( wp_strip_all_tags( $data['interval'] ) ), '</td>
368
-							<td>', intval( wp_strip_all_tags( $data['interval'] ) / 60 ), '</td>
369
-							<td>', intval( wp_strip_all_tags( $data['interval'] ) / ( 60 * 60 ) ), '</td>
370
-							<td>', esc_html( $data['display'] ) . '</td>
366
+							<td>', esc_html($interval_hook), '</td>
367
+							<td>', intval(wp_strip_all_tags($data['interval'])), '</td>
368
+							<td>', intval(wp_strip_all_tags($data['interval']) / 60), '</td>
369
+							<td>', intval(wp_strip_all_tags($data['interval']) / (60 * 60)), '</td>
370
+							<td>', esc_html($data['display']).'</td>
371 371
 						</tr>';
372 372
 			}
373 373
 
@@ -385,10 +385,10 @@  discard block
 block discarded – undo
385 385
 		 *
386 386
 		 * @return string
387 387
 		 */
388
-		private function display_past_time( $human_time, $time ) {
389
-			if ( time() > $time ) {
388
+		private function display_past_time($human_time, $time) {
389
+			if (time() > $time) {
390 390
 				/* TRANSLATORS: %s is a human readable time difference. */
391
-				return sprintf( __( '%s ago', 'zt-debug-bar-cron' ), $human_time );
391
+				return sprintf(__('%s ago', 'zt-debug-bar-cron'), $human_time);
392 392
 			} else {
393 393
 				return $human_time;
394 394
 			}
Please login to merge, or discard this patch.