Completed
Push — master ( caa748...46d5e9 )
by David
01:05
created
deliciousbrains/wp-background-processing/classes/wp-background-process.php 2 patches
Indentation   +487 added lines, -487 removed lines patch added patch discarded remove patch
@@ -13,492 +13,492 @@
 block discarded – undo
13 13
  */
14 14
 abstract class Wordlift_Plugin_WP_Background_Process extends Wordlift_Plugin_WP_Async_Request {
15 15
 
16
-	/**
17
-	 * Action
18
-	 *
19
-	 * (default value: 'background_process')
20
-	 *
21
-	 * @var string
22
-	 * @access protected
23
-	 */
24
-	protected $action = 'background_process';
25
-
26
-	/**
27
-	 * Start time of current process.
28
-	 *
29
-	 * (default value: 0)
30
-	 *
31
-	 * @var int
32
-	 * @access protected
33
-	 */
34
-	protected $start_time = 0;
35
-
36
-	/**
37
-	 * Cron_hook_identifier
38
-	 *
39
-	 * @var mixed
40
-	 * @access protected
41
-	 */
42
-	protected $cron_hook_identifier;
43
-
44
-	/**
45
-	 * Cron_interval_identifier
46
-	 *
47
-	 * @var mixed
48
-	 * @access protected
49
-	 */
50
-	protected $cron_interval_identifier;
51
-
52
-	/**
53
-	 * Initiate new background process
54
-	 */
55
-	public function __construct() {
56
-		parent::__construct();
57
-
58
-		$this->cron_hook_identifier     = $this->identifier . '_cron';
59
-		$this->cron_interval_identifier = $this->identifier . '_cron_interval';
60
-
61
-		add_action( $this->cron_hook_identifier, array( $this, 'handle_cron_healthcheck' ) );
62
-		add_filter( 'cron_schedules', array( $this, 'schedule_cron_healthcheck' ) );
63
-	}
64
-
65
-	/**
66
-	 * Dispatch
67
-	 *
68
-	 * @access public
69
-	 * @return void
70
-	 */
71
-	public function dispatch() {
72
-		// Schedule the cron healthcheck.
73
-		$this->schedule_event();
74
-
75
-		// Perform remote post.
76
-		return parent::dispatch();
77
-	}
78
-
79
-	/**
80
-	 * Push to queue
81
-	 *
82
-	 * @param mixed $data Data.
83
-	 *
84
-	 * @return $this
85
-	 */
86
-	public function push_to_queue( $data ) {
87
-		$this->data[] = $data;
88
-
89
-		return $this;
90
-	}
91
-
92
-	/**
93
-	 * Save queue
94
-	 *
95
-	 * @return $this
96
-	 */
97
-	public function save() {
98
-		$key = $this->generate_key();
99
-
100
-		if ( ! empty( $this->data ) ) {
101
-			update_site_option( $key, $this->data );
102
-		}
103
-
104
-		return $this;
105
-	}
106
-
107
-	/**
108
-	 * Update queue
109
-	 *
110
-	 * @param string $key  Key.
111
-	 * @param array  $data Data.
112
-	 *
113
-	 * @return $this
114
-	 */
115
-	public function update( $key, $data ) {
116
-		if ( ! empty( $data ) ) {
117
-			update_site_option( $key, $data );
118
-		}
119
-
120
-		return $this;
121
-	}
122
-
123
-	/**
124
-	 * Delete queue
125
-	 *
126
-	 * @param string $key Key.
127
-	 *
128
-	 * @return $this
129
-	 */
130
-	public function delete( $key ) {
131
-		delete_site_option( $key );
132
-
133
-		return $this;
134
-	}
135
-
136
-	/**
137
-	 * Generate key
138
-	 *
139
-	 * Generates a unique key based on microtime. Queue items are
140
-	 * given a unique key so that they can be merged upon save.
141
-	 *
142
-	 * @param int $length Length.
143
-	 *
144
-	 * @return string
145
-	 */
146
-	protected function generate_key( $length = 64 ) {
147
-		$unique  = md5( microtime() . rand() );
148
-		$prepend = $this->identifier . '_batch_';
149
-
150
-		return substr( $prepend . $unique, 0, $length );
151
-	}
152
-
153
-	/**
154
-	 * Maybe process queue
155
-	 *
156
-	 * Checks whether data exists within the queue and that
157
-	 * the process is not already running.
158
-	 */
159
-	public function maybe_handle() {
160
-		// Don't lock up other requests while processing
161
-		session_write_close();
162
-
163
-		if ( $this->is_process_running() ) {
164
-			// Background process already running.
165
-			wp_die();
166
-		}
167
-
168
-		if ( $this->is_queue_empty() ) {
169
-			// No data to process.
170
-			wp_die();
171
-		}
172
-
173
-		check_ajax_referer( $this->identifier, 'nonce' );
174
-
175
-		$this->handle();
176
-
177
-		wp_die();
178
-	}
179
-
180
-	/**
181
-	 * Is queue empty
182
-	 *
183
-	 * @return bool
184
-	 */
185
-	protected function is_queue_empty() {
186
-		global $wpdb;
187
-
188
-		$table  = $wpdb->options;
189
-		$column = 'option_name';
190
-
191
-		if ( is_multisite() ) {
192
-			$table  = $wpdb->sitemeta;
193
-			$column = 'meta_key';
194
-		}
195
-
196
-		$key = $wpdb->esc_like( $this->identifier . '_batch_' ) . '%';
197
-
198
-		$count = $wpdb->get_var(
199
-			$wpdb->prepare(
200
-				"SELECT COUNT(*) FROM {$table} WHERE {$column} LIKE %s", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
201
-				$key
202
-			)
203
-		);
204
-
205
-		return ( $count > 0 ) ? false : true;
206
-	}
207
-
208
-	/**
209
-	 * Is process running
210
-	 *
211
-	 * Check whether the current process is already running
212
-	 * in a background process.
213
-	 */
214
-	protected function is_process_running() {
215
-		if ( get_site_transient( $this->identifier . '_process_lock' ) ) {
216
-			// Process already running.
217
-			return true;
218
-		}
219
-
220
-		return false;
221
-	}
222
-
223
-	/**
224
-	 * Lock process
225
-	 *
226
-	 * Lock the process so that multiple instances can't run simultaneously.
227
-	 * Override if applicable, but the duration should be greater than that
228
-	 * defined in the time_exceeded() method.
229
-	 */
230
-	protected function lock_process() {
231
-		$this->start_time = time(); // Set start time of current process.
232
-
233
-		$lock_duration = ( property_exists( $this, 'queue_lock_time' ) ) ? $this->queue_lock_time : 60; // 1 minute
234
-		$lock_duration = apply_filters( $this->identifier . '_queue_lock_time', $lock_duration );
235
-
236
-		set_site_transient( $this->identifier . '_process_lock', microtime(), $lock_duration );
237
-	}
238
-
239
-	/**
240
-	 * Unlock process
241
-	 *
242
-	 * Unlock the process so that other instances can spawn.
243
-	 *
244
-	 * @return $this
245
-	 */
246
-	protected function unlock_process() {
247
-		delete_site_transient( $this->identifier . '_process_lock' );
248
-
249
-		return $this;
250
-	}
251
-
252
-	/**
253
-	 * Get batch
254
-	 *
255
-	 * @return stdClass Return the first batch from the queue
256
-	 */
257
-	protected function get_batch() {
258
-		global $wpdb;
259
-
260
-		$table        = $wpdb->options;
261
-		$column       = 'option_name';
262
-		$key_column   = 'option_id';
263
-		$value_column = 'option_value';
264
-
265
-		if ( is_multisite() ) {
266
-			$table        = $wpdb->sitemeta;
267
-			$column       = 'meta_key';
268
-			$key_column   = 'meta_id';
269
-			$value_column = 'meta_value';
270
-		}
271
-
272
-		$key = $wpdb->esc_like( $this->identifier . '_batch_' ) . '%';
273
-
274
-		$query = $wpdb->get_row(
275
-			$wpdb->prepare(
276
-				"SELECT * FROM {$table} WHERE {$column} LIKE %s ORDER BY {$key_column} ASC LIMIT 1", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
277
-				$key
278
-			)
279
-		);
280
-
281
-		$batch       = new stdClass();
282
-		$batch->key  = $query->$column;
283
-		$batch->data = maybe_unserialize( $query->$value_column );
284
-
285
-		return $batch;
286
-	}
287
-
288
-	/**
289
-	 * Handle
290
-	 *
291
-	 * Pass each queue item to the task handler, while remaining
292
-	 * within server memory and time limit constraints.
293
-	 */
294
-	protected function handle() {
295
-		$this->lock_process();
296
-
297
-		do {
298
-			$batch = $this->get_batch();
299
-
300
-			foreach ( $batch->data as $key => $value ) {
301
-				$task = $this->task( $value );
302
-
303
-				if ( false !== $task ) {
304
-					$batch->data[ $key ] = $task;
305
-				} else {
306
-					unset( $batch->data[ $key ] );
307
-				}
308
-
309
-				if ( $this->time_exceeded() || $this->memory_exceeded() ) {
310
-					// Batch limits reached.
311
-					break;
312
-				}
313
-			}
314
-
315
-			// Update or delete current batch.
316
-			if ( ! empty( $batch->data ) ) {
317
-				$this->update( $batch->key, $batch->data );
318
-			} else {
319
-				$this->delete( $batch->key );
320
-			}
321
-		} while ( ! $this->time_exceeded() && ! $this->memory_exceeded() && ! $this->is_queue_empty() );
322
-
323
-		$this->unlock_process();
324
-
325
-		// Start next batch or complete process.
326
-		if ( ! $this->is_queue_empty() ) {
327
-			$this->dispatch();
328
-		} else {
329
-			$this->complete();
330
-		}
331
-
332
-		wp_die();
333
-	}
334
-
335
-	/**
336
-	 * Memory exceeded
337
-	 *
338
-	 * Ensures the batch process never exceeds 90%
339
-	 * of the maximum WordPress memory.
340
-	 *
341
-	 * @return bool
342
-	 */
343
-	protected function memory_exceeded() {
344
-		$memory_limit   = $this->get_memory_limit() * 0.9; // 90% of max memory
345
-		$current_memory = memory_get_usage( true );
346
-		$return         = false;
347
-
348
-		if ( $current_memory >= $memory_limit ) {
349
-			$return = true;
350
-		}
351
-
352
-		return apply_filters( $this->identifier . '_memory_exceeded', $return );
353
-	}
354
-
355
-	/**
356
-	 * Get memory limit
357
-	 *
358
-	 * @return int
359
-	 */
360
-	protected function get_memory_limit() {
361
-		if ( function_exists( 'ini_get' ) ) {
362
-			$memory_limit = ini_get( 'memory_limit' );
363
-		} else {
364
-			// Sensible default.
365
-			$memory_limit = '128M';
366
-		}
367
-
368
-		if ( ! $memory_limit || - 1 === intval( $memory_limit ) ) {
369
-			// Unlimited, set to 32GB.
370
-			$memory_limit = '32000M';
371
-		}
372
-
373
-		return wp_convert_hr_to_bytes( $memory_limit );
374
-	}
375
-
376
-	/**
377
-	 * Time exceeded.
378
-	 *
379
-	 * Ensures the batch never exceeds a sensible time limit.
380
-	 * A timeout limit of 30s is common on shared hosting.
381
-	 *
382
-	 * @return bool
383
-	 */
384
-	protected function time_exceeded() {
385
-		$finish = $this->start_time + apply_filters( $this->identifier . '_default_time_limit', 20 ); // 20 seconds
386
-		$return = false;
387
-
388
-		if ( time() >= $finish ) {
389
-			$return = true;
390
-		}
391
-
392
-		return apply_filters( $this->identifier . '_time_exceeded', $return );
393
-	}
394
-
395
-	/**
396
-	 * Complete.
397
-	 *
398
-	 * Override if applicable, but ensure that the below actions are
399
-	 * performed, or, call parent::complete().
400
-	 */
401
-	protected function complete() {
402
-		// Unschedule the cron healthcheck.
403
-		$this->clear_scheduled_event();
404
-	}
405
-
406
-	/**
407
-	 * Schedule cron healthcheck
408
-	 *
409
-	 * @access public
410
-	 *
411
-	 * @param mixed $schedules Schedules.
412
-	 *
413
-	 * @return mixed
414
-	 */
415
-	public function schedule_cron_healthcheck( $schedules ) {
416
-		$interval = apply_filters( $this->identifier . '_cron_interval', 5 );
417
-
418
-		if ( property_exists( $this, 'cron_interval' ) ) {
419
-			$interval = apply_filters( $this->identifier . '_cron_interval', $this->cron_interval );
420
-		}
421
-
422
-		// Adds every 5 minutes to the existing schedules.
423
-		$schedules[ $this->identifier . '_cron_interval' ] = array(
424
-			'interval' => MINUTE_IN_SECONDS * $interval,
425
-			'display'  => sprintf( __( 'Every %d Minutes' ), $interval ),
426
-		);
427
-
428
-		return $schedules;
429
-	}
430
-
431
-	/**
432
-	 * Handle cron healthcheck
433
-	 *
434
-	 * Restart the background process if not already running
435
-	 * and data exists in the queue.
436
-	 */
437
-	public function handle_cron_healthcheck() {
438
-		if ( $this->is_process_running() ) {
439
-			// Background process already running.
440
-			exit;
441
-		}
442
-
443
-		if ( $this->is_queue_empty() ) {
444
-			// No data to process.
445
-			$this->clear_scheduled_event();
446
-			exit;
447
-		}
448
-
449
-		$this->handle();
450
-
451
-		exit;
452
-	}
453
-
454
-	/**
455
-	 * Schedule event
456
-	 */
457
-	protected function schedule_event() {
458
-		if ( ! wp_next_scheduled( $this->cron_hook_identifier ) ) {
459
-			wp_schedule_event( time(), $this->cron_interval_identifier, $this->cron_hook_identifier );
460
-		}
461
-	}
462
-
463
-	/**
464
-	 * Clear scheduled event
465
-	 */
466
-	protected function clear_scheduled_event() {
467
-		$timestamp = wp_next_scheduled( $this->cron_hook_identifier );
468
-
469
-		if ( $timestamp ) {
470
-			wp_unschedule_event( $timestamp, $this->cron_hook_identifier );
471
-		}
472
-	}
473
-
474
-	/**
475
-	 * Cancel Process
476
-	 *
477
-	 * Stop processing queue items, clear cronjob and delete batch.
478
-	 */
479
-	public function cancel_process() {
480
-		if ( ! $this->is_queue_empty() ) {
481
-			$batch = $this->get_batch();
482
-
483
-			$this->delete( $batch->key );
484
-
485
-			wp_clear_scheduled_hook( $this->cron_hook_identifier );
486
-		}
487
-
488
-	}
489
-
490
-	/**
491
-	 * Task
492
-	 *
493
-	 * Override this method to perform any actions required on each
494
-	 * queue item. Return the modified item for further processing
495
-	 * in the next pass through. Or, return false to remove the
496
-	 * item from the queue.
497
-	 *
498
-	 * @param mixed $item Queue item to iterate over.
499
-	 *
500
-	 * @return mixed
501
-	 */
502
-	abstract protected function task( $item );
16
+    /**
17
+     * Action
18
+     *
19
+     * (default value: 'background_process')
20
+     *
21
+     * @var string
22
+     * @access protected
23
+     */
24
+    protected $action = 'background_process';
25
+
26
+    /**
27
+     * Start time of current process.
28
+     *
29
+     * (default value: 0)
30
+     *
31
+     * @var int
32
+     * @access protected
33
+     */
34
+    protected $start_time = 0;
35
+
36
+    /**
37
+     * Cron_hook_identifier
38
+     *
39
+     * @var mixed
40
+     * @access protected
41
+     */
42
+    protected $cron_hook_identifier;
43
+
44
+    /**
45
+     * Cron_interval_identifier
46
+     *
47
+     * @var mixed
48
+     * @access protected
49
+     */
50
+    protected $cron_interval_identifier;
51
+
52
+    /**
53
+     * Initiate new background process
54
+     */
55
+    public function __construct() {
56
+        parent::__construct();
57
+
58
+        $this->cron_hook_identifier     = $this->identifier . '_cron';
59
+        $this->cron_interval_identifier = $this->identifier . '_cron_interval';
60
+
61
+        add_action( $this->cron_hook_identifier, array( $this, 'handle_cron_healthcheck' ) );
62
+        add_filter( 'cron_schedules', array( $this, 'schedule_cron_healthcheck' ) );
63
+    }
64
+
65
+    /**
66
+     * Dispatch
67
+     *
68
+     * @access public
69
+     * @return void
70
+     */
71
+    public function dispatch() {
72
+        // Schedule the cron healthcheck.
73
+        $this->schedule_event();
74
+
75
+        // Perform remote post.
76
+        return parent::dispatch();
77
+    }
78
+
79
+    /**
80
+     * Push to queue
81
+     *
82
+     * @param mixed $data Data.
83
+     *
84
+     * @return $this
85
+     */
86
+    public function push_to_queue( $data ) {
87
+        $this->data[] = $data;
88
+
89
+        return $this;
90
+    }
91
+
92
+    /**
93
+     * Save queue
94
+     *
95
+     * @return $this
96
+     */
97
+    public function save() {
98
+        $key = $this->generate_key();
99
+
100
+        if ( ! empty( $this->data ) ) {
101
+            update_site_option( $key, $this->data );
102
+        }
103
+
104
+        return $this;
105
+    }
106
+
107
+    /**
108
+     * Update queue
109
+     *
110
+     * @param string $key  Key.
111
+     * @param array  $data Data.
112
+     *
113
+     * @return $this
114
+     */
115
+    public function update( $key, $data ) {
116
+        if ( ! empty( $data ) ) {
117
+            update_site_option( $key, $data );
118
+        }
119
+
120
+        return $this;
121
+    }
122
+
123
+    /**
124
+     * Delete queue
125
+     *
126
+     * @param string $key Key.
127
+     *
128
+     * @return $this
129
+     */
130
+    public function delete( $key ) {
131
+        delete_site_option( $key );
132
+
133
+        return $this;
134
+    }
135
+
136
+    /**
137
+     * Generate key
138
+     *
139
+     * Generates a unique key based on microtime. Queue items are
140
+     * given a unique key so that they can be merged upon save.
141
+     *
142
+     * @param int $length Length.
143
+     *
144
+     * @return string
145
+     */
146
+    protected function generate_key( $length = 64 ) {
147
+        $unique  = md5( microtime() . rand() );
148
+        $prepend = $this->identifier . '_batch_';
149
+
150
+        return substr( $prepend . $unique, 0, $length );
151
+    }
152
+
153
+    /**
154
+     * Maybe process queue
155
+     *
156
+     * Checks whether data exists within the queue and that
157
+     * the process is not already running.
158
+     */
159
+    public function maybe_handle() {
160
+        // Don't lock up other requests while processing
161
+        session_write_close();
162
+
163
+        if ( $this->is_process_running() ) {
164
+            // Background process already running.
165
+            wp_die();
166
+        }
167
+
168
+        if ( $this->is_queue_empty() ) {
169
+            // No data to process.
170
+            wp_die();
171
+        }
172
+
173
+        check_ajax_referer( $this->identifier, 'nonce' );
174
+
175
+        $this->handle();
176
+
177
+        wp_die();
178
+    }
179
+
180
+    /**
181
+     * Is queue empty
182
+     *
183
+     * @return bool
184
+     */
185
+    protected function is_queue_empty() {
186
+        global $wpdb;
187
+
188
+        $table  = $wpdb->options;
189
+        $column = 'option_name';
190
+
191
+        if ( is_multisite() ) {
192
+            $table  = $wpdb->sitemeta;
193
+            $column = 'meta_key';
194
+        }
195
+
196
+        $key = $wpdb->esc_like( $this->identifier . '_batch_' ) . '%';
197
+
198
+        $count = $wpdb->get_var(
199
+            $wpdb->prepare(
200
+                "SELECT COUNT(*) FROM {$table} WHERE {$column} LIKE %s", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
201
+                $key
202
+            )
203
+        );
204
+
205
+        return ( $count > 0 ) ? false : true;
206
+    }
207
+
208
+    /**
209
+     * Is process running
210
+     *
211
+     * Check whether the current process is already running
212
+     * in a background process.
213
+     */
214
+    protected function is_process_running() {
215
+        if ( get_site_transient( $this->identifier . '_process_lock' ) ) {
216
+            // Process already running.
217
+            return true;
218
+        }
219
+
220
+        return false;
221
+    }
222
+
223
+    /**
224
+     * Lock process
225
+     *
226
+     * Lock the process so that multiple instances can't run simultaneously.
227
+     * Override if applicable, but the duration should be greater than that
228
+     * defined in the time_exceeded() method.
229
+     */
230
+    protected function lock_process() {
231
+        $this->start_time = time(); // Set start time of current process.
232
+
233
+        $lock_duration = ( property_exists( $this, 'queue_lock_time' ) ) ? $this->queue_lock_time : 60; // 1 minute
234
+        $lock_duration = apply_filters( $this->identifier . '_queue_lock_time', $lock_duration );
235
+
236
+        set_site_transient( $this->identifier . '_process_lock', microtime(), $lock_duration );
237
+    }
238
+
239
+    /**
240
+     * Unlock process
241
+     *
242
+     * Unlock the process so that other instances can spawn.
243
+     *
244
+     * @return $this
245
+     */
246
+    protected function unlock_process() {
247
+        delete_site_transient( $this->identifier . '_process_lock' );
248
+
249
+        return $this;
250
+    }
251
+
252
+    /**
253
+     * Get batch
254
+     *
255
+     * @return stdClass Return the first batch from the queue
256
+     */
257
+    protected function get_batch() {
258
+        global $wpdb;
259
+
260
+        $table        = $wpdb->options;
261
+        $column       = 'option_name';
262
+        $key_column   = 'option_id';
263
+        $value_column = 'option_value';
264
+
265
+        if ( is_multisite() ) {
266
+            $table        = $wpdb->sitemeta;
267
+            $column       = 'meta_key';
268
+            $key_column   = 'meta_id';
269
+            $value_column = 'meta_value';
270
+        }
271
+
272
+        $key = $wpdb->esc_like( $this->identifier . '_batch_' ) . '%';
273
+
274
+        $query = $wpdb->get_row(
275
+            $wpdb->prepare(
276
+                "SELECT * FROM {$table} WHERE {$column} LIKE %s ORDER BY {$key_column} ASC LIMIT 1", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
277
+                $key
278
+            )
279
+        );
280
+
281
+        $batch       = new stdClass();
282
+        $batch->key  = $query->$column;
283
+        $batch->data = maybe_unserialize( $query->$value_column );
284
+
285
+        return $batch;
286
+    }
287
+
288
+    /**
289
+     * Handle
290
+     *
291
+     * Pass each queue item to the task handler, while remaining
292
+     * within server memory and time limit constraints.
293
+     */
294
+    protected function handle() {
295
+        $this->lock_process();
296
+
297
+        do {
298
+            $batch = $this->get_batch();
299
+
300
+            foreach ( $batch->data as $key => $value ) {
301
+                $task = $this->task( $value );
302
+
303
+                if ( false !== $task ) {
304
+                    $batch->data[ $key ] = $task;
305
+                } else {
306
+                    unset( $batch->data[ $key ] );
307
+                }
308
+
309
+                if ( $this->time_exceeded() || $this->memory_exceeded() ) {
310
+                    // Batch limits reached.
311
+                    break;
312
+                }
313
+            }
314
+
315
+            // Update or delete current batch.
316
+            if ( ! empty( $batch->data ) ) {
317
+                $this->update( $batch->key, $batch->data );
318
+            } else {
319
+                $this->delete( $batch->key );
320
+            }
321
+        } while ( ! $this->time_exceeded() && ! $this->memory_exceeded() && ! $this->is_queue_empty() );
322
+
323
+        $this->unlock_process();
324
+
325
+        // Start next batch or complete process.
326
+        if ( ! $this->is_queue_empty() ) {
327
+            $this->dispatch();
328
+        } else {
329
+            $this->complete();
330
+        }
331
+
332
+        wp_die();
333
+    }
334
+
335
+    /**
336
+     * Memory exceeded
337
+     *
338
+     * Ensures the batch process never exceeds 90%
339
+     * of the maximum WordPress memory.
340
+     *
341
+     * @return bool
342
+     */
343
+    protected function memory_exceeded() {
344
+        $memory_limit   = $this->get_memory_limit() * 0.9; // 90% of max memory
345
+        $current_memory = memory_get_usage( true );
346
+        $return         = false;
347
+
348
+        if ( $current_memory >= $memory_limit ) {
349
+            $return = true;
350
+        }
351
+
352
+        return apply_filters( $this->identifier . '_memory_exceeded', $return );
353
+    }
354
+
355
+    /**
356
+     * Get memory limit
357
+     *
358
+     * @return int
359
+     */
360
+    protected function get_memory_limit() {
361
+        if ( function_exists( 'ini_get' ) ) {
362
+            $memory_limit = ini_get( 'memory_limit' );
363
+        } else {
364
+            // Sensible default.
365
+            $memory_limit = '128M';
366
+        }
367
+
368
+        if ( ! $memory_limit || - 1 === intval( $memory_limit ) ) {
369
+            // Unlimited, set to 32GB.
370
+            $memory_limit = '32000M';
371
+        }
372
+
373
+        return wp_convert_hr_to_bytes( $memory_limit );
374
+    }
375
+
376
+    /**
377
+     * Time exceeded.
378
+     *
379
+     * Ensures the batch never exceeds a sensible time limit.
380
+     * A timeout limit of 30s is common on shared hosting.
381
+     *
382
+     * @return bool
383
+     */
384
+    protected function time_exceeded() {
385
+        $finish = $this->start_time + apply_filters( $this->identifier . '_default_time_limit', 20 ); // 20 seconds
386
+        $return = false;
387
+
388
+        if ( time() >= $finish ) {
389
+            $return = true;
390
+        }
391
+
392
+        return apply_filters( $this->identifier . '_time_exceeded', $return );
393
+    }
394
+
395
+    /**
396
+     * Complete.
397
+     *
398
+     * Override if applicable, but ensure that the below actions are
399
+     * performed, or, call parent::complete().
400
+     */
401
+    protected function complete() {
402
+        // Unschedule the cron healthcheck.
403
+        $this->clear_scheduled_event();
404
+    }
405
+
406
+    /**
407
+     * Schedule cron healthcheck
408
+     *
409
+     * @access public
410
+     *
411
+     * @param mixed $schedules Schedules.
412
+     *
413
+     * @return mixed
414
+     */
415
+    public function schedule_cron_healthcheck( $schedules ) {
416
+        $interval = apply_filters( $this->identifier . '_cron_interval', 5 );
417
+
418
+        if ( property_exists( $this, 'cron_interval' ) ) {
419
+            $interval = apply_filters( $this->identifier . '_cron_interval', $this->cron_interval );
420
+        }
421
+
422
+        // Adds every 5 minutes to the existing schedules.
423
+        $schedules[ $this->identifier . '_cron_interval' ] = array(
424
+            'interval' => MINUTE_IN_SECONDS * $interval,
425
+            'display'  => sprintf( __( 'Every %d Minutes' ), $interval ),
426
+        );
427
+
428
+        return $schedules;
429
+    }
430
+
431
+    /**
432
+     * Handle cron healthcheck
433
+     *
434
+     * Restart the background process if not already running
435
+     * and data exists in the queue.
436
+     */
437
+    public function handle_cron_healthcheck() {
438
+        if ( $this->is_process_running() ) {
439
+            // Background process already running.
440
+            exit;
441
+        }
442
+
443
+        if ( $this->is_queue_empty() ) {
444
+            // No data to process.
445
+            $this->clear_scheduled_event();
446
+            exit;
447
+        }
448
+
449
+        $this->handle();
450
+
451
+        exit;
452
+    }
453
+
454
+    /**
455
+     * Schedule event
456
+     */
457
+    protected function schedule_event() {
458
+        if ( ! wp_next_scheduled( $this->cron_hook_identifier ) ) {
459
+            wp_schedule_event( time(), $this->cron_interval_identifier, $this->cron_hook_identifier );
460
+        }
461
+    }
462
+
463
+    /**
464
+     * Clear scheduled event
465
+     */
466
+    protected function clear_scheduled_event() {
467
+        $timestamp = wp_next_scheduled( $this->cron_hook_identifier );
468
+
469
+        if ( $timestamp ) {
470
+            wp_unschedule_event( $timestamp, $this->cron_hook_identifier );
471
+        }
472
+    }
473
+
474
+    /**
475
+     * Cancel Process
476
+     *
477
+     * Stop processing queue items, clear cronjob and delete batch.
478
+     */
479
+    public function cancel_process() {
480
+        if ( ! $this->is_queue_empty() ) {
481
+            $batch = $this->get_batch();
482
+
483
+            $this->delete( $batch->key );
484
+
485
+            wp_clear_scheduled_hook( $this->cron_hook_identifier );
486
+        }
487
+
488
+    }
489
+
490
+    /**
491
+     * Task
492
+     *
493
+     * Override this method to perform any actions required on each
494
+     * queue item. Return the modified item for further processing
495
+     * in the next pass through. Or, return false to remove the
496
+     * item from the queue.
497
+     *
498
+     * @param mixed $item Queue item to iterate over.
499
+     *
500
+     * @return mixed
501
+     */
502
+    abstract protected function task( $item );
503 503
 
504 504
 }
