Passed
Pull Request — master (#51)
by
unknown
09:43 queued 05:04
created
classes/class-lsx-wetu-importer-settings.php 2 patches
Indentation   +218 added lines, -218 removed lines patch added patch discarded remove patch
@@ -14,85 +14,85 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class LSX_WETU_Importer_Settings {
16 16
 
17
-	/**
18
-	 * Holds instance of the class
19
-	 *
20
-	 * @var object
21
-	 */
22
-	private static $instance;
17
+     /**
18
+      * Holds instance of the class
19
+      *
20
+      * @var object
21
+      */
22
+     private static $instance;
23 23
 
24
-	/**
25
-	 * Holds the default settings.
26
-	 *
27
-	 * @var array
28
-	 */
29
-	public $defaults = array();
24
+     /**
25
+      * Holds the default settings.
26
+      *
27
+      * @var array
28
+      */
29
+     public $defaults = array();
30 30
 
31
-	/**
32
-	 * Holds the settings fields available.
33
-	 *
34
-	 * @var array
35
-	 */
36
-	public $fields = array();
31
+     /**
32
+      * Holds the settings fields available.
33
+      *
34
+      * @var array
35
+      */
36
+     public $fields = array();
37 37
 
38
-	/**
39
-	 * Initialize the plugin by setting localization, filters, and administration functions.
40
-	 *
41
-	 * @since 1.0.0
42
-	 *
43
-	 * @access private
44
-	 */
45
-	public function __construct() {
46
-		$this->defaults = array(
47
-			'api_key'                            => '',
48
-			'disable_tour_title'                 => '',
49
-			'disable_tour_descriptions'          => '',
50
-			'disable_tour_tags'                  => 'on',
51
-			'enable_tour_featured_random'        => '',
52
-			'disable_accommodation_title'        => '',
53
-			'disable_accommodation_descriptions' => '',
54
-			'disable_accommodation_filtering'    => '',
55
-			'disable_accommodation_excerpts'     => '',
56
-			'disable_destination_title'          => '',
57
-			'disable_destination_descriptions'   => '',
58
-			'image_replacing'                    => 'on',
59
-			'image_limit'                        => '15',
60
-			'image_scaling'                      => 'on',
61
-			'width'                              => '800',
62
-			'height'                             => '600',
63
-			'scaling'                            => 'h',
64
-			'enable_tour_ref_column'             => '',
65
-			'cron_schedule'                      => 'daily',
66
-			'accommodation_images_cron'          => '',
67
-			'accommodation_images_cron_featured' => '',
68
-		);
69
-		$this->fields   = array_keys( $this->defaults );
70
-		add_action( 'admin_init', array( $this, 'save_options' ) );
71
-	}
38
+     /**
39
+      * Initialize the plugin by setting localization, filters, and administration functions.
40
+      *
41
+      * @since 1.0.0
42
+      *
43
+      * @access private
44
+      */
45
+     public function __construct() {
46
+          $this->defaults = array(
47
+               'api_key'                            => '',
48
+               'disable_tour_title'                 => '',
49
+               'disable_tour_descriptions'          => '',
50
+               'disable_tour_tags'                  => 'on',
51
+               'enable_tour_featured_random'        => '',
52
+               'disable_accommodation_title'        => '',
53
+               'disable_accommodation_descriptions' => '',
54
+               'disable_accommodation_filtering'    => '',
55
+               'disable_accommodation_excerpts'     => '',
56
+               'disable_destination_title'          => '',
57
+               'disable_destination_descriptions'   => '',
58
+               'image_replacing'                    => 'on',
59
+               'image_limit'                        => '15',
60
+               'image_scaling'                      => 'on',
61
+               'width'                              => '800',
62
+               'height'                             => '600',
63
+               'scaling'                            => 'h',
64
+               'enable_tour_ref_column'             => '',
65
+               'cron_schedule'                      => 'daily',
66
+               'accommodation_images_cron'          => '',
67
+               'accommodation_images_cron_featured' => '',
68
+          );
69
+          $this->fields   = array_keys( $this->defaults );
70
+          add_action( 'admin_init', array( $this, 'save_options' ) );
71
+     }
72 72
 
73
-	/**
74
-	 * Return an instance of this class.
75
-	 *
76
-	 * @return  object
77
-	 */
78
-	public static function get_instance() {
79
-		// If the single instance hasn't been set, set it now.
80
-		if ( ! isset( self::$instance ) ) {
81
-			self::$instance = new self();
82
-		}
83
-		return self::$instance;
84
-	}
73
+     /**
74
+      * Return an instance of this class.
75
+      *
76
+      * @return  object
77
+      */
78
+     public static function get_instance() {
79
+          // If the single instance hasn't been set, set it now.
80
+          if ( ! isset( self::$instance ) ) {
81
+               self::$instance = new self();
82
+          }
83
+          return self::$instance;
84
+     }
85 85
 
86
-	/**
87
-	 * Display the importer welcome screen
88
-	 */
89
-	public function display_page() {
90
-		$options = lsx_wetu_get_options();
91
-		foreach ( $options as $key => $value ) {
92
-			$value = trim( $value );
93
-		}
94
-		$options = wp_parse_args( $options, $this->defaults );
95
-		?>
86
+     /**
87
+      * Display the importer welcome screen
88
+      */
89
+     public function display_page() {
90
+          $options = lsx_wetu_get_options();
91
+          foreach ( $options as $key => $value ) {
92
+               $value = trim( $value );
93
+          }
94
+          $options = wp_parse_args( $options, $this->defaults );
95
+          ?>
96 96
 		<div class="wrap">
97 97
 			<form method="post" class="">
98 98
 				<?php wp_nonce_field( 'lsx_wetu_importer_save', 'lsx_wetu_importer_save_options' ); ?>
@@ -107,10 +107,10 @@  discard block
 block discarded – undo
107 107
 							<td>
108 108
 								<input data-toggle="tooltip" data-placement="top" title="The API key can be found on your My Account page of your WETU account." type="text" value="
109 109
                                 <?php
110
-								if ( isset( $options['api_key'] ) ) {
111
-									echo esc_attr( $options['api_key'] );
112
-								}
113
-								?>
110
+                                        if ( isset( $options['api_key'] ) ) {
111
+                                             echo esc_attr( $options['api_key'] );
112
+                                        }
113
+                                        ?>
114 114
                                 " name="api_key" />
115 115
 							</td>
116 116
 						</tr>
@@ -127,10 +127,10 @@  discard block
 block discarded – undo
127 127
 							<td>
128 128
 								<input type="checkbox"
129 129
 								<?php
130
-								if ( isset( $options['disable_tour_title'] ) && '' !== $options['disable_tour_title'] ) {
131
-									echo esc_attr( 'checked="checked"' );
132
-								}
133
-								?>
130
+                                        if ( isset( $options['disable_tour_title'] ) && '' !== $options['disable_tour_title'] ) {
131
+                                             echo esc_attr( 'checked="checked"' );
132
+                                        }
133
+                                        ?>
134 134
 								name="disable_tour_title" />
135 135
 
136 136
 								<small><?php esc_html_e( 'If you are going to manage your tour descriptions on this site and not on WETU then enable this setting.', 'lsx-wetu-importer' ); ?></small>
@@ -143,10 +143,10 @@  discard block
 block discarded – undo
143 143
 							<td>
144 144
 								<input type="checkbox"
145 145
 								<?php
146
-								if ( isset( $options['disable_tour_descriptions'] ) && '' !== $options['disable_tour_descriptions'] ) {
147
-									echo esc_attr( 'checked="checked"' );
148
-								}
149
-								?>
146
+                                        if ( isset( $options['disable_tour_descriptions'] ) && '' !== $options['disable_tour_descriptions'] ) {
147
+                                             echo esc_attr( 'checked="checked"' );
148
+                                        }
149
+                                        ?>
150 150
 								name="disable_tour_descriptions" />
151 151
 
152 152
 								<small><?php esc_html_e( 'If you are going to manage your tour descriptions on this site and not on WETU then enable this setting.', 'lsx-wetu-importer' ); ?></small>
@@ -159,10 +159,10 @@  discard block
 block discarded – undo
159 159
 							<td>
160 160
 								<input type="checkbox"
161 161
 								<?php
162
-								if ( isset( $options['disable_tour_tags'] ) && '' !== $options['disable_tour_tags'] ) {
163
-									echo esc_attr( 'checked="checked"' );
164
-								}
165
-								?>
162
+                                        if ( isset( $options['disable_tour_tags'] ) && '' !== $options['disable_tour_tags'] ) {
163
+                                             echo esc_attr( 'checked="checked"' );
164
+                                        }
165
+                                        ?>
166 166
 								name="disable_tour_tags" />
167 167
 
168 168
 								<small><?php esc_html_e( 'Disable this is you dont want the option available on the import screen.', 'lsx-wetu-importer' ); ?></small>
@@ -176,10 +176,10 @@  discard block
 block discarded – undo
176 176
 							<td>
177 177
 								<input type="checkbox"
178 178
 								<?php
179
-								if ( isset( $options['enable_tour_ref_column'] ) && '' !== $options['enable_tour_ref_column'] ) {
180
-									echo esc_attr( 'checked="checked"' );
181
-								}
182
-								?>
179
+                                        if ( isset( $options['enable_tour_ref_column'] ) && '' !== $options['enable_tour_ref_column'] ) {
180
+                                             echo esc_attr( 'checked="checked"' );
181
+                                        }
182
+                                        ?>
183 183
 								name="enable_tour_ref_column" />
184 184
 								<small><?php esc_html_e( 'Enables the use of the WETU Reference Column for better tours management.', 'lsx-wetu-importer' ); ?></small>
185 185
 							</td>
@@ -192,10 +192,10 @@  discard block
 block discarded – undo
192 192
 							<td>
193 193
 								<input type="checkbox"
194 194
 								<?php
195
-								if ( isset( $options['enable_tour_featured_random'] ) && '' !== $options['enable_tour_featured_random'] ) {
196
-									echo esc_attr( 'checked="checked"' );
197
-								}
198
-								?>
195
+                                        if ( isset( $options['enable_tour_featured_random'] ) && '' !== $options['enable_tour_featured_random'] ) {
196
+                                             echo esc_attr( 'checked="checked"' );
197
+                                        }
198
+                                        ?>
199 199
 								name="enable_tour_featured_random" />
200 200
 								<small><?php esc_html_e( 'This will randomize the featured image from the destination gallery.', 'lsx-wetu-importer' ); ?></small>
201 201
 							</td>
@@ -214,10 +214,10 @@  discard block
 block discarded – undo
214 214
 							<td>
215 215
 								<input type="checkbox"
216 216
 								<?php
217
-								if ( isset( $options['disable_accommodation_title'] ) && '' !== $options['disable_accommodation_title'] ) {
218
-									echo esc_attr( 'checked="checked"' );
219
-								}
220
-								?>
217
+                                        if ( isset( $options['disable_accommodation_title'] ) && '' !== $options['disable_accommodation_title'] ) {
218
+                                             echo esc_attr( 'checked="checked"' );
219
+                                        }
220
+                                        ?>
221 221
 								name="disable_accommodation_title" />
222 222
 
223 223
 								<small><?php esc_html_e( 'If you are going to manage your tour descriptions on this site and not on WETU then enable this setting.', 'lsx-wetu-importer' ); ?></small>
@@ -230,10 +230,10 @@  discard block
 block discarded – undo
230 230
 							<td>
231 231
 								<input type="checkbox"
232 232
 								<?php
233
-								if ( isset( $options['disable_accommodation_descriptions'] ) && '' !== $options['disable_accommodation_descriptions'] ) {
234
-									echo esc_attr( 'checked="checked"' );
235
-								}
236
-								?>
233
+                                        if ( isset( $options['disable_accommodation_descriptions'] ) && '' !== $options['disable_accommodation_descriptions'] ) {
234
+                                             echo esc_attr( 'checked="checked"' );
235
+                                        }
236
+                                        ?>
237 237
 								name="disable_accommodation_descriptions" />
238 238
 								<small><?php esc_html_e( 'If you are going to edit the accommodation descriptions imported then enable this setting.', 'lsx-wetu-importer' ); ?></small>
239 239
 							</td>
@@ -245,10 +245,10 @@  discard block
 block discarded – undo
245 245
 							<td>
246 246
 								<input type="checkbox"
247 247
 								<?php
248
-								if ( isset( $options['disable_accommodation_filtering'] ) && '' !== $options['disable_accommodation_filtering'] ) {
249
-									echo esc_attr( 'checked="checked"' );
250
-								}
251
-								?>
248
+                                        if ( isset( $options['disable_accommodation_filtering'] ) && '' !== $options['disable_accommodation_filtering'] ) {
249
+                                             echo esc_attr( 'checked="checked"' );
250
+                                        }
251
+                                        ?>
252 252
 								name="disable_accommodation_filtering" />
253 253
 								<small><?php esc_html_e( 'This will stop the HTML from being stripped out of the description.', 'lsx-wetu-importer' ); ?></small>
254 254
 							</td>
@@ -261,10 +261,10 @@  discard block
 block discarded – undo
261 261
 							<td>
262 262
 								<input type="checkbox"
263 263
 								<?php
264
-								if ( isset( $options['disable_accommodation_excerpts'] ) && '' !== $options['disable_accommodation_excerpts'] ) {
265
-									echo esc_attr( 'checked="checked"' );
266
-								}
267
-								?>
264
+                                        if ( isset( $options['disable_accommodation_excerpts'] ) && '' !== $options['disable_accommodation_excerpts'] ) {
265
+                                             echo esc_attr( 'checked="checked"' );
266
+                                        }
267
+                                        ?>
268 268
 								name="disable_accommodation_excerpts" />
269 269
 								<small><?php esc_html_e( 'If you are going to edit the accommodation excerpts then enable this setting.', 'lsx-wetu-importer' ); ?></small>
270 270
 							</td>
@@ -283,10 +283,10 @@  discard block
 block discarded – undo
283 283
 							<td>
284 284
 								<input type="checkbox"
285 285
 								<?php
286
-								if ( isset( $options['disable_destination_title'] ) && '' !== $options['disable_destination_title'] ) {
287
-									echo esc_attr( 'checked="checked"' );
288
-								}
289
-								?>
286
+                                        if ( isset( $options['disable_destination_title'] ) && '' !== $options['disable_destination_title'] ) {
287
+                                             echo esc_attr( 'checked="checked"' );
288
+                                        }
289
+                                        ?>
290 290
 								name="disable_destination_title" />
291 291
 
292 292
 								<small><?php esc_html_e( 'If you are going to manage your tour descriptions on this site and not on WETU then enable this setting.', 'lsx-wetu-importer' ); ?></small>
@@ -299,10 +299,10 @@  discard block
 block discarded – undo
299 299
 							<td>
300 300
 								<input type="checkbox"
301 301
 								<?php
302
-								if ( isset( $options['disable_destination_descriptions'] ) && '' !== $options['disable_destination_descriptions'] ) {
303
-									echo esc_attr( 'checked="checked"' );
304
-								}
305
-								?>
302
+                                        if ( isset( $options['disable_destination_descriptions'] ) && '' !== $options['disable_destination_descriptions'] ) {
303
+                                             echo esc_attr( 'checked="checked"' );
304
+                                        }
305
+                                        ?>
306 306
 								name="disable_destination_descriptions" />
307 307
 								<small><?php esc_html_e( 'If you are going to edit the destination descriptions on this site then enable this setting.', 'lsx-wetu-importer' ); ?></small>
308 308
 							</td>
@@ -321,10 +321,10 @@  discard block
 block discarded – undo
321 321
 							<td>
322 322
 								<input type="checkbox"
323 323
 								<?php
324
-								if ( isset( $options['image_replacing'] ) && '' !== $options['image_replacing'] ) {
325
-									echo esc_attr( 'checked="checked"' );
326
-								}
327
-								?>
324
+                                        if ( isset( $options['image_replacing'] ) && '' !== $options['image_replacing'] ) {
325
+                                             echo esc_attr( 'checked="checked"' );
326
+                                        }
327
+                                        ?>
328 328
 								name="image_replacing" />
329 329
 								<p><?php esc_html_e( 'Do you want your images to be replaced on each import.', 'lsx-wetu-importer' ); ?></p>
330 330
 							</td>
@@ -336,10 +336,10 @@  discard block
 block discarded – undo
336 336
 							<td>
337 337
 								<input placeholder="" type="text" value="
338 338
                                 <?php
339
-								if ( isset( $options['image_limit'] ) && '' !== $options['image_limit'] ) {
340
-									echo esc_attr( $options['image_limit'] );
341
-								}
342
-								?>
339
+                                        if ( isset( $options['image_limit'] ) && '' !== $options['image_limit'] ) {
340
+                                             echo esc_attr( $options['image_limit'] );
341
+                                        }
342
+                                        ?>
343 343
                                 "
344 344
 								name="image_limit" />
345 345
 							</td>
@@ -352,10 +352,10 @@  discard block
 block discarded – undo
352 352
 							<td>
353 353
 								<input type="checkbox"
354 354
 								<?php
355
-								if ( isset( $options['image_scaling'] ) && '' !== $options['image_scaling'] ) {
356
-									echo esc_attr( 'checked="checked"' );
357
-								}
358
-								?>
355
+                                        if ( isset( $options['image_scaling'] ) && '' !== $options['image_scaling'] ) {
356
+                                             echo esc_attr( 'checked="checked"' );
357
+                                        }
358
+                                        ?>
359 359
 								name="image_scaling" />
360 360
 							</td>
361 361
 						</tr>
@@ -366,10 +366,10 @@  discard block
 block discarded – undo
366 366
 							<td>
367 367
 								<input placeholder="800" type="text" value="
368 368
                                 <?php
369
-								if ( isset( $options['width'] ) && '' !== $options['width'] ) {
370
-									echo esc_attr( $options['width'] );
371
-								}
372
-								?>
369
+                                        if ( isset( $options['width'] ) && '' !== $options['width'] ) {
370
+                                             echo esc_attr( $options['width'] );
371
+                                        }
372
+                                        ?>
373 373
                                 "
374 374
 								name="width" />
375 375
 							</td>
@@ -381,10 +381,10 @@  discard block
 block discarded – undo
381 381
 							<td>
382 382
 								<input placeholder="600" type="text" value="
383 383
                                 <?php
384
-								if ( isset( $options['height'] ) && '' !== $options['height'] ) {
385
-									echo esc_attr( $options['height'] );
386
-								}
387
-								?>
384
+                                        if ( isset( $options['height'] ) && '' !== $options['height'] ) {
385
+                                             echo esc_attr( $options['height'] );
386
+                                        }
387
+                                        ?>
388 388
                                 "
389 389
 								name="height" />
390 390
 							</td>
@@ -397,52 +397,52 @@  discard block
 block discarded – undo
397 397
 							<td>
398 398
 								<input type="radio"
399 399
 								<?php
400
-								if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'raw' === $options['scaling'] ) {
401
-									echo esc_attr( 'checked="checked"' );
402
-								}
403
-								?>
400
+                                        if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'raw' === $options['scaling'] ) {
401
+                                             echo esc_attr( 'checked="checked"' );
402
+                                        }
403
+                                        ?>
404 404
 								name="scaling" value="raw" /> <?php esc_html_e( 'Get the Full size image, no cropping takes place.', 'lsx-wetu-importer' ); ?><br />
405 405
 								<input type="radio"
406 406
 								<?php
407
-								if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'c' === $options['scaling'] ) {
408
-									echo esc_attr( 'checked="checked"' );
409
-								}
410
-								?>
407
+                                        if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'c' === $options['scaling'] ) {
408
+                                             echo esc_attr( 'checked="checked"' );
409
+                                        }
410
+                                        ?>
411 411
 								name="scaling"  value="c" /> <?php esc_html_e( 'Crop image to fit fully into the frame, Crop is taken from middle, preserving as much of the image as possible.', 'lsx-wetu-importer' ); ?><br />
