Completed
Push — develop ( 13b240...504ca3 )
by David
02:16 queued 15s
created
deliciousbrains/wp-background-processing/classes/wp-background-process.php 1 patch
Spacing   +108 added lines, -108 removed lines patch added patch discarded remove patch
@@ -75,28 +75,28 @@  discard block
 block discarded – undo
75 75
 	 *
76 76
 	 * @param bool|array $allowed_batch_data_classes Optional. Array of class names that can be unserialized. Default true (any class).
77 77
 	 */
78
-	public function __construct( $allowed_batch_data_classes = true ) {
78
+	public function __construct($allowed_batch_data_classes = true) {
79 79
 		parent::__construct();
80 80
 
81
-		if ( empty( $allowed_batch_data_classes ) && false !== $allowed_batch_data_classes ) {
81
+		if (empty($allowed_batch_data_classes) && false !== $allowed_batch_data_classes) {
82 82
 			$allowed_batch_data_classes = true;
83 83
 		}
84 84
 
85
-		if ( ! is_bool( $allowed_batch_data_classes ) && ! is_array( $allowed_batch_data_classes ) ) {
85
+		if ( ! is_bool($allowed_batch_data_classes) && ! is_array($allowed_batch_data_classes)) {
86 86
 			$allowed_batch_data_classes = true;
87 87
 		}
88 88
 
89 89
 		// If allowed_batch_data_classes property set in subclass,
90 90
 		// only apply override if not allowing any class.
91
-		if ( true === $this->allowed_batch_data_classes || true !== $allowed_batch_data_classes ) {
91
+		if (true === $this->allowed_batch_data_classes || true !== $allowed_batch_data_classes) {
92 92
 			$this->allowed_batch_data_classes = $allowed_batch_data_classes;
93 93
 		}
94 94
 
95
-		$this->cron_hook_identifier     = $this->identifier . '_cron';
96
-		$this->cron_interval_identifier = $this->identifier . '_cron_interval';
95
+		$this->cron_hook_identifier     = $this->identifier.'_cron';
96
+		$this->cron_interval_identifier = $this->identifier.'_cron_interval';
97 97
 
98
-		add_action( $this->cron_hook_identifier, array( $this, 'handle_cron_healthcheck' ) );
99
-		add_filter( 'cron_schedules', array( $this, 'schedule_cron_healthcheck' ) );
98
+		add_action($this->cron_hook_identifier, array($this, 'handle_cron_healthcheck'));
99
+		add_filter('cron_schedules', array($this, 'schedule_cron_healthcheck'));
100 100
 	}
101 101
 
102 102
 	/**
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
 	 * @return array|WP_Error|false HTTP Response array, WP_Error on failure, or false if not attempted.
107 107
 	 */
108 108
 	public function dispatch() {
109
-		if ( $this->is_processing() ) {
109
+		if ($this->is_processing()) {
110 110
 			// Process already running.
111 111
 			return false;
112 112
 		}
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
 	 *
128 128
 	 * @return $this
129 129
 	 */
130
-	public function push_to_queue( $data ) {
130
+	public function push_to_queue($data) {
131 131
 		$this->data[] = $data;
132 132
 
133 133
 		return $this;
@@ -141,8 +141,8 @@  discard block
 block discarded – undo
141 141
 	public function save() {
142 142
 		$key = $this->generate_key();
143 143
 
144
-		if ( ! empty( $this->data ) ) {
145
-			update_site_option( $key, $this->data );
144
+		if ( ! empty($this->data)) {
145
+			update_site_option($key, $this->data);
146 146
 		}
147 147
 
148 148
 		// Clean out data so that new data isn't prepended with closed session's data.
@@ -159,9 +159,9 @@  discard block
 block discarded – undo
159 159
 	 *
160 160
 	 * @return $this
161 161
 	 */
162
-	public function update( $key, $data ) {
163
-		if ( ! empty( $data ) ) {
164
-			update_site_option( $key, $data );
162
+	public function update($key, $data) {
163
+		if ( ! empty($data)) {
164
+			update_site_option($key, $data);
165 165
 		}
166 166
 
167 167
 		return $this;
@@ -174,8 +174,8 @@  discard block
 block discarded – undo
174 174
 	 *
175 175
 	 * @return $this
176 176
 	 */
177
-	public function delete( $key ) {
178
-		delete_site_option( $key );
177
+	public function delete($key) {
178
+		delete_site_option($key);
179 179
 
180 180
 		return $this;
181 181
 	}
@@ -186,11 +186,11 @@  discard block
 block discarded – undo
186 186
 	public function delete_all() {
187 187
 		$batches = $this->get_batches();
188 188
 
189
-		foreach ( $batches as $batch ) {
190
-			$this->delete( $batch->key );
189
+		foreach ($batches as $batch) {
190
+			$this->delete($batch->key);
191 191
 		}
192 192
 
193
-		delete_site_option( $this->get_status_key() );
193
+		delete_site_option($this->get_status_key());
194 194
 
195 195
 		$this->cancelled();
196 196
 	}
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
 	 * Cancel job on next batch.
200 200
 	 */
201 201
 	public function cancel() {
202
-		update_site_option( $this->get_status_key(), self::STATUS_CANCELLED );
202
+		update_site_option($this->get_status_key(), self::STATUS_CANCELLED);
203 203
 
204 204
 		// Just in case the job was paused at the time.
205 205
 		$this->dispatch();
@@ -211,23 +211,23 @@  discard block
 block discarded – undo
211 211
 	 * @return bool
212 212
 	 */
213 213
 	public function is_cancelled() {
214
-		$status = get_site_option( $this->get_status_key(), 0 );
214
+		$status = get_site_option($this->get_status_key(), 0);
215 215
 
216
-		return absint( $status ) === self::STATUS_CANCELLED;
216
+		return absint($status) === self::STATUS_CANCELLED;
217 217
 	}
218 218
 
219 219
 	/**
220 220
 	 * Called when background process has been cancelled.
221 221
 	 */
222 222
 	protected function cancelled() {
223
-		do_action( $this->identifier . '_cancelled' );
223
+		do_action($this->identifier.'_cancelled');
224 224
 	}
225 225
 
226 226
 	/**
227 227
 	 * Pause job on next batch.
228 228
 	 */
229 229
 	public function pause() {
230
-		update_site_option( $this->get_status_key(), self::STATUS_PAUSED );
230
+		update_site_option($this->get_status_key(), self::STATUS_PAUSED);
231 231
 	}
232 232
 
233 233
 	/**
@@ -236,23 +236,23 @@  discard block
 block discarded – undo
236 236
 	 * @return bool
237 237
 	 */
238 238
 	public function is_paused() {
239
-		$status = get_site_option( $this->get_status_key(), 0 );
239
+		$status = get_site_option($this->get_status_key(), 0);
240 240
 
241
-		return absint( $status ) === self::STATUS_PAUSED;
241
+		return absint($status) === self::STATUS_PAUSED;
242 242
 	}
243 243
 
244 244
 	/**
245 245
 	 * Called when background process has been paused.
246 246
 	 */
247 247
 	protected function paused() {
248
-		do_action( $this->identifier . '_paused' );
248
+		do_action($this->identifier.'_paused');
249 249
 	}
250 250
 
251 251
 	/**
252 252
 	 * Resume job.
253 253
 	 */
254 254
 	public function resume() {
255
-		delete_site_option( $this->get_status_key() );
255
+		delete_site_option($this->get_status_key());
256 256
 
257 257
 		$this->schedule_event();
258 258
 		$this->dispatch();
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
 	 * Called when background process has been resumed.
264 264
 	 */
265 265
 	protected function resumed() {
266
-		do_action( $this->identifier . '_resumed' );
266
+		do_action($this->identifier.'_resumed');
267 267
 	}
268 268
 
269 269
 	/**
@@ -295,11 +295,11 @@  discard block
 block discarded – undo
295 295
 	 *
296 296
 	 * @return string
297 297
 	 */
298
-	protected function generate_key( $length = 64, $key = 'batch' ) {
299
-		$unique  = md5( microtime() . wp_rand() );
300
-		$prepend = $this->identifier . '_' . $key . '_';
298
+	protected function generate_key($length = 64, $key = 'batch') {
299
+		$unique  = md5(microtime().wp_rand());
300
+		$prepend = $this->identifier.'_'.$key.'_';
301 301
 
302
-		return substr( $prepend . $unique, 0, $length );
302
+		return substr($prepend.$unique, 0, $length);
303 303
 	}
304 304
 
305 305
 	/**
@@ -308,7 +308,7 @@  discard block
 block discarded – undo
308 308
 	 * @return string
309 309
 	 */
310 310
 	protected function get_status_key() {
311
-		return $this->identifier . '_status';
311
+		return $this->identifier.'_status';
312 312
 	}
313 313
 
314 314
 	/**
@@ -321,31 +321,31 @@  discard block
 block discarded – undo
321 321
 		// Don't lock up other requests while processing.
322 322
 		session_write_close();
323 323
 
324
-		if ( $this->is_processing() ) {
324
+		if ($this->is_processing()) {
325 325
 			// Background process already running.
326 326
 			return $this->maybe_wp_die();
327 327
 		}
328 328
 
329
-		if ( $this->is_cancelled() ) {
329
+		if ($this->is_cancelled()) {
330 330
 			$this->clear_scheduled_event();
331 331
 			$this->delete_all();
332 332
 
333 333
 			return $this->maybe_wp_die();
334 334
 		}
335 335
 
336
-		if ( $this->is_paused() ) {
336
+		if ($this->is_paused()) {
337 337
 			$this->clear_scheduled_event();
338 338
 			$this->paused();
339 339
 
340 340
 			return $this->maybe_wp_die();
341 341
 		}
342 342
 
343
-		if ( $this->is_queue_empty() ) {
343
+		if ($this->is_queue_empty()) {
344 344
 			// No data to process.
345 345
 			return $this->maybe_wp_die();
346 346
 		}
347 347
 
348
-		check_ajax_referer( $this->identifier, 'nonce' );
348
+		check_ajax_referer($this->identifier, 'nonce');
349 349
 
350 350
 		$this->handle();
351 351
 
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
 	 * @return bool
359 359
 	 */
360 360
 	protected function is_queue_empty() {
361
-		return empty( $this->get_batch() );
361
+		return empty($this->get_batch());
362 362
 	}
363 363
 
364 364
 	/**
@@ -382,7 +382,7 @@  discard block
 block discarded – undo
382 382
 	 * @return bool
383 383
 	 */
384 384
 	public function is_processing() {
385
-		if ( get_site_transient( $this->identifier . '_process_lock' ) ) {
385
+		if (get_site_transient($this->identifier.'_process_lock')) {
386 386
 			// Process already running.
387 387
 			return true;
388 388
 		}
@@ -400,10 +400,10 @@  discard block
 block discarded – undo
400 400
 	protected function lock_process() {
401 401
 		$this->start_time = time(); // Set start time of current process.
402 402
 
403
-		$lock_duration = ( property_exists( $this, 'queue_lock_time' ) ) ? $this->queue_lock_time : 60; // 1 minute
404
-		$lock_duration = apply_filters( $this->identifier . '_queue_lock_time', $lock_duration );
403
+		$lock_duration = (property_exists($this, 'queue_lock_time')) ? $this->queue_lock_time : 60; // 1 minute
404
+		$lock_duration = apply_filters($this->identifier.'_queue_lock_time', $lock_duration);
405 405
 
406
-		set_site_transient( $this->identifier . '_process_lock', microtime(), $lock_duration );
406
+		set_site_transient($this->identifier.'_process_lock', microtime(), $lock_duration);
407 407
 	}
408 408
 
409 409
 	/**
@@ -414,7 +414,7 @@  discard block
 block discarded – undo
414 414
 	 * @return $this
415 415
 	 */
416 416
 	protected function unlock_process() {
417
-		delete_site_transient( $this->identifier . '_process_lock' );
417
+		delete_site_transient($this->identifier.'_process_lock');
418 418
 
419 419
 		return $this;
420 420
 	}
@@ -426,8 +426,8 @@  discard block
 block discarded – undo
426 426
 	 */
427 427
 	protected function get_batch() {
428 428
 		return array_reduce(
429
-			$this->get_batches( 1 ),
430
-			static function ( $carry, $batch ) {
429
+			$this->get_batches(1),
430
+			static function($carry, $batch) {
431 431
 				return $batch;
432 432
 			},
433 433
 			array()
@@ -441,10 +441,10 @@  discard block
 block discarded – undo
441 441
 	 *
442 442
 	 * @return array of stdClass
443 443
 	 */
444
-	public function get_batches( $limit = 0 ) {
444
+	public function get_batches($limit = 0) {
445 445
 		global $wpdb;
446 446
 
447
-		if ( empty( $limit ) || ! is_int( $limit ) ) {
447
+		if (empty($limit) || ! is_int($limit)) {
448 448
 			$limit = 0;
449 449
 		}
450 450
 
@@ -453,42 +453,42 @@  discard block
 block discarded – undo
453 453
 		$key_column   = 'option_id';
454 454
 		$value_column = 'option_value';
455 455
 
456
-		if ( is_multisite() ) {
456
+		if (is_multisite()) {
457 457
 			$table        = $wpdb->sitemeta;
458 458
 			$column       = 'meta_key';
459 459
 			$key_column   = 'meta_id';
460 460
 			$value_column = 'meta_value';
461 461
 		}
462 462
 
463
-		$key = $wpdb->esc_like( $this->identifier . '_batch_' ) . '%';
463
+		$key = $wpdb->esc_like($this->identifier.'_batch_').'%';
464 464
 
465 465
 		$sql = '
466 466
 			SELECT *
467
-			FROM ' . $table . '
468
-			WHERE ' . $column . ' LIKE %s
469
-			ORDER BY ' . $key_column . ' ASC
467
+			FROM ' . $table.'
468
+			WHERE ' . $column.' LIKE %s
469
+			ORDER BY ' . $key_column.' ASC
470 470
 			';
471 471
 
472
-		$args = array( $key );
472
+		$args = array($key);
473 473
 
474
-		if ( ! empty( $limit ) ) {
474
+		if ( ! empty($limit)) {
475 475
 			$sql .= ' LIMIT %d';
476 476
 
477 477
 			$args[] = $limit;
478 478
 		}
479 479
 
480
-		$items = $wpdb->get_results( $wpdb->prepare( $sql, $args ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
480
+		$items = $wpdb->get_results($wpdb->prepare($sql, $args)); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
481 481
 
482 482
 		$batches = array();
483 483
 
484
-		if ( ! empty( $items ) ) {
484
+		if ( ! empty($items)) {
485 485
 			$allowed_classes = $this->allowed_batch_data_classes;
486 486
 
487 487
 			$batches = array_map(
488
-				static function ( $item ) use ( $column, $value_column, $allowed_classes ) {
488
+				static function($item) use ($column, $value_column, $allowed_classes) {
489 489
 					$batch       = new stdClass();
490 490
 					$batch->key  = $item->{$column};
491
-					$batch->data = static::maybe_unserialize( $item->{$value_column}, $allowed_classes );
491
+					$batch->data = static::maybe_unserialize($item->{$value_column}, $allowed_classes);
492 492
 
493 493
 					return $batch;
494 494
 				},
@@ -516,9 +516,9 @@  discard block
 block discarded – undo
516 516
 		$throttle_seconds = max(
517 517
 			0,
518 518
 			apply_filters(
519
-				$this->identifier . '_seconds_between_batches',
519
+				$this->identifier.'_seconds_between_batches',
520 520
 				apply_filters(
521
-					$this->prefix . '_seconds_between_batches',
521
+					$this->prefix.'_seconds_between_batches',
522 522
 					0
523 523
 				)
524 524
 			)
@@ -527,39 +527,39 @@  discard block
 block discarded – undo
527 527
 		do {
528 528
 			$batch = $this->get_batch();
529 529
 
530
-			foreach ( $batch->data as $key => $value ) {
531
-				$task = $this->task( $value );
530
+			foreach ($batch->data as $key => $value) {
531
+				$task = $this->task($value);
532 532
 
533
-				if ( false !== $task ) {
534
-					$batch->data[ $key ] = $task;
533
+				if (false !== $task) {
534
+					$batch->data[$key] = $task;
535 535
 				} else {
536
-					unset( $batch->data[ $key ] );
536
+					unset($batch->data[$key]);
537 537
 				}
538 538
 
539 539
 				// Keep the batch up to date while processing it.
540
-				if ( ! empty( $batch->data ) ) {
541
-					$this->update( $batch->key, $batch->data );
540
+				if ( ! empty($batch->data)) {
541
+					$this->update($batch->key, $batch->data);
542 542
 				}
543 543
 
544 544
 				// Let the server breathe a little.
545
-				sleep( $throttle_seconds );
545
+				sleep($throttle_seconds);
546 546
 
547 547
 				// Batch limits reached, or pause or cancel request.
548
-				if ( $this->time_exceeded() || $this->memory_exceeded() || $this->is_paused() || $this->is_cancelled() ) {
548
+				if ($this->time_exceeded() || $this->memory_exceeded() || $this->is_paused() || $this->is_cancelled()) {
549 549
 					break;
550 550
 				}
551 551
 			}
552 552
 
553 553
 			// Delete current batch if fully processed.
554
-			if ( empty( $batch->data ) ) {
555
-				$this->delete( $batch->key );
554
+			if (empty($batch->data)) {
555
+				$this->delete($batch->key);
556 556
 			}
557
-		} while ( ! $this->time_exceeded() && ! $this->memory_exceeded() && ! $this->is_queue_empty() && ! $this->is_paused() && ! $this->is_cancelled() );
557
+		} while ( ! $this->time_exceeded() && ! $this->memory_exceeded() && ! $this->is_queue_empty() && ! $this->is_paused() && ! $this->is_cancelled());
558 558
 
559 559
 		$this->unlock_process();
560 560
 
561 561
 		// Start next batch or complete process.
562
-		if ( ! $this->is_queue_empty() ) {
562
+		if ( ! $this->is_queue_empty()) {
563 563
 			$this->dispatch();
564 564
 		} else {
565 565
 			$this->complete();
@@ -578,14 +578,14 @@  discard block
 block discarded – undo
578 578
 	 */
579 579
 	protected function memory_exceeded() {
580 580
 		$memory_limit   = $this->get_memory_limit() * 0.9; // 90% of max memory
581
-		$current_memory = memory_get_usage( true );
581
+		$current_memory = memory_get_usage(true);
582 582
 		$return         = false;
583 583
 
584
-		if ( $current_memory >= $memory_limit ) {
584
+		if ($current_memory >= $memory_limit) {
585 585
 			$return = true;
586 586
 		}
587 587
 
588
-		return apply_filters( $this->identifier . '_memory_exceeded', $return );
588
+		return apply_filters($this->identifier.'_memory_exceeded', $return);
589 589
 	}
590 590
 
591 591
 	/**
@@ -594,19 +594,19 @@  discard block
 block discarded – undo
594 594
 	 * @return int
595 595
 	 */
596 596
 	protected function get_memory_limit() {
597
-		if ( function_exists( 'ini_get' ) ) {
598
-			$memory_limit = ini_get( 'memory_limit' );
597
+		if (function_exists('ini_get')) {
598
+			$memory_limit = ini_get('memory_limit');
599 599
 		} else {
600 600
 			// Sensible default.
601 601
 			$memory_limit = '128M';
602 602
 		}
603 603
 
604
-		if ( ! $memory_limit || -1 === intval( $memory_limit ) ) {
604
+		if ( ! $memory_limit || -1 === intval($memory_limit)) {
605 605
 			// Unlimited, set to 32GB.
606 606
 			$memory_limit = '32000M';
607 607
 		}
608 608
 
609
-		return wp_convert_hr_to_bytes( $memory_limit );
609
+		return wp_convert_hr_to_bytes($memory_limit);
610 610
 	}
611 611
 
612 612
 	/**
@@ -618,14 +618,14 @@  discard block
 block discarded – undo
618 618
 	 * @return bool
619 619
 	 */
620 620
 	protected function time_exceeded() {
621
-		$finish = $this->start_time + apply_filters( $this->identifier . '_default_time_limit', 20 ); // 20 seconds
621
+		$finish = $this->start_time + apply_filters($this->identifier.'_default_time_limit', 20); // 20 seconds
622 622
 		$return = false;
623 623
 
624
-		if ( time() >= $finish ) {
624
+		if (time() >= $finish) {
625 625
 			$return = true;
626 626
 		}
627 627
 
628
-		return apply_filters( $this->identifier . '_time_exceeded', $return );
628
+		return apply_filters($this->identifier.'_time_exceeded', $return);
629 629
 	}
630 630
 
631 631
 	/**
@@ -635,7 +635,7 @@  discard block
 block discarded – undo
635 635
 	 * performed, or, call parent::complete().
636 636
 	 */
637 637
 	protected function complete() {
638
-		delete_site_option( $this->get_status_key() );
638
+		delete_site_option($this->get_status_key());
639 639
 
640 640
 		// Remove the cron healthcheck job from the cron schedule.
641 641
 		$this->clear_scheduled_event();
@@ -647,7 +647,7 @@  discard block
 block discarded – undo
647 647
 	 * Called when background process has completed.
648 648
 	 */
649 649
 	protected function completed() {
650
-		do_action( $this->identifier . '_completed' );
650
+		do_action($this->identifier.'_completed');
651 651
 	}
652 652
 
653 653
 	/**
@@ -660,13 +660,13 @@  discard block
 block discarded – undo
660 660
 	public function get_cron_interval() {
661 661
 		$interval = 5;
662 662
 
663
-		if ( property_exists( $this, 'cron_interval' ) ) {
663
+		if (property_exists($this, 'cron_interval')) {
664 664
 			$interval = $this->cron_interval;
665 665
 		}
666 666
 
667
-		$interval = apply_filters( $this->cron_interval_identifier, $interval );
667
+		$interval = apply_filters($this->cron_interval_identifier, $interval);
668 668
 
669
-		return is_int( $interval ) && 0 < $interval ? $interval : 5;
669
+		return is_int($interval) && 0 < $interval ? $interval : 5;
670 670
 	}
671 671
 
672 672
 	/**
@@ -678,17 +678,17 @@  discard block
 block discarded – undo
678 678
 	 *
679 679
 	 * @return mixed
680 680
 	 */
681
-	public function schedule_cron_healthcheck( $schedules ) {
681
+	public function schedule_cron_healthcheck($schedules) {
682 682
 		$interval = $this->get_cron_interval();
683 683
 
684
-		if ( 1 === $interval ) {
685
-			$display = __( 'Every Minute' );
684
+		if (1 === $interval) {
685
+			$display = __('Every Minute');
686 686
 		} else {
687
-			$display = sprintf( __( 'Every %d Minutes' ), $interval );
687
+			$display = sprintf(__('Every %d Minutes'), $interval);
688 688
 		}
689 689
 
690 690
 		// Adds an "Every NNN Minute(s)" schedule to the existing cron schedules.
691
-		$schedules[ $this->cron_interval_identifier ] = array(
691
+		$schedules[$this->cron_interval_identifier] = array(
692 692
 			'interval' => MINUTE_IN_SECONDS * $interval,
693 693
 			'display'  => $display,
694 694
 		);
@@ -703,12 +703,12 @@  discard block
 block discarded – undo
703 703
 	 * and data exists in the queue.
704 704
 	 */
705 705
 	public function handle_cron_healthcheck() {
706
-		if ( $this->is_processing() ) {
706
+		if ($this->is_processing()) {
707 707
 			// Background process already running.
708 708
 			exit;
709 709
 		}
710 710
 
711
-		if ( $this->is_queue_empty() ) {
711
+		if ($this->is_queue_empty()) {
712 712
 			// No data to process.
713 713
 			$this->clear_scheduled_event();
714 714
 			exit;
@@ -721,8 +721,8 @@  discard block
 block discarded – undo
721 721
 	 * Schedule the cron healthcheck event.
722 722
 	 */
723 723
 	protected function schedule_event() {
724
-		if ( ! wp_next_scheduled( $this->cron_hook_identifier ) ) {
725
-			wp_schedule_event( time() + ( $this->get_cron_interval() * MINUTE_IN_SECONDS ), $this->cron_interval_identifier, $this->cron_hook_identifier );
724
+		if ( ! wp_next_scheduled($this->cron_hook_identifier)) {
725
+			wp_schedule_event(time() + ($this->get_cron_interval() * MINUTE_IN_SECONDS), $this->cron_interval_identifier, $this->cron_hook_identifier);
726 726
 		}
727 727
 	}
728 728
 
@@ -730,10 +730,10 @@  discard block
 block discarded – undo
730 730
 	 * Clear scheduled cron healthcheck event.
731 731
 	 */
732 732
 	protected function clear_scheduled_event() {
733
-		$timestamp = wp_next_scheduled( $this->cron_hook_identifier );
733
+		$timestamp = wp_next_scheduled($this->cron_hook_identifier);
734 734
 
735
-		if ( $timestamp ) {
736
-			wp_unschedule_event( $timestamp, $this->cron_hook_identifier );
735
+		if ($timestamp) {
736
+			wp_unschedule_event($timestamp, $this->cron_hook_identifier);
737 737
 		}
738 738
 	}
739 739
 
@@ -761,7 +761,7 @@  discard block
 block discarded – undo
761 761
 	 *
762 762
 	 * @return mixed
763 763
 	 */
764
-	abstract protected function task( $item );
764
+	abstract protected function task($item);
765 765
 
766 766
 	/**
767 767
 	 * Maybe unserialize data, but not if an object.
@@ -771,14 +771,14 @@  discard block
 block discarded – undo
771 771
 	 *
772 772
 	 * @return mixed
773 773
 	 */
774
-	protected static function maybe_unserialize( $data, $allowed_classes ) {
775
-		if ( is_serialized( $data ) ) {
774
+	protected static function maybe_unserialize($data, $allowed_classes) {
775
+		if (is_serialized($data)) {
776 776
 			$options = array();
777
-			if ( is_bool( $allowed_classes ) || is_array( $allowed_classes ) ) {
777
+			if (is_bool($allowed_classes) || is_array($allowed_classes)) {
778 778
 				$options['allowed_classes'] = $allowed_classes;
779 779
 			}
780 780
 
781
-			return @unserialize( $data, $options ); // @phpcs:ignore
781
+			return @unserialize($data, $options); // @phpcs:ignore
782 782
 		}
783 783
 
784 784
 		return $data;
Please login to merge, or discard this patch.
deliciousbrains/wp-background-processing/classes/wp-async-request.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -54,10 +54,10 @@  discard block
 block discarded – undo
54 54
 	 * Initiate new async request.
55 55
 	 */
56 56
 	public function __construct() {
57
-		$this->identifier = $this->prefix . '_' . $this->action;
57
+		$this->identifier = $this->prefix.'_'.$this->action;
58 58
 
59
-		add_action( 'wp_ajax_' . $this->identifier, array( $this, 'maybe_handle' ) );
60
-		add_action( 'wp_ajax_nopriv_' . $this->identifier, array( $this, 'maybe_handle' ) );
59
+		add_action('wp_ajax_'.$this->identifier, array($this, 'maybe_handle'));
60
+		add_action('wp_ajax_nopriv_'.$this->identifier, array($this, 'maybe_handle'));
61 61
 	}
62 62
 
63 63
 	/**
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 	 *
68 68
 	 * @return $this
69 69
 	 */
70
-	public function data( $data ) {
70
+	public function data($data) {
71 71
 		$this->data = $data;
72 72
 
73 73
 		return $this;
@@ -79,10 +79,10 @@  discard block
 block discarded – undo
79 79
 	 * @return array|WP_Error|false HTTP Response array, WP_Error on failure, or false if not attempted.
80 80
 	 */
81 81
 	public function dispatch() {
82
-		$url  = add_query_arg( $this->get_query_args(), $this->get_query_url() );
82
+		$url  = add_query_arg($this->get_query_args(), $this->get_query_url());
83 83
 		$args = $this->get_post_args();
84 84
 
85
-		return wp_remote_post( esc_url_raw( $url ), $args );
85
+		return wp_remote_post(esc_url_raw($url), $args);
86 86
 	}
87 87
 
88 88
 	/**
@@ -91,13 +91,13 @@  discard block
 block discarded – undo
91 91
 	 * @return array
92 92
 	 */
93 93
 	protected function get_query_args() {
94
-		if ( property_exists( $this, 'query_args' ) ) {
94
+		if (property_exists($this, 'query_args')) {
95 95
 			return $this->query_args;
96 96
 		}
97 97
 
98 98
 		$args = array(
99 99
 			'action' => $this->identifier,
100
-			'nonce'  => wp_create_nonce( $this->identifier ),
100
+			'nonce'  => wp_create_nonce($this->identifier),
101 101
 		);
102 102
 
103 103
 		/**
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 		 *
106 106
 		 * @param array $url
107 107
 		 */
108
-		return apply_filters( $this->identifier . '_query_args', $args );
108
+		return apply_filters($this->identifier.'_query_args', $args);
109 109
 	}
110 110
 
111 111
 	/**
@@ -114,18 +114,18 @@  discard block
 block discarded – undo
114 114
 	 * @return string
115 115
 	 */
116 116
 	protected function get_query_url() {
117
-		if ( property_exists( $this, 'query_url' ) ) {
117
+		if (property_exists($this, 'query_url')) {
118 118
 			return $this->query_url;
119 119
 		}
120 120
 
121
-		$url = admin_url( 'admin-ajax.php' );
121
+		$url = admin_url('admin-ajax.php');
122 122
 
123 123
 		/**
124 124
 		 * Filters the post arguments used during an async request.
125 125
 		 *
126 126
 		 * @param string $url
127 127
 		 */
128
-		return apply_filters( $this->identifier . '_query_url', $url );
128
+		return apply_filters($this->identifier.'_query_url', $url);
129 129
 	}
130 130
 
131 131
 	/**
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 	 * @return array
135 135
 	 */
136 136
 	protected function get_post_args() {
137
-		if ( property_exists( $this, 'post_args' ) ) {
137
+		if (property_exists($this, 'post_args')) {
138 138
 			return $this->post_args;
139 139
 		}
140 140
 
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
 			'blocking'  => false,
144 144
 			'body'      => $this->data,
145 145
 			'cookies'   => $_COOKIE, // Passing cookies ensures request is performed as initiating user.
146
-			'sslverify' => apply_filters( 'https_local_ssl_verify', false ), // Local requests, fine to pass false.
146
+			'sslverify' => apply_filters('https_local_ssl_verify', false), // Local requests, fine to pass false.
147 147
 		);
148 148
 
149 149
 		/**
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
 		 *
152 152
 		 * @param array $args
153 153
 		 */
154
-		return apply_filters( $this->identifier . '_post_args', $args );
154
+		return apply_filters($this->identifier.'_post_args', $args);
155 155
 	}
156 156
 
157 157
 	/**
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 		// Don't lock up other requests while processing.
166 166
 		session_write_close();
167 167
 
168
-		check_ajax_referer( $this->identifier, 'nonce' );
168
+		check_ajax_referer($this->identifier, 'nonce');
169 169
 
170 170
 		$this->handle();
171 171
 
@@ -179,13 +179,13 @@  discard block
 block discarded – undo
179 179
 	 *
180 180
 	 * @return void|mixed
181 181
 	 */
182
-	protected function maybe_wp_die( $return = null ) {
182
+	protected function maybe_wp_die($return = null) {
183 183
 		/**
184 184
 		 * Should wp_die be used?
185 185
 		 *
186 186
 		 * @return bool
187 187
 		 */
188
-		if ( apply_filters( $this->identifier . '_wp_die', true ) ) {
188
+		if (apply_filters($this->identifier.'_wp_die', true)) {
189 189
 			wp_die();
190 190
 		}
191 191
 
Please login to merge, or discard this patch.
deliciousbrains/wp-background-processing/wp-background-processing.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -16,9 +16,9 @@
 block discarded – undo
16 16
  * GitHub Branch: master
17 17
  */
18 18
 
19
-if ( ! class_exists( 'WP_Async_Request' ) ) {
20
-	require_once plugin_dir_path( __FILE__ ) . 'classes/wp-async-request.php';
19
+if ( ! class_exists('WP_Async_Request')) {
20
+	require_once plugin_dir_path(__FILE__).'classes/wp-async-request.php';
21 21
 }
22
-if ( ! class_exists( 'WP_Background_Process' ) ) {
23
-	require_once plugin_dir_path( __FILE__ ) . 'classes/wp-background-process.php';
22
+if ( ! class_exists('WP_Background_Process')) {
23
+	require_once plugin_dir_path(__FILE__).'classes/wp-background-process.php';
24 24
 }
Please login to merge, or discard this patch.
src/includes/class-wordlift-jsonld-service.php 1 patch
Spacing   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
 	 *
257 257
 	 * @since 3.8.0
258 258
 	 */
259
-	public function __construct( $entity_service, $converter, $website_converter, $term_jsonld_adapter ) {
259
+	public function __construct($entity_service, $converter, $website_converter, $term_jsonld_adapter) {
260 260
 		$this->entity_service      = $entity_service;
261 261
 		$this->converter           = $converter;
262 262
 		$this->website_converter   = $website_converter;
@@ -289,11 +289,11 @@  discard block
 block discarded – undo
289 289
 		@ob_clean();
290 290
 
291 291
 		// Get the parameter from the request.
292
-		$is_homepage = isset( $_REQUEST['homepage'] ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended
293
-		$post_id     = isset( $_REQUEST['id'] ) && is_numeric( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : null; //phpcs:ignore WordPress.Security.NonceVerification.Recommended
292
+		$is_homepage = isset($_REQUEST['homepage']); //phpcs:ignore WordPress.Security.NonceVerification.Recommended
293
+		$post_id     = isset($_REQUEST['id']) && is_numeric($_REQUEST['id']) ? intval($_REQUEST['id']) : null; //phpcs:ignore WordPress.Security.NonceVerification.Recommended
294 294
 
295 295
 		// Send the generated JSON-LD.
296
-		$this->send_jsonld( $this->get_jsonld( $is_homepage, $post_id ) );
296
+		$this->send_jsonld($this->get_jsonld($is_homepage, $post_id));
297 297
 
298 298
 	}
299 299
 
@@ -305,11 +305,11 @@  discard block
 block discarded – undo
305 305
 	 *
306 306
 	 * @since 3.18.5
307 307
 	 */
308
-	private function send_jsonld( $response ) {
308
+	private function send_jsonld($response) {
309 309
 		// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
310
-		@header( 'Content-Type: application/ld+json; charset=' . get_option( 'blog_charset' ) );
311
-		echo wp_json_encode( $response );
312
-		if ( apply_filters( 'wp_doing_ajax', defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
310
+		@header('Content-Type: application/ld+json; charset='.get_option('blog_charset'));
311
+		echo wp_json_encode($response);
312
+		if (apply_filters('wp_doing_ajax', defined('DOING_AJAX') && DOING_AJAX)) {
313 313
 			wp_die();
314 314
 		} else {
315 315
 			die;
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
 	 * @return array A JSON-LD structure.
327 327
 	 * @since 3.15.1
328 328
 	 */
329
-	public function get_jsonld( $is_homepage = false, $post_id = null, $context = Jsonld_Context_Enum::UNKNOWN ) {
329
+	public function get_jsonld($is_homepage = false, $post_id = null, $context = Jsonld_Context_Enum::UNKNOWN) {
330 330
 
331 331
 		/**
332 332
 		 * Filter name: wl_before_get_jsonld
@@ -337,7 +337,7 @@  discard block
 block discarded – undo
337 337
 		 *
338 338
 		 * @since 3.52.7
339 339
 		 */
340
-		do_action( 'wl_before_get_jsonld', $is_homepage, $post_id, $context );
340
+		do_action('wl_before_get_jsonld', $is_homepage, $post_id, $context);
341 341
 
342 342
 		// Tell NewRelic to ignore us, otherwise NewRelic customers might receive
343 343
 		// e-mails with a low apdex score.
@@ -346,14 +346,14 @@  discard block
 block discarded – undo
346 346
 		Wordlift_NewRelic_Adapter::ignore_apdex();
347 347
 
348 348
 		// Switch to Website converter if is home page.
349
-		if ( $is_homepage ) {
349
+		if ($is_homepage) {
350 350
 			/**
351 351
 			 * Filter: 'wordlift_disable_website_json_ld' - Allow disabling of the json+ld output.
352 352
 			 *
353 353
 			 * @since  3.14.0
354 354
 			 * @api    bool $display_search Whether or not to display json+ld search on the frontend.
355 355
 			 */
356
-			if ( apply_filters( 'wordlift_disable_website_json_ld', false ) ) {
356
+			if (apply_filters('wordlift_disable_website_json_ld', false)) {
357 357
 				return array();
358 358
 			}
359 359
 
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
 		}
366 366
 
367 367
 		// If no id has been provided return an empty array.
368
-		if ( ! isset( $post_id ) ) {
368
+		if ( ! isset($post_id)) {
369 369
 			return array();
370 370
 		}
371 371
 
@@ -378,32 +378,32 @@  discard block
 block discarded – undo
378 378
 		$entity_to_jsonld_converter = $this->converter;
379 379
 
380 380
 		$relations = new Relations();
381
-		$jsonld    = $entity_to_jsonld_converter->convert( $post_id, $references, $references_infos, $relations );
381
+		$jsonld    = $entity_to_jsonld_converter->convert($post_id, $references, $references_infos, $relations);
382 382
 
383
-		$graph = new Graph( $jsonld, $entity_to_jsonld_converter, Wordlift_Term_JsonLd_Adapter::get_instance() );
383
+		$graph = new Graph($jsonld, $entity_to_jsonld_converter, Wordlift_Term_JsonLd_Adapter::get_instance());
384 384
 
385
-		$schema_type = is_array( $jsonld['@type'] ) ? $jsonld['@type'] : array( $jsonld['@type'] );
385
+		$schema_type = is_array($jsonld['@type']) ? $jsonld['@type'] : array($jsonld['@type']);
386 386
 
387 387
 		// Add `about`/`mentions` only for `CreativeWork` and descendants.
388
-		if ( array_intersect( $schema_type, self::$creative_work_types ) ) {
388
+		if (array_intersect($schema_type, self::$creative_work_types)) {
389 389
 
390
-			foreach ( $relations->toArray() as $relation ) {
390
+			foreach ($relations->toArray() as $relation) {
391 391
 
392 392
 				// Setting about or mentions by label match is currently supported only for posts
393
-				if ( Object_Type_Enum::POST !== $relation->get_object()->get_type() ) {
393
+				if (Object_Type_Enum::POST !== $relation->get_object()->get_type()) {
394 394
 					continue;
395 395
 				}
396 396
 
397 397
 				// Add the `mentions`/`about` prop.
398
-				$this->add_mention_or_about( $jsonld, $post_id, $relation );
398
+				$this->add_mention_or_about($jsonld, $post_id, $relation);
399 399
 			}
400
-			$graph->set_main_jsonld( $jsonld );
400
+			$graph->set_main_jsonld($jsonld);
401 401
 		}
402 402
 
403
-		$jsonld_arr = $graph->add_references( $references )
404
-							->add_relations( $relations )
405
-							->add_required_reference_infos( $references_infos )
406
-							->render( $context );
403
+		$jsonld_arr = $graph->add_references($references)
404
+							->add_relations($relations)
405
+							->add_required_reference_infos($references_infos)
406
+							->render($context);
407 407
 
408 408
 		/**
409 409
 		 * Filter name: wl_after_get_jsonld
@@ -413,7 +413,7 @@  discard block
 block discarded – undo
413 413
 		 * @var $jsonld_arr array The final jsonld before outputting to page.
414 414
 		 * @var $post_id int The post id for which the jsonld is generated.
415 415
 		 */
416
-		$jsonld_arr = apply_filters( 'wl_after_get_jsonld', $jsonld_arr, $post_id, $context );
416
+		$jsonld_arr = apply_filters('wl_after_get_jsonld', $jsonld_arr, $post_id, $context);
417 417
 
418 418
 		return $jsonld_arr;
419 419
 	}
@@ -432,9 +432,9 @@  discard block
 block discarded – undo
432 432
 		$is_homepage = is_home() || is_front_page();
433 433
 		$post_id     = is_singular() ? get_the_ID() : null;
434 434
 
435
-		$jsonld = wp_json_encode( $this->get_jsonld( $is_homepage, $post_id, Jsonld_Context_Enum::PAGE ) );
435
+		$jsonld = wp_json_encode($this->get_jsonld($is_homepage, $post_id, Jsonld_Context_Enum::PAGE));
436 436
 		?>
437
-		<script type="application/ld+json"><?php echo esc_html( $jsonld ); ?></script>
437
+		<script type="application/ld+json"><?php echo esc_html($jsonld); ?></script>
438 438
 		<?php
439 439
 	}
440 440
 
@@ -444,17 +444,17 @@  discard block
 block discarded – undo
444 444
 	 *
445 445
 	 * @return void
446 446
 	 */
447
-	private function add_mention_or_about( &$jsonld, $post_id, $relation ) {
447
+	private function add_mention_or_about(&$jsonld, $post_id, $relation) {
448 448
 		$content_service = Wordpress_Content_Service::get_instance();
449 449
 		$entity_service  = Wordlift_Entity_Service::get_instance();
450 450
 
451 451
 		$object     = $relation->get_object();
452
-		$entity_uri = $content_service->get_entity_id( $object );
453
-		$labels     = $entity_service->get_labels( $object->get_id(), $object->get_type() );
452
+		$entity_uri = $content_service->get_entity_id($object);
453
+		$labels     = $entity_service->get_labels($object->get_id(), $object->get_type());
454 454
 
455 455
 		$escaped_labels = array_map(
456
-			function ( $value ) {
457
-				return preg_quote( $value, '/' );
456
+			function($value) {
457
+				return preg_quote($value, '/');
458 458
 			},
459 459
 			$labels
460 460
 		);
@@ -462,17 +462,17 @@  discard block
 block discarded – undo
462 462
 		$matches = false;
463 463
 
464 464
 		// When the title is empty, then we shouldn't yield a match to about section.
465
-		if ( array_filter( $escaped_labels ) ) {
465
+		if (array_filter($escaped_labels)) {
466 466
 			// Check if the labels match any part of the title.
467
-			$post    = get_post( $post_id );
468
-			$matches = $this->check_title_match( $escaped_labels, $post->post_title );
467
+			$post    = get_post($post_id);
468
+			$matches = $this->check_title_match($escaped_labels, $post->post_title);
469 469
 		}
470 470
 
471
-		if ( $entity_uri ) {
471
+		if ($entity_uri) {
472 472
 			// If the title matches, assign the entity to the about, otherwise to the mentions.
473 473
 			$property_name              = $matches ? 'about' : 'mentions';
474
-			$jsonld[ $property_name ]   = isset( $jsonld[ $property_name ] ) ? (array) $jsonld[ $property_name ] : array();
475
-			$jsonld[ $property_name ][] = array( '@id' => $entity_uri );
474
+			$jsonld[$property_name]   = isset($jsonld[$property_name]) ? (array) $jsonld[$property_name] : array();
475
+			$jsonld[$property_name][] = array('@id' => $entity_uri);
476 476
 		}
477 477
 
478 478
 	}
@@ -485,15 +485,15 @@  discard block
 block discarded – undo
485 485
 	 *
486 486
 	 * @return boolean
487 487
 	 */
488
-	public function check_title_match( $labels, $title ) {
488
+	public function check_title_match($labels, $title) {
489 489
 
490 490
 		// If the title is empty, then we shouldn't yield a match to about section.
491
-		if ( empty( $title ) ) {
491
+		if (empty($title)) {
492 492
 			return false;
493 493
 		}
494 494
 
495 495
 		// Check if the labels match any part of the title.
496
-		return 1 === preg_match( '/\b(' . implode( '|', $labels ) . ')\b/iu', $title );
496
+		return 1 === preg_match('/\b('.implode('|', $labels).')\b/iu', $title);
497 497
 
498 498
 	}
499 499
 
Please login to merge, or discard this patch.
src/includes/class-wordlift-post-to-jsonld-converter.php 1 patch
Spacing   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -46,11 +46,11 @@  discard block
 block discarded – undo
46 46
 	 *
47 47
 	 * @since 3.10.0
48 48
 	 */
49
-	public function __construct( $entity_type_service, $user_service, $attachment_service, $disable_convert_filters = false ) {
50
-		parent::__construct( $entity_type_service, $user_service, $attachment_service, Wordlift_Property_Getter_Factory::create() );
49
+	public function __construct($entity_type_service, $user_service, $attachment_service, $disable_convert_filters = false) {
50
+		parent::__construct($entity_type_service, $user_service, $attachment_service, Wordlift_Property_Getter_Factory::create());
51 51
 		$this->disable_convert_filters = $disable_convert_filters;
52 52
 		// Set a reference to the logger.
53
-		$this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Post_To_Jsonld_Converter' );
53
+		$this->log = Wordlift_Log_Service::get_logger('Wordlift_Post_To_Jsonld_Converter');
54 54
 
55 55
 		self::$instance = $this;
56 56
 
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 	}
63 63
 
64 64
 	public function new_instance_with_filters_disabled() {
65
-		return new static( $this->entity_type_service, $this->user_service, $this->attachment_service, true );
65
+		return new static($this->entity_type_service, $this->user_service, $this->attachment_service, true);
66 66
 	}
67 67
 
68 68
 	/**
@@ -76,20 +76,20 @@  discard block
 block discarded – undo
76 76
 	 * @return array A JSON-LD array.
77 77
 	 * @since 3.10.0
78 78
 	 */
79
-	public function convert( $post_id, &$references = array(), &$references_infos = array(), $relations = null ) {
79
+	public function convert($post_id, &$references = array(), &$references_infos = array(), $relations = null) {
80 80
 
81 81
 		// Get the post instance.
82
-		$post = get_post( $post_id );
83
-		if ( null === $post ) {
82
+		$post = get_post($post_id);
83
+		if (null === $post) {
84 84
 			// Post not found.
85 85
 			return null;
86 86
 		}
87 87
 
88 88
 		// Get the base JSON-LD and the list of entities referenced by this entity.
89
-		$jsonld = parent::convert( $post_id, $references, $references_infos, $relations );
89
+		$jsonld = parent::convert($post_id, $references, $references_infos, $relations);
90 90
 
91 91
 		// Set WebPage by default.
92
-		if ( empty( $jsonld['@type'] ) ) {
92
+		if (empty($jsonld['@type'])) {
93 93
 			$jsonld['@type'] = 'WebPage';
94 94
 		}
95 95
 
@@ -99,12 +99,12 @@  discard block
 block discarded – undo
99 99
 		// Convert entities as `Article`.
100 100
 		//
101 101
 		// @see https://github.com/insideout10/wordlift-plugin/issues/1731
102
-		$custom_fields = Wordlift_Entity_Service::get_instance()->is_entity( $post_id )
103
-			? $this->entity_type_service->get_custom_fields_for_term( $this->entity_type_service->get_term_by_slug( 'article' ) )
104
-			: $this->entity_type_service->get_custom_fields_for_post( $post_id );
102
+		$custom_fields = Wordlift_Entity_Service::get_instance()->is_entity($post_id)
103
+			? $this->entity_type_service->get_custom_fields_for_term($this->entity_type_service->get_term_by_slug('article'))
104
+			: $this->entity_type_service->get_custom_fields_for_post($post_id);
105 105
 
106
-		if ( isset( $custom_fields ) ) {
107
-			$this->process_type_custom_fields( $jsonld, $custom_fields, $post, $references, $references_infos );
106
+		if (isset($custom_fields)) {
107
+			$this->process_type_custom_fields($jsonld, $custom_fields, $post, $references, $references_infos);
108 108
 		}
109 109
 
110 110
 		// Set the published and modified dates.
@@ -117,19 +117,19 @@  discard block
 block discarded – undo
117 117
 		 */
118 118
 		try {
119 119
 			$default_timezone = date_default_timezone_get();
120
-			$timezone         = get_option( 'timezone_string' );
121
-			if ( ! empty( $timezone ) ) {
122
-				date_default_timezone_set( $timezone ); //phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set
123
-				$jsonld['datePublished'] = get_post_time( 'Y-m-d\TH:i:sP', false, $post );
124
-				$jsonld['dateModified']  = get_post_modified_time( 'Y-m-d\TH:i:sP', false, $post );
125
-				date_default_timezone_set( $default_timezone ); //phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set
120
+			$timezone         = get_option('timezone_string');
121
+			if ( ! empty($timezone)) {
122
+				date_default_timezone_set($timezone); //phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set
123
+				$jsonld['datePublished'] = get_post_time('Y-m-d\TH:i:sP', false, $post);
124
+				$jsonld['dateModified']  = get_post_modified_time('Y-m-d\TH:i:sP', false, $post);
125
+				date_default_timezone_set($default_timezone); //phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set
126 126
 			} else {
127
-				$jsonld['datePublished'] = get_post_time( 'Y-m-d\TH:i', true, $post, false );
128
-				$jsonld['dateModified']  = get_post_modified_time( 'Y-m-d\TH:i', true, $post, false );
127
+				$jsonld['datePublished'] = get_post_time('Y-m-d\TH:i', true, $post, false);
128
+				$jsonld['dateModified']  = get_post_modified_time('Y-m-d\TH:i', true, $post, false);
129 129
 			}
130
-		} catch ( Exception $e ) {
131
-			$jsonld['datePublished'] = get_post_time( 'Y-m-d\TH:i', true, $post, false );
132
-			$jsonld['dateModified']  = get_post_modified_time( 'Y-m-d\TH:i', true, $post, false );
130
+		} catch (Exception $e) {
131
+			$jsonld['datePublished'] = get_post_time('Y-m-d\TH:i', true, $post, false);
132
+			$jsonld['dateModified']  = get_post_modified_time('Y-m-d\TH:i', true, $post, false);
133 133
 		}
134 134
 
135 135
 		// Get the word count for the post.
@@ -140,8 +140,8 @@  discard block
 block discarded – undo
140 140
 		 *
141 141
 		 * @since 3.20.0
142 142
 		 */
143
-		if ( ! empty( $jsonld['@type'] ) && 'WebPage' !== $jsonld['@type'] ) {
144
-			$post_adapter        = new Wordlift_Post_Adapter( $post_id );
143
+		if ( ! empty($jsonld['@type']) && 'WebPage' !== $jsonld['@type']) {
144
+			$post_adapter        = new Wordlift_Post_Adapter($post_id);
145 145
 			$jsonld['wordCount'] = $post_adapter->word_count();
146 146
 		}
147 147
 
@@ -152,17 +152,17 @@  discard block
 block discarded – undo
152 152
 		 *
153 153
 		 * @since 3.27.2
154 154
 		 */
155
-		if ( ! empty( $jsonld['@type'] ) && 'WebPage' !== $jsonld['@type'] ) {
156
-			$post_adapter    = new Wordlift_Post_Adapter( $post_id );
155
+		if ( ! empty($jsonld['@type']) && 'WebPage' !== $jsonld['@type']) {
156
+			$post_adapter    = new Wordlift_Post_Adapter($post_id);
157 157
 			$keywords        = $post_adapter->keywords();
158 158
 			$article_section = $post_adapter->article_section();
159 159
 			$comment_count   = $post_adapter->comment_count();
160 160
 			$locale          = $post_adapter->locale();
161 161
 
162
-			if ( isset( $keywords ) ) {
162
+			if (isset($keywords)) {
163 163
 				$jsonld['keywords'] = $keywords;
164 164
 			}
165
-			if ( ! empty( $article_section ) ) {
165
+			if ( ! empty($article_section)) {
166 166
 				$jsonld['articleSection'] = $article_section;
167 167
 			}
168 168
 			$jsonld['commentCount'] = $comment_count;
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 		}
171 171
 
172 172
 		// Set the publisher.
173
-		$this->set_publisher( $jsonld );
173
+		$this->set_publisher($jsonld);
174 174
 
175 175
 		/**
176 176
 		 * Call the `wl_post_jsonld_author` filter.
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
 		$ret_val = apply_filters(
194 194
 			'wl_jsonld_author',
195 195
 			array(
196
-				'author'     => $this->get_author( $post->post_author, $references ),
196
+				'author'     => $this->get_author($post->post_author, $references),
197 197
 				'references' => $references,
198 198
 			),
199 199
 			$post_id
@@ -207,13 +207,13 @@  discard block
 block discarded – undo
207 207
 		 *
208 208
 		 * @since 3.53.2
209 209
 		 */
210
-		if ( ! empty( $ret_val['author'] ) ) {
210
+		if ( ! empty($ret_val['author'])) {
211 211
 			$jsonld['author'] = $ret_val['author'];
212 212
 			$references       = $ret_val['references'];
213 213
 		}
214 214
 
215 215
 		// Return the JSON-LD if filters are disabled by the client.
216
-		if ( $this->disable_convert_filters ) {
216
+		if ($this->disable_convert_filters) {
217 217
 			return $jsonld;
218 218
 		}
219 219
 
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
 		 *
259 259
 		 * @api
260 260
 		 */
261
-		return apply_filters( 'wl_post_jsonld', $jsonld, $post_id, $references );
261
+		return apply_filters('wl_post_jsonld', $jsonld, $post_id, $references);
262 262
 	}
263 263
 
264 264
 	/**
@@ -273,14 +273,14 @@  discard block
 block discarded – undo
273 273
 	 * @return string|array A JSON-LD structure.
274 274
 	 * @since 3.14.0
275 275
 	 */
276
-	public function get_author( $author_id, &$references ) {
276
+	public function get_author($author_id, &$references) {
277 277
 
278 278
 		// Get the entity bound to this user.
279
-		$entity_id = $this->user_service->get_entity( $author_id );
279
+		$entity_id = $this->user_service->get_entity($author_id);
280 280
 
281
-		if ( ! empty( $entity_id ) && 'publish' === get_post_status( $entity_id ) ) {
281
+		if ( ! empty($entity_id) && 'publish' === get_post_status($entity_id)) {
282 282
 			// Add the author to the references.
283
-			$author_uri   = Wordlift_Entity_Service::get_instance()->get_uri( $entity_id );
283
+			$author_uri   = Wordlift_Entity_Service::get_instance()->get_uri($entity_id);
284 284
 			$references[] = $entity_id;
285 285
 
286 286
 			// Return the JSON-LD for the referenced entity.
@@ -290,11 +290,11 @@  discard block
 block discarded – undo
290 290
 		}
291 291
 
292 292
 		// If there's no entity bound return a simple author structure.
293
-		if ( false !== get_userdata( $author_id ) ) {
294
-			$author            = get_the_author_meta( 'display_name', $author_id );
295
-			$author_first_name = get_the_author_meta( 'first_name', $author_id );
296
-			$author_last_name  = get_the_author_meta( 'last_name', $author_id );
297
-			$author_uri        = $this->user_service->get_uri( $author_id );
293
+		if (false !== get_userdata($author_id)) {
294
+			$author            = get_the_author_meta('display_name', $author_id);
295
+			$author_first_name = get_the_author_meta('first_name', $author_id);
296
+			$author_last_name  = get_the_author_meta('last_name', $author_id);
297
+			$author_uri        = $this->user_service->get_uri($author_id);
298 298
 
299 299
 			return array(
300 300
 				'@type'      => 'Person',
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
 				'name'       => $author,
303 303
 				'givenName'  => $author_first_name,
304 304
 				'familyName' => $author_last_name,
305
-				'url'        => get_author_posts_url( $author_id ),
305
+				'url'        => get_author_posts_url($author_id),
306 306
 			);
307 307
 		}
308 308
 
@@ -317,41 +317,41 @@  discard block
 block discarded – undo
317 317
 	 *
318 318
 	 * @since 3.10.0
319 319
 	 */
320
-	protected function set_publisher( &$params ) {
320
+	protected function set_publisher(&$params) {
321 321
 
322 322
 		// If the publisher id isn't set don't do anything.
323 323
 		$publisher_id = Wordlift_Configuration_Service::get_instance()->get_publisher_id();
324
-		if ( empty( $publisher_id ) ) {
324
+		if (empty($publisher_id)) {
325 325
 			return;
326 326
 		}
327 327
 
328 328
 		// Get the post instance.
329
-		$post = get_post( $publisher_id );
330
-		if ( ! is_a( $post, '\WP_Post' ) ) {
329
+		$post = get_post($publisher_id);
330
+		if ( ! is_a($post, '\WP_Post')) {
331 331
 			// Publisher not found.
332 332
 			return;
333 333
 		}
334 334
 
335 335
 		// Get the item id.
336
-		$id = Wordlift_Entity_Service::get_instance()->get_uri( $publisher_id );
336
+		$id = Wordlift_Entity_Service::get_instance()->get_uri($publisher_id);
337 337
 
338 338
 		// Get the type.
339
-		$type = $this->entity_type_service->get( $publisher_id );
339
+		$type = $this->entity_type_service->get($publisher_id);
340 340
 
341 341
 		// Get the name.
342 342
 		$name = $post->post_title;
343 343
 
344 344
 		// Set the publisher data.
345 345
 		$params['publisher'] = array(
346
-			'@type' => $this->relative_to_context( $type['uri'] ),
346
+			'@type' => $this->relative_to_context($type['uri']),
347 347
 			'@id'   => $id,
348 348
 			'name'  => $name,
349 349
 		);
350 350
 
351 351
 		// Add the sameAs values associated with the publisher.
352 352
 		$storage_factory = Wordlift_Storage_Factory::get_instance();
353
-		$sameas          = $storage_factory->post_meta( Wordlift_Schema_Service::FIELD_SAME_AS )->get( $publisher_id );
354
-		if ( ! empty( $sameas ) ) {
353
+		$sameas          = $storage_factory->post_meta(Wordlift_Schema_Service::FIELD_SAME_AS)->get($publisher_id);
354
+		if ( ! empty($sameas)) {
355 355
 			$params['publisher']['sameAs'] = $sameas;
356 356
 		}
357 357
 
@@ -359,15 +359,15 @@  discard block
 block discarded – undo
359 359
 		// support the logo property.
360 360
 		//
361 361
 		// See http://schema.org/logo.
362
-		if ( 1 !== preg_match( '~Organization$~', $type['uri'] ) ) {
362
+		if (1 !== preg_match('~Organization$~', $type['uri'])) {
363 363
 			return;
364 364
 		}
365 365
 
366 366
 		// Get the publisher logo.
367
-		$publisher_logo = $this->get_publisher_logo( $post->ID );
367
+		$publisher_logo = $this->get_publisher_logo($post->ID);
368 368
 
369 369
 		// Bail out if the publisher logo isn't set.
370
-		if ( false === $publisher_logo ) {
370
+		if (false === $publisher_logo) {
371 371
 			return;
372 372
 		}
373 373
 
@@ -401,14 +401,14 @@  discard block
 block discarded – undo
401 401
 	 * @since 3.19.2
402 402
 	 * @see https://github.com/insideout10/wordlift-plugin/issues/823 related issue.
403 403
 	 */
404
-	private function get_publisher_logo( $post_id ) {
404
+	private function get_publisher_logo($post_id) {
405 405
 
406 406
 		// Get the featured image for the post.
407
-		$thumbnail_id = get_post_thumbnail_id( $post_id );
407
+		$thumbnail_id = get_post_thumbnail_id($post_id);
408 408
 
409 409
 		// Bail out if thumbnail not available.
410
-		if ( empty( $thumbnail_id ) || 0 === $thumbnail_id ) {
411
-			$this->log->info( "Featured image not set for post $post_id." );
410
+		if (empty($thumbnail_id) || 0 === $thumbnail_id) {
411
+			$this->log->info("Featured image not set for post $post_id.");
412 412
 
413 413
 			return false;
414 414
 		}
@@ -417,24 +417,24 @@  discard block
 block discarded – undo
417 417
 		$uploads_dir = wp_upload_dir();
418 418
 
419 419
 		// Get the attachment metadata.
420
-		$metadata = wp_get_attachment_metadata( $thumbnail_id );
420
+		$metadata = wp_get_attachment_metadata($thumbnail_id);
421 421
 
422 422
 		// Bail out if the file isn't set.
423
-		if ( ! isset( $metadata['file'] ) ) {
424
-			$this->log->warn( "Featured image file not found for post $post_id." );
423
+		if ( ! isset($metadata['file'])) {
424
+			$this->log->warn("Featured image file not found for post $post_id.");
425 425
 
426 426
 			return false;
427 427
 		}
428 428
 
429 429
 		// Retrieve the relative filename, e.g. "2018/05/logo_publisher.png"
430
-		$path = $uploads_dir['basedir'] . DIRECTORY_SEPARATOR . $metadata['file'];
430
+		$path = $uploads_dir['basedir'].DIRECTORY_SEPARATOR.$metadata['file'];
431 431
 
432 432
 		// Use image src, if local file does not exist. @see https://github.com/insideout10/wordlift-plugin/issues/1149
433
-		if ( ! file_exists( $path ) ) {
434
-			$this->log->warn( "Featured image file $path doesn't exist for post $post_id." );
433
+		if ( ! file_exists($path)) {
434
+			$this->log->warn("Featured image file $path doesn't exist for post $post_id.");
435 435
 
436
-			$attachment_image_src = wp_get_attachment_image_src( $thumbnail_id, '' );
437
-			if ( $attachment_image_src ) {
436
+			$attachment_image_src = wp_get_attachment_image_src($thumbnail_id, '');
437
+			if ($attachment_image_src) {
438 438
 				return array(
439 439
 					'url'    => $attachment_image_src[0],
440 440
 					'width'  => $attachment_image_src[1],
@@ -448,27 +448,27 @@  discard block
 block discarded – undo
448 448
 		}
449 449
 
450 450
 		// Try to get the image editor and bail out if the editor cannot be instantiated.
451
-		$original_file_editor = wp_get_image_editor( $path );
452
-		if ( is_wp_error( $original_file_editor ) ) {
453
-			$this->log->warn( "Cannot instantiate WP Image Editor on file $path for post $post_id." );
451
+		$original_file_editor = wp_get_image_editor($path);
452
+		if (is_wp_error($original_file_editor)) {
453
+			$this->log->warn("Cannot instantiate WP Image Editor on file $path for post $post_id.");
454 454
 
455 455
 			return false;
456 456
 		}
457 457
 
458 458
 		// Generate the publisher logo filename, we cannot use the `width` and `height` because we're scaling
459 459
 		// and we don't actually know the end values.
460
-		$publisher_logo_path = $original_file_editor->generate_filename( '-publisher-logo' );
460
+		$publisher_logo_path = $original_file_editor->generate_filename('-publisher-logo');
461 461
 
462 462
 		// If the file doesn't exist yet, create it.
463
-		if ( ! file_exists( $publisher_logo_path ) ) {
464
-			$original_file_editor->resize( 600, 60 );
465
-			$original_file_editor->save( $publisher_logo_path );
463
+		if ( ! file_exists($publisher_logo_path)) {
464
+			$original_file_editor->resize(600, 60);
465
+			$original_file_editor->save($publisher_logo_path);
466 466
 		}
467 467
 
468 468
 		// Try to get the image editor and bail out if the editor cannot be instantiated.
469
-		$publisher_logo_editor = wp_get_image_editor( $publisher_logo_path );
470
-		if ( is_wp_error( $publisher_logo_editor ) ) {
471
-			$this->log->warn( "Cannot instantiate WP Image Editor on file $publisher_logo_path for post $post_id." );
469
+		$publisher_logo_editor = wp_get_image_editor($publisher_logo_path);
470
+		if (is_wp_error($publisher_logo_editor)) {
471
+			$this->log->warn("Cannot instantiate WP Image Editor on file $publisher_logo_path for post $post_id.");
472 472
 
473 473
 			return false;
474 474
 		}
@@ -478,7 +478,7 @@  discard block
 block discarded – undo
478 478
 
479 479
 		// Finally return the array with data.
480 480
 		return array(
481
-			'url'    => $uploads_dir['baseurl'] . substr( $publisher_logo_path, strlen( $uploads_dir['basedir'] ) ),
481
+			'url'    => $uploads_dir['baseurl'].substr($publisher_logo_path, strlen($uploads_dir['basedir'])),
482 482
 			'width'  => $size['width'],
483 483
 			'height' => $size['height'],
484 484
 		);
Please login to merge, or discard this patch.
src/includes/class-wordlift-entity-type-service.php 1 patch
Spacing   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
 	 */
45 45
 	protected function __construct() {
46 46
 
47
-		$this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Entity_Type_Service' );
47
+		$this->log = Wordlift_Log_Service::get_logger('Wordlift_Entity_Type_Service');
48 48
 
49 49
 		$this->schema_service = Wordlift_Schema_Service::get_instance();
50 50
 
@@ -61,11 +61,11 @@  discard block
 block discarded – undo
61 61
 
62 62
 		add_action(
63 63
 			'init',
64
-			function () {
64
+			function() {
65 65
 				// Add post type support for 'custom-fields' for all post types. Specifically needed in Gutenberg
66 66
 				$post_types = get_post_types();
67
-				foreach ( $post_types as $post_type ) {
68
-					add_post_type_support( $post_type, 'custom-fields' );
67
+				foreach ($post_types as $post_type) {
68
+					add_post_type_support($post_type, 'custom-fields');
69 69
 				}
70 70
 			}
71 71
 		);
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 	 */
89 89
 	public static function get_instance() {
90 90
 
91
-		if ( ! isset( self::$instance ) ) {
91
+		if ( ! isset(self::$instance)) {
92 92
 			self::$instance = new self();
93 93
 		}
94 94
 
@@ -126,34 +126,34 @@  discard block
 block discarded – undo
126 126
 	 *      c) the post is a custom post type then it is
127 127
 	 *          assigned the `WebPage` entity type by default.
128 128
 	 */
129
-	public function get( $post_id ) {
129
+	public function get($post_id) {
130 130
 
131
-		$this->log->trace( "Getting the post type for post $post_id..." );
131
+		$this->log->trace("Getting the post type for post $post_id...");
132 132
 
133 133
 		// Get the post type.
134
-		$post_type = get_post_type( $post_id );
134
+		$post_type = get_post_type($post_id);
135 135
 
136 136
 		// Return `web-page` for non entities.
137
-		if ( ! self::is_valid_entity_post_type( $post_type ) ) {
138
-			$this->log->info( "Returning `web-page` for post $post_id." );
137
+		if ( ! self::is_valid_entity_post_type($post_type)) {
138
+			$this->log->info("Returning `web-page` for post $post_id.");
139 139
 
140
-			return $this->schema_service->get_schema( 'web-page' );
140
+			return $this->schema_service->get_schema('web-page');
141 141
 		}
142 142
 
143 143
 		// Get the type from the associated classification.
144
-		$terms = wp_get_object_terms( $post_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
144
+		$terms = wp_get_object_terms($post_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME);
145 145
 
146 146
 		// Return the schema type if there is a term found.
147
-		if ( ! is_wp_error( $terms ) && ! empty( $terms ) ) {
147
+		if ( ! is_wp_error($terms) && ! empty($terms)) {
148 148
 			// Cycle through the terms and return the first one with a valid schema.
149
-			foreach ( $terms as $term ) {
150
-				$this->log->debug( "Found `{$term->slug}` term for post $post_id." );
149
+			foreach ($terms as $term) {
150
+				$this->log->debug("Found `{$term->slug}` term for post $post_id.");
151 151
 
152 152
 				// Try to get the schema for the term.
153
-				$schema = $this->schema_service->get_schema( $term->slug );
153
+				$schema = $this->schema_service->get_schema($term->slug);
154 154
 
155 155
 				// If found, return it, ignoring the other types.
156
-				if ( null !== $schema ) {
156
+				if (null !== $schema) {
157 157
 					// Return the entity type with the specified id.
158 158
 					return $schema;
159 159
 				}
@@ -169,22 +169,22 @@  discard block
 block discarded – undo
169 169
 			 * @since 3.20.0
170 170
 			 */
171 171
 
172
-			return $this->schema_service->get_schema( 'thing' );
172
+			return $this->schema_service->get_schema('thing');
173 173
 		}
174 174
 
175 175
 		// If it's a page or post return `Article`.
176
-		if ( in_array( $post_type, array( 'post', 'page' ), true ) ) {
177
-			$this->log->debug( "Post $post_id has no terms, and it's a `post` type, returning `Article`." );
176
+		if (in_array($post_type, array('post', 'page'), true)) {
177
+			$this->log->debug("Post $post_id has no terms, and it's a `post` type, returning `Article`.");
178 178
 
179 179
 			// Return "Article" schema type for posts.
180
-			return $this->schema_service->get_schema( 'article' );
180
+			return $this->schema_service->get_schema('article');
181 181
 		}
182 182
 
183 183
 		// Return "Thing" schema type for entities.
184
-		$this->log->debug( "Post $post_id has no terms, but it's a `wl_entity` type, returning `Thing`." );
184
+		$this->log->debug("Post $post_id has no terms, but it's a `wl_entity` type, returning `Thing`.");
185 185
 
186 186
 		// Return the entity type with the specified id.
187
-		return $this->schema_service->get_schema( 'thing' );
187
+		return $this->schema_service->get_schema('thing');
188 188
 
189 189
 	}
190 190
 
@@ -196,9 +196,9 @@  discard block
 block discarded – undo
196 196
 	 * @return array|WP_Error An array of entity types ids or a {@link WP_Error}.
197 197
 	 * @since 3.20.0
198 198
 	 */
199
-	public function get_ids( $post_id ) {
199
+	public function get_ids($post_id) {
200 200
 
201
-		return wp_get_object_terms( $post_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, array( 'fields' => 'ids' ) );
201
+		return wp_get_object_terms($post_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, array('fields' => 'ids'));
202 202
 	}
203 203
 
204 204
 	/**
@@ -209,16 +209,16 @@  discard block
 block discarded – undo
209 209
 	 * @return array|WP_Error An array of entity types camel case names or a {@link WP_Error}.
210 210
 	 * @since 3.20.0
211 211
 	 */
212
-	public function get_names( $post_id ) {
212
+	public function get_names($post_id) {
213 213
 
214
-		$ids = $this->get_ids( $post_id );
214
+		$ids = $this->get_ids($post_id);
215 215
 
216 216
 		// Filter out invalid terms (ones without _wl_name term meta)
217 217
 		return array_values(
218 218
 			array_filter(
219 219
 				array_map(
220
-					function ( $id ) {
221
-						return get_term_meta( $id, '_wl_name', true );
220
+					function($id) {
221
+						return get_term_meta($id, '_wl_name', true);
222 222
 					},
223 223
 					$ids
224 224
 				)
@@ -235,25 +235,25 @@  discard block
 block discarded – undo
235 235
 	 *
236 236
 	 * @since 3.8.0
237 237
 	 */
238
-	public function set( $post_id, $type_uri, $replace = true ) {
238
+	public function set($post_id, $type_uri, $replace = true) {
239 239
 
240 240
 		// If the type URI is empty we remove the type.
241
-		if ( empty( $type_uri ) ) {
242
-			$this->log->debug( "Removing entity type for post $post_id..." );
241
+		if (empty($type_uri)) {
242
+			$this->log->debug("Removing entity type for post $post_id...");
243 243
 
244
-			wp_set_object_terms( $post_id, null, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
244
+			wp_set_object_terms($post_id, null, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME);
245 245
 
246 246
 			return;
247 247
 		}
248 248
 
249
-		$this->log->debug( "Setting entity type for post $post_id..." );
249
+		$this->log->debug("Setting entity type for post $post_id...");
250 250
 
251 251
 		// if the `$type_uri` starts with `wl-`, we're looking at the class name, which is `wl-` + slug.
252
-		$term = ( 0 === strpos( $type_uri, 'wl-' ) )
252
+		$term = (0 === strpos($type_uri, 'wl-'))
253 253
 			// Get term by slug.
254
-			? $this->get_term_by_slug( substr( $type_uri, 3 ) )
254
+			? $this->get_term_by_slug(substr($type_uri, 3))
255 255
 			// Get term by URI.
256
-			: $this->get_term_by_uri( $type_uri );
256
+			: $this->get_term_by_uri($type_uri);
257 257
 
258 258
 		/*
259 259
 		 * We always want to assign a type to an entity otherwise it won't show in the Vocabulary and it won't be
@@ -266,22 +266,22 @@  discard block
 block discarded – undo
266 266
 		 *
267 267
 		 * @since 3.23.4
268 268
 		 */
269
-		if ( false === $term ) {
270
-			$this->log->warn( "No term found for URI $type_uri, will use Thing." );
269
+		if (false === $term) {
270
+			$this->log->warn("No term found for URI $type_uri, will use Thing.");
271 271
 
272
-			$term = $this->get_term_by_slug( 'thing' );
272
+			$term = $this->get_term_by_slug('thing');
273 273
 
274 274
 			// We still need to be able to bali out here, for example WordPress 5.1 tests create posts before our taxonomy
275 275
 			// is installed.
276
-			if ( false === $term ) {
276
+			if (false === $term) {
277 277
 				return;
278 278
 			}
279 279
 		}
280 280
 
281
-		$this->log->debug( "Setting entity type [ post id :: $post_id ][ term id :: $term->term_id ][ term slug :: $term->slug ][ type uri :: $type_uri ]..." );
281
+		$this->log->debug("Setting entity type [ post id :: $post_id ][ term id :: $term->term_id ][ term slug :: $term->slug ][ type uri :: $type_uri ]...");
282 282
 
283 283
 		// `$replace` is passed to decide whether to replace or append the term.
284
-		wp_set_object_terms( $post_id, $term->term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, ! $replace );
284
+		wp_set_object_terms($post_id, $term->term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, ! $replace);
285 285
 
286 286
 	}
287 287
 
@@ -294,9 +294,9 @@  discard block
 block discarded – undo
294 294
 	 *                             or `$term` was not found.
295 295
 	 * @since 3.20.0
296 296
 	 */
297
-	public function get_term_by_slug( $slug ) {
297
+	public function get_term_by_slug($slug) {
298 298
 
299
-		return get_term_by( 'slug', $slug, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
299
+		return get_term_by('slug', $slug, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME);
300 300
 	}
301 301
 
302 302
 	/**
@@ -308,7 +308,7 @@  discard block
 block discarded – undo
308 308
 	 *                             or `$term` was not found.
309 309
 	 * @since 3.20.0
310 310
 	 */
311
-	public function get_term_by_uri( $uri ) {
311
+	public function get_term_by_uri($uri) {
312 312
 
313 313
 		$terms = get_terms(
314 314
 			Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME,
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
 			)
330 330
 		);
331 331
 
332
-		return is_array( $terms ) && ! empty( $terms ) ? $terms[0] : false;
332
+		return is_array($terms) && ! empty($terms) ? $terms[0] : false;
333 333
 	}
334 334
 
335 335
 	/**
@@ -342,19 +342,19 @@  discard block
 block discarded – undo
342 342
 	 * @return bool True if an entity type is set otherwise false.
343 343
 	 * @since 3.15.0
344 344
 	 */
345
-	public function has_entity_type( $post_id, $uri = null ) {
345
+	public function has_entity_type($post_id, $uri = null) {
346 346
 
347
-		$this->log->debug( "Checking if post $post_id has an entity type [ $uri ]..." );
347
+		$this->log->debug("Checking if post $post_id has an entity type [ $uri ]...");
348 348
 
349 349
 		// If an URI hasn't been specified just check whether we have at least
350 350
 		// one entity type.
351
-		if ( null === $uri ) {
352
-			return has_term( '', Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, $post_id );
351
+		if (null === $uri) {
352
+			return has_term('', Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, $post_id);
353 353
 		}
354 354
 
355
-		$has_entity_type = $this->has_post_term_by_uri( $post_id, $uri );
355
+		$has_entity_type = $this->has_post_term_by_uri($post_id, $uri);
356 356
 
357
-		$this->log->debug( "Post $post_id has $uri type: " . ( $has_entity_type ? 'yes' : 'no' ) );
357
+		$this->log->debug("Post $post_id has $uri type: ".($has_entity_type ? 'yes' : 'no'));
358 358
 
359 359
 		// Check whether the post has an entity type with that URI.
360 360
 		return $has_entity_type;
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
 	 * @return array|WP_Error An array of entity types' terms or {@link WP_Error}.
369 369
 	 * @since 3.15.0
370 370
 	 */
371
-	private function get_post_terms( $post_id ) {
371
+	private function get_post_terms($post_id) {
372 372
 
373 373
 		return wp_get_object_terms(
374 374
 			$post_id,
@@ -396,15 +396,15 @@  discard block
 block discarded – undo
396 396
 	 *
397 397
 	 * @since 3.20.0 function renamed to `has_post_term_by_uri` and return type changed to `bool`.
398 398
 	 */
399
-	private function has_post_term_by_uri( $post_id, $uri ) {
399
+	private function has_post_term_by_uri($post_id, $uri) {
400 400
 
401 401
 		// Get the post terms bound to the specified post.
402
-		$terms = $this->get_post_terms( $post_id );
402
+		$terms = $this->get_post_terms($post_id);
403 403
 
404 404
 		// Look for a term if the specified URI.
405
-		foreach ( $terms as $term ) {
406
-			$term_uri = get_term_meta( $term->term_id, '_wl_uri', true );
407
-			if ( $uri === $term_uri ) {
405
+		foreach ($terms as $term) {
406
+			$term_uri = get_term_meta($term->term_id, '_wl_uri', true);
407
+			if ($uri === $term_uri) {
408 408
 				return true;
409 409
 			}
410 410
 		}
@@ -421,26 +421,26 @@  discard block
 block discarded – undo
421 421
 	 * @return array An array of custom fields (see `custom_fields` in Wordlift_Schema_Service).
422 422
 	 * @since 3.25.2
423 423
 	 */
424
-	public function get_custom_fields_for_post( $post_id ) {
424
+	public function get_custom_fields_for_post($post_id) {
425 425
 
426 426
 		// Return custom fields for this specific entity's type.
427
-		$types = $this->get_ids( $post_id );
427
+		$types = $this->get_ids($post_id);
428 428
 
429 429
 		/** @var WP_Term[] $terms */
430 430
 		$terms = array_filter(
431 431
 			array_map(
432
-				function ( $item ) {
433
-					return get_term( $item );
432
+				function($item) {
433
+					return get_term($item);
434 434
 				},
435 435
 				$types
436 436
 			),
437
-			function ( $item ) {
438
-				return isset( $item ) && is_a( $item, 'WP_Term' );
437
+			function($item) {
438
+				return isset($item) && is_a($item, 'WP_Term');
439 439
 			}
440 440
 		);
441 441
 
442 442
 		$term_slugs = array_map(
443
-			function ( $item ) {
443
+			function($item) {
444 444
 				return $item->slug;
445 445
 			},
446 446
 			$terms
@@ -448,7 +448,7 @@  discard block
 block discarded – undo
448 448
 
449 449
 		$term_slugs[] = 'thing';
450 450
 
451
-		return $this->get_custom_fields_by_term_slugs( $term_slugs );
451
+		return $this->get_custom_fields_by_term_slugs($term_slugs);
452 452
 	}
453 453
 
454 454
 	/**
@@ -459,12 +459,12 @@  discard block
 block discarded – undo
459 459
 	 * @return array An array of custom fields (see `custom_fields` in Wordlift_Schema_Service).
460 460
 	 * @since 3.32.0
461 461
 	 */
462
-	public function get_custom_fields_for_term( $term_id ) {
463
-		$selected_entity_types   = get_term_meta( $term_id, 'wl_entity_type' );
462
+	public function get_custom_fields_for_term($term_id) {
463
+		$selected_entity_types   = get_term_meta($term_id, 'wl_entity_type');
464 464
 		$selected_entity_types[] = 'thing';
465
-		$selected_entity_types   = array_unique( $selected_entity_types );
465
+		$selected_entity_types   = array_unique($selected_entity_types);
466 466
 
467
-		return $this->get_custom_fields_by_term_slugs( $selected_entity_types );
467
+		return $this->get_custom_fields_by_term_slugs($selected_entity_types);
468 468
 	}
469 469
 
470 470
 	/**
@@ -478,9 +478,9 @@  discard block
 block discarded – undo
478 478
 	 * @return bool Return true if the post type can be used for entities, otherwise false.
479 479
 	 * @since 3.15.0
480 480
 	 */
481
-	public static function is_valid_entity_post_type( $post_type ) {
481
+	public static function is_valid_entity_post_type($post_type) {
482 482
 
483
-		return in_array( $post_type, Wordlift_Entity_Service::valid_entity_post_types(), true );
483
+		return in_array($post_type, Wordlift_Entity_Service::valid_entity_post_types(), true);
484 484
 	}
485 485
 
486 486
 	/**
@@ -488,16 +488,16 @@  discard block
 block discarded – undo
488 488
 	 *
489 489
 	 * @return array
490 490
 	 */
491
-	private function get_custom_fields_by_term_slugs( $term_slugs ) {
491
+	private function get_custom_fields_by_term_slugs($term_slugs) {
492 492
 		$schema_service = Wordlift_Schema_Service::get_instance();
493 493
 
494 494
 		return array_reduce(
495 495
 			$term_slugs,
496
-			function ( $carry, $item ) use ( $schema_service ) {
496
+			function($carry, $item) use ($schema_service) {
497 497
 
498
-				$schema = $schema_service->get_schema( $item );
498
+				$schema = $schema_service->get_schema($item);
499 499
 
500
-				if ( ! isset( $schema['custom_fields'] ) ) {
500
+				if ( ! isset($schema['custom_fields'])) {
501 501
 					return $carry;
502 502
 				}
503 503
 
Please login to merge, or discard this patch.
src/wordlift.php 1 patch
Spacing   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -31,27 +31,27 @@  discard block
 block discarded – undo
31 31
 use Wordlift\Features\Features_Registry;
32 32
 use Wordlift\Post\Post_Adapter;
33 33
 
34
-define( 'WORDLIFT_PLUGIN_FILE', __FILE__ );
35
-define( 'WORDLIFT_VERSION', '3.53.0-0' );
36
-define( 'WORDLIFT_VERSION', '3.52.7' );
34
+define('WORDLIFT_PLUGIN_FILE', __FILE__);
35
+define('WORDLIFT_VERSION', '3.53.0-0');
36
+define('WORDLIFT_VERSION', '3.52.7');
37 37
 
38 38
 // ## DO NOT REMOVE THIS LINE: WHITELABEL PLACEHOLDER ##
39 39
 
40
-require_once plugin_dir_path( __FILE__ ) . '/libraries/action-scheduler/action-scheduler.php';
41
-require_once __DIR__ . '/modules/common/load.php';
42
-require_once __DIR__ . '/modules/app/load.php';
43
-require_once __DIR__ . '/modules/include-exclude/load.php';
40
+require_once plugin_dir_path(__FILE__).'/libraries/action-scheduler/action-scheduler.php';
41
+require_once __DIR__.'/modules/common/load.php';
42
+require_once __DIR__.'/modules/app/load.php';
43
+require_once __DIR__.'/modules/include-exclude/load.php';
44 44
 
45 45
 /**
46 46
  * Filter to disable WLP on any request, defaults to true.
47 47
  *
48 48
  * @since 3.33.6
49 49
  */
50
-if ( ! apply_filters( 'wl_is_enabled', true ) ) {
50
+if ( ! apply_filters('wl_is_enabled', true)) {
51 51
 	return;
52 52
 }
53 53
 
54
-require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php';
54
+require_once plugin_dir_path(__FILE__).'vendor/autoload.php';
55 55
 
56 56
 /*
57 57
  * We introduce the WordLift autoloader, since we start using classes in namespaces, i.e. Wordlift\Http.
@@ -61,15 +61,15 @@  discard block
 block discarded – undo
61 61
 wordlift_plugin_autoload_register();
62 62
 
63 63
 // Include WordLift constants.
64
-require_once plugin_dir_path( __FILE__ ) . 'wordlift-constants.php';
64
+require_once plugin_dir_path(__FILE__).'wordlift-constants.php';
65 65
 
66 66
 // Load modules.
67
-require_once plugin_dir_path( __FILE__ ) . 'modules/core/wordlift-core.php';
67
+require_once plugin_dir_path(__FILE__).'modules/core/wordlift-core.php';
68 68
 
69
-require_once plugin_dir_path( __FILE__ ) . 'deprecations.php';
69
+require_once plugin_dir_path(__FILE__).'deprecations.php';
70 70
 
71 71
 // Load early to enable/disable features.
72
-require_once plugin_dir_path( __FILE__ ) . 'classes/features/index.php';
72
+require_once plugin_dir_path(__FILE__).'classes/features/index.php';
73 73
 
74 74
 /**
75 75
  * The code that runs during plugin activation.
@@ -77,11 +77,11 @@  discard block
 block discarded – undo
77 77
  */
78 78
 function activate_wordlift() {
79 79
 
80
-	$log = Wordlift_Log_Service::get_logger( 'activate_wordlift' );
80
+	$log = Wordlift_Log_Service::get_logger('activate_wordlift');
81 81
 
82
-	$log->info( 'Activating WordLift...' );
82
+	$log->info('Activating WordLift...');
83 83
 
84
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php';
84
+	require_once plugin_dir_path(__FILE__).'includes/class-wordlift-activator.php';
85 85
 	Wordlift_Activator::activate();
86 86
 
87 87
 	/**
@@ -101,8 +101,8 @@  discard block
 block discarded – undo
101 101
 	 */
102 102
 	Top_Entities::activate();
103 103
 
104
-	if ( ! wp_next_scheduled( 'wl_daily_cron' ) ) {
105
-		wp_schedule_event( time(), 'daily', 'wl_daily_cron' );
104
+	if ( ! wp_next_scheduled('wl_daily_cron')) {
105
+		wp_schedule_event(time(), 'daily', 'wl_daily_cron');
106 106
 	}
107 107
 
108 108
 }
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
  */
114 114
 function deactivate_wordlift() {
115 115
 
116
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php';
116
+	require_once plugin_dir_path(__FILE__).'includes/class-wordlift-deactivator.php';
117 117
 	Wordlift_Deactivator::deactivate();
118 118
 	Wordlift_Http_Api::deactivate();
119 119
 	Ttl_Cache_Cleaner::deactivate();
@@ -129,18 +129,18 @@  discard block
 block discarded – undo
129 129
 	Key_Validation_Notice::remove_notification_flag();
130 130
 	flush_rewrite_rules();
131 131
 
132
-	wp_clear_scheduled_hook( 'wl_daily_cron' );
132
+	wp_clear_scheduled_hook('wl_daily_cron');
133 133
 
134 134
 }
135 135
 
136
-register_activation_hook( __FILE__, 'activate_wordlift' );
137
-register_deactivation_hook( __FILE__, 'deactivate_wordlift' );
136
+register_activation_hook(__FILE__, 'activate_wordlift');
137
+register_deactivation_hook(__FILE__, 'deactivate_wordlift');
138 138
 
139 139
 /**
140 140
  * The core plugin class that is used to define internationalization,
141 141
  * admin-specific hooks, and public-facing site hooks.
142 142
  */
143
-require plugin_dir_path( __FILE__ ) . 'includes/class-wordlift.php';
143
+require plugin_dir_path(__FILE__).'includes/class-wordlift.php';
144 144
 
145 145
 /**
146 146
  * Begins execution of the plugin.
@@ -160,12 +160,12 @@  discard block
 block discarded – undo
160 160
 	 * @return bool
161 161
 	 * @since 3.27.6
162 162
 	 */
163
-	if ( apply_filters( 'wl_feature__enable__widgets', true ) ) {
164
-		add_action( 'widgets_init', 'wl_register_chord_widget' );
165
-		add_action( 'widgets_init', 'wl_register_geo_widget' );
166
-		add_action( 'widgets_init', 'wl_register_timeline_widget' );
163
+	if (apply_filters('wl_feature__enable__widgets', true)) {
164
+		add_action('widgets_init', 'wl_register_chord_widget');
165
+		add_action('widgets_init', 'wl_register_geo_widget');
166
+		add_action('widgets_init', 'wl_register_timeline_widget');
167 167
 	}
168
-	add_filter( 'widget_text', 'do_shortcode' );
168
+	add_filter('widget_text', 'do_shortcode');
169 169
 
170 170
 	/**
171 171
 	 * Filter: wl_feature__enable__analysis
@@ -175,10 +175,10 @@  discard block
 block discarded – undo
175 175
 	 * @return bool
176 176
 	 * @since 3.27.6
177 177
 	 */
178
-	if ( apply_filters( 'wl_feature__enable__analysis', true ) ) {
179
-		add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_action' );
178
+	if (apply_filters('wl_feature__enable__analysis', true)) {
179
+		add_action('wp_ajax_wl_analyze', 'wl_ajax_analyze_action');
180 180
 	} else {
181
-		add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action' );
181
+		add_action('wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action');
182 182
 	}
183 183
 
184 184
 	$plugin = new Wordlift();
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
 
196 196
 	add_action(
197 197
 		'plugins_loaded',
198
-		function () {
198
+		function() {
199 199
 			// All features from registry should be initialized here.
200 200
 			$features_registry = Features_Registry::get_instance();
201 201
 			$features_registry->initialize_all_features();
@@ -206,27 +206,27 @@  discard block
 block discarded – undo
206 206
 	add_action(
207 207
 		'plugins_loaded',
208 208
 		// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
209
-		function () use ( $plugin ) {
209
+		function() use ($plugin) {
210 210
 
211 211
 			new Wordlift_Products_Navigator_Shortcode_REST();
212 212
 
213 213
 			// Register the Dataset module, requires `$api_service`.
214
-			require_once plugin_dir_path( __FILE__ ) . 'classes/dataset/index.php';
215
-			require_once plugin_dir_path( __FILE__ ) . 'classes/shipping-data/index.php';
214
+			require_once plugin_dir_path(__FILE__).'classes/dataset/index.php';
215
+			require_once plugin_dir_path(__FILE__).'classes/shipping-data/index.php';
216 216
 
217 217
 			/*
218 218
 			* Require the Entity annotation cleanup module.
219 219
 			*
220 220
 			* @since 3.34.6
221 221
 			*/
222
-			require_once plugin_dir_path( __FILE__ ) . 'classes/cleanup/index.php';
222
+			require_once plugin_dir_path(__FILE__).'classes/cleanup/index.php';
223 223
 
224 224
 			/*
225 225
 			* Import LOD entities.
226 226
 			*
227 227
 			* @since 3.35.0
228 228
 			*/
229
-			require_once plugin_dir_path( __FILE__ ) . 'classes/lod-import/index.php';
229
+			require_once plugin_dir_path(__FILE__).'classes/lod-import/index.php';
230 230
 
231 231
 		}
232 232
 	);
@@ -244,31 +244,31 @@  discard block
 block discarded – undo
244 244
 function wordlift_plugin_autoload_register() {
245 245
 
246 246
 	spl_autoload_register(
247
-		function ( $class_name ) {
247
+		function($class_name) {
248 248
 
249 249
 			// Bail out if these are not our classes.
250
-			if ( 0 !== strpos( $class_name, 'Wordlift\\' ) ) {
250
+			if (0 !== strpos($class_name, 'Wordlift\\')) {
251 251
 				return false;
252 252
 			}
253 253
 
254
-			$class_name_lc = strtolower( str_replace( '_', '-', $class_name ) );
254
+			$class_name_lc = strtolower(str_replace('_', '-', $class_name));
255 255
 
256
-			preg_match( '|^wordlift\\\\(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches );
256
+			preg_match('|^wordlift\\\\(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches);
257 257
 
258
-			$path = str_replace( '\\', DIRECTORY_SEPARATOR, $matches[1] );
259
-			$file = 'class-' . $matches[2] . '.php';
258
+			$path = str_replace('\\', DIRECTORY_SEPARATOR, $matches[1]);
259
+			$file = 'class-'.$matches[2].'.php';
260 260
 
261
-			$full_path = plugin_dir_path( __FILE__ ) . 'classes' . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . $file;
261
+			$full_path = plugin_dir_path(__FILE__).'classes'.DIRECTORY_SEPARATOR.$path.DIRECTORY_SEPARATOR.$file;
262 262
 
263
-			if ( ! file_exists( $full_path ) ) {
263
+			if ( ! file_exists($full_path)) {
264 264
 				return false;
265 265
 			}
266 266
 
267 267
 			try {
268 268
 				require_once $full_path;
269
-			} catch ( Exception $e ) {
269
+			} catch (Exception $e) {
270 270
 				// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
271
-				error_log( "[WordLift] $full_path not found, cannot include." );
271
+				error_log("[WordLift] $full_path not found, cannot include.");
272 272
 			}
273 273
 
274 274
 			return true;
@@ -277,13 +277,13 @@  discard block
 block discarded – undo
277 277
 
278 278
 }
279 279
 
280
-function wl_block_categories( $categories ) {
280
+function wl_block_categories($categories) {
281 281
 	return array_merge(
282 282
 		$categories,
283 283
 		array(
284 284
 			array(
285 285
 				'slug'  => 'wordlift',
286
-				'title' => __( 'WordLift', 'wordlift' ),
286
+				'title' => __('WordLift', 'wordlift'),
287 287
 			),
288 288
 		)
289 289
 	);
@@ -293,52 +293,52 @@  discard block
 block discarded – undo
293 293
  * This function is created temporarily to handle the legacy library,
294 294
  * this has to be removed when removing the legacy fields from the ui.
295 295
  */
296
-function wl_enqueue_leaflet( $in_footer = false ) {
296
+function wl_enqueue_leaflet($in_footer = false) {
297 297
 	// Leaflet.
298
-	wp_enqueue_style( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.css', array(), '1.6.0' );
299
-	wp_enqueue_script( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.js', array(), '1.6.0', $in_footer );
298
+	wp_enqueue_style('wl-leaflet', plugin_dir_url(__FILE__).'js/leaflet/leaflet.css', array(), '1.6.0');
299
+	wp_enqueue_script('wl-leaflet', plugin_dir_url(__FILE__).'js/leaflet/leaflet.js', array(), '1.6.0', $in_footer);
300 300
 }
301 301
 
302
-add_filter( 'block_categories', 'wl_block_categories', 10 );
302
+add_filter('block_categories', 'wl_block_categories', 10);
303 303
 
304 304
 // Temporary fix for a typo in WooCommerce Extension.
305 305
 add_filter(
306 306
 	'wl_feature__enable__dataset',
307
-	function ( $value ) {
308
-		return apply_filters( 'wl_features__enable__dataset', $value );
307
+	function($value) {
308
+		return apply_filters('wl_features__enable__dataset', $value);
309 309
 	}
310 310
 );
311 311
 
312
-require_once __DIR__ . '/modules/food-kg/load.php';
313
-require_once __DIR__ . '/modules/gardening-kg/load.php';
314
-require_once __DIR__ . '/modules/acf4so/load.php';
315
-require_once __DIR__ . '/modules/dashboard/load.php';
316
-require_once __DIR__ . '/modules/pods/load.php';
317
-require_once __DIR__ . '/modules/include-exclude-push-config/load.php';
318
-require_once __DIR__ . '/modules/super-resolution/load.php';
319
-require_once __DIR__ . '/modules/redeem-code/load.php';
320
-require_once __DIR__ . '/modules/raptive-setup/load.php';
321
-require_once __DIR__ . '/modules/events/load.php';
322
-require_once __DIR__ . '/modules/plugin-diagnostics/load.php';
323
-require_once __DIR__ . '/modules/override-url/load.php';
324
-require_once __DIR__ . '/modules/jsonld-author-filter/load.php';
325
-
326
-function _wl_update_plugins_raptive_domain( $update, $plugin_data, $plugin_file ) {
312
+require_once __DIR__.'/modules/food-kg/load.php';
313
+require_once __DIR__.'/modules/gardening-kg/load.php';
314
+require_once __DIR__.'/modules/acf4so/load.php';
315
+require_once __DIR__.'/modules/dashboard/load.php';
316
+require_once __DIR__.'/modules/pods/load.php';
317
+require_once __DIR__.'/modules/include-exclude-push-config/load.php';
318
+require_once __DIR__.'/modules/super-resolution/load.php';
319
+require_once __DIR__.'/modules/redeem-code/load.php';
320
+require_once __DIR__.'/modules/raptive-setup/load.php';
321
+require_once __DIR__.'/modules/events/load.php';
322
+require_once __DIR__.'/modules/plugin-diagnostics/load.php';
323
+require_once __DIR__.'/modules/override-url/load.php';
324
+require_once __DIR__.'/modules/jsonld-author-filter/load.php';
325
+
326
+function _wl_update_plugins_raptive_domain($update, $plugin_data, $plugin_file) {
327 327
 	// Bail out if it's not our plugin.
328 328
 	$update_uri = $plugin_data['UpdateURI'];
329
-	if ( 'wordlift/wordlift.php' !== $plugin_file || ! isset( $update_uri ) ) {
329
+	if ('wordlift/wordlift.php' !== $plugin_file || ! isset($update_uri)) {
330 330
 		return $update;
331 331
 	}
332 332
 
333
-	$response = wp_remote_get( "$update_uri?nocache=" . time() );
333
+	$response = wp_remote_get("$update_uri?nocache=".time());
334 334
 
335
-	if ( is_wp_error( $response ) ) {
335
+	if (is_wp_error($response)) {
336 336
 		return $update;
337 337
 	}
338 338
 
339 339
 	try {
340
-		return json_decode( wp_remote_retrieve_body( $response ) );
341
-	} catch ( Exception $e ) {
340
+		return json_decode(wp_remote_retrieve_body($response));
341
+	} catch (Exception $e) {
342 342
 		return $update;
343 343
 	}
344 344
 }
Please login to merge, or discard this patch.
src/classes/videoobject/jsonld/class-jsonld.php 1 patch
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -21,53 +21,53 @@  discard block
 block discarded – undo
21 21
 	 *
22 22
 	 * @param $video_storage Storage
23 23
 	 */
24
-	public function __construct( $video_storage ) {
25
-		add_action( 'wl_post_jsonld', array( $this, 'wl_post_jsonld' ), 10, 2 );
26
-		add_filter( 'wl_after_get_jsonld', array( $this, 'wl_after_get_jsonld' ), 10, 2 );
24
+	public function __construct($video_storage) {
25
+		add_action('wl_post_jsonld', array($this, 'wl_post_jsonld'), 10, 2);
26
+		add_filter('wl_after_get_jsonld', array($this, 'wl_after_get_jsonld'), 10, 2);
27 27
 		$this->video_storage = $video_storage;
28 28
 	}
29 29
 
30
-	public function wl_after_get_jsonld( $jsonld, $post_id ) {
31
-		if ( 0 === count( $jsonld ) ) {
30
+	public function wl_after_get_jsonld($jsonld, $post_id) {
31
+		if (0 === count($jsonld)) {
32 32
 			return $jsonld;
33 33
 		}
34 34
 		$current_item = $jsonld[0];
35 35
 
36
-		if ( ! is_array( $current_item ) || ! array_key_exists( '@type', $current_item ) ) {
36
+		if ( ! is_array($current_item) || ! array_key_exists('@type', $current_item)) {
37 37
 			// Cant determine type return early.
38 38
 			return $jsonld;
39 39
 		}
40 40
 
41 41
 		$type = $current_item['@type'];
42
-		if ( is_string( $type ) ) {
43
-			$type = array( $type );
42
+		if (is_string($type)) {
43
+			$type = array($type);
44 44
 		}
45 45
 		// If its a article or descendant of article, then dont add the
46 46
 		// videoobject in this hook, they will be already added to video property.
47
-		if ( array_intersect( Jsonld_Article_Wrapper::$article_types, $type ) ) {
47
+		if (array_intersect(Jsonld_Article_Wrapper::$article_types, $type)) {
48 48
 			return $jsonld;
49 49
 		}
50 50
 
51
-		$videos_jsonld = $this->get_videos_jsonld( $post_id );
52
-		if ( 0 === count( $videos_jsonld ) ) {
51
+		$videos_jsonld = $this->get_videos_jsonld($post_id);
52
+		if (0 === count($videos_jsonld)) {
53 53
 			return $jsonld;
54 54
 		}
55 55
 
56 56
 		// check if we have @id in jsonld for first item.
57
-		$id = array_key_exists( '@id', $current_item ) ? $current_item['@id'] : '';
57
+		$id = array_key_exists('@id', $current_item) ? $current_item['@id'] : '';
58 58
 
59
-		foreach ( $videos_jsonld as &$video_jsonld ) {
60
-			if ( ! $id ) {
59
+		foreach ($videos_jsonld as &$video_jsonld) {
60
+			if ( ! $id) {
61 61
 				continue;
62 62
 			}
63
-			if ( ! array_key_exists( 'mentions', $video_jsonld ) ) {
64
-				$video_jsonld['mentions'] = array( '@id' => $id );
63
+			if ( ! array_key_exists('mentions', $video_jsonld)) {
64
+				$video_jsonld['mentions'] = array('@id' => $id);
65 65
 			} else {
66
-				$video_jsonld['mentions'] = array_merge( $video_jsonld['mentions'], array( '@id' => $id ) );
66
+				$video_jsonld['mentions'] = array_merge($video_jsonld['mentions'], array('@id' => $id));
67 67
 			}
68 68
 		}
69 69
 
70
-		return array_merge( $jsonld, $videos_jsonld );
70
+		return array_merge($jsonld, $videos_jsonld);
71 71
 	}
72 72
 
73 73
 	/**
@@ -76,32 +76,32 @@  discard block
 block discarded – undo
76 76
 	 *
77 77
 	 * @return array
78 78
 	 */
79
-	private function merge_video_data( $existing_video_data, $new_video_data ) {
80
-		if ( ! is_array( $existing_video_data ) ) {
79
+	private function merge_video_data($existing_video_data, $new_video_data) {
80
+		if ( ! is_array($existing_video_data)) {
81 81
 			$new_video_data[] = $existing_video_data;
82 82
 
83 83
 			return $new_video_data;
84 84
 		}
85 85
 
86
-		if ( $this->is_associative_array( $existing_video_data ) ) {
86
+		if ($this->is_associative_array($existing_video_data)) {
87 87
 			$new_video_data[] = $existing_video_data;
88 88
 
89 89
 			return $new_video_data;
90 90
 		}
91 91
 
92
-		return array_merge( $existing_video_data, $new_video_data );
92
+		return array_merge($existing_video_data, $new_video_data);
93 93
 	}
94 94
 
95
-	public function wl_post_jsonld( $jsonld, $post_id ) {
95
+	public function wl_post_jsonld($jsonld, $post_id) {
96 96
 
97
-		$video_jsonld = $this->get_videos_jsonld( $post_id );
98
-		if ( count( $video_jsonld ) === 0 ) {
97
+		$video_jsonld = $this->get_videos_jsonld($post_id);
98
+		if (count($video_jsonld) === 0) {
99 99
 			return $jsonld;
100 100
 		}
101 101
 		// Before adding the video jsonld check if the key
102 102
 		// is present and additional data might be present,
103 103
 		// if not present just add the data and return early.
104
-		if ( ! array_key_exists( 'video', $jsonld ) ) {
104
+		if ( ! array_key_exists('video', $jsonld)) {
105 105
 			$jsonld['video'] = $video_jsonld;
106 106
 
107 107
 			return $jsonld;
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 
110 110
 		// since key exists, we need to merge the data based on type.
111 111
 		$previous_video_data = $jsonld['video'];
112
-		$jsonld['video']     = $this->merge_video_data( $previous_video_data, $video_jsonld );
112
+		$jsonld['video']     = $this->merge_video_data($previous_video_data, $video_jsonld);
113 113
 
114 114
 		return $jsonld;
115 115
 	}
@@ -119,18 +119,18 @@  discard block
 block discarded – undo
119 119
 	 *
120 120
 	 * @return array
121 121
 	 */
122
-	public function get_videos_jsonld( $post_id ) {
122
+	public function get_videos_jsonld($post_id) {
123 123
 
124
-		$videos = $this->video_storage->get_all_videos( $post_id );
124
+		$videos = $this->video_storage->get_all_videos($post_id);
125 125
 
126 126
 		$jsonld = array();
127 127
 
128
-		foreach ( $videos as $video ) {
128
+		foreach ($videos as $video) {
129 129
 			/**
130 130
 			 * @var $video Video
131 131
 			 */
132 132
 			$description = $video->description;
133
-			if ( ! $video->description ) {
133
+			if ( ! $video->description) {
134 134
 				// If description is empty then use the video title as description
135 135
 				$description = $video->name;
136 136
 			}
@@ -145,11 +145,11 @@  discard block
 block discarded – undo
145 145
 				'duration'     => $video->duration,
146 146
 			);
147 147
 
148
-			if ( $video->embed_url ) {
148
+			if ($video->embed_url) {
149 149
 				$single_jsonld['embedUrl'] = $video->embed_url;
150 150
 			}
151 151
 
152
-			if ( $video->views ) {
152
+			if ($video->views) {
153 153
 				$single_jsonld['interactionStatistic'] = array(
154 154
 					'@type'                => 'InteractionCounter',
155 155
 					'interactionType'      => array(
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 				);
160 160
 			}
161 161
 
162
-			if ( $video->is_live_video ) {
162
+			if ($video->is_live_video) {
163 163
 				$single_jsonld['publication'] = array(
164 164
 					'@type'           => 'BroadcastEvent',
165 165
 					'isLiveBroadcast' => true,
@@ -174,12 +174,12 @@  discard block
 block discarded – undo
174 174
 		return $jsonld;
175 175
 	}
176 176
 
177
-	private function is_associative_array( $arr ) {
178
-		if ( array() === $arr ) {
177
+	private function is_associative_array($arr) {
178
+		if (array() === $arr) {
179 179
 			return false;
180 180
 		}
181 181
 
182
-		return array_keys( $arr ) !== range( 0, count( $arr ) - 1 );
182
+		return array_keys($arr) !== range(0, count($arr) - 1);
183 183
 	}
184 184
 
185 185
 }
Please login to merge, or discard this patch.
src/modules/include-exclude/includes/Jsonld_Interceptor.php 1 patch
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -7,46 +7,46 @@
 block discarded – undo
7 7
 	/** @var Plugin_Enabled $plugin_enabled */
8 8
 	private $plugin_enabled;
9 9
 
10
-	public function __construct( $plugin_enabled ) {
10
+	public function __construct($plugin_enabled) {
11 11
 		$this->plugin_enabled = $plugin_enabled;
12 12
 	}
13 13
 
14 14
 	public function register_hooks() {
15
-		add_action( 'wl_before_get_jsonld', array( $this, 'before_get_jsonld' ), 10, 2 );
16
-		add_filter( 'wl_after_get_jsonld', array( $this, 'after_get_jsonld' ) );
15
+		add_action('wl_before_get_jsonld', array($this, 'before_get_jsonld'), 10, 2);
16
+		add_filter('wl_after_get_jsonld', array($this, 'after_get_jsonld'));
17 17
 	}
18 18
 
19
-	public function before_get_jsonld( $is_homepage = false, $post_id = null ) {
20
-		if ( null !== filter_input( INPUT_SERVER, 'HTTP_X_WORDLIFT_BYPASS_INCLUDE_EXCLUDE' ) ) {
21
-			clean_post_cache( $post_id );
19
+	public function before_get_jsonld($is_homepage = false, $post_id = null) {
20
+		if (null !== filter_input(INPUT_SERVER, 'HTTP_X_WORDLIFT_BYPASS_INCLUDE_EXCLUDE')) {
21
+			clean_post_cache($post_id);
22 22
 		}
23 23
 	}
24 24
 
25
-	public function after_get_jsonld( $jsonld_arr ) {
25
+	public function after_get_jsonld($jsonld_arr) {
26 26
 		// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
27
-		@header( 'X-Wordlift-IncludeExclude-Stage-0: Filter Called with default ' . $this->plugin_enabled->get_configuration()->get_default() );
28
-		if ( ! is_array( $jsonld_arr ) || empty( $jsonld_arr ) || ! isset( $jsonld_arr[0]['url'] ) || null !== filter_input( INPUT_SERVER, 'HTTP_X_WORDLIFT_BYPASS_INCLUDE_EXCLUDE' ) ) {
27
+		@header('X-Wordlift-IncludeExclude-Stage-0: Filter Called with default '.$this->plugin_enabled->get_configuration()->get_default());
28
+		if ( ! is_array($jsonld_arr) || empty($jsonld_arr) || ! isset($jsonld_arr[0]['url']) || null !== filter_input(INPUT_SERVER, 'HTTP_X_WORDLIFT_BYPASS_INCLUDE_EXCLUDE')) {
29 29
 			// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
30
-			@header( 'X-Wordlift-IncludeExclude-Stage-1: Condition Not Matched' );
30
+			@header('X-Wordlift-IncludeExclude-Stage-1: Condition Not Matched');
31 31
 
32 32
 			return $jsonld_arr;
33 33
 		}
34 34
 
35 35
 		// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
36
-		@header( 'X-Wordlift-IncludeExclude-Stage-1: Condition Matched for ' . $jsonld_arr[0]['url'] );
36
+		@header('X-Wordlift-IncludeExclude-Stage-1: Condition Matched for '.$jsonld_arr[0]['url']);
37 37
 		// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
38
-		@header( 'X-Wordlift-IncludeExclude-Note: To bypass the Include/Exclude filter add a `x-wordlift-bypass-include-exclude` HTTP request header with any value.' );
38
+		@header('X-Wordlift-IncludeExclude-Note: To bypass the Include/Exclude filter add a `x-wordlift-bypass-include-exclude` HTTP request header with any value.');
39 39
 
40 40
 		// If the URLs are included then publish them.
41
-		if ( $this->plugin_enabled->are_urls_included( $jsonld_arr[0]['url'] ) ) {
41
+		if ($this->plugin_enabled->are_urls_included($jsonld_arr[0]['url'])) {
42 42
 			// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
43
-			@header( 'X-Wordlift-IncludeExclude-Stage-2: URL Included' );
43
+			@header('X-Wordlift-IncludeExclude-Stage-2: URL Included');
44 44
 
45 45
 			return $jsonld_arr;
46 46
 		}
47 47
 
48 48
 		// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
49
-		@header( 'X-Wordlift-IncludeExclude-Stage-2: URL Excluded' );
49
+		@header('X-Wordlift-IncludeExclude-Stage-2: URL Excluded');
50 50
 
51 51
 		return array();
52 52
 	}
Please login to merge, or discard this patch.