Please login to merge, or discard this patch.
Spacing   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -55,11 +55,11 @@  discard block
 block discarded – undo
55 55
 	public function __construct() {
56 56
 		parent::__construct();
57 57
 
58
-		$this->cron_hook_identifier     = $this->identifier . '_cron';
59
-		$this->cron_interval_identifier = $this->identifier . '_cron_interval';
58
+		$this->cron_hook_identifier     = $this->identifier.'_cron';
59
+		$this->cron_interval_identifier = $this->identifier.'_cron_interval';
60 60
 
61
-		add_action( $this->cron_hook_identifier, array( $this, 'handle_cron_healthcheck' ) );
62
-		add_filter( 'cron_schedules', array( $this, 'schedule_cron_healthcheck' ) );
61
+		add_action($this->cron_hook_identifier, array($this, 'handle_cron_healthcheck'));
62
+		add_filter('cron_schedules', array($this, 'schedule_cron_healthcheck'));
63 63
 	}
64 64
 
65 65
 	/**
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 	 *
84 84
 	 * @return $this
85 85
 	 */
86
-	public function push_to_queue( $data ) {
86
+	public function push_to_queue($data) {
87 87
 		$this->data[] = $data;
88 88
 
89 89
 		return $this;
@@ -97,8 +97,8 @@  discard block
 block discarded – undo
97 97
 	public function save() {
98 98
 		$key = $this->generate_key();
99 99
 
100
-		if ( ! empty( $this->data ) ) {
101
-			update_site_option( $key, $this->data );
100
+		if ( ! empty($this->data)) {
101
+			update_site_option($key, $this->data);
102 102
 		}
103 103
 
104 104
 		return $this;
@@ -112,9 +112,9 @@  discard block
 block discarded – undo
112 112
 	 *
113 113
 	 * @return $this
114 114
 	 */
115
-	public function update( $key, $data ) {
116
-		if ( ! empty( $data ) ) {
117
-			update_site_option( $key, $data );
115
+	public function update($key, $data) {
116
+		if ( ! empty($data)) {
117
+			update_site_option($key, $data);
118 118
 		}
119 119
 
120 120
 		return $this;
@@ -127,8 +127,8 @@  discard block
 block discarded – undo
127 127
 	 *
128 128
 	 * @return $this
129 129
 	 */
130
-	public function delete( $key ) {
131
-		delete_site_option( $key );
130
+	public function delete($key) {
131
+		delete_site_option($key);
132 132
 
133 133
 		return $this;
134 134
 	}
@@ -143,11 +143,11 @@  discard block
 block discarded – undo
143 143
 	 *
144 144
 	 * @return string
145 145
 	 */
146
-	protected function generate_key( $length = 64 ) {
147
-		$unique  = md5( microtime() . rand() );
148
-		$prepend = $this->identifier . '_batch_';
146
+	protected function generate_key($length = 64) {
147
+		$unique  = md5(microtime().rand());
148
+		$prepend = $this->identifier.'_batch_';
149 149
 
150
-		return substr( $prepend . $unique, 0, $length );
150
+		return substr($prepend.$unique, 0, $length);
151 151
 	}
152 152
 
153 153
 	/**
@@ -160,17 +160,17 @@  discard block
 block discarded – undo
160 160
 		// Don't lock up other requests while processing
161 161
 		session_write_close();
162 162
 
163
-		if ( $this->is_process_running() ) {
163
+		if ($this->is_process_running()) {
164 164
 			// Background process already running.
165 165
 			wp_die();
166 166
 		}
167 167
 
168
-		if ( $this->is_queue_empty() ) {
168
+		if ($this->is_queue_empty()) {
169 169
 			// No data to process.
170 170
 			wp_die();
171 171
 		}
172 172
 
173
-		check_ajax_referer( $this->identifier, 'nonce' );
173
+		check_ajax_referer($this->identifier, 'nonce');
174 174
 
175 175
 		$this->handle();
176 176
 
@@ -188,12 +188,12 @@  discard block
 block discarded – undo
188 188
 		$table  = $wpdb->options;
189 189
 		$column = 'option_name';
190 190
 
191
-		if ( is_multisite() ) {
191
+		if (is_multisite()) {
192 192
 			$table  = $wpdb->sitemeta;
193 193
 			$column = 'meta_key';
194 194
 		}
195 195
 
196
-		$key = $wpdb->esc_like( $this->identifier . '_batch_' ) . '%';
196
+		$key = $wpdb->esc_like($this->identifier.'_batch_').'%';
197 197
 
198 198
 		$count = $wpdb->get_var(
199 199
 			$wpdb->prepare(
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
 			)
203 203
 		);
204 204
 
205
-		return ( $count > 0 ) ? false : true;
205
+		return ($count > 0) ? false : true;
206 206
 	}
207 207
 
208 208
 	/**
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
 	 * in a background process.
213 213
 	 */
214 214
 	protected function is_process_running() {
215
-		if ( get_site_transient( $this->identifier . '_process_lock' ) ) {
215
+		if (get_site_transient($this->identifier.'_process_lock')) {
216 216
 			// Process already running.
217 217
 			return true;
218 218
 		}
@@ -230,10 +230,10 @@  discard block
 block discarded – undo
230 230
 	protected function lock_process() {
231 231
 		$this->start_time = time(); // Set start time of current process.
232 232
 
233
-		$lock_duration = ( property_exists( $this, 'queue_lock_time' ) ) ? $this->queue_lock_time : 60; // 1 minute
234
-		$lock_duration = apply_filters( $this->identifier . '_queue_lock_time', $lock_duration );
233
+		$lock_duration = (property_exists($this, 'queue_lock_time')) ? $this->queue_lock_time : 60; // 1 minute
234
+		$lock_duration = apply_filters($this->identifier.'_queue_lock_time', $lock_duration);
235 235
 
236
-		set_site_transient( $this->identifier . '_process_lock', microtime(), $lock_duration );
236
+		set_site_transient($this->identifier.'_process_lock', microtime(), $lock_duration);
237 237
 	}
238 238
 
239 239
 	/**
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
 	 * @return $this
245 245
 	 */
246 246
 	protected function unlock_process() {
247
-		delete_site_transient( $this->identifier . '_process_lock' );
247
+		delete_site_transient($this->identifier.'_process_lock');
248 248
 
249 249
 		return $this;
250 250
 	}
@@ -262,14 +262,14 @@  discard block
 block discarded – undo
262 262
 		$key_column   = 'option_id';
263 263
 		$value_column = 'option_value';
264 264
 
265
-		if ( is_multisite() ) {
265
+		if (is_multisite()) {
266 266
 			$table        = $wpdb->sitemeta;
267 267
 			$column       = 'meta_key';
268 268
 			$key_column   = 'meta_id';
269 269
 			$value_column = 'meta_value';
270 270
 		}
271 271
 
272
-		$key = $wpdb->esc_like( $this->identifier . '_batch_' ) . '%';
272
+		$key = $wpdb->esc_like($this->identifier.'_batch_').'%';
273 273
 
274 274
 		$query = $wpdb->get_row(
275 275
 			$wpdb->prepare(
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
 
281 281
 		$batch       = new stdClass();
282 282
 		$batch->key  = $query->$column;
283
-		$batch->data = maybe_unserialize( $query->$value_column );
283
+		$batch->data = maybe_unserialize($query->$value_column);
284 284
 
285 285
 		return $batch;
286 286
 	}
@@ -297,33 +297,33 @@  discard block
 block discarded – undo
297 297
 		do {
298 298
 			$batch = $this->get_batch();
299 299
 
300
-			foreach ( $batch->data as $key => $value ) {
301
-				$task = $this->task( $value );
300
+			foreach ($batch->data as $key => $value) {
301
+				$task = $this->task($value);
302 302
 
303
-				if ( false !== $task ) {
304
-					$batch->data[ $key ] = $task;
303
+				if (false !== $task) {
304
+					$batch->data[$key] = $task;
305 305
 				} else {
306
-					unset( $batch->data[ $key ] );
306
+					unset($batch->data[$key]);
307 307
 				}
308 308
 
309
-				if ( $this->time_exceeded() || $this->memory_exceeded() ) {
309
+				if ($this->time_exceeded() || $this->memory_exceeded()) {
310 310
 					// Batch limits reached.
311 311
 					break;
312 312
 				}
313 313
 			}
314 314
 
315 315
 			// Update or delete current batch.
316
-			if ( ! empty( $batch->data ) ) {
317
-				$this->update( $batch->key, $batch->data );
316
+			if ( ! empty($batch->data)) {
317
+				$this->update($batch->key, $batch->data);
318 318
 			} else {
319
-				$this->delete( $batch->key );
319
+				$this->delete($batch->key);
320 320
 			}
321
-		} while ( ! $this->time_exceeded() && ! $this->memory_exceeded() && ! $this->is_queue_empty() );
321
+		} while ( ! $this->time_exceeded() && ! $this->memory_exceeded() && ! $this->is_queue_empty());
322 322
 
323 323
 		$this->unlock_process();
324 324
 
325 325
 		// Start next batch or complete process.
326
-		if ( ! $this->is_queue_empty() ) {
326
+		if ( ! $this->is_queue_empty()) {
327 327
 			$this->dispatch();
328 328
 		} else {
329 329
 			$this->complete();
@@ -342,14 +342,14 @@  discard block
 block discarded – undo
342 342
 	 */
343 343
 	protected function memory_exceeded() {
344 344
 		$memory_limit   = $this->get_memory_limit() * 0.9; // 90% of max memory
345
-		$current_memory = memory_get_usage( true );
345
+		$current_memory = memory_get_usage(true);
346 346
 		$return         = false;
347 347
 
348
-		if ( $current_memory >= $memory_limit ) {
348
+		if ($current_memory >= $memory_limit) {
349 349
 			$return = true;
350 350
 		}
351 351
 
352
-		return apply_filters( $this->identifier . '_memory_exceeded', $return );
352
+		return apply_filters($this->identifier.'_memory_exceeded', $return);
353 353
 	}
354 354
 
355 355
 	/**
@@ -358,19 +358,19 @@  discard block
 block discarded – undo
358 358
 	 * @return int
359 359
 	 */
360 360
 	protected function get_memory_limit() {
361
-		if ( function_exists( 'ini_get' ) ) {
362
-			$memory_limit = ini_get( 'memory_limit' );
361
+		if (function_exists('ini_get')) {
362
+			$memory_limit = ini_get('memory_limit');
363 363
 		} else {
364 364
 			// Sensible default.
365 365
 			$memory_limit = '128M';
366 366
 		}
367 367
 
368
-		if ( ! $memory_limit || - 1 === intval( $memory_limit ) ) {
368
+		if ( ! $memory_limit || - 1 === intval($memory_limit)) {
369 369
 			// Unlimited, set to 32GB.
370 370
 			$memory_limit = '32000M';
371 371
 		}
372 372
 
373
-		return wp_convert_hr_to_bytes( $memory_limit );
373
+		return wp_convert_hr_to_bytes($memory_limit);
374 374
 	}
375 375
 
376 376
 	/**
@@ -382,14 +382,14 @@  discard block
 block discarded – undo
382 382
 	 * @return bool
383 383
 	 */
384 384
 	protected function time_exceeded() {
385
-		$finish = $this->start_time + apply_filters( $this->identifier . '_default_time_limit', 20 ); // 20 seconds
385
+		$finish = $this->start_time + apply_filters($this->identifier.'_default_time_limit', 20); // 20 seconds
386 386
 		$return = false;
387 387
 
388
-		if ( time() >= $finish ) {
388
+		if (time() >= $finish) {
389 389
 			$return = true;
390 390
 		}
391 391
 
392
-		return apply_filters( $this->identifier . '_time_exceeded', $return );
392
+		return apply_filters($this->identifier.'_time_exceeded', $return);
393 393
 	}
394 394
 
395 395
 	/**
@@ -412,17 +412,17 @@  discard block
 block discarded – undo
412 412
 	 *
413 413
 	 * @return mixed
414 414
 	 */
415
-	public function schedule_cron_healthcheck( $schedules ) {
416
-		$interval = apply_filters( $this->identifier . '_cron_interval', 5 );
415
+	public function schedule_cron_healthcheck($schedules) {
416
+		$interval = apply_filters($this->identifier.'_cron_interval', 5);
417 417
 
418
-		if ( property_exists( $this, 'cron_interval' ) ) {
419
-			$interval = apply_filters( $this->identifier . '_cron_interval', $this->cron_interval );
418
+		if (property_exists($this, 'cron_interval')) {
419
+			$interval = apply_filters($this->identifier.'_cron_interval', $this->cron_interval);
420 420
 		}
421 421
 
422 422
 		// Adds every 5 minutes to the existing schedules.
423
-		$schedules[ $this->identifier . '_cron_interval' ] = array(
423
+		$schedules[$this->identifier.'_cron_interval'] = array(
424 424
 			'interval' => MINUTE_IN_SECONDS * $interval,
425
-			'display'  => sprintf( __( 'Every %d Minutes' ), $interval ),
425
+			'display'  => sprintf(__('Every %d Minutes'), $interval),
426 426
 		);
427 427
 
428 428
 		return $schedules;
@@ -435,12 +435,12 @@  discard block
 block discarded – undo
435 435
 	 * and data exists in the queue.
436 436
 	 */
437 437
 	public function handle_cron_healthcheck() {
438
-		if ( $this->is_process_running() ) {
438
+		if ($this->is_process_running()) {
439 439
 			// Background process already running.
440 440
 			exit;
441 441
 		}
442 442
 
443
-		if ( $this->is_queue_empty() ) {
443
+		if ($this->is_queue_empty()) {
444 444
 			// No data to process.
445 445
 			$this->clear_scheduled_event();
446 446
 			exit;
@@ -455,8 +455,8 @@  discard block
 block discarded – undo
455 455
 	 * Schedule event
456 456
 	 */
457 457
 	protected function schedule_event() {
458
-		if ( ! wp_next_scheduled( $this->cron_hook_identifier ) ) {
459
-			wp_schedule_event( time(), $this->cron_interval_identifier, $this->cron_hook_identifier );
458
+		if ( ! wp_next_scheduled($this->cron_hook_identifier)) {
459
+			wp_schedule_event(time(), $this->cron_interval_identifier, $this->cron_hook_identifier);
460 460
 		}
461 461
 	}
462 462
 
@@ -464,10 +464,10 @@  discard block
 block discarded – undo
464 464
 	 * Clear scheduled event
465 465
 	 */
466 466
 	protected function clear_scheduled_event() {
467
-		$timestamp = wp_next_scheduled( $this->cron_hook_identifier );
467
+		$timestamp = wp_next_scheduled($this->cron_hook_identifier);
468 468
 
469
-		if ( $timestamp ) {
470
-			wp_unschedule_event( $timestamp, $this->cron_hook_identifier );
469
+		if ($timestamp) {
470
+			wp_unschedule_event($timestamp, $this->cron_hook_identifier);
471 471
 		}
472 472
 	}
473 473
 
@@ -477,12 +477,12 @@  discard block
 block discarded – undo
477 477
 	 * Stop processing queue items, clear cronjob and delete batch.
478 478
 	 */
479 479
 	public function cancel_process() {
480
-		if ( ! $this->is_queue_empty() ) {
480
+		if ( ! $this->is_queue_empty()) {
481 481
 			$batch = $this->get_batch();
482 482
 
483
-			$this->delete( $batch->key );
483
+			$this->delete($batch->key);
484 484
 
485
-			wp_clear_scheduled_hook( $this->cron_hook_identifier );
485
+			wp_clear_scheduled_hook($this->cron_hook_identifier);
486 486
 		}
487 487
 
488 488
 	}
@@ -499,6 +499,6 @@  discard block
 block discarded – undo
499 499
 	 *
500 500
 	 * @return mixed
501 501
 	 */
502
-	abstract protected function task( $item );
502
+	abstract protected function task($item);
503 503
 
504 504
 }
Please login to merge, or discard this patch.
src/widgets/class-wordlift-timeline-widget.php 2 patches
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -2,53 +2,53 @@
 block discarded – undo
2 2
 
3 3
 class Wordlift_Timeline_Widget extends WP_Widget {
4 4
 
5
-	/**
6
-	 * Sets up the widgets name etc
7
-	 */
8
-	public function __construct() {
9
-		// widget actual processes
10
-		parent::__construct(
11
-			'wl_timeline_widget', // Base ID
12
-			__( 'WordLift Timeline Widget', 'wordlift' ), // Name
13
-			array( 'description' => __( 'Displays entities of type event using an interactive timeline.', 'wordlift' ) ) // Args
14
-		);
15
-	}
5
+    /**
6
+     * Sets up the widgets name etc
7
+     */
8
+    public function __construct() {
9
+        // widget actual processes
10
+        parent::__construct(
11
+            'wl_timeline_widget', // Base ID
12
+            __( 'WordLift Timeline Widget', 'wordlift' ), // Name
13
+            array( 'description' => __( 'Displays entities of type event using an interactive timeline.', 'wordlift' ) ) // Args
14
+        );
15
+    }
16 16
 
17
-	/**
18
-	 * Outputs the content of the widget
19
-	 *
20
-	 * @param array $args
21
-	 * @param array $instance
22
-	 */
23
-	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
24
-	public function widget( $args, $instance ) {
25
-		// outputs the content of the widget
26
-		echo do_shortcode( '[wl_timeline global=true]' );
27
-	}
17
+    /**
18
+     * Outputs the content of the widget
19
+     *
20
+     * @param array $args
21
+     * @param array $instance
22
+     */
23
+    // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
24
+    public function widget( $args, $instance ) {
25
+        // outputs the content of the widget
26
+        echo do_shortcode( '[wl_timeline global=true]' );
27
+    }
28 28
 
29
-	/**
30
-	 * Outputs the options form on admin
31
-	 *
32
-	 * @param array $instance The widget options
33
-	 */
34
-	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
35
-	public function form( $instance ) {
36
-		// outputs the options form on admin
37
-	}
29
+    /**
30
+     * Outputs the options form on admin
31
+     *
32
+     * @param array $instance The widget options
33
+     */
34
+    // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
35
+    public function form( $instance ) {
36
+        // outputs the options form on admin
37
+    }
38 38
 
39
-	/**
40
-	 * Processing widget options on save
41
-	 *
42
-	 * @param array $new_instance The new options
43
-	 * @param array $old_instance The previous options
44
-	 */
45
-	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
46
-	public function update( $new_instance, $old_instance ) {
47
-		// processes widget options to be saved
48
-	}
39
+    /**
40
+     * Processing widget options on save
41
+     *
42
+     * @param array $new_instance The new options
43
+     * @param array $old_instance The previous options
44
+     */
45
+    // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
46
+    public function update( $new_instance, $old_instance ) {
47
+        // processes widget options to be saved
48
+    }
49 49
 }
50 50
 
51 51
 function wl_register_timeline_widget() {
52 52
 
53
-	register_widget( 'WordLift_Timeline_Widget' );
53
+    register_widget( 'WordLift_Timeline_Widget' );
54 54
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -9,8 +9,8 @@  discard block
 block discarded – undo
9 9
 		// widget actual processes
10 10
 		parent::__construct(
11 11
 			'wl_timeline_widget', // Base ID
12
-			__( 'WordLift Timeline Widget', 'wordlift' ), // Name
13
-			array( 'description' => __( 'Displays entities of type event using an interactive timeline.', 'wordlift' ) ) // Args
12
+			__('WordLift Timeline Widget', 'wordlift'), // Name
13
+			array('description' => __('Displays entities of type event using an interactive timeline.', 'wordlift')) // Args
14 14
 		);
15 15
 	}
16 16
 
@@ -21,9 +21,9 @@  discard block
 block discarded – undo
21 21
 	 * @param array $instance
22 22
 	 */
23 23
 	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
24
-	public function widget( $args, $instance ) {
24
+	public function widget($args, $instance) {
25 25
 		// outputs the content of the widget
26
-		echo do_shortcode( '[wl_timeline global=true]' );
26
+		echo do_shortcode('[wl_timeline global=true]');
27 27
 	}
28 28
 
29 29
 	/**
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
 	 * @param array $instance The widget options
33 33
 	 */
34 34
 	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
35
-	public function form( $instance ) {
35
+	public function form($instance) {
36 36
 		// outputs the options form on admin
37 37
 	}
38 38
 
@@ -43,12 +43,12 @@  discard block
 block discarded – undo
43 43
 	 * @param array $old_instance The previous options
44 44
 	 */
45 45
 	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
46
-	public function update( $new_instance, $old_instance ) {
46
+	public function update($new_instance, $old_instance) {
47 47
 		// processes widget options to be saved
48 48
 	}
49 49
 }
50 50
 
51 51
 function wl_register_timeline_widget() {
52 52
 
53
-	register_widget( 'WordLift_Timeline_Widget' );
53
+	register_widget('WordLift_Timeline_Widget');
54 54
 }
Please login to merge, or discard this patch.
src/widgets/class-wordlift-chord-widget.php 2 patches
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -10,56 +10,56 @@  discard block
 block discarded – undo
10 10
  */
11 11
 class Wordlift_Chord_Widget extends WP_Widget {
12 12
 
13
-	/**
14
-	 * Sets up the widgets name etc
15
-	 */
16
-	public function __construct() {
17
-		// widget actual processes.
18
-		parent::__construct(
19
-			'wl_chord_widget', // Base ID.
20
-			__( 'Chord Widget', 'wordlift' ), // Name.
21
-			array(
22
-				'description' => __( 'The Chord Widget depicts the main topics of your blog in concise graph.', 'wordlift' ),
23
-			) // Args.
24
-		);
25
-	}
13
+    /**
14
+     * Sets up the widgets name etc
15
+     */
16
+    public function __construct() {
17
+        // widget actual processes.
18
+        parent::__construct(
19
+            'wl_chord_widget', // Base ID.
20
+            __( 'Chord Widget', 'wordlift' ), // Name.
21
+            array(
22
+                'description' => __( 'The Chord Widget depicts the main topics of your blog in concise graph.', 'wordlift' ),
23
+            ) // Args.
24
+        );
25
+    }
26 26
 
27
-	/**
28
-	 * Outputs the content of the widget
29
-	 *
30
-	 * @param array $args widget args.
31
-	 * @param array $instance widget instance.
32
-	 */
33
-	// @codingStandardsIgnoreLine Generic.CodeAnalysis.UnusedFunctionParameter.Found
34
-	public function widget( $args, $instance ) {
35
-		// outputs the content of the widget.
36
-		echo do_shortcode( '[wl_chord global=true]' );
37
-	}
27
+    /**
28
+     * Outputs the content of the widget
29
+     *
30
+     * @param array $args widget args.
31
+     * @param array $instance widget instance.
32
+     */
33
+    // @codingStandardsIgnoreLine Generic.CodeAnalysis.UnusedFunctionParameter.Found
34
+    public function widget( $args, $instance ) {
35
+        // outputs the content of the widget.
36
+        echo do_shortcode( '[wl_chord global=true]' );
37
+    }
38 38
 
39
-	/**
40
-	 * Outputs the options form on admin
41
-	 *
42
-	 * @param array $instance The widget options.
43
-	 *
44
-	 * @return string|void
45
-	 */
46
-	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
47
-	public function form( $instance ) {
48
-		// outputs the options form on admin.
49
-	}
39
+    /**
40
+     * Outputs the options form on admin
41
+     *
42
+     * @param array $instance The widget options.
43
+     *
44
+     * @return string|void
45
+     */
46
+    // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
47
+    public function form( $instance ) {
48
+        // outputs the options form on admin.
49
+    }
50 50
 
51
-	/**
52
-	 * Processing widget options on save
53
-	 *
54
-	 * @param array $new_instance The new options.
55
-	 * @param array $old_instance The previous options.
56
-	 *
57
-	 * @return array|void
58
-	 */
59
-	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
60
-	public function update( $new_instance, $old_instance ) {
61
-		// processes widget options to be saved.
62
-	}
51
+    /**
52
+     * Processing widget options on save
53
+     *
54
+     * @param array $new_instance The new options.
55
+     * @param array $old_instance The previous options.
56
+     *
57
+     * @return array|void
58
+     */
59
+    // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
60
+    public function update( $new_instance, $old_instance ) {
61
+        // processes widget options to be saved.
62
+    }
63 63
 }
64 64
 
65 65
 /**
@@ -69,5 +69,5 @@  discard block
 block discarded – undo
69 69
  */
70 70
 function wl_register_chord_widget() {
71 71
 
72
-	register_widget( 'WordLift_Chord_Widget' );
72
+    register_widget( 'WordLift_Chord_Widget' );
73 73
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -17,9 +17,9 @@  discard block
 block discarded – undo
17 17
 		// widget actual processes.
18 18
 		parent::__construct(
19 19
 			'wl_chord_widget', // Base ID.
20
-			__( 'Chord Widget', 'wordlift' ), // Name.
20
+			__('Chord Widget', 'wordlift'), // Name.
21 21
 			array(
22
-				'description' => __( 'The Chord Widget depicts the main topics of your blog in concise graph.', 'wordlift' ),
22
+				'description' => __('The Chord Widget depicts the main topics of your blog in concise graph.', 'wordlift'),
23 23
 			) // Args.
24 24
 		);
25 25
 	}
@@ -31,9 +31,9 @@  discard block
 block discarded – undo
31 31
 	 * @param array $instance widget instance.
32 32
 	 */
33 33
 	// @codingStandardsIgnoreLine Generic.CodeAnalysis.UnusedFunctionParameter.Found
34
-	public function widget( $args, $instance ) {
34
+	public function widget($args, $instance) {
35 35
 		// outputs the content of the widget.
36
-		echo do_shortcode( '[wl_chord global=true]' );
36
+		echo do_shortcode('[wl_chord global=true]');
37 37
 	}
38 38
 
39 39
 	/**
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
 	 * @return string|void
45 45
 	 */
46 46
 	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
47
-	public function form( $instance ) {
47
+	public function form($instance) {
48 48
 		// outputs the options form on admin.
49 49
 	}
50 50
 
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 	 * @return array|void
58 58
 	 */
59 59
 	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
60
-	public function update( $new_instance, $old_instance ) {
60
+	public function update($new_instance, $old_instance) {
61 61
 		// processes widget options to be saved.
62 62
 	}
63 63
 }
@@ -69,5 +69,5 @@  discard block
 block discarded – undo
69 69
  */
70 70
 function wl_register_chord_widget() {
71 71
 
72
-	register_widget( 'WordLift_Chord_Widget' );
72
+	register_widget('WordLift_Chord_Widget');
73 73
 }
Please login to merge, or discard this patch.
src/wordlift-constants.php 2 patches
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
 
14 14
 // Use the WordLift API URL set on the command line.
15 15
 if ( ! defined( 'WORDLIFT_API_URL' ) && false !== getenv( 'WORDLIFT_API_URL' ) ) {
16
-	define( 'WORDLIFT_API_URL', getenv( 'WORDLIFT_API_URL' ) );
16
+    define( 'WORDLIFT_API_URL', getenv( 'WORDLIFT_API_URL' ) );
17 17
 }
18 18
 
19 19
 // 3.13.0, we use by default WLS 1.11 which provides us with the new, faster
@@ -52,15 +52,15 @@  discard block
 block discarded – undo
52 52
  * @since 3.16.0
53 53
  */
54 54
 function wl_temp_dir() {
55
-	$tempdir         = get_temp_dir();
56
-	$unique          = md5( site_url() . get_current_blog_id() );
57
-	$unique_temp_dir = $tempdir . 'wl_' . $unique; // $tempdir should have a trailing slash.
55
+    $tempdir         = get_temp_dir();
56
+    $unique          = md5( site_url() . get_current_blog_id() );
57
+    $unique_temp_dir = $tempdir . 'wl_' . $unique; // $tempdir should have a trailing slash.
58 58
 
59
-	// If directory do not exist, create it.
60
-	if ( ! file_exists( $unique_temp_dir ) ) {
61
-		// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
62
-		@mkdir( $unique_temp_dir );
63
-	}
59
+    // If directory do not exist, create it.
60
+    if ( ! file_exists( $unique_temp_dir ) ) {
61
+        // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
62
+        @mkdir( $unique_temp_dir );
63
+    }
64 64
 
65
-	return $unique_temp_dir . '/';
65
+    return $unique_temp_dir . '/';
66 66
 }
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -6,43 +6,43 @@  discard block
 block discarded – undo
6 6
  */
7 7
 
8 8
 // Set the temporary files folder.
9
-defined( 'WL_TEMP_DIR' ) || define( 'WL_TEMP_DIR', wl_temp_dir() );
9
+defined('WL_TEMP_DIR') || define('WL_TEMP_DIR', wl_temp_dir());
10 10
 
11 11
 // Define the meta name used to store the entity URL.
12
-define( 'WL_ENTITY_URL_META_NAME', 'entity_url' );
12
+define('WL_ENTITY_URL_META_NAME', 'entity_url');
13 13
 
14 14
 // WordLift Directory URL.
15
-defined( 'WL_DIR_URL' ) || define( 'WL_DIR_URL', plugin_dir_url( __FILE__ ) );
15
+defined('WL_DIR_URL') || define('WL_DIR_URL', plugin_dir_url(__FILE__));
16 16
 
17 17
 // Use the WordLift API URL set on the command line.
18
-if ( ! defined( 'WORDLIFT_API_URL' ) && false !== getenv( 'WORDLIFT_API_URL' ) ) {
19
-	define( 'WORDLIFT_API_URL', getenv( 'WORDLIFT_API_URL' ) );
18
+if ( ! defined('WORDLIFT_API_URL') && false !== getenv('WORDLIFT_API_URL')) {
19
+	define('WORDLIFT_API_URL', getenv('WORDLIFT_API_URL'));
20 20
 }
21 21
 
22 22
 // 3.13.0, we use by default WLS 1.11 which provides us with the new, faster
23 23
 // chunked analysis.
24
-define( 'WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE', defined( 'WORDLIFT_API_URL' ) ? WORDLIFT_API_URL . '/' : 'https://api.wordlift.io/' );
24
+define('WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE', defined('WORDLIFT_API_URL') ? WORDLIFT_API_URL . '/' : 'https://api.wordlift.io/');
25 25
 
26 26
 // @since 3.29.0 we do not use https://developers.google.com/structured-data/testing-tool/?url=
27
-define( 'WL_CONFIG_TEST_GOOGLE_RICH_SNIPPETS_URL', 'https://search.google.com/test/rich-results?url=' );
27
+define('WL_CONFIG_TEST_GOOGLE_RICH_SNIPPETS_URL', 'https://search.google.com/test/rich-results?url=');
28 28
 
29 29
 // If is set to true, there will be additional button in 'Download Your Data' page
30 30
 // that will allow users to download their data in JSON-LD format.
31
-defined( 'WL_CONFIG_DOWNLOAD_GA_CONTENT_DATA' ) || define( 'WL_CONFIG_DOWNLOAD_GA_CONTENT_DATA', false );
31
+defined('WL_CONFIG_DOWNLOAD_GA_CONTENT_DATA') || define('WL_CONFIG_DOWNLOAD_GA_CONTENT_DATA', false);
32 32
 
33 33
 /*
34 34
  * Define the default scope for autocomplete requests.
35 35
  *
36 36
  * @see https://github.com/insideout10/wordlift-plugin/issues/839
37 37
  */
38
-defined( 'WL_AUTOCOMPLETE_SCOPE' ) || define( 'WL_AUTOCOMPLETE_SCOPE', 'cloud' );
38
+defined('WL_AUTOCOMPLETE_SCOPE') || define('WL_AUTOCOMPLETE_SCOPE', 'cloud');
39 39
 
40 40
 /*
41 41
  * Enable/disable the `all entity types` feature. Initially we keep the feature disabled to enture proper Q/A.
42 42
  *
43 43
  * @see https://github.com/insideout10/wordlift-plugin/issues/835
44 44
  */
45
-defined( 'WL_ALL_ENTITY_TYPES' ) || define( 'WL_ALL_ENTITY_TYPES', false );
45
+defined('WL_ALL_ENTITY_TYPES') || define('WL_ALL_ENTITY_TYPES', false);
46 46
 
47 47
 /**
48 48
  * Get a site unique directory under the system or WordPress temporary directory.
@@ -56,14 +56,14 @@  discard block
 block discarded – undo
56 56
  */
57 57
 function wl_temp_dir() {
58 58
 	$tempdir         = get_temp_dir();
59
-	$unique          = md5( site_url() . get_current_blog_id() );
60
-	$unique_temp_dir = $tempdir . 'wl_' . $unique; // $tempdir should have a trailing slash.
59
+	$unique          = md5(site_url().get_current_blog_id());
60
+	$unique_temp_dir = $tempdir.'wl_'.$unique; // $tempdir should have a trailing slash.
61 61
 
62 62
 	// If directory do not exist, create it.
63
-	if ( ! file_exists( $unique_temp_dir ) ) {
63
+	if ( ! file_exists($unique_temp_dir)) {
64 64
 		// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
65
-		@mkdir( $unique_temp_dir );
65
+		@mkdir($unique_temp_dir);
66 66
 	}
67 67
 
68
-	return $unique_temp_dir . '/';
68
+	return $unique_temp_dir.'/';
69 69
 }
Please login to merge, or discard this patch.
src/deprecations.php 2 patches
Indentation   +96 added lines, -96 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  */
18 18
 function wl_write_log( $log ) {
19 19
 
20
-	Wordlift_Log_Service::get_instance()->debug( $log );
20
+    Wordlift_Log_Service::get_instance()->debug( $log );
21 21
 
22 22
 }
23 23
 
@@ -26,21 +26,21 @@  discard block
 block discarded – undo
26 26
  * see http://vip.wordpress.com/documentation/register-additional-html-attributes-for-tinymce-and-wp-kses/
27 27
  */
28 28
 function wordlift_allowed_post_tags() {
29
-	global $allowedposttags;
30
-
31
-	$tags           = array( 'span' );
32
-	$new_attributes = array(
33
-		'itemscope' => array(),
34
-		'itemtype'  => array(),
35
-		'itemprop'  => array(),
36
-		'itemid'    => array(),
37
-	);
38
-
39
-	foreach ( $tags as $tag ) {
40
-		if ( isset( $allowedposttags[ $tag ] ) && is_array( $allowedposttags[ $tag ] ) ) {
41
-			$allowedposttags[ $tag ] = array_merge( $allowedposttags[ $tag ], $new_attributes ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
42
-		}
43
-	}
29
+    global $allowedposttags;
30
+
31
+    $tags           = array( 'span' );
32
+    $new_attributes = array(
33
+        'itemscope' => array(),
34
+        'itemtype'  => array(),
35
+        'itemprop'  => array(),
36
+        'itemid'    => array(),
37
+    );
38
+
39
+    foreach ( $tags as $tag ) {
40
+        if ( isset( $allowedposttags[ $tag ] ) && is_array( $allowedposttags[ $tag ] ) ) {
41
+            $allowedposttags[ $tag ] = array_merge( $allowedposttags[ $tag ], $new_attributes ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
42
+        }
43
+    }
44 44
 }
45 45
 
46 46
 // add allowed post tags.
@@ -51,18 +51,18 @@  discard block
 block discarded – undo
51 51
  */
52 52
 function wordlift_admin_enqueue_scripts() {
53 53
 
54
-	// Added for compatibility with WordPress 3.9 (see http://make.wordpress.org/core/2014/04/16/jquery-ui-and-wpdialogs-in-wordpress-3-9/)
55
-	wp_enqueue_script( 'wpdialogs' );
56
-	wp_enqueue_style( 'wp-jquery-ui-dialog' );
54
+    // Added for compatibility with WordPress 3.9 (see http://make.wordpress.org/core/2014/04/16/jquery-ui-and-wpdialogs-in-wordpress-3-9/)
55
+    wp_enqueue_script( 'wpdialogs' );
56
+    wp_enqueue_style( 'wp-jquery-ui-dialog' );
57 57
 
58
-	wp_enqueue_style( 'wordlift-reloaded', plugin_dir_url( __FILE__ ) . 'css/wordlift-reloaded.min.css', array(), WORDLIFT_VERSION );
58
+    wp_enqueue_style( 'wordlift-reloaded', plugin_dir_url( __FILE__ ) . 'css/wordlift-reloaded.min.css', array(), WORDLIFT_VERSION );
59 59
 
60
-	wp_enqueue_script( 'jquery-ui-autocomplete' );
60
+    wp_enqueue_script( 'jquery-ui-autocomplete' );
61 61
 
62
-	// Disable auto-save for custom entity posts only
63
-	if ( Wordlift_Entity_Service::TYPE_NAME === get_post_type() ) {
64
-		wp_dequeue_script( 'autosave' );
65
-	}
62
+    // Disable auto-save for custom entity posts only
63
+    if ( Wordlift_Entity_Service::TYPE_NAME === get_post_type() ) {
64
+        wp_dequeue_script( 'autosave' );
65
+    }
66 66
 
67 67
 }
68 68
 
@@ -78,21 +78,21 @@  discard block
 block discarded – undo
78 78
  */
79 79
 function wordlift_allowed_html( $allowedtags, $context ) {
80 80
 
81
-	if ( 'post' !== $context ) {
82
-		return $allowedtags;
83
-	}
84
-
85
-	return array_merge_recursive(
86
-		$allowedtags,
87
-		array(
88
-			'span' => array(
89
-				'itemscope' => true,
90
-				'itemtype'  => true,
91
-				'itemid'    => true,
92
-				'itemprop'  => true,
93
-			),
94
-		)
95
-	);
81
+    if ( 'post' !== $context ) {
82
+        return $allowedtags;
83
+    }
84
+
85
+    return array_merge_recursive(
86
+        $allowedtags,
87
+        array(
88
+            'span' => array(
89
+                'itemscope' => true,
90
+                'itemtype'  => true,
91
+                'itemid'    => true,
92
+                'itemprop'  => true,
93
+            ),
94
+        )
95
+    );
96 96
 }
97 97
 
98 98
 add_filter( 'wp_kses_allowed_html', 'wordlift_allowed_html', 10, 2 );
@@ -107,9 +107,9 @@  discard block
 block discarded – undo
107 107
  */
108 108
 function wl_get_image_urls( $post_id ) {
109 109
 
110
-	return Wordlift_Storage_Factory::get_instance()
111
-								   ->post_images()
112
-								   ->get( $post_id );
110
+    return Wordlift_Storage_Factory::get_instance()
111
+                                    ->post_images()
112
+                                    ->get( $post_id );
113 113
 
114 114
 }
115 115
 
@@ -123,26 +123,26 @@  discard block
 block discarded – undo
123 123
  */
124 124
 function wl_get_attachment_for_source_url( $parent_post_id, $source_url ) {
125 125
 
126
-	// wl_write_log( "wl_get_attachment_for_source_url [ parent post id :: $parent_post_id ][ source url :: $source_url ]" );
127
-
128
-	$posts = get_posts(
129
-		array(
130
-			'post_type'      => 'attachment',
131
-			'posts_per_page' => 1,
132
-			'post_status'    => 'any',
133
-			'post_parent'    => $parent_post_id,
134
-			'meta_key'       => 'wl_source_url',
135
-			'meta_value'     => $source_url,
136
-		)
137
-	);
138
-
139
-	// Return the found post.
140
-	if ( 1 === count( $posts ) ) {
141
-		return $posts[0];
142
-	}
143
-
144
-	// Return null.
145
-	return null;
126
+    // wl_write_log( "wl_get_attachment_for_source_url [ parent post id :: $parent_post_id ][ source url :: $source_url ]" );
127
+
128
+    $posts = get_posts(
129
+        array(
130
+            'post_type'      => 'attachment',
131
+            'posts_per_page' => 1,
132
+            'post_status'    => 'any',
133
+            'post_parent'    => $parent_post_id,
134
+            'meta_key'       => 'wl_source_url',
135
+            'meta_value'     => $source_url,
136
+        )
137
+    );
138
+
139
+    // Return the found post.
140
+    if ( 1 === count( $posts ) ) {
141
+        return $posts[0];
142
+    }
143
+
144
+    // Return null.
145
+    return null;
146 146
 }
147 147
 
148 148
 /**
@@ -153,8 +153,8 @@  discard block
 block discarded – undo
153 153
  */
154 154
 function wl_set_source_url( $post_id, $source_url ) {
155 155
 
156
-	delete_post_meta( $post_id, 'wl_source_url' );
157
-	add_post_meta( $post_id, 'wl_source_url', $source_url );
156
+    delete_post_meta( $post_id, 'wl_source_url' );
157
+    add_post_meta( $post_id, 'wl_source_url', $source_url );
158 158
 }
159 159
 
160 160
 /**
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
  */
171 171
 function wl_sanitize_uri_path( $path, $char = '_' ) {
172 172
 
173
-	return Wordlift_Uri_Service::get_instance()->sanitize_path( $path, $char );
173
+    return Wordlift_Uri_Service::get_instance()->sanitize_path( $path, $char );
174 174
 }
175 175
 
176 176
 /**
@@ -182,47 +182,47 @@  discard block
 block discarded – undo
182 182
  */
183 183
 function wl_replace_item_id_with_uri( $content ) {
184 184
 
185
-	$log = Wordlift_Log_Service::get_logger( 'wl_replace_item_id_with_uri' );
186
-	$log->trace( 'Replacing item IDs with URIs...' );
185
+    $log = Wordlift_Log_Service::get_logger( 'wl_replace_item_id_with_uri' );
186
+    $log->trace( 'Replacing item IDs with URIs...' );
187 187
 
188
-	// Strip slashes, see https://core.trac.wordpress.org/ticket/21767
189
-	$content = stripslashes( $content );
188
+    // Strip slashes, see https://core.trac.wordpress.org/ticket/21767
189
+    $content = stripslashes( $content );
190 190
 
191
-	// If any match are found.
192
-	$matches = array();
193
-	if ( 0 < preg_match_all( '/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER ) ) {
191
+    // If any match are found.
192
+    $matches = array();
193
+    if ( 0 < preg_match_all( '/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER ) ) {
194 194
 
195
-		foreach ( $matches as $match ) {
195
+        foreach ( $matches as $match ) {
196 196
 
197
-			// Get the item ID.
198
-			$item_id = $match[1];
197
+            // Get the item ID.
198
+            $item_id = $match[1];
199 199
 
200
-			// Get the post bound to that item ID (looking both in the 'official' URI and in the 'same-as' .
201
-			$post = Wordlift_Entity_Service::get_instance()
202
-										   ->get_entity_post_by_uri( $item_id );
200
+            // Get the post bound to that item ID (looking both in the 'official' URI and in the 'same-as' .
201
+            $post = Wordlift_Entity_Service::get_instance()
202
+                                            ->get_entity_post_by_uri( $item_id );
203 203
 
204
-			// If no entity is found, continue to the next one.
205
-			if ( null === $post ) {
206
-				continue;
207
-			}
204
+            // If no entity is found, continue to the next one.
205
+            if ( null === $post ) {
206
+                continue;
207
+            }
208 208
 
209
-			// Get the URI for that post.
210
-			$uri = wl_get_entity_uri( $post->ID );
209
+            // Get the URI for that post.
210
+            $uri = wl_get_entity_uri( $post->ID );
211 211
 
212
-			// wl_write_log( "wl_replace_item_id_with_uri [ item id :: $item_id ][ uri :: $uri ]" );
212
+            // wl_write_log( "wl_replace_item_id_with_uri [ item id :: $item_id ][ uri :: $uri ]" );
213 213
 
214
-			// If the item ID and the URI differ, replace the item ID with the URI saved in WordPress.
215
-			if ( ! empty( $uri ) && $item_id !== $uri ) {
216
-				$uri_e   = esc_html( $uri );
217
-				$content = str_replace( " itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content );
218
-			}
219
-		}
220
-	}
214
+            // If the item ID and the URI differ, replace the item ID with the URI saved in WordPress.
215
+            if ( ! empty( $uri ) && $item_id !== $uri ) {
216
+                $uri_e   = esc_html( $uri );
217
+                $content = str_replace( " itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content );
218
+            }
219
+        }
220
+    }
221 221
 
222
-	// Reapply slashes.
223
-	$content = addslashes( $content );
222
+    // Reapply slashes.
223
+    $content = addslashes( $content );
224 224
 
225
-	return $content;
225
+    return $content;
226 226
 }
227 227
 
228 228
 add_filter( 'content_save_pre', 'wl_replace_item_id_with_uri', 1, 1 );
Please login to merge, or discard this patch.
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -15,9 +15,9 @@  discard block
 block discarded – undo
15 15
  *
16 16
  * @deprecated use Wordlift_Log_Service::get_instance()->info( $log );
17 17
  */
18
-function wl_write_log( $log ) {
18
+function wl_write_log($log) {
19 19
 
20
-	Wordlift_Log_Service::get_instance()->debug( $log );
20
+	Wordlift_Log_Service::get_instance()->debug($log);
21 21
 
22 22
 }
23 23
 
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
 function wordlift_allowed_post_tags() {
29 29
 	global $allowedposttags;
30 30
 
31
-	$tags           = array( 'span' );
31
+	$tags           = array('span');
32 32
 	$new_attributes = array(
33 33
 		'itemscope' => array(),
34 34
 		'itemtype'  => array(),
@@ -36,15 +36,15 @@  discard block
 block discarded – undo
36 36
 		'itemid'    => array(),
37 37
 	);
38 38
 
39
-	foreach ( $tags as $tag ) {
40
-		if ( isset( $allowedposttags[ $tag ] ) && is_array( $allowedposttags[ $tag ] ) ) {
41
-			$allowedposttags[ $tag ] = array_merge( $allowedposttags[ $tag ], $new_attributes ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
39
+	foreach ($tags as $tag) {
40
+		if (isset($allowedposttags[$tag]) && is_array($allowedposttags[$tag])) {
41
+			$allowedposttags[$tag] = array_merge($allowedposttags[$tag], $new_attributes); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
42 42
 		}
43 43
 	}
44 44
 }
45 45
 
46 46
 // add allowed post tags.
47
-add_action( 'init', 'wordlift_allowed_post_tags' );
47
+add_action('init', 'wordlift_allowed_post_tags');
48 48
 
49 49
 /**
50 50
  * Register additional scripts for the admin UI.
@@ -52,21 +52,21 @@  discard block
 block discarded – undo
52 52
 function wordlift_admin_enqueue_scripts() {
53 53
 
54 54
 	// Added for compatibility with WordPress 3.9 (see http://make.wordpress.org/core/2014/04/16/jquery-ui-and-wpdialogs-in-wordpress-3-9/)
55
-	wp_enqueue_script( 'wpdialogs' );
56
-	wp_enqueue_style( 'wp-jquery-ui-dialog' );
55
+	wp_enqueue_script('wpdialogs');
56
+	wp_enqueue_style('wp-jquery-ui-dialog');
57 57
 
58
-	wp_enqueue_style( 'wordlift-reloaded', plugin_dir_url( __FILE__ ) . 'css/wordlift-reloaded.min.css', array(), WORDLIFT_VERSION );
58
+	wp_enqueue_style('wordlift-reloaded', plugin_dir_url(__FILE__).'css/wordlift-reloaded.min.css', array(), WORDLIFT_VERSION);
59 59
 
60
-	wp_enqueue_script( 'jquery-ui-autocomplete' );
60
+	wp_enqueue_script('jquery-ui-autocomplete');
61 61
 
62 62
 	// Disable auto-save for custom entity posts only
63
-	if ( Wordlift_Entity_Service::TYPE_NAME === get_post_type() ) {
64
-		wp_dequeue_script( 'autosave' );
63
+	if (Wordlift_Entity_Service::TYPE_NAME === get_post_type()) {
64
+		wp_dequeue_script('autosave');
65 65
 	}
66 66
 
67 67
 }
68 68
 
69
-add_action( 'admin_enqueue_scripts', 'wordlift_admin_enqueue_scripts' );
69
+add_action('admin_enqueue_scripts', 'wordlift_admin_enqueue_scripts');
70 70
 
71 71
 /**
72 72
  * Hooked to *wp_kses_allowed_html* filter, adds microdata attributes.
@@ -76,9 +76,9 @@  discard block
 block discarded – undo
76 76
  *
77 77
  * @return array An array which contains allowed microdata attributes.
78 78
  */
79
-function wordlift_allowed_html( $allowedtags, $context ) {
79
+function wordlift_allowed_html($allowedtags, $context) {
80 80
 
81
-	if ( 'post' !== $context ) {
81
+	if ('post' !== $context) {
82 82
 		return $allowedtags;
83 83
 	}
84 84
 
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
 	);
96 96
 }
97 97
 
98
-add_filter( 'wp_kses_allowed_html', 'wordlift_allowed_html', 10, 2 );
98
+add_filter('wp_kses_allowed_html', 'wordlift_allowed_html', 10, 2);
99 99
 
100 100
 /**
101 101
  * Get all the images bound to a post.
@@ -105,11 +105,11 @@  discard block
 block discarded – undo
105 105
  * @return array An array of image URLs.
106 106
  * @deprecated use Wordlift_Storage_Factory::get_instance()->post_images()->get( $post_id )
107 107
  */
108
-function wl_get_image_urls( $post_id ) {
108
+function wl_get_image_urls($post_id) {
109 109
 
110 110
 	return Wordlift_Storage_Factory::get_instance()
111 111
 								   ->post_images()
112
-								   ->get( $post_id );
112
+								   ->get($post_id);
113 113
 
114 114
 }
115 115
 
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
  *
122 122
  * @return WP_Post|null A post instance or null if not found.
123 123
  */
124
-function wl_get_attachment_for_source_url( $parent_post_id, $source_url ) {
124
+function wl_get_attachment_for_source_url($parent_post_id, $source_url) {
125 125
 
126 126
 	// wl_write_log( "wl_get_attachment_for_source_url [ parent post id :: $parent_post_id ][ source url :: $source_url ]" );
127 127
 
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
 	);
138 138
 
139 139
 	// Return the found post.
140
-	if ( 1 === count( $posts ) ) {
140
+	if (1 === count($posts)) {
141 141
 		return $posts[0];
142 142
 	}
143 143
 
@@ -151,10 +151,10 @@  discard block
 block discarded – undo
151 151
  * @param int    $post_id The post ID.
152 152
  * @param string $source_url The source URL.
153 153
  */
154
-function wl_set_source_url( $post_id, $source_url ) {
154
+function wl_set_source_url($post_id, $source_url) {
155 155
 
156
-	delete_post_meta( $post_id, 'wl_source_url' );
157
-	add_post_meta( $post_id, 'wl_source_url', $source_url );
156
+	delete_post_meta($post_id, 'wl_source_url');
157
+	add_post_meta($post_id, 'wl_source_url', $source_url);
158 158
 }
159 159
 
160 160
 /**
@@ -168,9 +168,9 @@  discard block
 block discarded – undo
168 168
  * @deprecated use Wordlift_Uri_Service::get_instance()->sanitize_path();
169 169
  * @see        https://codex.wordpress.org/Function_Reference/sanitize_title
170 170
  */
171
-function wl_sanitize_uri_path( $path, $char = '_' ) {
171
+function wl_sanitize_uri_path($path, $char = '_') {
172 172
 
173
-	return Wordlift_Uri_Service::get_instance()->sanitize_path( $path, $char );
173
+	return Wordlift_Uri_Service::get_instance()->sanitize_path($path, $char);
174 174
 }
175 175
 
176 176
 /**
@@ -180,52 +180,52 @@  discard block
 block discarded – undo
180 180
  *
181 181
  * @return string The updated post content.
182 182
  */
183
-function wl_replace_item_id_with_uri( $content ) {
183
+function wl_replace_item_id_with_uri($content) {
184 184
 
185
-	$log = Wordlift_Log_Service::get_logger( 'wl_replace_item_id_with_uri' );
186
-	$log->trace( 'Replacing item IDs with URIs...' );
185
+	$log = Wordlift_Log_Service::get_logger('wl_replace_item_id_with_uri');
186
+	$log->trace('Replacing item IDs with URIs...');
187 187
 
188 188
 	// Strip slashes, see https://core.trac.wordpress.org/ticket/21767
189
-	$content = stripslashes( $content );
189
+	$content = stripslashes($content);
190 190
 
191 191
 	// If any match are found.
192 192
 	$matches = array();
193
-	if ( 0 < preg_match_all( '/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER ) ) {
193
+	if (0 < preg_match_all('/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER)) {
194 194
 
195
-		foreach ( $matches as $match ) {
195
+		foreach ($matches as $match) {
196 196
 
197 197
 			// Get the item ID.
198 198
 			$item_id = $match[1];
199 199
 
200 200
 			// Get the post bound to that item ID (looking both in the 'official' URI and in the 'same-as' .
201 201
 			$post = Wordlift_Entity_Service::get_instance()
202
-										   ->get_entity_post_by_uri( $item_id );
202
+										   ->get_entity_post_by_uri($item_id);
203 203
 
204 204
 			// If no entity is found, continue to the next one.
205
-			if ( null === $post ) {
205
+			if (null === $post) {
206 206
 				continue;
207 207
 			}
208 208
 
209 209
 			// Get the URI for that post.
210
-			$uri = wl_get_entity_uri( $post->ID );
210
+			$uri = wl_get_entity_uri($post->ID);
211 211
 
212 212
 			// wl_write_log( "wl_replace_item_id_with_uri [ item id :: $item_id ][ uri :: $uri ]" );
213 213
 
214 214
 			// If the item ID and the URI differ, replace the item ID with the URI saved in WordPress.
215
-			if ( ! empty( $uri ) && $item_id !== $uri ) {
216
-				$uri_e   = esc_html( $uri );
217
-				$content = str_replace( " itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content );
215
+			if ( ! empty($uri) && $item_id !== $uri) {
216
+				$uri_e   = esc_html($uri);
217
+				$content = str_replace(" itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content);
218 218
 			}
219 219
 		}
220 220
 	}
221 221
 
222 222
 	// Reapply slashes.
223
-	$content = addslashes( $content );
223
+	$content = addslashes($content);
224 224
 
225 225
 	return $content;
226 226
 }
227 227
 
228
-add_filter( 'content_save_pre', 'wl_replace_item_id_with_uri', 1, 1 );
228
+add_filter('content_save_pre', 'wl_replace_item_id_with_uri', 1, 1);
229 229
 
230 230
 require_once 'wordlift-entity-functions.php';
231 231
 
Please login to merge, or discard this patch.
src/js/dist/gutenberg-faq-plugin.asset.php 2 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@
 block discarded – undo
1 1
 <?php return array(
2
-	'dependencies' => array( 'wp-polyfill', 'wp-rich-text' ),
3
-	'version'      => '18770cde607d785a81b65ef98e409669',
2
+    'dependencies' => array( 'wp-polyfill', 'wp-rich-text' ),
3
+    'version'      => '18770cde607d785a81b65ef98e409669',
4 4
 );
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@
 block discarded – undo
1 1
 <?php return array(
2
-	'dependencies' => array( 'wp-polyfill', 'wp-rich-text' ),
2
+	'dependencies' => array('wp-polyfill', 'wp-rich-text'),
3 3
 	'version'      => '18770cde607d785a81b65ef98e409669',
4 4
 );
Please login to merge, or discard this patch.
src/admin/class-wordlift-entity-types-taxonomy-walker.php 2 patches
Indentation   +109 added lines, -109 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
  * @subpackage Wordlift/includes
11 11
  */
12 12
 if ( ! class_exists( 'Walker_Category_Checklist' ) ) {
13
-	require_once ABSPATH . 'wp-admin/includes/template.php';
13
+    require_once ABSPATH . 'wp-admin/includes/template.php';
14 14
 }
15 15
 
16 16
 /**
@@ -24,113 +24,113 @@  discard block
 block discarded – undo
24 24
 // phpcs:ignore Generic.Classes.DuplicateClassName.Found
25 25
 class Wordlift_Entity_Types_Taxonomy_Walker extends Walker_Category_Checklist {
26 26
 
27
-	/**
28
-	 * Entity taxonomy metabox must show exclusive options, no checkboxes.
29
-	 *
30
-	 * @since 3.1.0
31
-	 *
32
-	 * @param       $args     {
33
-	 *                        An array of arguments.
34
-	 *
35
-	 * @type string $taxonomy The taxonomy name.
36
-	 *              }
37
-	 *
38
-	 * @return array An array of arguments, with this walker in case the taxonomy is the Entity Type taxonomy.
39
-	 */
40
-	public function terms_checklist_args( $args ) {
41
-
42
-		if ( ! isset( $args['taxonomy'] ) || Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME !== $args['taxonomy'] ) {
43
-			return $args;
44
-		}
45
-
46
-		// We override the way WP prints the taxonomy metabox HTML.
47
-		$args['walker']        = $this;
48
-		$args['checked_ontop'] = false;
49
-
50
-		return $args;
51
-
52
-	}
53
-
54
-	/**
55
-	 * Change checkboxes to radios.
56
-	 *
57
-	 * $max_depth = -1 means flatly display every element.
58
-	 * $max_depth = 0 means display all levels.
59
-	 * $max_depth > 0 specifies the number of display levels.
60
-	 *
61
-	 * @since 3.1.0
62
-	 *
63
-	 * @param array $elements  An array of elements.
64
-	 * @param int   $max_depth The maximum hierarchical depth.
65
-	 *
66
-	 * @param array $args      Additional arguments.
67
-	 *
68
-	 * @return string The hierarchical item output.
69
-	 */
70
-	public function walk( $elements, $max_depth, $args = array() ) {
71
-
72
-		// `max_depth` force to -1 to display a flat taxonomy.
73
-		//
74
-		// See https://github.com/insideout10/wordlift-plugin/issues/305
75
-		$output = parent::walk( $elements, - 1, $args );
76
-
77
-		$output = str_replace(
78
-			array( 'type="checkbox"', "type='checkbox'" ),
79
-			array( 'type="radio"', "type='radio'" ),
80
-			$output
81
-		);
82
-
83
-		return $output;
84
-	}
85
-
86
-	/**
87
-	 * Start the element output, output nothing in case of article term.
88
-	 *
89
-	 * @since 3.15.0
90
-	 *
91
-	 * @param string $output   Passed by reference. Used to append additional content.
92
-	 * @param object $category The current term object.
93
-	 * @param int    $depth    Depth of the term in reference to parents. Default 0.
94
-	 * @param array  $args     An array of arguments. @see wp_terms_checklist()
95
-	 * @param int    $id       ID of the current term.
96
-	 */
97
-	public function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
98
-		global $post;
99
-
100
-		if ( ! isset( $post ) ) {
101
-			return;
102
-		}
103
-
104
-		if ( Wordlift_Entity_Service::TYPE_NAME !== $post->post_type
105
-			 || 'article' !== $category->slug
106
-			 || Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME !== $args['taxonomy'] ) {
107
-			parent::start_el( $output, $category, $depth, $args, $id );
108
-		}
109
-	}
110
-
111
-	/**
112
-	 * End the element output, output nothing in case of article term.
113
-	 *
114
-	 * @since 3.15.0
115
-	 *
116
-	 * @param string $output   Passed by reference. Used to append additional content.
117
-	 * @param object $category The current term object.
118
-	 * @param int    $depth    Depth of the term in reference to parents. Default 0.
119
-	 * @param array  $args     An array of arguments. @see wp_terms_checklist()
120
-	 */
121
-	public function end_el( &$output, $category, $depth = 0, $args = array() ) {
122
-		global $post;
123
-
124
-		if ( ! isset( $post ) ) {
125
-			return;
126
-		}
127
-
128
-		if ( Wordlift_Entity_Service::TYPE_NAME !== $post->post_type
129
-			 || 'article' !== $category->slug
130
-			 || Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME !== $args['taxonomy'] ) {
131
-			parent::end_el( $output, $category, $depth, $args );
132
-		}
133
-
134
-	}
27
+    /**
28
+     * Entity taxonomy metabox must show exclusive options, no checkboxes.
29
+     *
30
+     * @since 3.1.0
31
+     *
32
+     * @param       $args     {
33
+     *                        An array of arguments.
34
+     *
35
+     * @type string $taxonomy The taxonomy name.
36
+     *              }
37
+     *
38
+     * @return array An array of arguments, with this walker in case the taxonomy is the Entity Type taxonomy.
39
+     */
40
+    public function terms_checklist_args( $args ) {
41
+
42
+        if ( ! isset( $args['taxonomy'] ) || Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME !== $args['taxonomy'] ) {
43
+            return $args;
44
+        }
45
+
46
+        // We override the way WP prints the taxonomy metabox HTML.
47
+        $args['walker']        = $this;
48
+        $args['checked_ontop'] = false;
49
+
50
+        return $args;
51
+
52
+    }
53
+
54
+    /**
55
+     * Change checkboxes to radios.
56
+     *
57
+     * $max_depth = -1 means flatly display every element.
58
+     * $max_depth = 0 means display all levels.
59
+     * $max_depth > 0 specifies the number of display levels.
60
+     *
61
+     * @since 3.1.0
62
+     *
63
+     * @param array $elements  An array of elements.
64
+     * @param int   $max_depth The maximum hierarchical depth.
65
+     *
66
+     * @param array $args      Additional arguments.
67
+     *
68
+     * @return string The hierarchical item output.
69
+     */
70
+    public function walk( $elements, $max_depth, $args = array() ) {
71
+
72
+        // `max_depth` force to -1 to display a flat taxonomy.
73
+        //
74
+        // See https://github.com/insideout10/wordlift-plugin/issues/305
75
+        $output = parent::walk( $elements, - 1, $args );
76
+
77
+        $output = str_replace(
78
+            array( 'type="checkbox"', "type='checkbox'" ),
79
+            array( 'type="radio"', "type='radio'" ),
80
+            $output
81
+        );
82
+
83
+        return $output;
84
+    }
85
+
86
+    /**
87
+     * Start the element output, output nothing in case of article term.
88
+     *
89
+     * @since 3.15.0
90
+     *
91
+     * @param string $output   Passed by reference. Used to append additional content.
92
+     * @param object $category The current term object.
93
+     * @param int    $depth    Depth of the term in reference to parents. Default 0.
94
+     * @param array  $args     An array of arguments. @see wp_terms_checklist()
95
+     * @param int    $id       ID of the current term.
96
+     */
97
+    public function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
98
+        global $post;
99
+
100
+        if ( ! isset( $post ) ) {
101
+            return;
102
+        }
103
+
104
+        if ( Wordlift_Entity_Service::TYPE_NAME !== $post->post_type
105
+             || 'article' !== $category->slug
106
+             || Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME !== $args['taxonomy'] ) {
107
+            parent::start_el( $output, $category, $depth, $args, $id );
108
+        }
109
+    }
110
+
111
+    /**
112
+     * End the element output, output nothing in case of article term.
113
+     *
114
+     * @since 3.15.0
115
+     *
116
+     * @param string $output   Passed by reference. Used to append additional content.
117
+     * @param object $category The current term object.
118
+     * @param int    $depth    Depth of the term in reference to parents. Default 0.
119
+     * @param array  $args     An array of arguments. @see wp_terms_checklist()
120
+     */
121
+    public function end_el( &$output, $category, $depth = 0, $args = array() ) {
122
+        global $post;
123
+
124
+        if ( ! isset( $post ) ) {
125
+            return;
126
+        }
127
+
128
+        if ( Wordlift_Entity_Service::TYPE_NAME !== $post->post_type
129
+             || 'article' !== $category->slug
130
+             || Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME !== $args['taxonomy'] ) {
131
+            parent::end_el( $output, $category, $depth, $args );
132
+        }
133
+
134
+    }
135 135
 
136 136
 }
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -9,8 +9,8 @@  discard block
 block discarded – undo
9 9
  * @package    Wordlift
10 10
  * @subpackage Wordlift/includes
11 11
  */
12
-if ( ! class_exists( 'Walker_Category_Checklist' ) ) {
13
-	require_once ABSPATH . 'wp-admin/includes/template.php';
12
+if ( ! class_exists('Walker_Category_Checklist')) {
13
+	require_once ABSPATH.'wp-admin/includes/template.php';
14 14
 }
15 15
 
16 16
 /**
@@ -37,9 +37,9 @@  discard block
 block discarded – undo
37 37
 	 *
38 38
 	 * @return array An array of arguments, with this walker in case the taxonomy is the Entity Type taxonomy.
39 39
 	 */
40
-	public function terms_checklist_args( $args ) {
40
+	public function terms_checklist_args($args) {
41 41
 
42
-		if ( ! isset( $args['taxonomy'] ) || Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME !== $args['taxonomy'] ) {
42
+		if ( ! isset($args['taxonomy']) || Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME !== $args['taxonomy']) {
43 43
 			return $args;
44 44
 		}
45 45
 
@@ -67,16 +67,16 @@  discard block
 block discarded – undo
67 67
 	 *
68 68
 	 * @return string The hierarchical item output.
69 69
 	 */
70
-	public function walk( $elements, $max_depth, $args = array() ) {
70
+	public function walk($elements, $max_depth, $args = array()) {
71 71
 
72 72
 		// `max_depth` force to -1 to display a flat taxonomy.
73 73
 		//
74 74
 		// See https://github.com/insideout10/wordlift-plugin/issues/305
75
-		$output = parent::walk( $elements, - 1, $args );
75
+		$output = parent::walk($elements, - 1, $args);
76 76
 
77 77
 		$output = str_replace(
78
-			array( 'type="checkbox"', "type='checkbox'" ),
79
-			array( 'type="radio"', "type='radio'" ),
78
+			array('type="checkbox"', "type='checkbox'"),
79
+			array('type="radio"', "type='radio'"),
80 80
 			$output
81 81
 		);
82 82
 
@@ -94,17 +94,17 @@  discard block
 block discarded – undo
94 94
 	 * @param array  $args     An array of arguments. @see wp_terms_checklist()
95 95
 	 * @param int    $id       ID of the current term.
96 96
 	 */
97
-	public function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
97
+	public function start_el(&$output, $category, $depth = 0, $args = array(), $id = 0) {
98 98
 		global $post;
99 99
 
100
-		if ( ! isset( $post ) ) {
100
+		if ( ! isset($post)) {
101 101
 			return;
102 102
 		}
103 103
 
104
-		if ( Wordlift_Entity_Service::TYPE_NAME !== $post->post_type
104
+		if (Wordlift_Entity_Service::TYPE_NAME !== $post->post_type
105 105
 			 || 'article' !== $category->slug
106
-			 || Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME !== $args['taxonomy'] ) {
107
-			parent::start_el( $output, $category, $depth, $args, $id );
106
+			 || Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME !== $args['taxonomy']) {
107
+			parent::start_el($output, $category, $depth, $args, $id);
108 108
 		}
109 109
 	}
110 110
 
@@ -118,17 +118,17 @@  discard block
 block discarded – undo
118 118
 	 * @param int    $depth    Depth of the term in reference to parents. Default 0.
119 119
 	 * @param array  $args     An array of arguments. @see wp_terms_checklist()
120 120
 	 */
121
-	public function end_el( &$output, $category, $depth = 0, $args = array() ) {
121
+	public function end_el(&$output, $category, $depth = 0, $args = array()) {
122 122
 		global $post;
123 123
 
124
-		if ( ! isset( $post ) ) {
124
+		if ( ! isset($post)) {
125 125
 			return;
126 126
 		}
127 127
 
128
-		if ( Wordlift_Entity_Service::TYPE_NAME !== $post->post_type
128
+		if (Wordlift_Entity_Service::TYPE_NAME !== $post->post_type
129 129
 			 || 'article' !== $category->slug
130
-			 || Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME !== $args['taxonomy'] ) {
131
-			parent::end_el( $output, $category, $depth, $args );
130
+			 || Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME !== $args['taxonomy']) {
131
+			parent::end_el($output, $category, $depth, $args);
132 132
 		}
133 133
 
134 134
 	}
Please login to merge, or discard this patch.
src/admin/class-wordlift-admin-post-edit-page.php 2 patches
Indentation   +290 added lines, -290 removed lines patch added patch discarded remove patch
@@ -20,131 +20,131 @@  discard block
 block discarded – undo
20 20
  */
21 21
 class Wordlift_Admin_Post_Edit_Page {
22 22
 
23
-	/**
24
-	 * Constants to be used instead of text inside FAQ
25
-	 * helper methods.
26
-	 */
27
-	const GUTENBERG       = 'gutenberg';
28
-	const TINY_MCE        = 'tiny_mce';
29
-	const FAQ_LIST_BOX_ID = 'wl-faq-meta-list-box';
30
-
31
-	/** Constant to be used for translation domain */
32
-	const WORDLIFT_TEXT_DOMAIN = 'wordlift';
33
-
34
-	/**
35
-	 * The {@link Wordlift} plugin instance.
36
-	 *
37
-	 * @since 3.11.0
38
-	 *
39
-	 * @var \Wordlift $plugin The {@link Wordlift} plugin instance.
40
-	 */
41
-	private $plugin;
42
-
43
-	/**
44
-	 * A {@link Wordlift_Log_Service} instance.
45
-	 *
46
-	 * @since 3.15.4
47
-	 *
48
-	 * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
49
-	 */
50
-	private $log;
51
-
52
-	/**
53
-	 * Create the {@link Wordlift_Admin_Post_Edit_Page} instance.
54
-	 *
55
-	 * @param \Wordlift $plugin The {@link Wordlift} plugin instance.
56
-	 *
57
-	 * @since 3.11.0
58
-	 */
59
-	public function __construct( $plugin ) {
60
-
61
-		$this->log = Wordlift_Log_Service::get_logger( get_class() );
62
-
63
-		add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_scripts_gutenberg' ) );
64
-
65
-		// Bail out if we're in the UX Builder editor.
66
-		if ( $this->is_ux_builder_editor() ) {
67
-			$this->log->info( 'WordLift will not show, since we are in UX Builder editor.' );
68
-
69
-			return;
70
-		}
71
-
72
-		// Define the callbacks.
73
-		$callback = array( $this, 'enqueue_scripts' );
74
-		// Set a hook to enqueue scripts only when the edit page is displayed.
75
-		add_action( 'admin_print_scripts-post.php', $callback );
76
-		add_action( 'admin_print_scripts-post-new.php', $callback );
77
-
78
-		$this->plugin = $plugin;
79
-	}
80
-
81
-	/**
82
-	 * Check whether the current post opens with G'berg or not.
83
-	 *
84
-	 * @return bool True if G'berg is used otherwise false.
85
-	 * @since 3.22.3
86
-	 */
87
-	public function is_gutenberg_page() {
88
-		if ( function_exists( 'is_gutenberg_page' ) && is_gutenberg_page() ) {
89
-			// The Gutenberg plugin is on.
90
-			return true;
91
-		}
92
-
93
-		$current_screen = get_current_screen();
94
-		if ( method_exists( $current_screen, 'is_block_editor' ) && $current_screen->is_block_editor() ) {
95
-			// Gutenberg page on 5+.
96
-			return true;
97
-		}
98
-
99
-		return false;
100
-	}
101
-
102
-	/**
103
-	 * Check if we're in UX builder.
104
-	 *
105
-	 * @see   https://github.com/insideout10/wordlift-plugin/issues/691
106
-	 *
107
-	 * @since 3.15.4
108
-	 *
109
-	 * @return bool True if we're in UX builder, otherwise false.
110
-	 */
111
-	private function is_ux_builder_editor() {
112
-
113
-		return function_exists( 'ux_builder_is_editor' )
114
-			   && ux_builder_is_editor();
115
-	}
116
-
117
-	/**
118
-	 * Enqueue scripts and styles for the edit page.
119
-	 *
120
-	 * @since 3.11.0
121
-	 */
122
-	public function enqueue_scripts() {
123
-
124
-		// Dequeue potentially conflicting ontrapages angular scripts which any *are not* used on the edit screen.
125
-		//
126
-		// @see https://github.com/insideout10/wordlift-plugin/issues/832
127
-		wp_dequeue_script( 'ontrapagesAngular' );
128
-		wp_dequeue_script( 'ontrapagesApp' );
129
-		wp_dequeue_script( 'ontrapagesController' );
130
-
131
-		// Bail out if this is G'berg.
132
-		if ( $this->is_gutenberg_page() ) {
133
-			return;
134
-		}
135
-
136
-		// If Gutenberg is enabled for the post, do not load the legacy edit.js.
137
-		if ( function_exists( 'use_block_editor_for_post' ) && use_block_editor_for_post( get_post() ) ) {
138
-			return;
139
-		}
140
-
141
-		// Bail out if classification sidebar is not enabled via hook
142
-		// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
143
-		if ( ! apply_filters( 'wl_feature__enable__classification-sidebar', true ) ) {
144
-			return;
145
-		}
146
-
147
-		/*
23
+    /**
24
+     * Constants to be used instead of text inside FAQ
25
+     * helper methods.
26
+     */
27
+    const GUTENBERG       = 'gutenberg';
28
+    const TINY_MCE        = 'tiny_mce';
29
+    const FAQ_LIST_BOX_ID = 'wl-faq-meta-list-box';
30
+
31
+    /** Constant to be used for translation domain */
32
+    const WORDLIFT_TEXT_DOMAIN = 'wordlift';
33
+
34
+    /**
35
+     * The {@link Wordlift} plugin instance.
36
+     *
37
+     * @since 3.11.0
38
+     *
39
+     * @var \Wordlift $plugin The {@link Wordlift} plugin instance.
40
+     */
41
+    private $plugin;
42
+
43
+    /**
44
+     * A {@link Wordlift_Log_Service} instance.
45
+     *
46
+     * @since 3.15.4
47
+     *
48
+     * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
49
+     */
50
+    private $log;
51
+
52
+    /**
53
+     * Create the {@link Wordlift_Admin_Post_Edit_Page} instance.
54
+     *
55
+     * @param \Wordlift $plugin The {@link Wordlift} plugin instance.
56
+     *
57
+     * @since 3.11.0
58
+     */
59
+    public function __construct( $plugin ) {
60
+
61
+        $this->log = Wordlift_Log_Service::get_logger( get_class() );
62
+
63
+        add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_scripts_gutenberg' ) );
64
+
65
+        // Bail out if we're in the UX Builder editor.
66
+        if ( $this->is_ux_builder_editor() ) {
67
+            $this->log->info( 'WordLift will not show, since we are in UX Builder editor.' );
68
+
69
+            return;
70
+        }
71
+
72
+        // Define the callbacks.
73
+        $callback = array( $this, 'enqueue_scripts' );
74
+        // Set a hook to enqueue scripts only when the edit page is displayed.
75
+        add_action( 'admin_print_scripts-post.php', $callback );
76
+        add_action( 'admin_print_scripts-post-new.php', $callback );
77
+
78
+        $this->plugin = $plugin;
79
+    }
80
+
81
+    /**
82
+     * Check whether the current post opens with G'berg or not.
83
+     *
84
+     * @return bool True if G'berg is used otherwise false.
85
+     * @since 3.22.3
86
+     */
87
+    public function is_gutenberg_page() {
88
+        if ( function_exists( 'is_gutenberg_page' ) && is_gutenberg_page() ) {
89
+            // The Gutenberg plugin is on.
90
+            return true;
91
+        }
92
+
93
+        $current_screen = get_current_screen();
94
+        if ( method_exists( $current_screen, 'is_block_editor' ) && $current_screen->is_block_editor() ) {
95
+            // Gutenberg page on 5+.
96
+            return true;
97
+        }
98
+
99
+        return false;
100
+    }
101
+
102
+    /**
103
+     * Check if we're in UX builder.
104
+     *
105
+     * @see   https://github.com/insideout10/wordlift-plugin/issues/691
106
+     *
107
+     * @since 3.15.4
108
+     *
109
+     * @return bool True if we're in UX builder, otherwise false.
110
+     */
111
+    private function is_ux_builder_editor() {
112
+
113
+        return function_exists( 'ux_builder_is_editor' )
114
+               && ux_builder_is_editor();
115
+    }
116
+
117
+    /**
118
+     * Enqueue scripts and styles for the edit page.
119
+     *
120
+     * @since 3.11.0
121
+     */
122
+    public function enqueue_scripts() {
123
+
124
+        // Dequeue potentially conflicting ontrapages angular scripts which any *are not* used on the edit screen.
125
+        //
126
+        // @see https://github.com/insideout10/wordlift-plugin/issues/832
127
+        wp_dequeue_script( 'ontrapagesAngular' );
128
+        wp_dequeue_script( 'ontrapagesApp' );
129
+        wp_dequeue_script( 'ontrapagesController' );
130
+
131
+        // Bail out if this is G'berg.
132
+        if ( $this->is_gutenberg_page() ) {
133
+            return;
134
+        }
135
+
136
+        // If Gutenberg is enabled for the post, do not load the legacy edit.js.
137
+        if ( function_exists( 'use_block_editor_for_post' ) && use_block_editor_for_post( get_post() ) ) {
138
+            return;
139
+        }
140
+
141
+        // Bail out if classification sidebar is not enabled via hook
142
+        // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
143
+        if ( ! apply_filters( 'wl_feature__enable__classification-sidebar', true ) ) {
144
+            return;
145
+        }
146
+
147
+        /*
148 148
 		 * Enqueue the edit screen JavaScript. The `wordlift-admin.bundle.js` file
149 149
 		 * is scheduled to replace the older `wordlift-admin.min.js` once client-side
150 150
 		 * code is properly refactored.
@@ -153,178 +153,178 @@  discard block
 block discarded – undo
153 153
 		 *
154 154
 		 * @since 3.20.0 edit.js has been migrated to the new webpack configuration.
155 155
 		 */
156
-		$script_name = plugin_dir_url( __DIR__ ) . 'js/dist/edit';
157
-
158
-		/**
159
-		 * Scripts_Helper introduced.
160
-		 *
161
-		 * @since 3.25.0 Scripts are loaded using script helper to ensure WP 4.4 compatibiility.
162
-		 * @since 3.25.1 The handle is used to hook the wp_localize_script for the _wlEntityTypes global object.
163
-		 */
164
-		Scripts_Helper::enqueue_based_on_wordpress_version(
165
-			'wl-classic-editor',
166
-			$script_name,
167
-			array(
168
-				$this->plugin->get_plugin_name(),
169
-				'jquery',
170
-				// Require wp.ajax.
171
-				'wp-util',
172
-				// @@todo: provide the following dependencies when we're in WP < 5.0 (i.e. when these dependencies aren't already defined).
173
-				'react',
174
-				'react-dom',
175
-				'wp-element',
176
-				'wp-polyfill',
177
-				/*
156
+        $script_name = plugin_dir_url( __DIR__ ) . 'js/dist/edit';
157
+
158
+        /**
159
+         * Scripts_Helper introduced.
160
+         *
161
+         * @since 3.25.0 Scripts are loaded using script helper to ensure WP 4.4 compatibiility.
162
+         * @since 3.25.1 The handle is used to hook the wp_localize_script for the _wlEntityTypes global object.
163
+         */
164
+        Scripts_Helper::enqueue_based_on_wordpress_version(
165
+            'wl-classic-editor',
166
+            $script_name,
167
+            array(
168
+                $this->plugin->get_plugin_name(),
169
+                'jquery',
170
+                // Require wp.ajax.
171
+                'wp-util',
172
+                // @@todo: provide the following dependencies when we're in WP < 5.0 (i.e. when these dependencies aren't already defined).
173
+                'react',
174
+                'react-dom',
175
+                'wp-element',
176
+                'wp-polyfill',
177
+                /*
178 178
 				* Angular isn't loaded anymore remotely, but it is loaded within wordlift-reloaded.js.
179 179
 				*
180 180
 				* See https://github.com/insideout10/wordlift-plugin/issues/865.
181 181
 				*
182 182
 				* @since 3.19.6
183 183
 				*/
184
-				// Require Angular.
185
-				// 'wl-angular',
186
-				// 'wl-angular-geolocation',
187
-				// 'wl-angular-touch',
188
-				// 'wl-angular-animate',
189
-				/**
190
-				 * We need the `wp.hooks` global to allow the edit.js script to send actions.
191
-				 *
192
-				 * @since 3.23.0
193
-				 */
194
-				'wp-hooks',
195
-			)
196
-		);
197
-
198
-		wp_enqueue_style( 'wl-classic-editor', "$script_name.css", array(), $this->plugin->get_version() );
199
-		// Disable Faq Editor.
200
-		// $this->load_faq_scripts_and_styles();
201
-		// $this->load_faq_settings( self::TINY_MCE );
202
-	}
203
-
204
-	/**
205
-	 * Enqueue the scripts and styles needed for FAQ
206
-	 */
207
-	private function load_faq_scripts_and_styles() {
208
-		wp_enqueue_style(
209
-			'wl-faq-metabox-style',
210
-			plugin_dir_url( __DIR__ ) . 'js/dist/faq.css',
211
-			array(),
212
-			WORDLIFT_VERSION
213
-		);
214
-		Scripts_Helper::enqueue_based_on_wordpress_version(
215
-			'wl-faq-metabox-script',
216
-			plugin_dir_url( __DIR__ ) . 'js/dist/faq',
217
-			array( 'wp-polyfill' ),
218
-			true
219
-		);
220
-	}
221
-
222
-	/**
223
-	 * Get FAQ settings array
224
-	 *
225
-	 * @return array
226
-	 */
227
-	public function get_faq_settings() {
228
-		return array(
229
-			'restUrl'                 => get_rest_url( null, WL_REST_ROUTE_DEFAULT_NAMESPACE . '/faq' ),
230
-			'listBoxId'               => self::FAQ_LIST_BOX_ID,
231
-			'nonce'                   => wp_create_nonce( 'wp_rest' ),
232
-			'postId'                  => get_the_ID(),
233
-			// Translation for warning, error message.
234
-			/* translators: %s: The invalid tag. */
235
-			'invalidTagMessage'       => sprintf( __( 'Invalid tags %s is present in answer', 'wordlift' ), '{INVALID_TAGS}' ),
236
-			/* translators: %s: The word count limit warning. */
237
-			'invalidWordCountMessage' => sprintf( __( 'Answer word count must not exceed %s words', 'wordlift' ), '{ANSWER_WORD_COUNT_WARNING_LIMIT}' ),
238
-			'questionText'            => __( 'Question', 'wordlift' ),
239
-			'answerText'              => __( 'Answer', 'wordlift' ),
240
-			'addQuestionOrAnswerText' => __( 'Add Question / Answer', 'wordlift' ),
241
-			'addQuestionText'         => __( 'Add Question', 'wordlift' ),
242
-			'addAnswerText'           => __( 'Add Answer', 'wordlift' ),
243
-			'noFaqItemsText'          => __( 'Highlight a question in content, then click Add Question.', 'wordlift' ),
244
-			'updatingText'            => __( 'Updating...', 'wordlift' ),
245
-		);
246
-	}
247
-
248
-	/**
249
-	 * Load FAQ settings to the add/edit post page
250
-	 *
251
-	 * @param $editor string specifying which text editor needed to be used.
252
-	 */
253
-	private function load_faq_settings( $editor ) {
254
-		// This script also provides translations to gutenberg.
255
-		wp_localize_script( 'wl-faq-metabox-script', '_wlFaqSettings', $this->get_faq_settings() );
256
-
257
-		// Enqueue the FAQ style
258
-		if ( self::GUTENBERG === $editor ) {
259
-			Scripts_Helper::enqueue_based_on_wordpress_version(
260
-				'wl-faq-gutenberg-plugin',
261
-				plugin_dir_url( __DIR__ ) . 'js/dist/block-editor-faq-plugin',
262
-				array( 'wp-polyfill' ),
263
-				true
264
-			);
265
-		}
266
-	}
267
-
268
-	/**
269
-	 * Enqueue scripts and styles for the gutenberg edit page.
270
-	 *
271
-	 * @since 3.21.0
272
-	 */
273
-	public function enqueue_scripts_gutenberg() {
274
-		// Load FAQ settings. - Disabled for now
275
-		// $this->load_faq_scripts_and_styles();
276
-		// $this->load_faq_settings( self::GUTENBERG );
277
-
278
-		wp_register_script(
279
-			'wl-block-editor',
280
-			plugin_dir_url( __DIR__ ) . 'js/dist/block-editor.js',
281
-			array(
282
-				'react',
283
-				'wordlift',
284
-				'wp-hooks',
285
-				'wp-data',
286
-				'wp-rich-text',
287
-				'wp-blocks',
288
-				'wp-plugins',
289
-				'wp-edit-post',
290
-			),
291
-			$this->plugin->get_version(),
292
-			false
293
-		);
294
-		wp_localize_script(
295
-			'wl-block-editor',
296
-			'_wlBlockEditorSettings',
297
-			array(
298
-				'root'  => esc_url_raw( rest_url() ),
299
-				'nonce' => wp_create_nonce( 'wp_rest' ),
300
-			)
301
-		);
302
-
303
-		/*
184
+                // Require Angular.
185
+                // 'wl-angular',
186
+                // 'wl-angular-geolocation',
187
+                // 'wl-angular-touch',
188
+                // 'wl-angular-animate',
189
+                /**
190
+                 * We need the `wp.hooks` global to allow the edit.js script to send actions.
191
+                 *
192
+                 * @since 3.23.0
193
+                 */
194
+                'wp-hooks',
195
+            )
196
+        );
197
+
198
+        wp_enqueue_style( 'wl-classic-editor', "$script_name.css", array(), $this->plugin->get_version() );
199
+        // Disable Faq Editor.
200
+        // $this->load_faq_scripts_and_styles();
201
+        // $this->load_faq_settings( self::TINY_MCE );
202
+    }
203
+
204
+    /**
205
+     * Enqueue the scripts and styles needed for FAQ
206
+     */
207
+    private function load_faq_scripts_and_styles() {
208
+        wp_enqueue_style(
209
+            'wl-faq-metabox-style',
210
+            plugin_dir_url( __DIR__ ) . 'js/dist/faq.css',
211
+            array(),
212
+            WORDLIFT_VERSION
213
+        );
214
+        Scripts_Helper::enqueue_based_on_wordpress_version(
215
+            'wl-faq-metabox-script',
216
+            plugin_dir_url( __DIR__ ) . 'js/dist/faq',
217
+            array( 'wp-polyfill' ),
218
+            true
219
+        );
220
+    }
221
+
222
+    /**
223
+     * Get FAQ settings array
224
+     *
225
+     * @return array
226
+     */
227
+    public function get_faq_settings() {
228
+        return array(
229
+            'restUrl'                 => get_rest_url( null, WL_REST_ROUTE_DEFAULT_NAMESPACE . '/faq' ),
230
+            'listBoxId'               => self::FAQ_LIST_BOX_ID,
231
+            'nonce'                   => wp_create_nonce( 'wp_rest' ),
232
+            'postId'                  => get_the_ID(),
233
+            // Translation for warning, error message.
234
+            /* translators: %s: The invalid tag. */
235
+            'invalidTagMessage'       => sprintf( __( 'Invalid tags %s is present in answer', 'wordlift' ), '{INVALID_TAGS}' ),
236
+            /* translators: %s: The word count limit warning. */
237
+            'invalidWordCountMessage' => sprintf( __( 'Answer word count must not exceed %s words', 'wordlift' ), '{ANSWER_WORD_COUNT_WARNING_LIMIT}' ),
238
+            'questionText'            => __( 'Question', 'wordlift' ),
239
+            'answerText'              => __( 'Answer', 'wordlift' ),
240
+            'addQuestionOrAnswerText' => __( 'Add Question / Answer', 'wordlift' ),
241
+            'addQuestionText'         => __( 'Add Question', 'wordlift' ),
242
+            'addAnswerText'           => __( 'Add Answer', 'wordlift' ),
243
+            'noFaqItemsText'          => __( 'Highlight a question in content, then click Add Question.', 'wordlift' ),
244
+            'updatingText'            => __( 'Updating...', 'wordlift' ),
245
+        );
246
+    }
247
+
248
+    /**
249
+     * Load FAQ settings to the add/edit post page
250
+     *
251
+     * @param $editor string specifying which text editor needed to be used.
252
+     */
253
+    private function load_faq_settings( $editor ) {
254
+        // This script also provides translations to gutenberg.
255
+        wp_localize_script( 'wl-faq-metabox-script', '_wlFaqSettings', $this->get_faq_settings() );
256
+
257
+        // Enqueue the FAQ style
258
+        if ( self::GUTENBERG === $editor ) {
259
+            Scripts_Helper::enqueue_based_on_wordpress_version(
260
+                'wl-faq-gutenberg-plugin',
261
+                plugin_dir_url( __DIR__ ) . 'js/dist/block-editor-faq-plugin',
262
+                array( 'wp-polyfill' ),
263
+                true
264
+            );
265
+        }
266
+    }
267
+
268
+    /**
269
+     * Enqueue scripts and styles for the gutenberg edit page.
270
+     *
271
+     * @since 3.21.0
272
+     */
273
+    public function enqueue_scripts_gutenberg() {
274
+        // Load FAQ settings. - Disabled for now
275
+        // $this->load_faq_scripts_and_styles();
276
+        // $this->load_faq_settings( self::GUTENBERG );
277
+
278
+        wp_register_script(
279
+            'wl-block-editor',
280
+            plugin_dir_url( __DIR__ ) . 'js/dist/block-editor.js',
281
+            array(
282
+                'react',
283
+                'wordlift',
284
+                'wp-hooks',
285
+                'wp-data',
286
+                'wp-rich-text',
287
+                'wp-blocks',
288
+                'wp-plugins',
289
+                'wp-edit-post',
290
+            ),
291
+            $this->plugin->get_version(),
292
+            false
293
+        );
294
+        wp_localize_script(
295
+            'wl-block-editor',
296
+            '_wlBlockEditorSettings',
297
+            array(
298
+                'root'  => esc_url_raw( rest_url() ),
299
+                'nonce' => wp_create_nonce( 'wp_rest' ),
300
+            )
301
+        );
302
+
303
+        /*
304 304
 		 * @since 3.25.1 The hook is used by the wp_localize_script to register the _wlEntityTypes global object.
305 305
 		 */
306
-		wp_enqueue_style(
307
-			'wl-block-editor',
308
-			plugin_dir_url( __DIR__ ) . 'js/dist/block-editor.css',
309
-			array(),
310
-			$this->plugin->get_version()
311
-		);
312
-
313
-		wp_enqueue_script(
314
-			'wl-autocomplete-select',
315
-			plugin_dir_url( __DIR__ ) . 'js/dist/autocomplete-select.js',
316
-			array(),
317
-			$this->plugin->get_version(),
318
-			true
319
-		);
320
-
321
-		wp_enqueue_style(
322
-			'wl-autocomplete-select',
323
-			plugin_dir_url( __DIR__ ) . 'js/dist/autocomplete-select.css',
324
-			array(),
325
-			$this->plugin->get_version()
326
-		);
327
-
328
-	}
306
+        wp_enqueue_style(
307
+            'wl-block-editor',
308
+            plugin_dir_url( __DIR__ ) . 'js/dist/block-editor.css',
309
+            array(),
310
+            $this->plugin->get_version()
311
+        );
312
+
313
+        wp_enqueue_script(
314
+            'wl-autocomplete-select',
315
+            plugin_dir_url( __DIR__ ) . 'js/dist/autocomplete-select.js',
316
+            array(),
317
+            $this->plugin->get_version(),
318
+            true
319
+        );
320
+
321
+        wp_enqueue_style(
322
+            'wl-autocomplete-select',
323
+            plugin_dir_url( __DIR__ ) . 'js/dist/autocomplete-select.css',
324
+            array(),
325
+            $this->plugin->get_version()
326
+        );
327
+
328
+    }
329 329
 
330 330
 }
Please login to merge, or discard this patch.
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -56,24 +56,24 @@  discard block
 block discarded – undo
56 56
 	 *
57 57
 	 * @since 3.11.0
58 58
 	 */
59
-	public function __construct( $plugin ) {
59
+	public function __construct($plugin) {
60 60
 
61
-		$this->log = Wordlift_Log_Service::get_logger( get_class() );
61
+		$this->log = Wordlift_Log_Service::get_logger(get_class());
62 62
 
63
-		add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_scripts_gutenberg' ) );
63
+		add_action('enqueue_block_editor_assets', array($this, 'enqueue_scripts_gutenberg'));
64 64
 
65 65
 		// Bail out if we're in the UX Builder editor.
66
-		if ( $this->is_ux_builder_editor() ) {
67
-			$this->log->info( 'WordLift will not show, since we are in UX Builder editor.' );
66
+		if ($this->is_ux_builder_editor()) {
67
+			$this->log->info('WordLift will not show, since we are in UX Builder editor.');
68 68
 
69 69
 			return;
70 70
 		}
71 71
 
72 72
 		// Define the callbacks.
73
-		$callback = array( $this, 'enqueue_scripts' );
73
+		$callback = array($this, 'enqueue_scripts');
74 74
 		// Set a hook to enqueue scripts only when the edit page is displayed.
75
-		add_action( 'admin_print_scripts-post.php', $callback );
76
-		add_action( 'admin_print_scripts-post-new.php', $callback );
75
+		add_action('admin_print_scripts-post.php', $callback);
76
+		add_action('admin_print_scripts-post-new.php', $callback);
77 77
 
78 78
 		$this->plugin = $plugin;
79 79
 	}
@@ -85,13 +85,13 @@  discard block
 block discarded – undo
85 85
 	 * @since 3.22.3
86 86
 	 */
87 87
 	public function is_gutenberg_page() {
88
-		if ( function_exists( 'is_gutenberg_page' ) && is_gutenberg_page() ) {
88
+		if (function_exists('is_gutenberg_page') && is_gutenberg_page()) {
89 89
 			// The Gutenberg plugin is on.
90 90
 			return true;
91 91
 		}
92 92
 
93 93
 		$current_screen = get_current_screen();
94
-		if ( method_exists( $current_screen, 'is_block_editor' ) && $current_screen->is_block_editor() ) {
94
+		if (method_exists($current_screen, 'is_block_editor') && $current_screen->is_block_editor()) {
95 95
 			// Gutenberg page on 5+.
96 96
 			return true;
97 97
 		}
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 	 */
111 111
 	private function is_ux_builder_editor() {
112 112
 
113
-		return function_exists( 'ux_builder_is_editor' )
113
+		return function_exists('ux_builder_is_editor')
114 114
 			   && ux_builder_is_editor();
115 115
 	}
116 116
 
@@ -124,23 +124,23 @@  discard block
 block discarded – undo
124 124
 		// Dequeue potentially conflicting ontrapages angular scripts which any *are not* used on the edit screen.
125 125
 		//
126 126
 		// @see https://github.com/insideout10/wordlift-plugin/issues/832
127
-		wp_dequeue_script( 'ontrapagesAngular' );
128
-		wp_dequeue_script( 'ontrapagesApp' );
129
-		wp_dequeue_script( 'ontrapagesController' );
127
+		wp_dequeue_script('ontrapagesAngular');
128
+		wp_dequeue_script('ontrapagesApp');
129
+		wp_dequeue_script('ontrapagesController');
130 130
 
131 131
 		// Bail out if this is G'berg.
132
-		if ( $this->is_gutenberg_page() ) {
132
+		if ($this->is_gutenberg_page()) {
133 133
 			return;
134 134
 		}
135 135
 
136 136
 		// If Gutenberg is enabled for the post, do not load the legacy edit.js.
137
-		if ( function_exists( 'use_block_editor_for_post' ) && use_block_editor_for_post( get_post() ) ) {
137
+		if (function_exists('use_block_editor_for_post') && use_block_editor_for_post(get_post())) {
138 138
 			return;
139 139
 		}
140 140
 
141 141
 		// Bail out if classification sidebar is not enabled via hook
142 142
 		// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
143
-		if ( ! apply_filters( 'wl_feature__enable__classification-sidebar', true ) ) {
143
+		if ( ! apply_filters('wl_feature__enable__classification-sidebar', true)) {
144 144
 			return;
145 145
 		}
146 146
 
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
 		 *
154 154
 		 * @since 3.20.0 edit.js has been migrated to the new webpack configuration.
155 155
 		 */
156
-		$script_name = plugin_dir_url( __DIR__ ) . 'js/dist/edit';
156
+		$script_name = plugin_dir_url(__DIR__).'js/dist/edit';
157 157
 
158 158
 		/**
159 159
 		 * Scripts_Helper introduced.
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
 			)
196 196
 		);
197 197
 
198
-		wp_enqueue_style( 'wl-classic-editor', "$script_name.css", array(), $this->plugin->get_version() );
198
+		wp_enqueue_style('wl-classic-editor', "$script_name.css", array(), $this->plugin->get_version());
199 199
 		// Disable Faq Editor.
200 200
 		// $this->load_faq_scripts_and_styles();
201 201
 		// $this->load_faq_settings( self::TINY_MCE );
@@ -207,14 +207,14 @@  discard block
 block discarded – undo
207 207
 	private function load_faq_scripts_and_styles() {
208 208
 		wp_enqueue_style(
209 209
 			'wl-faq-metabox-style',
210
-			plugin_dir_url( __DIR__ ) . 'js/dist/faq.css',
210
+			plugin_dir_url(__DIR__).'js/dist/faq.css',
211 211
 			array(),
212 212
 			WORDLIFT_VERSION
213 213
 		);
214 214
 		Scripts_Helper::enqueue_based_on_wordpress_version(
215 215
 			'wl-faq-metabox-script',
216
-			plugin_dir_url( __DIR__ ) . 'js/dist/faq',
217
-			array( 'wp-polyfill' ),
216
+			plugin_dir_url(__DIR__).'js/dist/faq',
217
+			array('wp-polyfill'),
218 218
 			true
219 219
 		);
220 220
 	}
@@ -226,22 +226,22 @@  discard block
 block discarded – undo
226 226
 	 */
227 227
 	public function get_faq_settings() {
228 228
 		return array(
229
-			'restUrl'                 => get_rest_url( null, WL_REST_ROUTE_DEFAULT_NAMESPACE . '/faq' ),
229
+			'restUrl'                 => get_rest_url(null, WL_REST_ROUTE_DEFAULT_NAMESPACE.'/faq'),
230 230
 			'listBoxId'               => self::FAQ_LIST_BOX_ID,
231
-			'nonce'                   => wp_create_nonce( 'wp_rest' ),
231
+			'nonce'                   => wp_create_nonce('wp_rest'),
232 232
 			'postId'                  => get_the_ID(),
233 233
 			// Translation for warning, error message.
234 234
 			/* translators: %s: The invalid tag. */
235
-			'invalidTagMessage'       => sprintf( __( 'Invalid tags %s is present in answer', 'wordlift' ), '{INVALID_TAGS}' ),
235
+			'invalidTagMessage'       => sprintf(__('Invalid tags %s is present in answer', 'wordlift'), '{INVALID_TAGS}'),
236 236
 			/* translators: %s: The word count limit warning. */
237
-			'invalidWordCountMessage' => sprintf( __( 'Answer word count must not exceed %s words', 'wordlift' ), '{ANSWER_WORD_COUNT_WARNING_LIMIT}' ),
238
-			'questionText'            => __( 'Question', 'wordlift' ),
239
-			'answerText'              => __( 'Answer', 'wordlift' ),
240
-			'addQuestionOrAnswerText' => __( 'Add Question / Answer', 'wordlift' ),
241
-			'addQuestionText'         => __( 'Add Question', 'wordlift' ),
242
-			'addAnswerText'           => __( 'Add Answer', 'wordlift' ),
243
-			'noFaqItemsText'          => __( 'Highlight a question in content, then click Add Question.', 'wordlift' ),
244
-			'updatingText'            => __( 'Updating...', 'wordlift' ),
237
+			'invalidWordCountMessage' => sprintf(__('Answer word count must not exceed %s words', 'wordlift'), '{ANSWER_WORD_COUNT_WARNING_LIMIT}'),
238
+			'questionText'            => __('Question', 'wordlift'),
239
+			'answerText'              => __('Answer', 'wordlift'),
240
+			'addQuestionOrAnswerText' => __('Add Question / Answer', 'wordlift'),
241
+			'addQuestionText'         => __('Add Question', 'wordlift'),
242
+			'addAnswerText'           => __('Add Answer', 'wordlift'),
243
+			'noFaqItemsText'          => __('Highlight a question in content, then click Add Question.', 'wordlift'),
244
+			'updatingText'            => __('Updating...', 'wordlift'),
245 245
 		);
246 246
 	}
247 247
 
@@ -250,16 +250,16 @@  discard block
 block discarded – undo
250 250
 	 *
251 251
 	 * @param $editor string specifying which text editor needed to be used.
252 252
 	 */
253
-	private function load_faq_settings( $editor ) {
253
+	private function load_faq_settings($editor) {
254 254
 		// This script also provides translations to gutenberg.
255
-		wp_localize_script( 'wl-faq-metabox-script', '_wlFaqSettings', $this->get_faq_settings() );
255
+		wp_localize_script('wl-faq-metabox-script', '_wlFaqSettings', $this->get_faq_settings());
256 256
 
257 257
 		// Enqueue the FAQ style
258
-		if ( self::GUTENBERG === $editor ) {
258
+		if (self::GUTENBERG === $editor) {
259 259
 			Scripts_Helper::enqueue_based_on_wordpress_version(
260 260
 				'wl-faq-gutenberg-plugin',
261
-				plugin_dir_url( __DIR__ ) . 'js/dist/block-editor-faq-plugin',
262
-				array( 'wp-polyfill' ),
261
+				plugin_dir_url(__DIR__).'js/dist/block-editor-faq-plugin',
262
+				array('wp-polyfill'),
263 263
 				true
264 264
 			);
265 265
 		}
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
 
278 278
 		wp_register_script(
279 279
 			'wl-block-editor',
280
-			plugin_dir_url( __DIR__ ) . 'js/dist/block-editor.js',
280
+			plugin_dir_url(__DIR__).'js/dist/block-editor.js',
281 281
 			array(
282 282
 				'react',
283 283
 				'wordlift',
@@ -295,8 +295,8 @@  discard block
 block discarded – undo
295 295
 			'wl-block-editor',
296 296
 			'_wlBlockEditorSettings',
297 297
 			array(
298
-				'root'  => esc_url_raw( rest_url() ),
299
-				'nonce' => wp_create_nonce( 'wp_rest' ),
298
+				'root'  => esc_url_raw(rest_url()),
299
+				'nonce' => wp_create_nonce('wp_rest'),
300 300
 			)
301 301
 		);
302 302
 
@@ -305,14 +305,14 @@  discard block
 block discarded – undo
305 305
 		 */
306 306
 		wp_enqueue_style(
307 307
 			'wl-block-editor',
308
-			plugin_dir_url( __DIR__ ) . 'js/dist/block-editor.css',
308
+			plugin_dir_url(__DIR__).'js/dist/block-editor.css',
309 309
 			array(),
310 310
 			$this->plugin->get_version()
311 311
 		);
312 312
 
313 313
 		wp_enqueue_script(
314 314
 			'wl-autocomplete-select',
315
-			plugin_dir_url( __DIR__ ) . 'js/dist/autocomplete-select.js',
315
+			plugin_dir_url(__DIR__).'js/dist/autocomplete-select.js',
316 316
 			array(),
317 317
 			$this->plugin->get_version(),
318 318
 			true
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
 
321 321
 		wp_enqueue_style(
322 322
 			'wl-autocomplete-select',
323
-			plugin_dir_url( __DIR__ ) . 'js/dist/autocomplete-select.css',
323
+			plugin_dir_url(__DIR__).'js/dist/autocomplete-select.css',
324 324
 			array(),
325 325
 			$this->plugin->get_version()
326 326
 		);
Please login to merge, or discard this patch.
src/admin/class-wordlift-admin-settings-analytics-page.php 2 patches
Indentation   +303 added lines, -303 removed lines patch added patch discarded remove patch
@@ -18,308 +18,308 @@
 block discarded – undo
18 18
  */
19 19
 class Wordlift_Admin_Settings_Analytics_Page extends Wordlift_Admin_Page {
20 20
 
21
-	/**
22
-	 * A singleton instance of the Notice service.
23
-	 *
24
-	 * @since  3.21.0
25
-	 * @access private
26
-	 * @var \Wordlift_Admin_Settings_Analytics_Page $instance A singleton instance of a {@link Wordlift_Admin_Settings_Analytics_Page} class.
27
-	 */
28
-	private static $instance;
29
-
30
-	/**
31
-	 * A {@link Wordlift_Admin_Input_Element} element renderer.
32
-	 *
33
-	 * @since  3.21.0
34
-	 * @access private
35
-	 * @var \Wordlift_Admin_Input_Element $input_element An {@link Wordlift_Admin_Input_Element} element renderer.
36
-	 */
37
-	private $input_element;
38
-
39
-	/**
40
-	 * A {@link Wordlift_Admin_Radio_Input_Element} element renderer.
41
-	 *
42
-	 * @since  3.21.0
43
-	 * @access protected
44
-	 * @var \Wordlift_Admin_Radio_Input_Element $radio_input_element A {@link Wordlift_Admin_Radio_Input_Element} element renderer.
45
-	 */
46
-	private $radio_input_element;
47
-
48
-	/**
49
-	 * Create a {@link Wordlift_Admin_Settings_Page} instance.
50
-	 *
51
-	 * @param \Wordlift_Admin_Input_Element       $input_element An input element class to output input boxes in a settings form.
52
-	 * @param \Wordlift_Admin_Radio_Input_Element $radio_input_element A radio element input class for use in a settings form.
53
-	 *
54
-	 * @since 3.21.0
55
-	 */
56
-	public function __construct( $input_element, $radio_input_element ) {
57
-
58
-		// Set a reference to the UI elements.
59
-		$this->input_element       = $input_element;
60
-		$this->radio_input_element = $radio_input_element;
61
-
62
-		// Adds this page to the main admin settings tabbed menu.
63
-		add_filter( 'wl_admin_page_tabs', array( $this, 'add_admin_page_tab' ) );
64
-
65
-		self::$instance = $this;
66
-	}
67
-
68
-	/**
69
-	 * Get the singleton instance of the Notice service.
70
-	 *
71
-	 * @return \Wordlift_Admin_Settings_Page The singleton instance of the settings page service.
72
-	 * @since 3.21.0
73
-	 */
74
-	public static function get_instance() {
75
-
76
-		return self::$instance;
77
-	}
78
-
79
-	/**
80
-	 * @inheritdoc
81
-	 */
82
-	protected function get_parent_slug() {
83
-
84
-		return 'wl_admin_menu';
85
-	}
86
-
87
-	/**
88
-	 * @inheritdoc
89
-	 */
90
-	protected function get_capability() {
91
-
92
-		return 'manage_options';
93
-	}
94
-
95
-	/**
96
-	 * @inheritdoc
97
-	 */
98
-	public function get_page_title() {
99
-
100
-		return __( 'WorldLift Analytics Settings', 'wordlift' );
101
-	}
102
-
103
-	/**
104
-	 * @inheritdoc
105
-	 */
106
-	public function get_menu_title() {
107
-
108
-		return __( 'Analytics Settings', 'wordlift' );
109
-	}
110
-
111
-	/**
112
-	 * @inheritdoc
113
-	 */
114
-	public function get_menu_slug() {
115
-
116
-		return 'wl_configuration_admin_analytics_menu';
117
-	}
118
-
119
-	/**
120
-	 * @inheritdoc
121
-	 */
122
-	public function get_partial_name() {
123
-
124
-		return 'wordlift-admin-settings-analytics-page.php';
125
-	}
126
-
127
-	/**
128
-	 * Returns the string to use for the tab slug on main admin settings page.
129
-	 *
130
-	 * @method get_admin_page_tab_slug
131
-	 * @return string
132
-	 * @since  3.21.0
133
-	 */
134
-	public function get_admin_page_tab_slug() {
135
-		return 'analytics';
136
-	}
137
-
138
-	/**
139
-	 * Adds pages to the tabs menu on the main admin settings page.
140
-	 *
141
-	 * @method add_admin_page_tab
142
-	 * @param array $tabs an array of tab titles and slugs to use when building a tabbed menu on option pages.
143
-	 *
144
-	 * @since  3.21.0
145
-	 */
146
-	public function add_admin_page_tab( $tabs ) {
147
-		if ( apply_filters( 'wl_feature__enable__analytics', true ) ) {
148
-			$tabs[] = array(
149
-				'title' => $this->get_menu_title(),
150
-				'slug'  => $this->get_admin_page_tab_slug(),
151
-			);
152
-		}
153
-
154
-		return $tabs;
155
-	}
156
-
157
-	/**
158
-	 * Configure all the configuration parameters.
159
-	 *
160
-	 * Called by the *admin_init* hook.
161
-	 *
162
-	 * @since 3.21.0
163
-	 */
164
-	public function admin_init() {
165
-
166
-		// Register WordLift's analytics settings with our in class sanitizer.
167
-		register_setting(
168
-			'wl_analytics_settings',
169
-			'wl_analytics_settings',
170
-			array( $this, 'sanitize_callback' )
171
-		);
172
-
173
-		// Add the analytics settings setction.
174
-		add_settings_section(
175
-			'wl_analytics_settings_section',
176
-			'',
177
-			'',
178
-			'wl_analytics_settings'
179
-		);
180
-
181
-		// Add a toggle to determine if analytics functions are enabled or not.
182
-		// NOTE: this uses yes/no rather than true/false.
183
-		add_settings_field(
184
-			'wl-analytics-enabled',
185
-			__( 'Enable Analytics', 'wordlift' ),
186
-			array( $this->radio_input_element, 'render' ),
187
-			'wl_analytics_settings',
188
-			'wl_analytics_settings_section',
189
-			array(
190
-				'id'          => 'wl-analytics-enable',
191
-				'name'        => 'wl_analytics_settings[' . Wordlift_Configuration_Service::ANALYTICS_ENABLE . ']',
192
-				'value'       => Wordlift_Configuration_Service::get_instance()->is_analytics_enable() ? 'yes' : 'no',
193
-				'description' => __( 'Toggle on/off the default values.', 'wordlift' ),
194
-			)
195
-		);
196
-
197
-		/**
198
-		 * A basic number field that will accept anything from 1 to 20.
199
-		 *
200
-		 * Represents the custom dim number for the uri.
201
-		 */
202
-		add_settings_field(
203
-			'wl-analytics-entity-uri-dimension',
204
-			__( 'Entity URI dimension', 'wordlift' ),
205
-			array( $this->input_element, 'render' ),
206
-			'wl_analytics_settings',
207
-			'wl_analytics_settings_section',
208
-			array(
209
-				'id'          => 'wl-analytics-entity-uri-dimension',
210
-				'name'        => 'wl_analytics_settings[' . Wordlift_Configuration_Service::ANALYTICS_ENTITY_URI_DIMENSION . ']',
211
-				'type'        => 'number',
212
-				'value'       => Wordlift_Configuration_Service::get_instance()->get_analytics_entity_uri_dimension(),
213
-				'description' => __( 'Entity URI dimesion', 'wordlift' ),
214
-			)
215
-		);
216
-
217
-		/**
218
-		 * A basic number field that will accept anything from 1 to 20.
219
-		 *
220
-		 * Represents the custom dim number for the type.
221
-		 */
222
-		add_settings_field(
223
-			'wl-analytics-entity-type-dimension',
224
-			__( 'Entity Type dimension', 'wordlift' ),
225
-			array( $this->input_element, 'render' ),
226
-			'wl_analytics_settings',
227
-			'wl_analytics_settings_section',
228
-			array(
229
-				'id'          => 'wl-analytics-entity-type-dimension',
230
-				'name'        => 'wl_analytics_settings[' . Wordlift_Configuration_Service::ANALYTICS_ENTITY_TYPE_DIMENSION . ']',
231
-				'type'        => 'number',
232
-				'value'       => Wordlift_Configuration_Service::get_instance()->get_analytics_entity_type_dimension(),
233
-				'description' => __( 'Entity Type dimension', 'wordlift' ),
234
-			)
235
-		);
236
-
237
-	}
238
-
239
-	/**
240
-	 * Validates an entity uri based on an integer passed.
241
-	 *
242
-	 * TODO: Needs a feedback method to pass back error messages.
243
-	 *
244
-	 * @method validate_entity_uri
245
-	 * @param string $uri a sting representing an entity ID that can be converted to a uri.
246
-	 *
247
-	 * @return int
248
-	 * @since 3.21.0
249
-	 */
250
-	public function validate_entity_uri( $uri ) {
251
-		// Basic validation is to ensure number is between 1 and 20.
252
-		// NOTE: certain analytics accounts have a much higher value - as many
253
-		// as 200 are allowed.
254
-		if ( (int) $uri < 1 || (int) $uri > 20 ) {
255
-			// if we are out of range then pass the default value.
256
-			$uri = Wordlift_Configuration_Service::get_instance()->get_analytics_entity_uri_dimension();
257
-		}
258
-
259
-		return absint( $uri );
260
-	}
261
-
262
-	/**
263
-	 * Validates an entity type.
264
-	 *
265
-	 * TODO: Needs a feedback method to pass back error messages.
266
-	 *
267
-	 * @method validate_entity_type
268
-	 * @param string $type This is an entity type ID in string form - really a number.
269
-	 *
270
-	 * @return int
271
-	 * @since  3.21.0
272
-	 */
273
-	public function validate_entity_type( $type ) {
274
-		// Basic validation is to ensure number is between 1 and 20.
275
-		// NOTE: certain analytics accounts have a much higher value - as many
276
-		// as 200 are allowed.
277
-		if ( (int) $type < 1 || (int) $type > 20 ) {
278
-			// if we are out of range then pass the default value.
279
-			$type = Wordlift_Configuration_Service::get_instance()->get_analytics_entity_type_dimension();
280
-		}
281
-
282
-		return absint( $type );
283
-	}
284
-
285
-	/**
286
-	 * Sanitize the configuration settings to be stored.
287
-	 *
288
-	 * If a new entity is being created for the publisher, create it and set The
289
-	 * publisher setting.
290
-	 *
291
-	 * @param array $input The configuration settings array.
292
-	 *
293
-	 * @return array The sanitized input array.
294
-	 * @since 3.21.0
295
-	 */
296
-	public function sanitize_callback( $input ) {
297
-		if ( ! check_admin_referer( 'wl_analytics_settings-options' ) ) {
298
-			// Any failing nonce checks already die().
299
-			return;
300
-		}
301
-
302
-		/**
303
-		 * Validate and sanitize the $inputs and store them in $output saved.
304
-		 */
305
-		$output = array();
306
-		if ( isset( $input['analytics_enable'] ) ) {
307
-			$output['analytics_enable'] = ( 'yes' === $input['analytics_enable'] ) ? 'yes' : 'no';
308
-		}
309
-		if ( isset( $input['analytics_entity_uri_dimension'] ) ) {
310
-			$output['analytics_entity_uri_dimension'] = (int) $this->validate_entity_uri( $input['analytics_entity_uri_dimension'] );
311
-		}
312
-		if ( isset( $input['analytics_entity_type_dimension'] ) ) {
313
-			// This dimension cannot be the same as the one set above. If it is
314
-			// then zero it out and it will fail validation.
315
-			if ( isset( $output['analytics_entity_uri_dimension'] ) && $output['analytics_entity_uri_dimension'] === (int) $input['analytics_entity_type_dimension'] ) {
316
-				$input['analytics_entity_type_dimension'] = 0;
317
-			}
318
-			$output['analytics_entity_type_dimension'] = (int) $this->validate_entity_type( $input['analytics_entity_type_dimension'] );
319
-		}
320
-
321
-		// return items added to the output for saving.
322
-		return $output;
323
-	}
21
+    /**
22
+     * A singleton instance of the Notice service.
23
+     *
24
+     * @since  3.21.0
25
+     * @access private
26
+     * @var \Wordlift_Admin_Settings_Analytics_Page $instance A singleton instance of a {@link Wordlift_Admin_Settings_Analytics_Page} class.
27
+     */
28
+    private static $instance;
29
+
30
+    /**
31
+     * A {@link Wordlift_Admin_Input_Element} element renderer.
32
+     *
33
+     * @since  3.21.0
34
+     * @access private
35
+     * @var \Wordlift_Admin_Input_Element $input_element An {@link Wordlift_Admin_Input_Element} element renderer.
36
+     */
37
+    private $input_element;
38
+
39
+    /**
40
+     * A {@link Wordlift_Admin_Radio_Input_Element} element renderer.
41
+     *
42
+     * @since  3.21.0
43
+     * @access protected
44
+     * @var \Wordlift_Admin_Radio_Input_Element $radio_input_element A {@link Wordlift_Admin_Radio_Input_Element} element renderer.
45
+     */
46
+    private $radio_input_element;
47
+
48
+    /**
49
+     * Create a {@link Wordlift_Admin_Settings_Page} instance.
50
+     *
51
+     * @param \Wordlift_Admin_Input_Element       $input_element An input element class to output input boxes in a settings form.
52
+     * @param \Wordlift_Admin_Radio_Input_Element $radio_input_element A radio element input class for use in a settings form.
53
+     *
54
+     * @since 3.21.0
55
+     */
56
+    public function __construct( $input_element, $radio_input_element ) {
57
+
58
+        // Set a reference to the UI elements.
59
+        $this->input_element       = $input_element;
60
+        $this->radio_input_element = $radio_input_element;
61
+
62
+        // Adds this page to the main admin settings tabbed menu.
63
+        add_filter( 'wl_admin_page_tabs', array( $this, 'add_admin_page_tab' ) );
64
+
65
+        self::$instance = $this;
66
+    }
67
+
68
+    /**
69
+     * Get the singleton instance of the Notice service.
70
+     *
71
+     * @return \Wordlift_Admin_Settings_Page The singleton instance of the settings page service.
72
+     * @since 3.21.0
73
+     */
74
+    public static function get_instance() {
75
+
76
+        return self::$instance;
77
+    }
78
+
79
+    /**
80
+     * @inheritdoc
81
+     */
82
+    protected function get_parent_slug() {
83
+
84
+        return 'wl_admin_menu';
85
+    }
86
+
87
+    /**
88
+     * @inheritdoc
89
+     */
90
+    protected function get_capability() {
91
+
92
+        return 'manage_options';
93
+    }
94
+
95
+    /**
96
+     * @inheritdoc
97
+     */
98
+    public function get_page_title() {
99
+
100
+        return __( 'WorldLift Analytics Settings', 'wordlift' );
101
+    }
102
+
103
+    /**
104
+     * @inheritdoc
105
+     */
106
+    public function get_menu_title() {
107
+
108
+        return __( 'Analytics Settings', 'wordlift' );
109
+    }
110
+
111
+    /**
112
+     * @inheritdoc
113
+     */
114
+    public function get_menu_slug() {
115
+
116
+        return 'wl_configuration_admin_analytics_menu';
117
+    }
118
+
119
+    /**
120
+     * @inheritdoc
121
+     */
122
+    public function get_partial_name() {
123
+
124
+        return 'wordlift-admin-settings-analytics-page.php';
125
+    }
126
+
127
+    /**
128
+     * Returns the string to use for the tab slug on main admin settings page.
129
+     *
130
+     * @method get_admin_page_tab_slug
131
+     * @return string
132
+     * @since  3.21.0
133
+     */
134
+    public function get_admin_page_tab_slug() {
135
+        return 'analytics';
136
+    }
137
+
138
+    /**
139
+     * Adds pages to the tabs menu on the main admin settings page.
140
+     *
141
+     * @method add_admin_page_tab
142
+     * @param array $tabs an array of tab titles and slugs to use when building a tabbed menu on option pages.
143
+     *
144
+     * @since  3.21.0
145
+     */
146
+    public function add_admin_page_tab( $tabs ) {
147
+        if ( apply_filters( 'wl_feature__enable__analytics', true ) ) {
148
+            $tabs[] = array(
149
+                'title' => $this->get_menu_title(),
150
+                'slug'  => $this->get_admin_page_tab_slug(),
151
+            );
152
+        }
153
+
154
+        return $tabs;
155
+    }
156
+
157
+    /**
158
+     * Configure all the configuration parameters.
159
+     *
160
+     * Called by the *admin_init* hook.
161
+     *
162
+     * @since 3.21.0
163
+     */
164
+    public function admin_init() {
165
+
166
+        // Register WordLift's analytics settings with our in class sanitizer.
167
+        register_setting(
168
+            'wl_analytics_settings',
169
+            'wl_analytics_settings',
170
+            array( $this, 'sanitize_callback' )
171
+        );
172
+
173
+        // Add the analytics settings setction.
174
+        add_settings_section(
175
+            'wl_analytics_settings_section',
176
+            '',
177
+            '',
178
+            'wl_analytics_settings'
179
+        );
180
+
181
+        // Add a toggle to determine if analytics functions are enabled or not.
182
+        // NOTE: this uses yes/no rather than true/false.
183
+        add_settings_field(
184
+            'wl-analytics-enabled',
185
+            __( 'Enable Analytics', 'wordlift' ),
186
+            array( $this->radio_input_element, 'render' ),
187
+            'wl_analytics_settings',
188
+            'wl_analytics_settings_section',
189
+            array(
190
+                'id'          => 'wl-analytics-enable',
191
+                'name'        => 'wl_analytics_settings[' . Wordlift_Configuration_Service::ANALYTICS_ENABLE . ']',
192
+                'value'       => Wordlift_Configuration_Service::get_instance()->is_analytics_enable() ? 'yes' : 'no',
193
+                'description' => __( 'Toggle on/off the default values.', 'wordlift' ),
194
+            )
195
+        );
196
+
197
+        /**
198
+         * A basic number field that will accept anything from 1 to 20.
199
+         *
200
+         * Represents the custom dim number for the uri.
201
+         */
202
+        add_settings_field(
203
+            'wl-analytics-entity-uri-dimension',
204
+            __( 'Entity URI dimension', 'wordlift' ),
205
+            array( $this->input_element, 'render' ),
206
+            'wl_analytics_settings',
207
+            'wl_analytics_settings_section',
208
+            array(
209
+                'id'          => 'wl-analytics-entity-uri-dimension',
210
+                'name'        => 'wl_analytics_settings[' . Wordlift_Configuration_Service::ANALYTICS_ENTITY_URI_DIMENSION . ']',
211
+                'type'        => 'number',
212
+                'value'       => Wordlift_Configuration_Service::get_instance()->get_analytics_entity_uri_dimension(),
213
+                'description' => __( 'Entity URI dimesion', 'wordlift' ),
214
+            )
215
+        );
216
+
217
+        /**
218
+         * A basic number field that will accept anything from 1 to 20.
219
+         *
220
+         * Represents the custom dim number for the type.
221
+         */
222
+        add_settings_field(
223
+            'wl-analytics-entity-type-dimension',
224
+            __( 'Entity Type dimension', 'wordlift' ),
225
+            array( $this->input_element, 'render' ),
226
+            'wl_analytics_settings',
227
+            'wl_analytics_settings_section',
228
+            array(
229
+                'id'          => 'wl-analytics-entity-type-dimension',
230
+                'name'        => 'wl_analytics_settings[' . Wordlift_Configuration_Service::ANALYTICS_ENTITY_TYPE_DIMENSION . ']',
231
+                'type'        => 'number',
232
+                'value'       => Wordlift_Configuration_Service::get_instance()->get_analytics_entity_type_dimension(),
233
+                'description' => __( 'Entity Type dimension', 'wordlift' ),
234
+            )
235
+        );
236
+
237
+    }
238
+
239
+    /**
240
+     * Validates an entity uri based on an integer passed.
241
+     *
242
+     * TODO: Needs a feedback method to pass back error messages.
243
+     *
244
+     * @method validate_entity_uri
245
+     * @param string $uri a sting representing an entity ID that can be converted to a uri.
246
+     *
247
+     * @return int
248
+     * @since 3.21.0
249
+     */
250
+    public function validate_entity_uri( $uri ) {
251
+        // Basic validation is to ensure number is between 1 and 20.
252
+        // NOTE: certain analytics accounts have a much higher value - as many
253
+        // as 200 are allowed.
254
+        if ( (int) $uri < 1 || (int) $uri > 20 ) {
255
+            // if we are out of range then pass the default value.
256
+            $uri = Wordlift_Configuration_Service::get_instance()->get_analytics_entity_uri_dimension();
257
+        }
258
+
259
+        return absint( $uri );
260
+    }
261
+
262
+    /**
263
+     * Validates an entity type.
264
+     *
265
+     * TODO: Needs a feedback method to pass back error messages.
266
+     *
267
+     * @method validate_entity_type
268
+     * @param string $type This is an entity type ID in string form - really a number.
269
+     *
270
+     * @return int
271
+     * @since  3.21.0
272
+     */
273
+    public function validate_entity_type( $type ) {
274
+        // Basic validation is to ensure number is between 1 and 20.
275
+        // NOTE: certain analytics accounts have a much higher value - as many
276
+        // as 200 are allowed.
277
+        if ( (int) $type < 1 || (int) $type > 20 ) {
278
+            // if we are out of range then pass the default value.
279
+            $type = Wordlift_Configuration_Service::get_instance()->get_analytics_entity_type_dimension();
280
+        }
281
+
282
+        return absint( $type );
283
+    }
284
+
285
+    /**
286
+     * Sanitize the configuration settings to be stored.
287
+     *
288
+     * If a new entity is being created for the publisher, create it and set The
289
+     * publisher setting.
290
+     *
291
+     * @param array $input The configuration settings array.
292
+     *
293
+     * @return array The sanitized input array.
294
+     * @since 3.21.0
295
+     */
296
+    public function sanitize_callback( $input ) {
297
+        if ( ! check_admin_referer( 'wl_analytics_settings-options' ) ) {
298
+            // Any failing nonce checks already die().
299
+            return;
300
+        }
301
+
302
+        /**
303
+         * Validate and sanitize the $inputs and store them in $output saved.
304
+         */
305
+        $output = array();
306
+        if ( isset( $input['analytics_enable'] ) ) {
307
+            $output['analytics_enable'] = ( 'yes' === $input['analytics_enable'] ) ? 'yes' : 'no';
308
+        }
309
+        if ( isset( $input['analytics_entity_uri_dimension'] ) ) {
310
+            $output['analytics_entity_uri_dimension'] = (int) $this->validate_entity_uri( $input['analytics_entity_uri_dimension'] );
311
+        }
312
+        if ( isset( $input['analytics_entity_type_dimension'] ) ) {
313
+            // This dimension cannot be the same as the one set above. If it is
314
+            // then zero it out and it will fail validation.
315
+            if ( isset( $output['analytics_entity_uri_dimension'] ) && $output['analytics_entity_uri_dimension'] === (int) $input['analytics_entity_type_dimension'] ) {
316
+                $input['analytics_entity_type_dimension'] = 0;
317
+            }
318
+            $output['analytics_entity_type_dimension'] = (int) $this->validate_entity_type( $input['analytics_entity_type_dimension'] );
319
+        }
320
+
321
+        // return items added to the output for saving.
322
+        return $output;
323
+    }
324 324
 
325 325
 }
Please login to merge, or discard this patch.
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -53,14 +53,14 @@  discard block
 block discarded – undo
53 53
 	 *
54 54
 	 * @since 3.21.0
55 55
 	 */
56
-	public function __construct( $input_element, $radio_input_element ) {
56
+	public function __construct($input_element, $radio_input_element) {
57 57
 
58 58
 		// Set a reference to the UI elements.
59 59
 		$this->input_element       = $input_element;
60 60
 		$this->radio_input_element = $radio_input_element;
61 61
 
62 62
 		// Adds this page to the main admin settings tabbed menu.
63
-		add_filter( 'wl_admin_page_tabs', array( $this, 'add_admin_page_tab' ) );
63
+		add_filter('wl_admin_page_tabs', array($this, 'add_admin_page_tab'));
64 64
 
65 65
 		self::$instance = $this;
66 66
 	}
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 	 */
98 98
 	public function get_page_title() {
99 99
 
100
-		return __( 'WorldLift Analytics Settings', 'wordlift' );
100
+		return __('WorldLift Analytics Settings', 'wordlift');
101 101
 	}
102 102
 
103 103
 	/**
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 	 */
106 106
 	public function get_menu_title() {
107 107
 
108
-		return __( 'Analytics Settings', 'wordlift' );
108
+		return __('Analytics Settings', 'wordlift');
109 109
 	}
110 110
 
111 111
 	/**
@@ -143,8 +143,8 @@  discard block
 block discarded – undo
143 143
 	 *
144 144
 	 * @since  3.21.0
145 145
 	 */
146
-	public function add_admin_page_tab( $tabs ) {
147
-		if ( apply_filters( 'wl_feature__enable__analytics', true ) ) {
146
+	public function add_admin_page_tab($tabs) {
147
+		if (apply_filters('wl_feature__enable__analytics', true)) {
148 148
 			$tabs[] = array(
149 149
 				'title' => $this->get_menu_title(),
150 150
 				'slug'  => $this->get_admin_page_tab_slug(),
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
 		register_setting(
168 168
 			'wl_analytics_settings',
169 169
 			'wl_analytics_settings',
170
-			array( $this, 'sanitize_callback' )
170
+			array($this, 'sanitize_callback')
171 171
 		);
172 172
 
173 173
 		// Add the analytics settings setction.
@@ -182,15 +182,15 @@  discard block
 block discarded – undo
182 182
 		// NOTE: this uses yes/no rather than true/false.
183 183
 		add_settings_field(
184 184
 			'wl-analytics-enabled',
185
-			__( 'Enable Analytics', 'wordlift' ),
186
-			array( $this->radio_input_element, 'render' ),
185
+			__('Enable Analytics', 'wordlift'),
186
+			array($this->radio_input_element, 'render'),
187 187
 			'wl_analytics_settings',
188 188
 			'wl_analytics_settings_section',
189 189
 			array(
190 190
 				'id'          => 'wl-analytics-enable',
191
-				'name'        => 'wl_analytics_settings[' . Wordlift_Configuration_Service::ANALYTICS_ENABLE . ']',
191
+				'name'        => 'wl_analytics_settings['.Wordlift_Configuration_Service::ANALYTICS_ENABLE.']',
192 192
 				'value'       => Wordlift_Configuration_Service::get_instance()->is_analytics_enable() ? 'yes' : 'no',
193
-				'description' => __( 'Toggle on/off the default values.', 'wordlift' ),
193
+				'description' => __('Toggle on/off the default values.', 'wordlift'),
194 194
 			)
195 195
 		);
196 196
 
@@ -201,16 +201,16 @@  discard block
 block discarded – undo
201 201
 		 */
202 202
 		add_settings_field(
203 203
 			'wl-analytics-entity-uri-dimension',
204
-			__( 'Entity URI dimension', 'wordlift' ),
205
-			array( $this->input_element, 'render' ),
204
+			__('Entity URI dimension', 'wordlift'),
205
+			array($this->input_element, 'render'),
206 206
 			'wl_analytics_settings',
207 207
 			'wl_analytics_settings_section',
208 208
 			array(
209 209
 				'id'          => 'wl-analytics-entity-uri-dimension',
210
-				'name'        => 'wl_analytics_settings[' . Wordlift_Configuration_Service::ANALYTICS_ENTITY_URI_DIMENSION . ']',
210
+				'name'        => 'wl_analytics_settings['.Wordlift_Configuration_Service::ANALYTICS_ENTITY_URI_DIMENSION.']',
211 211
 				'type'        => 'number',
212 212
 				'value'       => Wordlift_Configuration_Service::get_instance()->get_analytics_entity_uri_dimension(),
213
-				'description' => __( 'Entity URI dimesion', 'wordlift' ),
213
+				'description' => __('Entity URI dimesion', 'wordlift'),
214 214
 			)
215 215
 		);
216 216
 
@@ -221,16 +221,16 @@  discard block
 block discarded – undo
221 221
 		 */
222 222
 		add_settings_field(
223 223
 			'wl-analytics-entity-type-dimension',
224
-			__( 'Entity Type dimension', 'wordlift' ),
225
-			array( $this->input_element, 'render' ),
224
+			__('Entity Type dimension', 'wordlift'),
225
+			array($this->input_element, 'render'),
226 226
 			'wl_analytics_settings',
227 227
 			'wl_analytics_settings_section',
228 228
 			array(
229 229
 				'id'          => 'wl-analytics-entity-type-dimension',
230
-				'name'        => 'wl_analytics_settings[' . Wordlift_Configuration_Service::ANALYTICS_ENTITY_TYPE_DIMENSION . ']',
230
+				'name'        => 'wl_analytics_settings['.Wordlift_Configuration_Service::ANALYTICS_ENTITY_TYPE_DIMENSION.']',
231 231
 				'type'        => 'number',
232 232
 				'value'       => Wordlift_Configuration_Service::get_instance()->get_analytics_entity_type_dimension(),
233
-				'description' => __( 'Entity Type dimension', 'wordlift' ),
233
+				'description' => __('Entity Type dimension', 'wordlift'),
234 234
 			)
235 235
 		);
236 236
 
@@ -247,16 +247,16 @@  discard block
 block discarded – undo
247 247
 	 * @return int
248 248
 	 * @since 3.21.0
249 249
 	 */
250
-	public function validate_entity_uri( $uri ) {
250
+	public function validate_entity_uri($uri) {
251 251
 		// Basic validation is to ensure number is between 1 and 20.
252 252
 		// NOTE: certain analytics accounts have a much higher value - as many
253 253
 		// as 200 are allowed.
254
-		if ( (int) $uri < 1 || (int) $uri > 20 ) {
254
+		if ((int) $uri < 1 || (int) $uri > 20) {
255 255
 			// if we are out of range then pass the default value.
256 256
 			$uri = Wordlift_Configuration_Service::get_instance()->get_analytics_entity_uri_dimension();
257 257
 		}
258 258
 
259
-		return absint( $uri );
259
+		return absint($uri);
260 260
 	}
261 261
 
262 262
 	/**
@@ -270,16 +270,16 @@  discard block
 block discarded – undo
270 270
 	 * @return int
271 271
 	 * @since  3.21.0
272 272
 	 */
273
-	public function validate_entity_type( $type ) {
273
+	public function validate_entity_type($type) {
274 274
 		// Basic validation is to ensure number is between 1 and 20.
275 275
 		// NOTE: certain analytics accounts have a much higher value - as many
276 276
 		// as 200 are allowed.
277
-		if ( (int) $type < 1 || (int) $type > 20 ) {
277
+		if ((int) $type < 1 || (int) $type > 20) {
278 278
 			// if we are out of range then pass the default value.
279 279
 			$type = Wordlift_Configuration_Service::get_instance()->get_analytics_entity_type_dimension();
280 280
 		}
281 281
 
282
-		return absint( $type );
282
+		return absint($type);
283 283
 	}
284 284
 
285 285
 	/**
@@ -293,8 +293,8 @@  discard block
 block discarded – undo
293 293
 	 * @return array The sanitized input array.
294 294
 	 * @since 3.21.0
295 295
 	 */
296
-	public function sanitize_callback( $input ) {
297
-		if ( ! check_admin_referer( 'wl_analytics_settings-options' ) ) {
296
+	public function sanitize_callback($input) {
297
+		if ( ! check_admin_referer('wl_analytics_settings-options')) {
298 298
 			// Any failing nonce checks already die().
299 299
 			return;
300 300
 		}
@@ -303,19 +303,19 @@  discard block
 block discarded – undo
303 303
 		 * Validate and sanitize the $inputs and store them in $output saved.
304 304
 		 */
305 305
 		$output = array();
306
-		if ( isset( $input['analytics_enable'] ) ) {
307
-			$output['analytics_enable'] = ( 'yes' === $input['analytics_enable'] ) ? 'yes' : 'no';
306
+		if (isset($input['analytics_enable'])) {
307
+			$output['analytics_enable'] = ('yes' === $input['analytics_enable']) ? 'yes' : 'no';
308 308
 		}
309
-		if ( isset( $input['analytics_entity_uri_dimension'] ) ) {
310
-			$output['analytics_entity_uri_dimension'] = (int) $this->validate_entity_uri( $input['analytics_entity_uri_dimension'] );
309
+		if (isset($input['analytics_entity_uri_dimension'])) {
310
+			$output['analytics_entity_uri_dimension'] = (int) $this->validate_entity_uri($input['analytics_entity_uri_dimension']);
311 311
 		}
312
-		if ( isset( $input['analytics_entity_type_dimension'] ) ) {
312
+		if (isset($input['analytics_entity_type_dimension'])) {
313 313
 			// This dimension cannot be the same as the one set above. If it is
314 314
 			// then zero it out and it will fail validation.
315
-			if ( isset( $output['analytics_entity_uri_dimension'] ) && $output['analytics_entity_uri_dimension'] === (int) $input['analytics_entity_type_dimension'] ) {
315
+			if (isset($output['analytics_entity_uri_dimension']) && $output['analytics_entity_uri_dimension'] === (int) $input['analytics_entity_type_dimension']) {
316 316
 				$input['analytics_entity_type_dimension'] = 0;
317 317
 			}
318
-			$output['analytics_entity_type_dimension'] = (int) $this->validate_entity_type( $input['analytics_entity_type_dimension'] );
318
+			$output['analytics_entity_type_dimension'] = (int) $this->validate_entity_type($input['analytics_entity_type_dimension']);
319 319
 		}
320 320
 
321 321
 		// return items added to the output for saving.
Please login to merge, or discard this patch.