412 412
 								<input type="radio"
413 413
 								<?php
414
-								if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'h' === $options['scaling'] ) {
415
-									echo esc_attr( 'checked="checked"' );
416
-								}
417
-								?>
414
+                                        if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'h' === $options['scaling'] ) {
415
+                                             echo esc_attr( 'checked="checked"' );
416
+                                        }
417
+                                        ?>
418 418
 								name="scaling"  value="h" /> <?php esc_html_e( 'Crop image to fit fully into the frame, but resize to height first, then crop on width if needed', 'lsx-wetu-importer' ); ?><br />
419 419
 								<input type="radio"
420 420
 								<?php
421
-								if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'w' === $options['scaling'] ) {
422
-									echo esc_attr( 'checked="checked"' );
423
-								}
424
-								?>
421
+                                        if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'w' === $options['scaling'] ) {
422
+                                             echo esc_attr( 'checked="checked"' );
423
+                                        }
424
+                                        ?>
425 425
 								name="scaling"  value="w" /> <?php esc_html_e( 'Crop image to fit fully into the frame, but resize to width first, then crop on height if needed', 'lsx-wetu-importer' ); ?><br />
426 426
 								<input type="radio"
427 427
 								<?php
428
-								if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'nf' === $options['scaling'] ) {
429
-									echo esc_attr( 'checked="checked"' );
430
-								}
431
-								?>
428
+                                        if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'nf' === $options['scaling'] ) {
429
+                                             echo esc_attr( 'checked="checked"' );
430
+                                        }
431
+                                        ?>
432 432
 								name="scaling"  value="nf" /> <?php esc_html_e( 'Resize the image to fit within the frame. but pad the image with white to ensure the resolution matches the frame', 'lsx-wetu-importer' ); ?><br />
433 433
 								<input type="radio"
434 434
 								<?php
435
-								if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'n' === $options['scaling'] ) {
436
-									echo esc_attr( 'checked="checked"' );
437
-								}
438
-								?>
435
+                                        if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'n' === $options['scaling'] ) {
436
+                                             echo esc_attr( 'checked="checked"' );
437
+                                        }
438
+                                        ?>
439 439
 								name="scaling"  value="n" /> <?php esc_html_e( 'Resize the image to fit within the frame. but do not upscale the image.', 'lsx-wetu-importer' ); ?><br />
440 440
 								<input type="radio"
441 441
 								<?php
442
-								if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'W' === $options['scaling'] ) {
443
-									echo esc_attr( 'checked="checked"' );
444
-								}
445
-								?>
442
+                                        if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'W' === $options['scaling'] ) {
443
+                                             echo esc_attr( 'checked="checked"' );
444
+                                        }
445
+                                        ?>
446 446
 								name="scaling"  value="W" /> <?php esc_html_e( 'Resize the image to fit within the frame. Image will not exceed specified dimensions', 'lsx-wetu-importer' ); ?>
447 447
 							</td>
448 448
 						</tr>
@@ -460,28 +460,28 @@  discard block
 block discarded – undo
460 460
 							<td>
461 461
 								<select name="cron_schedule" id="cron_schedule"	class="widefat layout">
462 462
 									<?php
463
-									if ( isset( $options['cron_schedule'] ) && '' !== $options['cron_schedule'] ) {
464
-										$schedule = $options['cron_schedule'];
465
-									} else {
466
-										$schedule = 'daily';
467
-									}
468
-									$timeslots = array(
469
-										'daily'      => __( 'Daily', 'lsx-wetu-importer' ),
470
-										'weekly-mon' => __( 'Weekly (Monday)', 'lsx-wetu-importer' ),
471
-										'weekly-tue' => __( 'Weekly (Tuesday)', 'lsx-wetu-importer' ),
472
-										'weekly-wed' => __( 'Weekly (Wednesday)', 'lsx-wetu-importer' ),
473
-										'weekly-thu' => __( 'Weekly (Thursday)', 'lsx-wetu-importer' ),
474
-										'weekly-fri' => __( 'Weekly (Friday)', 'lsx-wetu-importer' ),
475
-										'weekly-sat' => __( 'Weekly (Saturday)', 'lsx-wetu-importer' ),
476
-										'weekly-sun' => __( 'Weekly (Sunday)', 'lsx-wetu-importer' ),
477
-									);
478
-									foreach ( $timeslots as $key => $name ) {
479
-										$selected = ( $schedule == $key ) ? ' selected="selected"' : '';
480
-										?>
463
+                                             if ( isset( $options['cron_schedule'] ) && '' !== $options['cron_schedule'] ) {
464
+                                                  $schedule = $options['cron_schedule'];
465
+                                             } else {
466
+                                                  $schedule = 'daily';
467
+                                             }
468
+                                             $timeslots = array(
469
+                                                  'daily'      => __( 'Daily', 'lsx-wetu-importer' ),
470
+                                                  'weekly-mon' => __( 'Weekly (Monday)', 'lsx-wetu-importer' ),
471
+                                                  'weekly-tue' => __( 'Weekly (Tuesday)', 'lsx-wetu-importer' ),
472
+                                                  'weekly-wed' => __( 'Weekly (Wednesday)', 'lsx-wetu-importer' ),
473
+                                                  'weekly-thu' => __( 'Weekly (Thursday)', 'lsx-wetu-importer' ),
474
+                                                  'weekly-fri' => __( 'Weekly (Friday)', 'lsx-wetu-importer' ),
475
+                                                  'weekly-sat' => __( 'Weekly (Saturday)', 'lsx-wetu-importer' ),
476
+                                                  'weekly-sun' => __( 'Weekly (Sunday)', 'lsx-wetu-importer' ),
477
+                                             );
478
+                                             foreach ( $timeslots as $key => $name ) {
479
+                                                  $selected = ( $schedule == $key ) ? ' selected="selected"' : '';
480
+                                                  ?>
481 481
 										<option value="<?php echo wp_kses_post( $key ); ?>" id="<?php echo wp_kses_post( $key ); ?>" <?php echo wp_kses_post( $selected ); ?>><?php echo wp_kses_post( $name ); ?></option>
482 482
 										<?php
483
-									}
484
-									?>
483
+                                             }
484
+                                             ?>
485 485
 								</select>
486 486
 							</td>
487 487
 						</tr>
@@ -492,10 +492,10 @@  discard block
 block discarded – undo
492 492
 							<td>
493 493
 								<input type="checkbox"
494 494
 								<?php
495
-								if ( isset( $options['accommodation_images_cron'] ) && '' !== $options['accommodation_images_cron'] ) {
496
-									echo esc_attr( 'checked="checked"' );
497
-								}
498
-								?>
495
+                                        if ( isset( $options['accommodation_images_cron'] ) && '' !== $options['accommodation_images_cron'] ) {
496
+                                             echo esc_attr( 'checked="checked"' );
497
+                                        }
498
+                                        ?>
499 499
 								name="accommodation_images_cron" />
500 500
 								<p><?php esc_html_e( 'Update the accommodation images accodring to the schedule above.', 'lsx-wetu-importer' ); ?></p>
501 501
 							</td>
@@ -507,10 +507,10 @@  discard block
 block discarded – undo
507 507
 							<td>
508 508
 								<input type="checkbox"
509 509
 								<?php
510
-								if ( isset( $options['accommodation_images_cron_featured'] ) && '' !== $options['accommodation_images_cron_featured'] ) {
511
-									echo esc_attr( 'checked="checked"' );
512
-								}
513
-								?>
510
+                                        if ( isset( $options['accommodation_images_cron_featured'] ) && '' !== $options['accommodation_images_cron_featured'] ) {
511
+                                             echo esc_attr( 'checked="checked"' );
512
+                                        }
513
+                                        ?>
514 514
 								name="accommodation_images_cron_featured" />
515 515
 								<p><?php esc_html_e( 'Set the featured image when the gallery is created.', 'lsx-wetu-importer' ); ?></p>
516 516
 							</td>
@@ -522,25 +522,25 @@  discard block
 block discarded – undo
522 522
 			</form>
523 523
 		</div>
524 524
 		<?php
525
-	}
525
+     }
526 526
 
527
-	/**
528
-	 * Save the options fields
529
-	 *
530
-	 * @return void
531
-	 */
532
-	public function save_options() {
533
-		if ( ! isset( $_POST['lsx_wetu_importer_save_options'] ) || ! wp_verify_nonce( $_POST['lsx_wetu_importer_save_options'], 'lsx_wetu_importer_save' ) ) {
534
-			return;
535
-		}
536
-		$data_to_save = array();
537
-		foreach ( $this->defaults as $key => $field ) {
538
-			if ( isset( $_POST[ $key ] ) ) {
539
-				$data_to_save[ $key ] = sanitize_text_field( $_POST[ $key ] );
540
-			} else {
541
-				$data_to_save[ $key ] = '';
542
-			}
543
-		}
544
-		update_option( 'lsx_wetu_importer_settings', $data_to_save );
545
-	}
527
+     /**
528
+      * Save the options fields
529
+      *
530
+      * @return void
531
+      */
532
+     public function save_options() {
533
+          if ( ! isset( $_POST['lsx_wetu_importer_save_options'] ) || ! wp_verify_nonce( $_POST['lsx_wetu_importer_save_options'], 'lsx_wetu_importer_save' ) ) {
534
+               return;
535
+          }
536
+          $data_to_save = array();
537
+          foreach ( $this->defaults as $key => $field ) {
538
+               if ( isset( $_POST[ $key ] ) ) {
539
+                    $data_to_save[ $key ] = sanitize_text_field( $_POST[ $key ] );
540
+               } else {
541
+                    $data_to_save[ $key ] = '';
542
+               }
543
+          }
544
+          update_option( 'lsx_wetu_importer_settings', $data_to_save );
545
+     }
546 546
 }
Please login to merge, or discard this patch.
Spacing   +129 added lines, -129 removed lines patch added patch discarded remove patch
@@ -66,8 +66,8 @@  discard block
 block discarded – undo
66 66
 			'accommodation_images_cron'          => '',
67 67
 			'accommodation_images_cron_featured' => '',
68 68
 		);
69
-		$this->fields   = array_keys( $this->defaults );
70
-		add_action( 'admin_init', array( $this, 'save_options' ) );
69
+		$this->fields = array_keys($this->defaults);
70
+		add_action('admin_init', array($this, 'save_options'));
71 71
 	}
72 72
 
73 73
 	/**
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
 	 */
78 78
 	public static function get_instance() {
79 79
 		// If the single instance hasn't been set, set it now.
80
-		if ( ! isset( self::$instance ) ) {
80
+		if (!isset(self::$instance)) {
81 81
 			self::$instance = new self();
82 82
 		}
83 83
 		return self::$instance;
@@ -88,27 +88,27 @@  discard block
 block discarded – undo
88 88
 	 */
89 89
 	public function display_page() {
90 90
 		$options = lsx_wetu_get_options();
91
-		foreach ( $options as $key => $value ) {
92
-			$value = trim( $value );
91
+		foreach ($options as $key => $value) {
92
+			$value = trim($value);
93 93
 		}
94
-		$options = wp_parse_args( $options, $this->defaults );
94
+		$options = wp_parse_args($options, $this->defaults);
95 95
 		?>
96 96
 		<div class="wrap">
97 97
 			<form method="post" class="">
98
-				<?php wp_nonce_field( 'lsx_wetu_importer_save', 'lsx_wetu_importer_save_options' ); ?>
99
-				<?php do_action( 'lsx_wetu_importer_settings_before' ); ?>
100
-				<h1><?php esc_html_e( 'General', 'lsx-wetu-importer' ); ?></h1>
98
+				<?php wp_nonce_field('lsx_wetu_importer_save', 'lsx_wetu_importer_save_options'); ?>
99
+				<?php do_action('lsx_wetu_importer_settings_before'); ?>
100
+				<h1><?php esc_html_e('General', 'lsx-wetu-importer'); ?></h1>
101 101
 				<table class="form-table">
102 102
 					<tbody>
103 103
 						<tr class="form-field">
104 104
 							<th scope="row">
105
-								<label for="wetu_api_key"><span title="The API key can be found on your My Account page of your WETU account." id="doc-tooltip" class="dashicons dashicons-editor-help tooltip"></span> <?php esc_html_e( 'API Key', 'lsx-wetu-importer' ); ?></label>
105
+								<label for="wetu_api_key"><span title="The API key can be found on your My Account page of your WETU account." id="doc-tooltip" class="dashicons dashicons-editor-help tooltip"></span> <?php esc_html_e('API Key', 'lsx-wetu-importer'); ?></label>
106 106
 							</th>
107 107
 							<td>
108 108
 								<input data-toggle="tooltip" data-placement="top" title="The API key can be found on your My Account page of your WETU account." type="text" value="
109 109
                                 <?php
110
-								if ( isset( $options['api_key'] ) ) {
111
-									echo esc_attr( $options['api_key'] );
110
+								if (isset($options['api_key'])) {
111
+									echo esc_attr($options['api_key']);
112 112
 								}
113 113
 								?>
114 114
                                 " name="api_key" />
@@ -117,227 +117,227 @@  discard block
 block discarded – undo
117 117
 					</tbody>
118 118
 				</table>
119 119
 
120
-				<h1><?php esc_html_e( 'Tours', 'lsx-wetu-importer' ); ?></h1>
120
+				<h1><?php esc_html_e('Tours', 'lsx-wetu-importer'); ?></h1>
121 121
 				<table class="form-table">
122 122
 					<tbody>
123 123
 						<tr class="form-field -wrap">
124 124
 							<th scope="row">
125
-								<label for="disable_tour_title"><?php esc_html_e( 'Enable Custom Titles', 'lsx-wetu-importer' ); ?></label>
125
+								<label for="disable_tour_title"><?php esc_html_e('Enable Custom Titles', 'lsx-wetu-importer'); ?></label>
126 126
 							</th>
127 127
 							<td>
128 128
 								<input type="checkbox"
129 129
 								<?php
130
-								if ( isset( $options['disable_tour_title'] ) && '' !== $options['disable_tour_title'] ) {
131
-									echo esc_attr( 'checked="checked"' );
130
+								if (isset($options['disable_tour_title']) && '' !== $options['disable_tour_title']) {
131
+									echo esc_attr('checked="checked"');
132 132
 								}
133 133
 								?>
134 134
 								name="disable_tour_title" />
135 135
 
136
-								<small><?php esc_html_e( 'If you are going to manage your tour descriptions on this site and not on WETU then enable this setting.', 'lsx-wetu-importer' ); ?></small>
136
+								<small><?php esc_html_e('If you are going to manage your tour descriptions on this site and not on WETU then enable this setting.', 'lsx-wetu-importer'); ?></small>
137 137
 							</td>
138 138
 						</tr>
139 139
 						<tr class="form-field -wrap">
140 140
 							<th scope="row">
141
-								<label for="disable_tour_descriptions"><?php esc_html_e( 'Disable Descriptions', 'lsx-wetu-importer' ); ?></label>
141
+								<label for="disable_tour_descriptions"><?php esc_html_e('Disable Descriptions', 'lsx-wetu-importer'); ?></label>
142 142
 							</th>
143 143
 							<td>
144 144
 								<input type="checkbox"
145 145
 								<?php
146
-								if ( isset( $options['disable_tour_descriptions'] ) && '' !== $options['disable_tour_descriptions'] ) {
147
-									echo esc_attr( 'checked="checked"' );
146
+								if (isset($options['disable_tour_descriptions']) && '' !== $options['disable_tour_descriptions']) {
147
+									echo esc_attr('checked="checked"');
148 148
 								}
149 149
 								?>
150 150
 								name="disable_tour_descriptions" />
151 151
 
152
-								<small><?php esc_html_e( 'If you are going to manage your tour descriptions on this site and not on WETU then enable this setting.', 'lsx-wetu-importer' ); ?></small>
152
+								<small><?php esc_html_e('If you are going to manage your tour descriptions on this site and not on WETU then enable this setting.', 'lsx-wetu-importer'); ?></small>
153 153
 							</td>
154 154
 						</tr>
155 155
 						<tr class="form-field -wrap">
156 156
 							<th scope="row">
157
-								<label for="disable_tour_tags"><?php esc_html_e( 'Disable Tags / Travel Styles', 'lsx-wetu-importer' ); ?></label>
157
+								<label for="disable_tour_tags"><?php esc_html_e('Disable Tags / Travel Styles', 'lsx-wetu-importer'); ?></label>
158 158
 							</th>
159 159
 							<td>
160 160
 								<input type="checkbox"
161 161
 								<?php
162
-								if ( isset( $options['disable_tour_tags'] ) && '' !== $options['disable_tour_tags'] ) {
163
-									echo esc_attr( 'checked="checked"' );
162
+								if (isset($options['disable_tour_tags']) && '' !== $options['disable_tour_tags']) {
163
+									echo esc_attr('checked="checked"');
164 164
 								}
165 165
 								?>
166 166
 								name="disable_tour_tags" />
167 167
 
168
-								<small><?php esc_html_e( 'Disable this is you dont want the option available on the import screen.', 'lsx-wetu-importer' ); ?></small>
168
+								<small><?php esc_html_e('Disable this is you dont want the option available on the import screen.', 'lsx-wetu-importer'); ?></small>
169 169
 							</td>
170 170
 						</tr>
171 171
 
172 172
 						<tr class="form-field -wrap">
173 173
 							<th scope="row">
174
-								<label for="enable_tour_ref_column"><?php esc_html_e( 'Enable Reference Column', 'lsx-wetu-importer' ); ?></label>
174
+								<label for="enable_tour_ref_column"><?php esc_html_e('Enable Reference Column', 'lsx-wetu-importer'); ?></label>
175 175
 							</th>
176 176
 							<td>
177 177
 								<input type="checkbox"
178 178
 								<?php
179
-								if ( isset( $options['enable_tour_ref_column'] ) && '' !== $options['enable_tour_ref_column'] ) {
180
-									echo esc_attr( 'checked="checked"' );
179
+								if (isset($options['enable_tour_ref_column']) && '' !== $options['enable_tour_ref_column']) {
180
+									echo esc_attr('checked="checked"');
181 181
 								}
182 182
 								?>
183 183
 								name="enable_tour_ref_column" />
184
-								<small><?php esc_html_e( 'Enables the use of the WETU Reference Column for better tours management.', 'lsx-wetu-importer' ); ?></small>
184
+								<small><?php esc_html_e('Enables the use of the WETU Reference Column for better tours management.', 'lsx-wetu-importer'); ?></small>
185 185
 							</td>
186 186
 						</tr>
187 187
 
188 188
 						<tr class="form-field -wrap">
189 189
 							<th scope="row">
190
-								<label for="enable_tour_featured_random"><?php esc_html_e( 'Randomize Featured Image', 'lsx-wetu-importer' ); ?></label>
190
+								<label for="enable_tour_featured_random"><?php esc_html_e('Randomize Featured Image', 'lsx-wetu-importer'); ?></label>
191 191
 							</th>
192 192
 							<td>
193 193
 								<input type="checkbox"
194 194
 								<?php
195
-								if ( isset( $options['enable_tour_featured_random'] ) && '' !== $options['enable_tour_featured_random'] ) {
196
-									echo esc_attr( 'checked="checked"' );
195
+								if (isset($options['enable_tour_featured_random']) && '' !== $options['enable_tour_featured_random']) {
196
+									echo esc_attr('checked="checked"');
197 197
 								}
198 198
 								?>
199 199
 								name="enable_tour_featured_random" />
200
-								<small><?php esc_html_e( 'This will randomize the featured image from the destination gallery.', 'lsx-wetu-importer' ); ?></small>
200
+								<small><?php esc_html_e('This will randomize the featured image from the destination gallery.', 'lsx-wetu-importer'); ?></small>
201 201
 							</td>
202 202
 						</tr>
203 203
 					</tbody>
204 204
 				</table>
205 205
 
206
-				<h1><?php esc_html_e( 'Accommodation', 'lsx-wetu-importer' ); ?></h1>
206
+				<h1><?php esc_html_e('Accommodation', 'lsx-wetu-importer'); ?></h1>
207 207
 
208 208
 				<table class="form-table">
209 209
 					<tbody>
210 210
 						<tr class="form-field -wrap">
211 211
 							<th scope="row">
212
-								<label for="disable_accommodation_title"><?php esc_html_e( 'Enable Custom Titles', 'lsx-wetu-importer' ); ?></label>
212
+								<label for="disable_accommodation_title"><?php esc_html_e('Enable Custom Titles', 'lsx-wetu-importer'); ?></label>
213 213
 							</th>
214 214
 							<td>
215 215
 								<input type="checkbox"
216 216
 								<?php
217
-								if ( isset( $options['disable_accommodation_title'] ) && '' !== $options['disable_accommodation_title'] ) {
218
-									echo esc_attr( 'checked="checked"' );
217
+								if (isset($options['disable_accommodation_title']) && '' !== $options['disable_accommodation_title']) {
218
+									echo esc_attr('checked="checked"');
219 219
 								}
220 220
 								?>
221 221
 								name="disable_accommodation_title" />
222 222
 
223
-								<small><?php esc_html_e( 'If you are going to manage your tour descriptions on this site and not on WETU then enable this setting.', 'lsx-wetu-importer' ); ?></small>
223
+								<small><?php esc_html_e('If you are going to manage your tour descriptions on this site and not on WETU then enable this setting.', 'lsx-wetu-importer'); ?></small>
224 224
 							</td>
225 225
 						</tr>
226 226
 						<tr class="form-field -wrap">
227 227
 							<th scope="row">
228
-								<label for="disable_accommodation_descriptions"><?php esc_html_e( 'Disable Descriptions', 'lsx-wetu-importer' ); ?></label>
228
+								<label for="disable_accommodation_descriptions"><?php esc_html_e('Disable Descriptions', 'lsx-wetu-importer'); ?></label>
229 229
 							</th>
230 230
 							<td>
231 231
 								<input type="checkbox"
232 232
 								<?php
233
-								if ( isset( $options['disable_accommodation_descriptions'] ) && '' !== $options['disable_accommodation_descriptions'] ) {
234
-									echo esc_attr( 'checked="checked"' );
233
+								if (isset($options['disable_accommodation_descriptions']) && '' !== $options['disable_accommodation_descriptions']) {
234
+									echo esc_attr('checked="checked"');
235 235
 								}
236 236
 								?>
237 237
 								name="disable_accommodation_descriptions" />
238
-								<small><?php esc_html_e( 'If you are going to edit the accommodation descriptions imported then enable this setting.', 'lsx-wetu-importer' ); ?></small>
238
+								<small><?php esc_html_e('If you are going to edit the accommodation descriptions imported then enable this setting.', 'lsx-wetu-importer'); ?></small>
239 239
 							</td>
240 240
 						</tr>
241 241
 						<tr class="form-field -wrap">
242 242
 							<th scope="row">
243
-								<label for="disable_accommodation_filtering"><?php esc_html_e( 'Disable Description Filtering', 'lsx-wetu-importer' ); ?></label>
243
+								<label for="disable_accommodation_filtering"><?php esc_html_e('Disable Description Filtering', 'lsx-wetu-importer'); ?></label>
244 244
 							</th>
245 245
 							<td>
246 246
 								<input type="checkbox"
247 247
 								<?php
248
-								if ( isset( $options['disable_accommodation_filtering'] ) && '' !== $options['disable_accommodation_filtering'] ) {
249
-									echo esc_attr( 'checked="checked"' );
248
+								if (isset($options['disable_accommodation_filtering']) && '' !== $options['disable_accommodation_filtering']) {
249
+									echo esc_attr('checked="checked"');
250 250
 								}
251 251
 								?>
252 252
 								name="disable_accommodation_filtering" />
253
-								<small><?php esc_html_e( 'This will stop the HTML from being stripped out of the description.', 'lsx-wetu-importer' ); ?></small>
253
+								<small><?php esc_html_e('This will stop the HTML from being stripped out of the description.', 'lsx-wetu-importer'); ?></small>
254 254
 							</td>
255 255
 						</tr>
256 256
 
257 257
 						<tr class="form-field -wrap">
258 258
 							<th scope="row">
259
-								<label for="disable_accommodation_excerpts"><?php esc_html_e( 'Disable Excerpts', 'lsx-wetu-importer' ); ?></label>
259
+								<label for="disable_accommodation_excerpts"><?php esc_html_e('Disable Excerpts', 'lsx-wetu-importer'); ?></label>
260 260
 							</th>
261 261
 							<td>
262 262
 								<input type="checkbox"
263 263
 								<?php
264
-								if ( isset( $options['disable_accommodation_excerpts'] ) && '' !== $options['disable_accommodation_excerpts'] ) {
265
-									echo esc_attr( 'checked="checked"' );
264
+								if (isset($options['disable_accommodation_excerpts']) && '' !== $options['disable_accommodation_excerpts']) {
265
+									echo esc_attr('checked="checked"');
266 266
 								}
267 267
 								?>
268 268
 								name="disable_accommodation_excerpts" />
269
-								<small><?php esc_html_e( 'If you are going to edit the accommodation excerpts then enable this setting.', 'lsx-wetu-importer' ); ?></small>
269
+								<small><?php esc_html_e('If you are going to edit the accommodation excerpts then enable this setting.', 'lsx-wetu-importer'); ?></small>
270 270
 							</td>
271 271
 						</tr>
272 272
 					</tbody>
273 273
 				</table>
274 274
 
275
-				<h1><?php esc_html_e( 'Destinations', 'lsx-wetu-importer' ); ?></h1>
275
+				<h1><?php esc_html_e('Destinations', 'lsx-wetu-importer'); ?></h1>
276 276
 
277 277
 				<table class="form-table">
278 278
 					<tbody>
279 279
 						<tr class="form-field -wrap">
280 280
 							<th scope="row">
281
-								<label for="disable_destination_title"><?php esc_html_e( 'Enable Custom Titles', 'lsx-wetu-importer' ); ?></label>
281
+								<label for="disable_destination_title"><?php esc_html_e('Enable Custom Titles', 'lsx-wetu-importer'); ?></label>
282 282
 							</th>
283 283
 							<td>
284 284
 								<input type="checkbox"
285 285
 								<?php
286
-								if ( isset( $options['disable_destination_title'] ) && '' !== $options['disable_destination_title'] ) {
287
-									echo esc_attr( 'checked="checked"' );
286
+								if (isset($options['disable_destination_title']) && '' !== $options['disable_destination_title']) {
287
+									echo esc_attr('checked="checked"');
288 288
 								}
289 289
 								?>
290 290
 								name="disable_destination_title" />
291 291
 
292
-								<small><?php esc_html_e( 'If you are going to manage your tour descriptions on this site and not on WETU then enable this setting.', 'lsx-wetu-importer' ); ?></small>
292
+								<small><?php esc_html_e('If you are going to manage your tour descriptions on this site and not on WETU then enable this setting.', 'lsx-wetu-importer'); ?></small>
293 293
 							</td>
294 294
 						</tr>
295 295
 						<tr class="form-field -wrap">
296 296
 							<th scope="row">
297
-								<label for="disable_destination_descriptions"><?php esc_html_e( 'Disable Descriptions', 'lsx-wetu-importer' ); ?></label>
297
+								<label for="disable_destination_descriptions"><?php esc_html_e('Disable Descriptions', 'lsx-wetu-importer'); ?></label>
298 298
 							</th>
299 299
 							<td>
300 300
 								<input type="checkbox"
301 301
 								<?php
302
-								if ( isset( $options['disable_destination_descriptions'] ) && '' !== $options['disable_destination_descriptions'] ) {
303
-									echo esc_attr( 'checked="checked"' );
302
+								if (isset($options['disable_destination_descriptions']) && '' !== $options['disable_destination_descriptions']) {
303
+									echo esc_attr('checked="checked"');
304 304
 								}
305 305
 								?>
306 306
 								name="disable_destination_descriptions" />
307
-								<small><?php esc_html_e( 'If you are going to edit the destination descriptions on this site then enable this setting.', 'lsx-wetu-importer' ); ?></small>
307
+								<small><?php esc_html_e('If you are going to edit the destination descriptions on this site then enable this setting.', 'lsx-wetu-importer'); ?></small>
308 308
 							</td>
309 309
 						</tr>
310 310
 					</tbody>
311 311
 				</table>
312 312
 
313
-				<h1><?php esc_html_e( 'Images', 'lsx-wetu-importer' ); ?></h1>
313
+				<h1><?php esc_html_e('Images', 'lsx-wetu-importer'); ?></h1>
314 314
 
315 315
 				<table class="form-table">
316 316
 					<tbody>
317 317
 						<tr class="form-field -wrap">
318 318
 							<th scope="row">
319
-								<label for="image_replacing"><?php esc_html_e( 'Replace Images', 'lsx-wetu-importer' ); ?></label>
319
+								<label for="image_replacing"><?php esc_html_e('Replace Images', 'lsx-wetu-importer'); ?></label>
320 320
 							</th>
321 321
 							<td>
322 322
 								<input type="checkbox"
323 323
 								<?php
324
-								if ( isset( $options['image_replacing'] ) && '' !== $options['image_replacing'] ) {
325
-									echo esc_attr( 'checked="checked"' );
324
+								if (isset($options['image_replacing']) && '' !== $options['image_replacing']) {
325
+									echo esc_attr('checked="checked"');
326 326
 								}
327 327
 								?>
328 328
 								name="image_replacing" />
329
-								<p><?php esc_html_e( 'Do you want your images to be replaced on each import.', 'lsx-wetu-importer' ); ?></p>
329
+								<p><?php esc_html_e('Do you want your images to be replaced on each import.', 'lsx-wetu-importer'); ?></p>
330 330
 							</td>
331 331
 						</tr>
332 332
 						<tr class="form-field -wrap">
333 333
 							<th scope="row">
334
-								<label for="image_limit"> <?php esc_html_e( 'Limit the amount of images imported to the gallery', 'lsx-wetu-importer' ); ?></label>
334
+								<label for="image_limit"> <?php esc_html_e('Limit the amount of images imported to the gallery', 'lsx-wetu-importer'); ?></label>
335 335
 							</th>
336 336
 							<td>
337 337
 								<input placeholder="" type="text" value="
338 338
                                 <?php
339
-								if ( isset( $options['image_limit'] ) && '' !== $options['image_limit'] ) {
340
-									echo esc_attr( $options['image_limit'] );
339
+								if (isset($options['image_limit']) && '' !== $options['image_limit']) {
340
+									echo esc_attr($options['image_limit']);
341 341
 								}
342 342
 								?>
343 343
                                 "
@@ -347,13 +347,13 @@  discard block
 block discarded – undo
347 347
 
348 348
 						<tr class="form-field -wrap">
349 349
 							<th scope="row">
350
-								<label for="image_scaling"><?php esc_html_e( 'Enable Image Scaling', 'lsx-wetu-importer' ); ?></label>
350
+								<label for="image_scaling"><?php esc_html_e('Enable Image Scaling', 'lsx-wetu-importer'); ?></label>
351 351
 							</th>
352 352
 							<td>
353 353
 								<input type="checkbox"
354 354
 								<?php
355
-								if ( isset( $options['image_scaling'] ) && '' !== $options['image_scaling'] ) {
356
-									echo esc_attr( 'checked="checked"' );
355
+								if (isset($options['image_scaling']) && '' !== $options['image_scaling']) {
356
+									echo esc_attr('checked="checked"');
357 357
 								}
358 358
 								?>
359 359
 								name="image_scaling" />
@@ -361,13 +361,13 @@  discard block
 block discarded – undo
361 361
 						</tr>
362 362
 						<tr class="form-field -wrap">
363 363
 							<th scope="row">
364
-								<label for="width"> <?php esc_html_e( 'Width (px)', 'lsx-wetu-importer' ); ?></label>
364
+								<label for="width"> <?php esc_html_e('Width (px)', 'lsx-wetu-importer'); ?></label>
365 365
 							</th>
366 366
 							<td>
367 367
 								<input placeholder="800" type="text" value="
368 368
                                 <?php
369
-								if ( isset( $options['width'] ) && '' !== $options['width'] ) {
370
-									echo esc_attr( $options['width'] );
369
+								if (isset($options['width']) && '' !== $options['width']) {
370
+									echo esc_attr($options['width']);
371 371
 								}
372 372
 								?>
373 373
                                 "
@@ -376,13 +376,13 @@  discard block
 block discarded – undo
376 376
 						</tr>
377 377
 						<tr class="form-field -wrap">
378 378
 							<th scope="row">
379
-								<label for="height"> <?php esc_html_e( 'Height (px)', 'lsx-wetu-importer' ); ?></label>
379
+								<label for="height"> <?php esc_html_e('Height (px)', 'lsx-wetu-importer'); ?></label>
380 380
 							</th>
381 381
 							<td>
382 382
 								<input placeholder="600" type="text" value="
383 383
                                 <?php
384
-								if ( isset( $options['height'] ) && '' !== $options['height'] ) {
385
-									echo esc_attr( $options['height'] );
384
+								if (isset($options['height']) && '' !== $options['height']) {
385
+									echo esc_attr($options['height']);
386 386
 								}
387 387
 								?>
388 388
                                 "
@@ -392,93 +392,93 @@  discard block
 block discarded – undo
392 392
 
393 393
 						<tr class="form-field -wrap image-settings">
394 394
 							<th scope="row">
395
-								<label for="scaling"> <?php esc_html_e( 'Scaling', 'lsx-wetu-importer' ); ?></label>
395
+								<label for="scaling"> <?php esc_html_e('Scaling', 'lsx-wetu-importer'); ?></label>
396 396
 							</th>
397 397
 							<td>
398 398
 								<input type="radio"
399 399
 								<?php
400
-								if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'raw' === $options['scaling'] ) {
401
-									echo esc_attr( 'checked="checked"' );
400
+								if (isset($options['scaling']) && '' !== $options['scaling'] && 'raw' === $options['scaling']) {
401
+									echo esc_attr('checked="checked"');
402 402
 								}
403 403
 								?>
404
-								name="scaling" value="raw" /> <?php esc_html_e( 'Get the Full size image, no cropping takes place.', 'lsx-wetu-importer' ); ?><br />
404
+								name="scaling" value="raw" /> <?php esc_html_e('Get the Full size image, no cropping takes place.', 'lsx-wetu-importer'); ?><br />
405 405
 								<input type="radio"
406 406
 								<?php
407
-								if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'c' === $options['scaling'] ) {
408
-									echo esc_attr( 'checked="checked"' );
407
+								if (isset($options['scaling']) && '' !== $options['scaling'] && 'c' === $options['scaling']) {
408
+									echo esc_attr('checked="checked"');
409 409
 								}
410 410
 								?>
411
-								name="scaling"  value="c" /> <?php esc_html_e( 'Crop image to fit fully into the frame, Crop is taken from middle, preserving as much of the image as possible.', 'lsx-wetu-importer' ); ?><br />
411
+								name="scaling"  value="c" /> <?php esc_html_e('Crop image to fit fully into the frame, Crop is taken from middle, preserving as much of the image as possible.', 'lsx-wetu-importer'); ?><br />
412 412
 								<input type="radio"
413 413
 								<?php
414
-								if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'h' === $options['scaling'] ) {
415
-									echo esc_attr( 'checked="checked"' );
414
+								if (isset($options['scaling']) && '' !== $options['scaling'] && 'h' === $options['scaling']) {
415
+									echo esc_attr('checked="checked"');
416 416
 								}
417 417
 								?>
418
-								name="scaling"  value="h" /> <?php esc_html_e( 'Crop image to fit fully into the frame, but resize to height first, then crop on width if needed', 'lsx-wetu-importer' ); ?><br />
418
+								name="scaling"  value="h" /> <?php esc_html_e('Crop image to fit fully into the frame, but resize to height first, then crop on width if needed', 'lsx-wetu-importer'); ?><br />
419 419
 								<input type="radio"
420 420
 								<?php
421
-								if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'w' === $options['scaling'] ) {
422
-									echo esc_attr( 'checked="checked"' );
421
+								if (isset($options['scaling']) && '' !== $options['scaling'] && 'w' === $options['scaling']) {
422
+									echo esc_attr('checked="checked"');
423 423
 								}
424 424
 								?>
425
-								name="scaling"  value="w" /> <?php esc_html_e( 'Crop image to fit fully into the frame, but resize to width first, then crop on height if needed', 'lsx-wetu-importer' ); ?><br />
425
+								name="scaling"  value="w" /> <?php esc_html_e('Crop image to fit fully into the frame, but resize to width first, then crop on height if needed', 'lsx-wetu-importer'); ?><br />
426 426
 								<input type="radio"
427 427
 								<?php
428
-								if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'nf' === $options['scaling'] ) {
429
-									echo esc_attr( 'checked="checked"' );
428
+								if (isset($options['scaling']) && '' !== $options['scaling'] && 'nf' === $options['scaling']) {
429
+									echo esc_attr('checked="checked"');
430 430
 								}
431 431
 								?>
432
-								name="scaling"  value="nf" /> <?php esc_html_e( 'Resize the image to fit within the frame. but pad the image with white to ensure the resolution matches the frame', 'lsx-wetu-importer' ); ?><br />
432
+								name="scaling"  value="nf" /> <?php esc_html_e('Resize the image to fit within the frame. but pad the image with white to ensure the resolution matches the frame', 'lsx-wetu-importer'); ?><br />
433 433
 								<input type="radio"
434 434
 								<?php
435
-								if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'n' === $options['scaling'] ) {
436
-									echo esc_attr( 'checked="checked"' );
435
+								if (isset($options['scaling']) && '' !== $options['scaling'] && 'n' === $options['scaling']) {
436
+									echo esc_attr('checked="checked"');
437 437
 								}
438 438
 								?>
439
-								name="scaling"  value="n" /> <?php esc_html_e( 'Resize the image to fit within the frame. but do not upscale the image.', 'lsx-wetu-importer' ); ?><br />
439
+								name="scaling"  value="n" /> <?php esc_html_e('Resize the image to fit within the frame. but do not upscale the image.', 'lsx-wetu-importer'); ?><br />
440 440
 								<input type="radio"
441 441
 								<?php
442
-								if ( isset( $options['scaling'] ) && '' !== $options['scaling'] && 'W' === $options['scaling'] ) {
443
-									echo esc_attr( 'checked="checked"' );
442
+								if (isset($options['scaling']) && '' !== $options['scaling'] && 'W' === $options['scaling']) {
443
+									echo esc_attr('checked="checked"');
444 444
 								}
445 445
 								?>
446
-								name="scaling"  value="W" /> <?php esc_html_e( 'Resize the image to fit within the frame. Image will not exceed specified dimensions', 'lsx-wetu-importer' ); ?>
446
+								name="scaling"  value="W" /> <?php esc_html_e('Resize the image to fit within the frame. Image will not exceed specified dimensions', 'lsx-wetu-importer'); ?>
447 447
 							</td>
448 448
 						</tr>
449 449
 					</tbody>
450 450
 				</table>
451 451
 
452
-				<h1><?php esc_html_e( 'Sync', 'lsx-wetu-importer' ); ?></h1>
452
+				<h1><?php esc_html_e('Sync', 'lsx-wetu-importer'); ?></h1>
453 453
 
454 454
 				<table class="form-table">
455 455
 					<tbody>
456 456
 						<tr class="form-field -wrap">
457 457
 							<th scope="row">
458
-								<label for="cron_schedule"><?php esc_html_e( 'Schedule', 'lsx-wetu-importer' ); ?></label>
458
+								<label for="cron_schedule"><?php esc_html_e('Schedule', 'lsx-wetu-importer'); ?></label>
459 459
 							</th>
460 460
 							<td>
461 461
 								<select name="cron_schedule" id="cron_schedule"	class="widefat layout">
462 462
 									<?php
463
-									if ( isset( $options['cron_schedule'] ) && '' !== $options['cron_schedule'] ) {
463
+									if (isset($options['cron_schedule']) && '' !== $options['cron_schedule']) {
464 464
 										$schedule = $options['cron_schedule'];
465
-									} else {
465
+									}else {
466 466
 										$schedule = 'daily';
467 467
 									}
468 468
 									$timeslots = array(
469
-										'daily'      => __( 'Daily', 'lsx-wetu-importer' ),
470
-										'weekly-mon' => __( 'Weekly (Monday)', 'lsx-wetu-importer' ),
471
-										'weekly-tue' => __( 'Weekly (Tuesday)', 'lsx-wetu-importer' ),
472
-										'weekly-wed' => __( 'Weekly (Wednesday)', 'lsx-wetu-importer' ),
473
-										'weekly-thu' => __( 'Weekly (Thursday)', 'lsx-wetu-importer' ),
474
-										'weekly-fri' => __( 'Weekly (Friday)', 'lsx-wetu-importer' ),
475
-										'weekly-sat' => __( 'Weekly (Saturday)', 'lsx-wetu-importer' ),
476
-										'weekly-sun' => __( 'Weekly (Sunday)', 'lsx-wetu-importer' ),
469
+										'daily'      => __('Daily', 'lsx-wetu-importer'),
470
+										'weekly-mon' => __('Weekly (Monday)', 'lsx-wetu-importer'),
471
+										'weekly-tue' => __('Weekly (Tuesday)', 'lsx-wetu-importer'),
472
+										'weekly-wed' => __('Weekly (Wednesday)', 'lsx-wetu-importer'),
473
+										'weekly-thu' => __('Weekly (Thursday)', 'lsx-wetu-importer'),
474
+										'weekly-fri' => __('Weekly (Friday)', 'lsx-wetu-importer'),
475
+										'weekly-sat' => __('Weekly (Saturday)', 'lsx-wetu-importer'),
476
+										'weekly-sun' => __('Weekly (Sunday)', 'lsx-wetu-importer'),
477 477
 									);
478
-									foreach ( $timeslots as $key => $name ) {
479
-										$selected = ( $schedule == $key ) ? ' selected="selected"' : '';
478
+									foreach ($timeslots as $key => $name) {
479
+										$selected = ($schedule == $key) ? ' selected="selected"' : '';
480 480
 										?>
481
-										<option value="<?php echo wp_kses_post( $key ); ?>" id="<?php echo wp_kses_post( $key ); ?>" <?php echo wp_kses_post( $selected ); ?>><?php echo wp_kses_post( $name ); ?></option>
481
+										<option value="<?php echo wp_kses_post($key); ?>" id="<?php echo wp_kses_post($key); ?>" <?php echo wp_kses_post($selected); ?>><?php echo wp_kses_post($name); ?></option>
482 482
 										<?php
483 483
 									}
484 484
 									?>
@@ -487,38 +487,38 @@  discard block
 block discarded – undo
487 487
 						</tr>
488 488
 						<tr class="form-field -wrap">
489 489
 							<th scope="row">
490
-								<label for="accommodation_images_cron"><?php esc_html_e( 'Accommodation Images', 'lsx-wetu-importer' ); ?></label>
490
+								<label for="accommodation_images_cron"><?php esc_html_e('Accommodation Images', 'lsx-wetu-importer'); ?></label>
491 491
 							</th>
492 492
 							<td>
493 493
 								<input type="checkbox"
494 494
 								<?php
495
-								if ( isset( $options['accommodation_images_cron'] ) && '' !== $options['accommodation_images_cron'] ) {
496
-									echo esc_attr( 'checked="checked"' );
495
+								if (isset($options['accommodation_images_cron']) && '' !== $options['accommodation_images_cron']) {
496
+									echo esc_attr('checked="checked"');
497 497
 								}
498 498
 								?>
499 499
 								name="accommodation_images_cron" />
500
-								<p><?php esc_html_e( 'Update the accommodation images accodring to the schedule above.', 'lsx-wetu-importer' ); ?></p>
500
+								<p><?php esc_html_e('Update the accommodation images accodring to the schedule above.', 'lsx-wetu-importer'); ?></p>
501 501
 							</td>
502 502
 						</tr>
503 503
 						<tr class="form-field -wrap">
504 504
 							<th scope="row">
505
-								<label for="accommodation_images_cron_featured"><?php esc_html_e( 'Featured Images', 'lsx-wetu-importer' ); ?></label>
505
+								<label for="accommodation_images_cron_featured"><?php esc_html_e('Featured Images', 'lsx-wetu-importer'); ?></label>
506 506
 							</th>
507 507
 							<td>
508 508
 								<input type="checkbox"
509 509
 								<?php
510
-								if ( isset( $options['accommodation_images_cron_featured'] ) && '' !== $options['accommodation_images_cron_featured'] ) {
511
-									echo esc_attr( 'checked="checked"' );
510
+								if (isset($options['accommodation_images_cron_featured']) && '' !== $options['accommodation_images_cron_featured']) {
511
+									echo esc_attr('checked="checked"');
512 512
 								}
513 513
 								?>
514 514
 								name="accommodation_images_cron_featured" />
515
-								<p><?php esc_html_e( 'Set the featured image when the gallery is created.', 'lsx-wetu-importer' ); ?></p>
515
+								<p><?php esc_html_e('Set the featured image when the gallery is created.', 'lsx-wetu-importer'); ?></p>
516 516
 							</td>
517 517
 						</tr>
518 518
 					</tbody>
519 519
 				</table>
520 520
 
521
-				<p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php esc_html_e( 'Save Changes', 'lsx-wetu-importer' ); ?>"></p>
521
+				<p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php esc_html_e('Save Changes', 'lsx-wetu-importer'); ?>"></p>
522 522
 			</form>
523 523
 		</div>
524 524
 		<?php
@@ -530,17 +530,17 @@  discard block
 block discarded – undo
530 530
 	 * @return void
531 531
 	 */
532 532
 	public function save_options() {
533
-		if ( ! isset( $_POST['lsx_wetu_importer_save_options'] ) || ! wp_verify_nonce( $_POST['lsx_wetu_importer_save_options'], 'lsx_wetu_importer_save' ) ) {
533
+		if (!isset($_POST['lsx_wetu_importer_save_options']) || !wp_verify_nonce($_POST['lsx_wetu_importer_save_options'], 'lsx_wetu_importer_save')) {
534 534
 			return;
535 535
 		}
536 536
 		$data_to_save = array();
537
-		foreach ( $this->defaults as $key => $field ) {
538
-			if ( isset( $_POST[ $key ] ) ) {
539
-				$data_to_save[ $key ] = sanitize_text_field( $_POST[ $key ] );
540
-			} else {
541
-				$data_to_save[ $key ] = '';
537
+		foreach ($this->defaults as $key => $field) {
538
+			if (isset($_POST[$key])) {
539
+				$data_to_save[$key] = sanitize_text_field($_POST[$key]);
540
+			}else {
541
+				$data_to_save[$key] = '';
542 542
 			}
543 543
 		}
544
-		update_option( 'lsx_wetu_importer_settings', $data_to_save );
544
+		update_option('lsx_wetu_importer_settings', $data_to_save);
545 545
 	}
546 546
 }
Please login to merge, or discard this patch.
classes/class-cron.php 2 patches
Indentation   +283 added lines, -283 removed lines patch added patch discarded remove patch
@@ -16,288 +16,288 @@
 block discarded – undo
16 16
  */
17 17
 class Cron {
18 18
 
19
-	/**
20
-	 * Holds class instance
21
-	 *
22
-	 * @since 1.0.0
23
-	 *
24
-	 * @var      object|Module_Template
25
-	 */
26
-	protected static $instance = null;
27
-
28
-	/**
29
-	 * Initialize the plugin by setting localization, filters, and administration functions.
30
-	 *
31
-	 * @since 1.0.0
32
-	 *
33
-	 * @access private
34
-	 */
35
-	public function __construct() {
36
-		add_filter( 'cron_schedules', array( $this, 'register_schedule' ), 10, 1 );
37
-		add_action( 'lsx_wetu_importer_settings_before', array( $this, 'watch_for_trigger' ), 200 );
38
-		add_action( 'lsx_wetu_accommodation_images_cron', array( $this, 'process' ), 10, 1 );
39
-		add_action( 'lsx_wetu_accommodation_images_sync', array( $this, 'cron_callback' ), 10, 1 );
40
-		add_filter( 'cmb_meta_boxes', array( $this, 'metaboxes' ) );
41
-	}
42
-
43
-	/**
44
-	 * Return an instance of this class.
45
-	 *
46
-	 * @since 1.0.0
47
-	 *
48
-	 * @return    object Cron()    A single instance of this class.
49
-	 */
50
-	public static function get_instance() {
51
-		// If the single instance hasn't been set, set it now.
52
-		if ( null === self::$instance ) {
53
-			self::$instance = new self();
54
-		}
55
-		return self::$instance;
56
-	}
57
-
58
-	/**
59
-	 * Define the metabox and field configurations.
60
-	 *
61
-	 * @param  array $meta_boxes
62
-	 * @return array
63
-	 */
64
-	public function metaboxes( array $meta_boxes ) {
65
-		// Allowed post types.
66
-		$allowed_post_types = array( 'accommodation' );
67
-
68
-		$fields = array();
69
-
70
-		$fields[] = array(
71
-			'id'   => 'wetu_skip_banner',
72
-			'name' => esc_html__( 'Skip Banner Image', 'lsx-banners' ),
73
-			'type' => 'checkbox',
74
-		);
75
-
76
-		$fields[] = array(
77
-			'id'   => 'wetu_skip_featured',
78
-			'name' => esc_html__( 'Skip Featured Image', 'lsx-banners' ),
79
-			'type' => 'checkbox',
80
-		);
81
-
82
-		$meta_boxes[] = array(
83
-			'title'  => esc_html__( 'WETU Settings', 'lsx-banners' ),
84
-			'pages'  => $allowed_post_types,
85
-			'fields' => $fields,
86
-			'context'    => 'side',
87
-			'priority'   => 'low',
88
-		);
89
-
90
-		return $meta_boxes;
91
-	}
92
-
93
-	/**
94
-	 * Registers a 5 min schedule for us to use.
95
-	 *
96
-	 * @param  array $schedules
97
-	 * @return array
98
-	 */
99
-	public function register_schedule( $schedules ) {
100
-		$schedules['wetu-5-minutes'] = array(
101
-			'interval' => 5 * MINUTE_IN_SECONDS,
102
-			'display'  => __( 'Every 5 minutes', 'lsx-wetu-importer' ),
103
-		);
104
-		return $schedules;
105
-	}
106
-
107
-	/**
108
-	 * Watches for changes in the button triggers.
109
-	 *
110
-	 * @return void
111
-	 */
112
-	public function watch_for_trigger() {
113
-
114
-		if ( isset( $_GET['page'] ) && 'lsx-wetu-importer' === $_GET['page'] && isset( $_GET['tab'] ) && 'settings' === $_GET['tab'] ) {
115
-			$options = lsx_wetu_get_options();
116
-
117
-			// Check what state the option is in.
118
-			$accommodation_cron = 'deactivate';
119
-			if ( isset( $options['accommodation_images_cron'] ) && '' !== $options['accommodation_images_cron'] ) {
120
-				$accommodation_cron = 'activate';
121
-			}
122
-
123
-			// Check what state the cron is in.
124
-			$scheduled = false;
125
-			if ( wp_next_scheduled( 'lsx_wetu_accommodation_images_cron' ) ) {
126
-				$scheduled = true;
127
-			}
128
-
129
-			// If activate and its not running.
130
-			if ( false === $scheduled && 'activate' === $accommodation_cron ) {
131
-				$schedule = 'weekly';
132
-				$this->schedule( 'lsx_wetu_accommodation_images_cron', $schedule );
133
-			} elseif ( true === $scheduled && 'deactivate' === $accommodation_cron ) {
134
-				$this->deactivate();
135
-			}
136
-		}
137
-	}
138
-
139
-	/**
140
-	 * Remove our cron from the shedule.
141
-	 *
142
-	 * @return void
143
-	 */
144
-	public function deactivate( $task = 'lsx_wetu_accommodation_images_cron' ) {
145
-		wp_clear_scheduled_hook( $task, array( $task ) );
146
-	}
147
-
148
-	/**
149
-	 * This function will schedule the cron event.
150
-	 *
151
-	 * @param string $task
152
-	 * @param string $schedule
153
-	 * @param string $time
154
-	 * @return void
155
-	 */
156
-	public function schedule( $task = 'lsx_wetu_accommodation_images_cron', $schedule = 'weekly', $time = 'Sunday 10pm' ) {
157
-		$args = array( $task );
158
-		if ( '' === $time ) {
159
-			$time = time();
160
-		}
161
-
162
-		if ( isset( $_GET['accommodation_images_cron_featured'] ) && '' !== $_GET['accommodation_images_cron_featured'] ) {
163
-			$args[] = 'featured_image';
164
-		}
165
-		wp_schedule_event( $time, $schedule, $task, $args );
166
-	}
167
-
168
-	/**
169
-	 * This is the function that will be triggered by the cron event.
170
-	 *
171
-	 * @return void
172
-	 */
173
-	public function process( $task = '' ) {
174
-		switch ( $task ) {
175
-			case 'lsx_wetu_accommodation_images_cron':
176
-					$this->register_accommodation_images_sync();
177
-				break;
178
-
179
-			default:
180
-				break;
181
-		}
182
-	}
183
-
184
-	/**
185
-	 * This is the function that will be triggered by the cron event.
186
-	 *
187
-	 * @return void
188
-	 */
189
-	public function register_accommodation_images_sync() {
190
-		$time = strtotime( '+5 min' );
191
-		if ( ! wp_next_scheduled( 'lsx_wetu_accommodation_images_sync' ) ) {
192
-			$this->load_items_to_sync( 'accommodation_images' );
193
-			$this->schedule( 'lsx_wetu_accommodation_images_sync', 'wetu-5-minutes', $time );
194
-		}
195
-	}
196
-
197
-	/**
198
-	 * This is the function that will be triggered by the cron event.
199
-	 *
200
-	 * @return void
201
-	 */
202
-	public function cron_callback( $task = '', $featured_image = '' ) {
203
-		$has_accommodation = get_option( $task );
204
-		if ( false !== $has_accommodation && ! empty( $has_accommodation ) ) {
205
-			$next_time = array_slice( $has_accommodation, 3 );
206
-			$this_time = array_slice( $has_accommodation, 0, 2 );
207
-
208
-			$api_key = $this->get_api_key();
209
-			$url     = 'https://wetu.com/API/Pins/' . $api_key . '/Get?all=include&ids=';
210
-
211
-			// Run through the current items.
212
-			foreach ( $this_time as $accommodation ) {
213
-				$wetu_id   = get_post_meta( $accommodation, 'lsx_wetu_id', true );
214
-				$last_date = get_post_meta( $accommodation, 'lsx_wetu_modified_date', true );
215
-
216
-				// Grabbing the image sync.
217
-				$featured_image = get_post_meta( $accommodation, 'wetu_skip_featured', true );
218
-				$banner_image   = get_post_meta( $accommodation, 'wetu_skip_banner', true );
219
-
220
-				$accommodation_info = wp_remote_get( $url . $wetu_id );
221
-				if ( ! empty( $accommodation_info ) && isset( $accommodation_info['response'] ) && isset( $accommodation_info['response']['code'] ) && 200 === $accommodation_info['response']['code'] ) {
222
-					$adata = json_decode( $accommodation_info['body'], true );
223
-
224
-					if ( isset( $adata[0] ) && isset( $adata[0]['last_modified'] ) && '' !== $adata[0]['last_modified'] ) {
225
-						$modified_time = strtotime( $adata[0]['last_modified'] );
226
-						if ( $modified_time > $last_date ) {
227
-							$accommodation_importer = new \LSX_WETU_Importer_Accommodation();
228
-
229
-							if ( false === $banner_image || '' === $banner_image ) {
230
-								$accommodation_importer->set_banner_image( $adata, $accommodation );
231
-							}
232
-
233
-							if ( false === $featured_image || '' === $featured_image ) {
234
-								$accommodation_importer->set_featured_image( $adata, $accommodation );
235
-							}
236
-
237
-							$accommodation_importer->create_main_gallery( $adata, $accommodation );
238
-							update_post_meta( $accommodation, 'lsx_wetu_modified_date', $modified_time, $last_date );
239
-						}
240
-					}
241
-				}
242
-			}
243
-
244
-			// Save the values for next time.
245
-			if ( ! empty( $next_time ) ) {
246
-				update_option( $task, $next_time );
247
-			} else {
248
-				delete_option( $task );
249
-				$this->deactivate( $task );
250
-			}
251
-		} else {
252
-			$this->deactivate( $task );
253
-			update_option( 'lsx_wetu_nexttime', $task );
254
-		}
255
-	}
256
-
257
-	/**
258
-	 * This will grab the accommodation ids and load them up into an option field.
259
-	 *
260
-	 * @param  string $task
261
-	 * @return void
262
-	 */
263
-	public function load_items_to_sync( $task = 'accommodation_images' ) {
264
-		$args = array(
265
-			'post_status'    => 'publish',
266
-			'posts_per_page' => -1,
267
-			'nopagin'        => true,
268
-			'fields'         => 'ids',
269
-		);
270
-		switch ( $task ) {
271
-			case 'accommodation_images':
272
-					$args['post_type'] = 'accommodation';
273
-				break;
274
-
275
-			default:
276
-				break;
277
-		}
278
-		$items = new \WP_Query( $args );
279
-		if ( $items->have_posts() ) {
280
-			update_option( 'lsx_wetu_' . $task . '_sync', $items->posts );
281
-		}
282
-	}
283
-
284
-	/**
285
-	 * Gets the API key stored in the options table.
286
-	 *
287
-	 * @return string
288
-	 */
289
-	public function get_api_key() {
290
-		$api_key = false;
291
-		$options = lsx_wetu_get_options();
292
-
293
-		if ( ! defined( 'WETU_API_KEY' ) ) {
294
-			if ( isset( $options['api_key'] ) && '' !== $options['api_key'] ) {
295
-				$api_key = $options['api_key'];
296
-			}
297
-		} else {
298
-			$api_key = WETU_API_KEY;
299
-		}
300
-		return $api_key;
301
-	}
19
+     /**
20
+      * Holds class instance
21
+      *
22
+      * @since 1.0.0
23
+      *
24
+      * @var      object|Module_Template
25
+      */
26
+     protected static $instance = null;
27
+
28
+     /**
29
+      * Initialize the plugin by setting localization, filters, and administration functions.
30
+      *
31
+      * @since 1.0.0
32
+      *
33
+      * @access private
34
+      */
35
+     public function __construct() {
36
+          add_filter( 'cron_schedules', array( $this, 'register_schedule' ), 10, 1 );
37
+          add_action( 'lsx_wetu_importer_settings_before', array( $this, 'watch_for_trigger' ), 200 );
38
+          add_action( 'lsx_wetu_accommodation_images_cron', array( $this, 'process' ), 10, 1 );
39
+          add_action( 'lsx_wetu_accommodation_images_sync', array( $this, 'cron_callback' ), 10, 1 );
40
+          add_filter( 'cmb_meta_boxes', array( $this, 'metaboxes' ) );
41
+     }
42
+
43
+     /**
44
+      * Return an instance of this class.
45
+      *
46
+      * @since 1.0.0
47
+      *
48
+      * @return    object Cron()    A single instance of this class.
49
+      */
50
+     public static function get_instance() {
51
+          // If the single instance hasn't been set, set it now.
52
+          if ( null === self::$instance ) {
53
+               self::$instance = new self();
54
+          }
55
+          return self::$instance;
56
+     }
57
+
58
+     /**
59
+      * Define the metabox and field configurations.
60
+      *
61
+      * @param  array $meta_boxes
62
+      * @return array
63
+      */
64
+     public function metaboxes( array $meta_boxes ) {
65
+          // Allowed post types.
66
+          $allowed_post_types = array( 'accommodation' );
67
+
68
+          $fields = array();
69
+
70
+          $fields[] = array(
71
+               'id'   => 'wetu_skip_banner',
72
+               'name' => esc_html__( 'Skip Banner Image', 'lsx-banners' ),
73
+               'type' => 'checkbox',
74
+          );
75
+
76
+          $fields[] = array(
77
+               'id'   => 'wetu_skip_featured',
78
+               'name' => esc_html__( 'Skip Featured Image', 'lsx-banners' ),
79
+               'type' => 'checkbox',
80
+          );
81
+
82
+          $meta_boxes[] = array(
83
+               'title'  => esc_html__( 'WETU Settings', 'lsx-banners' ),
84
+               'pages'  => $allowed_post_types,
85
+               'fields' => $fields,
86
+               'context'    => 'side',
87
+               'priority'   => 'low',
88
+          );
89
+
90
+          return $meta_boxes;
91
+     }
92
+
93
+     /**
94
+      * Registers a 5 min schedule for us to use.
95
+      *
96
+      * @param  array $schedules
97
+      * @return array
98
+      */
99
+     public function register_schedule( $schedules ) {
100
+          $schedules['wetu-5-minutes'] = array(
101
+               'interval' => 5 * MINUTE_IN_SECONDS,
102
+               'display'  => __( 'Every 5 minutes', 'lsx-wetu-importer' ),
103
+          );
104
+          return $schedules;
105
+     }
106
+
107
+     /**
108
+      * Watches for changes in the button triggers.
109
+      *
110
+      * @return void
111
+      */
112
+     public function watch_for_trigger() {
113
+
114
+          if ( isset( $_GET['page'] ) && 'lsx-wetu-importer' === $_GET['page'] && isset( $_GET['tab'] ) && 'settings' === $_GET['tab'] ) {
115
+               $options = lsx_wetu_get_options();
116
+
117
+               // Check what state the option is in.
118
+               $accommodation_cron = 'deactivate';
119
+               if ( isset( $options['accommodation_images_cron'] ) && '' !== $options['accommodation_images_cron'] ) {
120
+                    $accommodation_cron = 'activate';
121
+               }
122
+
123
+               // Check what state the cron is in.
124
+               $scheduled = false;
125
+               if ( wp_next_scheduled( 'lsx_wetu_accommodation_images_cron' ) ) {
126
+                    $scheduled = true;
127
+               }
128
+
129
+               // If activate and its not running.
130
+               if ( false === $scheduled && 'activate' === $accommodation_cron ) {
131
+                    $schedule = 'weekly';
132
+                    $this->schedule( 'lsx_wetu_accommodation_images_cron', $schedule );
133
+               } elseif ( true === $scheduled && 'deactivate' === $accommodation_cron ) {
134
+                    $this->deactivate();
135
+               }
136
+          }
137
+     }
138
+
139
+     /**
140
+      * Remove our cron from the shedule.
141
+      *
142
+      * @return void
143
+      */
144
+     public function deactivate( $task = 'lsx_wetu_accommodation_images_cron' ) {
145
+          wp_clear_scheduled_hook( $task, array( $task ) );
146
+     }
147
+
148
+     /**
149
+      * This function will schedule the cron event.
150
+      *
151
+      * @param string $task
152
+      * @param string $schedule
153
+      * @param string $time
154
+      * @return void
155
+      */
156
+     public function schedule( $task = 'lsx_wetu_accommodation_images_cron', $schedule = 'weekly', $time = 'Sunday 10pm' ) {
157
+          $args = array( $task );
158
+          if ( '' === $time ) {
159
+               $time = time();
160
+          }
161
+
162
+          if ( isset( $_GET['accommodation_images_cron_featured'] ) && '' !== $_GET['accommodation_images_cron_featured'] ) {
163
+               $args[] = 'featured_image';
164
+          }
165
+          wp_schedule_event( $time, $schedule, $task, $args );
166
+     }
167
+
168
+     /**
169
+      * This is the function that will be triggered by the cron event.
170
+      *
171
+      * @return void
172
+      */
173
+     public function process( $task = '' ) {
174
+          switch ( $task ) {
175
+               case 'lsx_wetu_accommodation_images_cron':
176
+                         $this->register_accommodation_images_sync();
177
+                    break;
178
+
179
+               default:
180
+                    break;
181
+          }
182
+     }
183
+
184
+     /**
185
+      * This is the function that will be triggered by the cron event.
186
+      *
187
+      * @return void
188
+      */
189
+     public function register_accommodation_images_sync() {
190
+          $time = strtotime( '+5 min' );
191
+          if ( ! wp_next_scheduled( 'lsx_wetu_accommodation_images_sync' ) ) {
192
+               $this->load_items_to_sync( 'accommodation_images' );
193
+               $this->schedule( 'lsx_wetu_accommodation_images_sync', 'wetu-5-minutes', $time );
194
+          }
195
+     }
196
+
197
+     /**
198
+      * This is the function that will be triggered by the cron event.
199
+      *
200
+      * @return void
201
+      */
202
+     public function cron_callback( $task = '', $featured_image = '' ) {
203
+          $has_accommodation = get_option( $task );
204
+          if ( false !== $has_accommodation && ! empty( $has_accommodation ) ) {
205
+               $next_time = array_slice( $has_accommodation, 3 );
206
+               $this_time = array_slice( $has_accommodation, 0, 2 );
207
+
208
+               $api_key = $this->get_api_key();
209
+               $url     = 'https://wetu.com/API/Pins/' . $api_key . '/Get?all=include&ids=';
210
+
211
+               // Run through the current items.
212
+               foreach ( $this_time as $accommodation ) {
213
+                    $wetu_id   = get_post_meta( $accommodation, 'lsx_wetu_id', true );
214
+                    $last_date = get_post_meta( $accommodation, 'lsx_wetu_modified_date', true );
215
+
216
+                    // Grabbing the image sync.
217
+                    $featured_image = get_post_meta( $accommodation, 'wetu_skip_featured', true );
218
+                    $banner_image   = get_post_meta( $accommodation, 'wetu_skip_banner', true );
219
+
220
+                    $accommodation_info = wp_remote_get( $url . $wetu_id );
221
+                    if ( ! empty( $accommodation_info ) && isset( $accommodation_info['response'] ) && isset( $accommodation_info['response']['code'] ) && 200 === $accommodation_info['response']['code'] ) {
222
+                         $adata = json_decode( $accommodation_info['body'], true );
223
+
224
+                         if ( isset( $adata[0] ) && isset( $adata[0]['last_modified'] ) && '' !== $adata[0]['last_modified'] ) {
225
+                              $modified_time = strtotime( $adata[0]['last_modified'] );
226
+                              if ( $modified_time > $last_date ) {
227
+                                   $accommodation_importer = new \LSX_WETU_Importer_Accommodation();
228
+
229
+                                   if ( false === $banner_image || '' === $banner_image ) {
230
+                                        $accommodation_importer->set_banner_image( $adata, $accommodation );
231
+                                   }
232
+
233
+                                   if ( false === $featured_image || '' === $featured_image ) {
234
+                                        $accommodation_importer->set_featured_image( $adata, $accommodation );
235
+                                   }
236
+
237
+                                   $accommodation_importer->create_main_gallery( $adata, $accommodation );
238
+                                   update_post_meta( $accommodation, 'lsx_wetu_modified_date', $modified_time, $last_date );
239
+                              }
240
+                         }
241
+                    }
242
+               }
243
+
244
+               // Save the values for next time.
245
+               if ( ! empty( $next_time ) ) {
246
+                    update_option( $task, $next_time );
247
+               } else {
248
+                    delete_option( $task );
249
+                    $this->deactivate( $task );
250
+               }
251
+          } else {
252
+               $this->deactivate( $task );
253
+               update_option( 'lsx_wetu_nexttime', $task );
254
+          }
255
+     }
256
+
257
+     /**
258
+      * This will grab the accommodation ids and load them up into an option field.
259
+      *
260
+      * @param  string $task
261
+      * @return void
262
+      */
263
+     public function load_items_to_sync( $task = 'accommodation_images' ) {
264
+          $args = array(
265
+               'post_status'    => 'publish',
266
+               'posts_per_page' => -1,
267
+               'nopagin'        => true,
268
+               'fields'         => 'ids',
269
+          );
270
+          switch ( $task ) {
271
+               case 'accommodation_images':
272
+                         $args['post_type'] = 'accommodation';
273
+                    break;
274
+
275
+               default:
276
+                    break;
277
+          }
278
+          $items = new \WP_Query( $args );
279
+          if ( $items->have_posts() ) {
280
+               update_option( 'lsx_wetu_' . $task . '_sync', $items->posts );
281
+          }
282
+     }
283
+
284
+     /**
285
+      * Gets the API key stored in the options table.
286
+      *
287
+      * @return string
288
+      */
289
+     public function get_api_key() {
290
+          $api_key = false;
291
+          $options = lsx_wetu_get_options();
292
+
293
+          if ( ! defined( 'WETU_API_KEY' ) ) {
294
+               if ( isset( $options['api_key'] ) && '' !== $options['api_key'] ) {
295
+                    $api_key = $options['api_key'];
296
+               }
297
+          } else {
298
+               $api_key = WETU_API_KEY;
299
+          }
300
+          return $api_key;
301
+     }
302 302
 }
303 303
 Cron::get_instance();
Please login to merge, or discard this patch.
Spacing   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -33,11 +33,11 @@  discard block
 block discarded – undo
33 33
 	 * @access private
34 34
 	 */
35 35
 	public function __construct() {
36
-		add_filter( 'cron_schedules', array( $this, 'register_schedule' ), 10, 1 );
37
-		add_action( 'lsx_wetu_importer_settings_before', array( $this, 'watch_for_trigger' ), 200 );
38
-		add_action( 'lsx_wetu_accommodation_images_cron', array( $this, 'process' ), 10, 1 );
39
-		add_action( 'lsx_wetu_accommodation_images_sync', array( $this, 'cron_callback' ), 10, 1 );
40
-		add_filter( 'cmb_meta_boxes', array( $this, 'metaboxes' ) );
36
+		add_filter('cron_schedules', array($this, 'register_schedule'), 10, 1);
37
+		add_action('lsx_wetu_importer_settings_before', array($this, 'watch_for_trigger'), 200);
38
+		add_action('lsx_wetu_accommodation_images_cron', array($this, 'process'), 10, 1);
39
+		add_action('lsx_wetu_accommodation_images_sync', array($this, 'cron_callback'), 10, 1);
40
+		add_filter('cmb_meta_boxes', array($this, 'metaboxes'));
41 41
 	}
42 42
 
43 43
 	/**
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
 	 */
50 50
 	public static function get_instance() {
51 51
 		// If the single instance hasn't been set, set it now.
52
-		if ( null === self::$instance ) {
52
+		if (null === self::$instance) {
53 53
 			self::$instance = new self();
54 54
 		}
55 55
 		return self::$instance;
@@ -61,26 +61,26 @@  discard block
 block discarded – undo
61 61
 	 * @param  array $meta_boxes
62 62
 	 * @return array
63 63
 	 */
64
-	public function metaboxes( array $meta_boxes ) {
64
+	public function metaboxes(array $meta_boxes) {
65 65
 		// Allowed post types.
66
-		$allowed_post_types = array( 'accommodation' );
66
+		$allowed_post_types = array('accommodation');
67 67
 
68 68
 		$fields = array();
69 69
 
70 70
 		$fields[] = array(
71 71
 			'id'   => 'wetu_skip_banner',
72
-			'name' => esc_html__( 'Skip Banner Image', 'lsx-banners' ),
72
+			'name' => esc_html__('Skip Banner Image', 'lsx-banners'),
73 73
 			'type' => 'checkbox',
74 74
 		);
75 75
 
76 76
 		$fields[] = array(
77 77
 			'id'   => 'wetu_skip_featured',
78
-			'name' => esc_html__( 'Skip Featured Image', 'lsx-banners' ),
78
+			'name' => esc_html__('Skip Featured Image', 'lsx-banners'),
79 79
 			'type' => 'checkbox',
80 80
 		);
81 81
 
82 82
 		$meta_boxes[] = array(
83
-			'title'  => esc_html__( 'WETU Settings', 'lsx-banners' ),
83
+			'title'  => esc_html__('WETU Settings', 'lsx-banners'),
84 84
 			'pages'  => $allowed_post_types,
85 85
 			'fields' => $fields,
86 86
 			'context'    => 'side',
@@ -96,10 +96,10 @@  discard block
 block discarded – undo
96 96
 	 * @param  array $schedules
97 97
 	 * @return array
98 98
 	 */
99
-	public function register_schedule( $schedules ) {
99
+	public function register_schedule($schedules) {
100 100
 		$schedules['wetu-5-minutes'] = array(
101 101
 			'interval' => 5 * MINUTE_IN_SECONDS,
102
-			'display'  => __( 'Every 5 minutes', 'lsx-wetu-importer' ),
102
+			'display'  => __('Every 5 minutes', 'lsx-wetu-importer'),
103 103
 		);
104 104
 		return $schedules;
105 105
 	}
@@ -111,26 +111,26 @@  discard block
 block discarded – undo
111 111
 	 */
112 112
 	public function watch_for_trigger() {
113 113
 
114
-		if ( isset( $_GET['page'] ) && 'lsx-wetu-importer' === $_GET['page'] && isset( $_GET['tab'] ) && 'settings' === $_GET['tab'] ) {
114
+		if (isset($_GET['page']) && 'lsx-wetu-importer' === $_GET['page'] && isset($_GET['tab']) && 'settings' === $_GET['tab']) {
115 115
 			$options = lsx_wetu_get_options();
116 116
 
117 117
 			// Check what state the option is in.
118 118
 			$accommodation_cron = 'deactivate';
119
-			if ( isset( $options['accommodation_images_cron'] ) && '' !== $options['accommodation_images_cron'] ) {
119
+			if (isset($options['accommodation_images_cron']) && '' !== $options['accommodation_images_cron']) {
120 120
 				$accommodation_cron = 'activate';
121 121
 			}
122 122
 
123 123
 			// Check what state the cron is in.
124 124
 			$scheduled = false;
125
-			if ( wp_next_scheduled( 'lsx_wetu_accommodation_images_cron' ) ) {
125
+			if (wp_next_scheduled('lsx_wetu_accommodation_images_cron')) {
126 126
 				$scheduled = true;
127 127
 			}
128 128
 
129 129
 			// If activate and its not running.
130
-			if ( false === $scheduled && 'activate' === $accommodation_cron ) {
130
+			if (false === $scheduled && 'activate' === $accommodation_cron) {
131 131
 				$schedule = 'weekly';
132
-				$this->schedule( 'lsx_wetu_accommodation_images_cron', $schedule );
133
-			} elseif ( true === $scheduled && 'deactivate' === $accommodation_cron ) {
132
+				$this->schedule('lsx_wetu_accommodation_images_cron', $schedule);
133
+			} elseif (true === $scheduled && 'deactivate' === $accommodation_cron) {
134 134
 				$this->deactivate();
135 135
 			}
136 136
 		}
@@ -141,8 +141,8 @@  discard block
 block discarded – undo
141 141
 	 *
142 142
 	 * @return void
143 143
 	 */
144
-	public function deactivate( $task = 'lsx_wetu_accommodation_images_cron' ) {
145
-		wp_clear_scheduled_hook( $task, array( $task ) );
144
+	public function deactivate($task = 'lsx_wetu_accommodation_images_cron') {
145
+		wp_clear_scheduled_hook($task, array($task));
146 146
 	}
147 147
 
148 148
 	/**
@@ -153,16 +153,16 @@  discard block
 block discarded – undo
153 153
 	 * @param string $time
154 154
 	 * @return void
155 155
 	 */
156
-	public function schedule( $task = 'lsx_wetu_accommodation_images_cron', $schedule = 'weekly', $time = 'Sunday 10pm' ) {
157
-		$args = array( $task );
158
-		if ( '' === $time ) {
156
+	public function schedule($task = 'lsx_wetu_accommodation_images_cron', $schedule = 'weekly', $time = 'Sunday 10pm') {
157
+		$args = array($task);
158
+		if ('' === $time) {
159 159
 			$time = time();
160 160
 		}
161 161
 
162
-		if ( isset( $_GET['accommodation_images_cron_featured'] ) && '' !== $_GET['accommodation_images_cron_featured'] ) {
162
+		if (isset($_GET['accommodation_images_cron_featured']) && '' !== $_GET['accommodation_images_cron_featured']) {
163 163
 			$args[] = 'featured_image';
164 164
 		}
165
-		wp_schedule_event( $time, $schedule, $task, $args );
165
+		wp_schedule_event($time, $schedule, $task, $args);
166 166
 	}
167 167
 
168 168
 	/**
@@ -170,8 +170,8 @@  discard block
 block discarded – undo
170 170
 	 *
171 171
 	 * @return void
172 172
 	 */
173
-	public function process( $task = '' ) {
174
-		switch ( $task ) {
173
+	public function process($task = '') {
174
+		switch ($task) {
175 175
 			case 'lsx_wetu_accommodation_images_cron':
176 176
 					$this->register_accommodation_images_sync();
177 177
 				break;
@@ -187,10 +187,10 @@  discard block
 block discarded – undo
187 187
 	 * @return void
188 188
 	 */
189 189
 	public function register_accommodation_images_sync() {
190
-		$time = strtotime( '+5 min' );
191
-		if ( ! wp_next_scheduled( 'lsx_wetu_accommodation_images_sync' ) ) {
192
-			$this->load_items_to_sync( 'accommodation_images' );
193
-			$this->schedule( 'lsx_wetu_accommodation_images_sync', 'wetu-5-minutes', $time );
190
+		$time = strtotime('+5 min');
191
+		if (!wp_next_scheduled('lsx_wetu_accommodation_images_sync')) {
192
+			$this->load_items_to_sync('accommodation_images');
193
+			$this->schedule('lsx_wetu_accommodation_images_sync', 'wetu-5-minutes', $time);
194 194
 		}
195 195
 	}
196 196
 
@@ -199,58 +199,58 @@  discard block
 block discarded – undo
199 199
 	 *
200 200
 	 * @return void
201 201
 	 */
202
-	public function cron_callback( $task = '', $featured_image = '' ) {
203
-		$has_accommodation = get_option( $task );
204
-		if ( false !== $has_accommodation && ! empty( $has_accommodation ) ) {
205
-			$next_time = array_slice( $has_accommodation, 3 );
206
-			$this_time = array_slice( $has_accommodation, 0, 2 );
202
+	public function cron_callback($task = '', $featured_image = '') {
203
+		$has_accommodation = get_option($task);
204
+		if (false !== $has_accommodation && !empty($has_accommodation)) {
205
+			$next_time = array_slice($has_accommodation, 3);
206
+			$this_time = array_slice($has_accommodation, 0, 2);
207 207
 
208 208
 			$api_key = $this->get_api_key();
209
-			$url     = 'https://wetu.com/API/Pins/' . $api_key . '/Get?all=include&ids=';
209
+			$url     = 'https://wetu.com/API/Pins/'.$api_key.'/Get?all=include&ids=';
210 210
 
211 211
 			// Run through the current items.
212
-			foreach ( $this_time as $accommodation ) {
213
-				$wetu_id   = get_post_meta( $accommodation, 'lsx_wetu_id', true );
214
-				$last_date = get_post_meta( $accommodation, 'lsx_wetu_modified_date', true );
212
+			foreach ($this_time as $accommodation) {
213
+				$wetu_id   = get_post_meta($accommodation, 'lsx_wetu_id', true);
214
+				$last_date = get_post_meta($accommodation, 'lsx_wetu_modified_date', true);
215 215
 
216 216
 				// Grabbing the image sync.
217
-				$featured_image = get_post_meta( $accommodation, 'wetu_skip_featured', true );
218
-				$banner_image   = get_post_meta( $accommodation, 'wetu_skip_banner', true );
217
+				$featured_image = get_post_meta($accommodation, 'wetu_skip_featured', true);
218
+				$banner_image   = get_post_meta($accommodation, 'wetu_skip_banner', true);
219 219
 
220
-				$accommodation_info = wp_remote_get( $url . $wetu_id );
221
-				if ( ! empty( $accommodation_info ) && isset( $accommodation_info['response'] ) && isset( $accommodation_info['response']['code'] ) && 200 === $accommodation_info['response']['code'] ) {
222
-					$adata = json_decode( $accommodation_info['body'], true );
220
+				$accommodation_info = wp_remote_get($url.$wetu_id);
221
+				if (!empty($accommodation_info) && isset($accommodation_info['response']) && isset($accommodation_info['response']['code']) && 200 === $accommodation_info['response']['code']) {
222
+					$adata = json_decode($accommodation_info['body'], true);
223 223
 
224
-					if ( isset( $adata[0] ) && isset( $adata[0]['last_modified'] ) && '' !== $adata[0]['last_modified'] ) {
225
-						$modified_time = strtotime( $adata[0]['last_modified'] );
226
-						if ( $modified_time > $last_date ) {
224
+					if (isset($adata[0]) && isset($adata[0]['last_modified']) && '' !== $adata[0]['last_modified']) {
225
+						$modified_time = strtotime($adata[0]['last_modified']);
226
+						if ($modified_time > $last_date) {
227 227
 							$accommodation_importer = new \LSX_WETU_Importer_Accommodation();
228 228
 
229
-							if ( false === $banner_image || '' === $banner_image ) {
230
-								$accommodation_importer->set_banner_image( $adata, $accommodation );
229
+							if (false === $banner_image || '' === $banner_image) {
230
+								$accommodation_importer->set_banner_image($adata, $accommodation);
231 231
 							}
232 232
 
233
-							if ( false === $featured_image || '' === $featured_image ) {
234
-								$accommodation_importer->set_featured_image( $adata, $accommodation );
233
+							if (false === $featured_image || '' === $featured_image) {
234
+								$accommodation_importer->set_featured_image($adata, $accommodation);
235 235
 							}
236 236
 
237
-							$accommodation_importer->create_main_gallery( $adata, $accommodation );
238
-							update_post_meta( $accommodation, 'lsx_wetu_modified_date', $modified_time, $last_date );
237
+							$accommodation_importer->create_main_gallery($adata, $accommodation);
238
+							update_post_meta($accommodation, 'lsx_wetu_modified_date', $modified_time, $last_date);
239 239
 						}
240 240
 					}
241 241
 				}
242 242
 			}
243 243
 
244 244
 			// Save the values for next time.
245
-			if ( ! empty( $next_time ) ) {
246
-				update_option( $task, $next_time );
247
-			} else {
248
-				delete_option( $task );
249
-				$this->deactivate( $task );
245
+			if (!empty($next_time)) {
246
+				update_option($task, $next_time);
247
+			}else {
248
+				delete_option($task);
249
+				$this->deactivate($task);
250 250
 			}
251
-		} else {
252
-			$this->deactivate( $task );
253
-			update_option( 'lsx_wetu_nexttime', $task );
251
+		}else {
252
+			$this->deactivate($task);
253
+			update_option('lsx_wetu_nexttime', $task);
254 254
 		}
255 255
 	}
256 256
 
@@ -260,14 +260,14 @@  discard block
 block discarded – undo
260 260
 	 * @param  string $task
261 261
 	 * @return void
262 262
 	 */
263
-	public function load_items_to_sync( $task = 'accommodation_images' ) {
263
+	public function load_items_to_sync($task = 'accommodation_images') {
264 264
 		$args = array(
265 265
 			'post_status'    => 'publish',
266 266
 			'posts_per_page' => -1,
267 267
 			'nopagin'        => true,
268 268
 			'fields'         => 'ids',
269 269
 		);
270
-		switch ( $task ) {
270
+		switch ($task) {
271 271
 			case 'accommodation_images':
272 272
 					$args['post_type'] = 'accommodation';
273 273
 				break;
@@ -275,9 +275,9 @@  discard block
 block discarded – undo
275 275
 			default:
276 276
 				break;
277 277
 		}
278
-		$items = new \WP_Query( $args );
279
-		if ( $items->have_posts() ) {
280
-			update_option( 'lsx_wetu_' . $task . '_sync', $items->posts );
278
+		$items = new \WP_Query($args);
279
+		if ($items->have_posts()) {
280
+			update_option('lsx_wetu_'.$task.'_sync', $items->posts);
281 281
 		}
282 282
 	}
283 283
 
@@ -290,11 +290,11 @@  discard block
 block discarded – undo
290 290
 		$api_key = false;
291 291
 		$options = lsx_wetu_get_options();
292 292
 
293
-		if ( ! defined( 'WETU_API_KEY' ) ) {
294
-			if ( isset( $options['api_key'] ) && '' !== $options['api_key'] ) {
293
+		if (!defined('WETU_API_KEY')) {
294
+			if (isset($options['api_key']) && '' !== $options['api_key']) {
295 295
 				$api_key = $options['api_key'];
296 296
 			}
297
-		} else {
297
+		}else {
298 298
 			$api_key = WETU_API_KEY;
299 299
 		}
300 300
 		return $api_key;
Please login to merge, or discard this patch.