Passed
Push — master ( 15b6de...60601d )
by Warwick
04:55 queued 14s
created
classes/class-lsx-wetu-importer-tours.php 2 patches
Indentation   +1248 added lines, -1248 removed lines patch added patch discarded remove patch
@@ -9,109 +9,109 @@  discard block
 block discarded – undo
9 9
 
10 10
 class LSX_WETU_Importer_Tours extends LSX_WETU_Importer {
11 11
 
12
-	/**
13
-	 * The url to list items from WETU
14
-	 *
15
-	 * @since 0.0.1
16
-	 *
17
-	 * @var      string
18
-	 */
19
-	public $tab_slug = 'tour';
20
-
21
-	/**
22
-	 * The url to list items from WETU
23
-	 *
24
-	 * @since 0.0.1
25
-	 *
26
-	 * @var      string
27
-	 */
28
-	public $url = false;
29
-
30
-	/**
31
-	 * The query string url to list items from WETU
32
-	 *
33
-	 * @since 0.0.1
34
-	 *
35
-	 * @var      string
36
-	 */
37
-	public $url_qs = false;
38
-
39
-	/**
40
-	 * Holds a list of any current accommodation
41
-	 *
42
-	 * @since 0.0.1
43
-	 *
44
-	 * @var      string
45
-	 */
46
-	public $current_accommodation = false;
47
-
48
-	/**
49
-	 * Holds a list of any current destinations
50
-	 *
51
-	 * @since 0.0.1
52
-	 *
53
-	 * @var      string
54
-	 */
55
-	public $current_destinations = false;
56
-
57
-	/**
58
-	 * Holds a list of the destination and the image it needs to grab.
59
-	 *
60
-	 * @since 0.0.1
61
-	 *
62
-	 * @var      string
63
-	 */
64
-	public $destination_images = false;
65
-
66
-	/**
67
-	 * Options
68
-	 *
69
-	 * @since 0.0.1
70
-	 *
71
-	 * @var      string
72
-	 */
73
-	public $options = false;
74
-
75
-	/**
76
-	 * The fields you wish to import
77
-	 *
78
-	 * @since 0.0.1
79
-	 *
80
-	 * @var      string
81
-	 */
82
-	public $tour_options = false;
83
-
84
-	/**
85
-	 * Initialize the plugin by setting localization, filters, and administration functions.
86
-	 *
87
-	 * @since 1.0.0
88
-	 *
89
-	 * @access private
90
-	 */
91
-	public function __construct() {
92
-		$this->set_variables();
93
-	}
94
-
95
-	/**
96
-	 * Sets the variables used throughout the plugin.
97
-	 */
98
-	public function set_variables() {
99
-		parent::set_variables();
100
-		if ( false !== $this->api_key ) {
101
-			$this->url    = 'https://wetu.com/API/Itinerary/' . $this->api_key;
102
-			$this->url_qs = '';
103
-		}
104
-		$tour_options = get_option( 'lsx_wetu_importer_tour_settings', false );
105
-		if ( false !== $tour_options ) {
106
-			$this->tour_options = $tour_options;
107
-		}
108
-	}
109
-
110
-	/**
111
-	 * Display the importer administration screen
112
-	 */
113
-	public function display_page() {
114
-		?>
12
+     /**
13
+      * The url to list items from WETU
14
+      *
15
+      * @since 0.0.1
16
+      *
17
+      * @var      string
18
+      */
19
+     public $tab_slug = 'tour';
20
+
21
+     /**
22
+      * The url to list items from WETU
23
+      *
24
+      * @since 0.0.1
25
+      *
26
+      * @var      string
27
+      */
28
+     public $url = false;
29
+
30
+     /**
31
+      * The query string url to list items from WETU
32
+      *
33
+      * @since 0.0.1
34
+      *
35
+      * @var      string
36
+      */
37
+     public $url_qs = false;
38
+
39
+     /**
40
+      * Holds a list of any current accommodation
41
+      *
42
+      * @since 0.0.1
43
+      *
44
+      * @var      string
45
+      */
46
+     public $current_accommodation = false;
47
+
48
+     /**
49
+      * Holds a list of any current destinations
50
+      *
51
+      * @since 0.0.1
52
+      *
53
+      * @var      string
54
+      */
55
+     public $current_destinations = false;
56
+
57
+     /**
58
+      * Holds a list of the destination and the image it needs to grab.
59
+      *
60
+      * @since 0.0.1
61
+      *
62
+      * @var      string
63
+      */
64
+     public $destination_images = false;
65
+
66
+     /**
67
+      * Options
68
+      *
69
+      * @since 0.0.1
70
+      *
71
+      * @var      string
72
+      */
73
+     public $options = false;
74
+
75
+     /**
76
+      * The fields you wish to import
77
+      *
78
+      * @since 0.0.1
79
+      *
80
+      * @var      string
81
+      */
82
+     public $tour_options = false;
83
+
84
+     /**
85
+      * Initialize the plugin by setting localization, filters, and administration functions.
86
+      *
87
+      * @since 1.0.0
88
+      *
89
+      * @access private
90
+      */
91
+     public function __construct() {
92
+          $this->set_variables();
93
+     }
94
+
95
+     /**
96
+      * Sets the variables used throughout the plugin.
97
+      */
98
+     public function set_variables() {
99
+          parent::set_variables();
100
+          if ( false !== $this->api_key ) {
101
+               $this->url    = 'https://wetu.com/API/Itinerary/' . $this->api_key;
102
+               $this->url_qs = '';
103
+          }
104
+          $tour_options = get_option( 'lsx_wetu_importer_tour_settings', false );
105
+          if ( false !== $tour_options ) {
106
+               $this->tour_options = $tour_options;
107
+          }
108
+     }
109
+
110
+     /**
111
+      * Display the importer administration screen
112
+      */
113
+     public function display_page() {
114
+          ?>
115 115
 		<div class="wrap">
116 116
 
117 117
 			<div class="tablenav top">
@@ -225,19 +225,19 @@  discard block
 block discarded – undo
225 225
 			</div>
226 226
 		</div>
227 227
 		<?php
228
-	}
229
-
230
-	/**
231
-	 * Displays the options for the form.
232
-	 *
233
-	 * @return void
234
-	 */
235
-	public function update_options_form() {
236
-		$form_options = get_option( 'lsx_ti_tours_api_options' );
237
-		if ( false === $form_options ) {
238
-			$form_options = array( 'sample' );
239
-		}
240
-		?>
228
+     }
229
+
230
+     /**
231
+      * Displays the options for the form.
232
+      *
233
+      * @return void
234
+      */
235
+     public function update_options_form() {
236
+          $form_options = get_option( 'lsx_ti_tours_api_options' );
237
+          if ( false === $form_options ) {
238
+               $form_options = array( 'sample' );
239
+          }
240
+          ?>
241 241
 		<form method="get" class="tour-refresh-form">
242 242
 			<input type="hidden" name="page" value="<?php echo esc_attr( $this->plugin_slug ); ?>" />
243 243
 			<input type="hidden" name="tab" value="tour" />
@@ -247,31 +247,31 @@  discard block
 block discarded – undo
247 247
 			<select name="type">
248 248
 				<option 
249 249
 				<?php
250
-				if ( in_array( 'personal', $form_options ) ) {
251
-					echo esc_attr( 'selected="selected"' ); }
252
-				?>
250
+                    if ( in_array( 'personal', $form_options ) ) {
251
+                         echo esc_attr( 'selected="selected"' ); }
252
+                    ?>
253 253
 value="personal"><?php esc_html_e( 'Personal', 'lsx-wetu-importer' ); ?></option>
254 254
 				<option 
255 255
 				<?php
256
-				if ( in_array( 'sample', $form_options ) ) {
257
-					echo esc_attr( 'selected="selected"' ); }
258
-				?>
256
+                    if ( in_array( 'sample', $form_options ) ) {
257
+                         echo esc_attr( 'selected="selected"' ); }
258
+                    ?>
259 259
 value="sample"><?php esc_html_e( 'Sample', 'lsx-wetu-importer' ); ?></option>
260 260
 			</select>
261 261
 			<input class="button submit" type="submit" value="<?php esc_attr_e( 'Refresh', 'lsx-wetu-importer' ); ?>" />
262 262
 		</form>
263 263
 		<?php
264
-	}
264
+     }
265 265
 
266
-	/**
267
-	 * Grab all the current tour posts via the lsx_wetu_id field.
268
-	 */
269
-	public function find_current_tours() {
270
-		global $wpdb;
271
-		$return = array();
266
+     /**
267
+      * Grab all the current tour posts via the lsx_wetu_id field.
268
+      */
269
+     public function find_current_tours() {
270
+          global $wpdb;
271
+          $return = array();
272 272
 
273
-		$current_tours = $wpdb->get_results(
274
-			"
273
+          $current_tours = $wpdb->get_results(
274
+               "
275 275
 			SELECT key1.post_id,key1.meta_value,key2.post_title
276 276
 			FROM {$wpdb->postmeta} key1
277 277
 
@@ -283,138 +283,138 @@  discard block
 block discarded – undo
283 283
 
284 284
 			LIMIT 0,500
285 285
 		"
286
-		);
287
-
288
-		if ( null !== $current_tours && ! empty( $current_tours ) ) {
289
-			foreach ( $current_tours as $tour ) {
290
-				$return[ $tour->meta_value ] = $tour;
291
-			}
292
-		}
293
-
294
-		return $return;
295
-	}
296
-
297
-	/**
298
-	 * Run through the accommodation grabbed from the DB.
299
-	 */
300
-	public function process_ajax_search() {
301
-		$return = false;
302
-		check_ajax_referer( 'lsx_wetu_ajax_action', 'security' );
303
-
304
-		if ( isset( $_POST['action'] ) && 'lsx_tour_importer' === $_POST['action'] && isset( $_POST['type'] ) && $_POST['type'] === $this->tab_slug ) {
305
-			$tours = get_transient( 'lsx_ti_tours' );
306
-
307
-			if ( false !== $tours ) {
308
-				$searched_items = false;
309
-				if ( isset( $_POST['keyword'] ) ) {
310
-					$keyphrases = array_map( 'sanitize_text_field', wp_unslash( $_POST['keyword'] ) );
311
-				} else {
312
-					$keyphrases = array( 0 );
313
-				}
314
-
315
-				if ( ! is_array( $keyphrases ) ) {
316
-					$keyphrases = array( $keyphrases );
317
-				}
318
-				foreach ( $keyphrases as &$keyword ) {
319
-					$keyword = ltrim( rtrim( $keyword ) );
320
-				}
321
-
322
-				$post_status = false;
323
-				if ( in_array( 'publish', $keyphrases ) ) {
324
-					$post_status = 'publish';
325
-				}
326
-				if ( in_array( 'pending', $keyphrases ) ) {
327
-					$post_status = 'pending';
328
-				}
329
-				if ( in_array( 'draft', $keyphrases ) ) {
330
-					$post_status = 'draft';
331
-				}
332
-				if ( in_array( 'import', $keyphrases ) ) {
333
-					$post_status = 'import';
334
-				}
335
-
336
-				if ( ! empty( $tours ) ) {
337
-					$current_tours = $this->find_current_tours();
338
-
339
-					foreach ( $tours as $row_key => $row ) {
340
-						if ( isset( $row['is_disabled'] ) && true === $row['is_disabled'] ) {
341
-							continue;
342
-						}
343
-
344
-						// If this is a current tour, add its ID to the row.
345
-						$row['post_id']    = 0;
346
-						$row['post_title'] = $row['name'];
347
-
348
-						if ( false !== $current_tours && array_key_exists( $row['identifier'], $current_tours ) ) {
349
-							$row['post_id']    = $current_tours[ $row['identifier'] ]->post_id;
350
-							$row['post_title'] = $current_tours[ $row['identifier'] ]->post_title;
351
-						}
352
-
353
-						// If we are searching for.
354
-						if ( false !== $post_status ) {
355
-							if ( 'import' === $post_status ) {
356
-
357
-								if ( 0 !== $row['post_id'] ) {
358
-									continue;
359
-								} else {
360
-									$searched_items[ sanitize_title( $row['name'] ) . '-' . $row['identifier'] ] = $this->format_row( $row, $row_key );
361
-								}
362
-							} else {
363
-								if ( 0 === $row['post_id'] ) {
364
-									continue;
365
-								} else {
366
-									$current_status = get_post_status( $row['post_id'] );
367
-
368
-									if ( $current_status !== $post_status ) {
369
-										continue;
370
-									}
371
-								}
372
-
373
-								$searched_items[ sanitize_title( $row['name'] ) . '-' . $row['identifier'] ] = $this->format_row( $row, $row_key );
374
-							}
375
-						} else {
376
-							// Search through each keyword.
377
-							foreach ( $keyphrases as $keyphrase ) {
378
-
379
-								// Make sure the keyphrase is turned into an array.
380
-								$keywords = explode( ' ', $keyphrase );
381
-								if ( ! is_array( $keywords ) ) {
382
-									$keywords = array( $keywords );
383
-								}
384
-
385
-								if ( $this->multineedle_stripos( ltrim( rtrim( $row['name'] ) ), $keywords ) !== false ) {
386
-									$searched_items[ sanitize_title( $row['name'] ) . '-' . $row['identifier'] ] = $this->format_row( $row, $row_key );
387
-								} elseif ( $this->multineedle_stripos( ltrim( rtrim( $row['reference_number'] ) ), $keywords ) !== false ) {
388
-									$searched_items[ sanitize_title( $row['name'] ) . '-' . $row['identifier'] ] = $this->format_row( $row, $row_key );
389
-								} elseif ( $this->multineedle_stripos( ltrim( rtrim( $row['identifier_key'] ) ), $keywords ) !== false ) {
390
-									$searched_items[ sanitize_title( $row['name'] ) . '-' . $row['identifier'] ] = $this->format_row( $row, $row_key );
391
-								}
392
-							}
393
-						}
394
-					}
395
-				}
396
-
397
-				if ( false !== $searched_items ) {
398
-					$return = implode( $searched_items );
399
-				}
400
-			}
401
-			print_r( $return );
402
-			die();
403
-		}
404
-	}
405
-
406
-	/**
407
-	 * Formats the row for output on the screen.
408
-	 */
409
-	public function format_row( $row = false, $row_key = '' ) {
410
-		if ( false !== $row ) {
411
-			$status = 'import';
412
-
413
-			if ( 0 !== $row['post_id'] ) {
414
-				$status = '<a href="' . admin_url( '/post.php?post=' . $row['post_id'] . '&action=edit' ) . '" target="_blank">' . get_post_status( $row['post_id'] ) . '</a>';
415
-			}
416
-
417
-			$row_html = '
286
+          );
287
+
288
+          if ( null !== $current_tours && ! empty( $current_tours ) ) {
289
+               foreach ( $current_tours as $tour ) {
290
+                    $return[ $tour->meta_value ] = $tour;
291
+               }
292
+          }
293
+
294
+          return $return;
295
+     }
296
+
297
+     /**
298
+      * Run through the accommodation grabbed from the DB.
299
+      */
300
+     public function process_ajax_search() {
301
+          $return = false;
302
+          check_ajax_referer( 'lsx_wetu_ajax_action', 'security' );
303
+
304
+          if ( isset( $_POST['action'] ) && 'lsx_tour_importer' === $_POST['action'] && isset( $_POST['type'] ) && $_POST['type'] === $this->tab_slug ) {
305
+               $tours = get_transient( 'lsx_ti_tours' );
306
+
307
+               if ( false !== $tours ) {
308
+                    $searched_items = false;
309
+                    if ( isset( $_POST['keyword'] ) ) {
310
+                         $keyphrases = array_map( 'sanitize_text_field', wp_unslash( $_POST['keyword'] ) );
311
+                    } else {
312
+                         $keyphrases = array( 0 );
313
+                    }
314
+
315
+                    if ( ! is_array( $keyphrases ) ) {
316
+                         $keyphrases = array( $keyphrases );
317
+                    }
318
+                    foreach ( $keyphrases as &$keyword ) {
319
+                         $keyword = ltrim( rtrim( $keyword ) );
320
+                    }
321
+
322
+                    $post_status = false;
323
+                    if ( in_array( 'publish', $keyphrases ) ) {
324
+                         $post_status = 'publish';
325
+                    }
326
+                    if ( in_array( 'pending', $keyphrases ) ) {
327
+                         $post_status = 'pending';
328
+                    }
329
+                    if ( in_array( 'draft', $keyphrases ) ) {
330
+                         $post_status = 'draft';
331
+                    }
332
+                    if ( in_array( 'import', $keyphrases ) ) {
333
+                         $post_status = 'import';
334
+                    }
335
+
336
+                    if ( ! empty( $tours ) ) {
337
+                         $current_tours = $this->find_current_tours();
338
+
339
+                         foreach ( $tours as $row_key => $row ) {
340
+                              if ( isset( $row['is_disabled'] ) && true === $row['is_disabled'] ) {
341
+                                   continue;
342
+                              }
343
+
344
+                              // If this is a current tour, add its ID to the row.
345
+                              $row['post_id']    = 0;
346
+                              $row['post_title'] = $row['name'];
347
+
348
+                              if ( false !== $current_tours && array_key_exists( $row['identifier'], $current_tours ) ) {
349
+                                   $row['post_id']    = $current_tours[ $row['identifier'] ]->post_id;
350
+                                   $row['post_title'] = $current_tours[ $row['identifier'] ]->post_title;
351
+                              }
352
+
353
+                              // If we are searching for.
354
+                              if ( false !== $post_status ) {
355
+                                   if ( 'import' === $post_status ) {
356
+
357
+                                        if ( 0 !== $row['post_id'] ) {
358
+                                             continue;
359
+                                        } else {
360
+                                             $searched_items[ sanitize_title( $row['name'] ) . '-' . $row['identifier'] ] = $this->format_row( $row, $row_key );
361
+                                        }
362
+                                   } else {
363
+                                        if ( 0 === $row['post_id'] ) {
364
+                                             continue;
365
+                                        } else {
366
+                                             $current_status = get_post_status( $row['post_id'] );
367
+
368
+                                             if ( $current_status !== $post_status ) {
369
+                                                  continue;
370
+                                             }
371
+                                        }
372
+
373
+                                        $searched_items[ sanitize_title( $row['name'] ) . '-' . $row['identifier'] ] = $this->format_row( $row, $row_key );
374
+                                   }
375
+                              } else {
376
+                                   // Search through each keyword.
377
+                                   foreach ( $keyphrases as $keyphrase ) {
378
+
379
+                                        // Make sure the keyphrase is turned into an array.
380
+                                        $keywords = explode( ' ', $keyphrase );
381
+                                        if ( ! is_array( $keywords ) ) {
382
+                                             $keywords = array( $keywords );
383
+                                        }
384
+
385
+                                        if ( $this->multineedle_stripos( ltrim( rtrim( $row['name'] ) ), $keywords ) !== false ) {
386
+                                             $searched_items[ sanitize_title( $row['name'] ) . '-' . $row['identifier'] ] = $this->format_row( $row, $row_key );
387
+                                        } elseif ( $this->multineedle_stripos( ltrim( rtrim( $row['reference_number'] ) ), $keywords ) !== false ) {
388
+                                             $searched_items[ sanitize_title( $row['name'] ) . '-' . $row['identifier'] ] = $this->format_row( $row, $row_key );
389
+                                        } elseif ( $this->multineedle_stripos( ltrim( rtrim( $row['identifier_key'] ) ), $keywords ) !== false ) {
390
+                                             $searched_items[ sanitize_title( $row['name'] ) . '-' . $row['identifier'] ] = $this->format_row( $row, $row_key );
391
+                                        }
392
+                                   }
393
+                              }
394
+                         }
395
+                    }
396
+
397
+                    if ( false !== $searched_items ) {
398
+                         $return = implode( $searched_items );
399
+                    }
400
+               }
401
+               print_r( $return );
402
+               die();
403
+          }
404
+     }
405
+
406
+     /**
407
+      * Formats the row for output on the screen.
408
+      */
409
+     public function format_row( $row = false, $row_key = '' ) {
410
+          if ( false !== $row ) {
411
+               $status = 'import';
412
+
413
+               if ( 0 !== $row['post_id'] ) {
414
+                    $status = '<a href="' . admin_url( '/post.php?post=' . $row['post_id'] . '&action=edit' ) . '" target="_blank">' . get_post_status( $row['post_id'] ) . '</a>';
415
+               }
416
+
417
+               $row_html = '
418 418
 			<tr class="post-' . $row['post_id'] . ' type-tour" id="post-' . $row['post_id'] . '">
419 419
 				<td class="check-column">
420 420
 					<label for="cb-select-' . $row['identifier'] . '" class="screen-reader-text">' . $row['post_title'] . '</label>
@@ -436,992 +436,992 @@  discard block
 block discarded – undo
436 436
 					' . $row['identifier'] . '
437 437
 				</td>
438 438
 			</tr>';
439
-			return $row_html;
440
-		}
441
-	}
442
-
443
-	/**
444
-	 * Connect to wetu
445
-	 */
446
-	public function process_ajax_import( $force = false ) {
447
-		$return = false;
448
-		check_ajax_referer( 'lsx_wetu_ajax_action', 'security' );
449
-		if ( isset( $_POST['action'] ) && 'lsx_import_items' === $_POST['action'] && isset( $_POST['type'] ) && $_POST['type'] === $this->tab_slug && isset( $_POST['wetu_id'] ) ) {
450
-
451
-			$wetu_id = sanitize_text_field( $_POST['wetu_id'] );
452
-			if ( isset( $_POST['post_id'] ) ) {
453
-				$post_id = sanitize_text_field( $_POST['post_id'] );
454
-			} else {
455
-				$post_id = 0;
456
-			}
457
-
458
-			delete_option( 'lsx_wetu_importer_tour_settings' );
459
-
460
-			if ( isset( $_POST['team_members'] ) ) {
461
-				$team_members = array_map( 'sanitize_text_field', wp_unslash( $_POST['team_members'] ) );
462
-			} else {
463
-				$team_members = false;
464
-			}
465
-
466
-			if ( isset( $_POST['content'] ) && is_array( $_POST['content'] ) && ! empty( $_POST['content'] ) ) {
467
-				$content = array_map( 'sanitize_text_field', wp_unslash( $_POST['content'] ) );
468
-				add_option( 'lsx_wetu_importer_tour_settings', $content );
469
-			} else {
470
-				$content = false;
471
-			}
472
-			$jdata = wp_remote_get( 'https://wetu.com/API/Itinerary/V8/Get?id=' . $wetu_id );
473
-
474
-			if ( ! is_wp_error( $jdata ) && ! empty( $jdata ) && isset( $jdata['response'] ) && isset( $jdata['response']['code'] ) && 200 === $jdata['response']['code'] ) {
475
-				$jdata  = json_decode( $jdata['body'], true );
476
-				$return = $this->import_row( $jdata, $wetu_id, $post_id, $team_members, $content );
477
-				$this->format_completed_row( $return );
478
-				$this->save_queue();
479
-				$this->cleanup_posts();
480
-				$this->attach_destination_images( $content );
481
-				$this->clean_attached_destinations( $return );
482
-			} else {
483
-				$this->format_error( esc_html__( 'There was a problem importing your tour, please try again.', 'lsx-wetu-importer' ) );
484
-			}
485
-		}
486
-	}
487
-
488
-	/**
489
-	 * Amends the tours destinations instead of replace.
490
-	 *
491
-	 * @param $id string
492
-	 * @return void
493
-	 */
494
-	public function clean_attached_destinations( $id ) {
495
-		$current_connections = get_post_meta( $id, 'destination_to_tour', false );
496
-		delete_post_meta( $id, 'destination_to_tour' );
497
-		$current_connections = array_unique( $current_connections );
498
-
499
-		foreach ( $current_connections as $connection ) {
500
-			add_post_meta( $id, 'destination_to_tour', $connection, false );
501
-		}
502
-	}
503
-
504
-	/**
505
-	 * Connect to wetu
506
-	 *
507
-	 * @param $data array
508
-	 * @param $wetu_id string
509
-	 */
510
-	public function import_row( $data, $wetu_id, $id = 0, $team_members = false, $importable_content = array(), $old1 = false, $old2 = false ) {
511
-		$post_name         = '';
512
-		$data_post_content = '';
513
-		$data_post_excerpt = '';
514
-
515
-		$current_post = get_post( $id );
516
-
517
-		$post = array(
518
-			'post_type' => 'tour',
519
-		);
520
-
521
-		$content_used_general_description = false;
522
-
523
-		if ( ! empty( $importable_content ) && in_array( 'description', $importable_content ) ) {
524
-			$data_post_content = $current_post->post_content;
525
-			if ( isset( $data['summary'] ) && ! empty( $data['summary'] ) ) {
526
-				$data_post_content = $data['summary'];
527
-			}
528
-			$post['post_content'] = $data_post_content;
529
-		}
530
-
531
-		// Create or update the post.
532
-		if ( false !== $id && '0' !== $id ) {
533
-			$post['ID']          = $id;
534
-			$post['post_status'] = 'publish';
535
-			if ( isset( $this->options ) && 'on' !== $this->options['disable_accommodation_title'] ) {
536
-				$post['post_title'] = $data['name'];
537
-			}
538
-			$id = wp_update_post( $post );
539
-		} else {
540
-			// Set the name.
541
-			if ( isset( $data['name'] ) ) {
542
-				$post_name = wp_unique_post_slug( sanitize_title( $data['name'] ), $id, 'draft', 'tour', 0 );
543
-			}
544
-
545
-			if ( ! isset( $post['post_content'] ) ) {
546
-				$post['post_content'] = ' ';
547
-			}
548
-
549
-			$post['post_name']   = $post_name;
550
-			$post['post_title']  = $data['name'];
551
-			$post['post_status'] = 'publish';
552
-			$id                  = wp_insert_post( $post );
553
-
554
-			// Save the WETU ID and the Last date it was modified.
555
-			if ( false !== $id ) {
556
-				add_post_meta( $id, 'lsx_wetu_id', $wetu_id );
557
-				add_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data['last_modified'] ) );
558
-			}
559
-		}
560
-
561
-		// Set reference number.
562
-		$this->set_reference_number( $data, $id );
563
-
564
-		// Set the team member if it is there.
565
-		if ( post_type_exists( 'team' ) && false !== $team_members && '' !== $team_members ) {
566
-			$this->set_team_member( $id, $team_members );
567
-		}
568
-
569
-		// Set the price.
570
-		if ( false !== $importable_content && in_array( 'price', $importable_content ) ) {
571
-			$this->set_price( $data, $id );
572
-		}
573
-
574
-		// Set the Duration.
575
-		if ( false !== $importable_content && in_array( 'duration', $importable_content ) ) {
576
-			$this->set_duration( $data, $id );
577
-		}
578
-
579
-		// Set the Group Size.
580
-		if ( false !== $importable_content && in_array( 'group_size', $importable_content ) ) {
581
-			$this->set_group_size( $data, $id );
582
-		}
583
-
584
-		// Set the Group Size.
585
-		if ( false !== $importable_content && in_array( 'tags', $importable_content ) ) {
586
-			$this->set_travel_styles( $id, $data );
587
-		}
588
-
589
-		// Set the Start and End Point Destinations.
590
-		if ( false !== $importable_content && in_array( 'start_end_point', $importable_content ) ) {
591
-			$this->set_start_end_point( $data, $id );
592
-		}
593
-
594
-		if ( false !== $importable_content && in_array( 'itineraries', $importable_content ) && isset( $data['legs'] ) && ! empty( $data['legs'] ) ) {
595
-			$this->process_itineraries( $data, $id, $importable_content );
596
-		}
597
-
598
-		if ( in_array( 'map', $importable_content ) && isset( $data['routes'] ) && ! empty( $data['routes'] ) ) {
599
-			$this->set_map_data( $data, $id );
600
-		}
601
-
602
-		return $id;
603
-	}
604
-
605
-	/**
606
-	 * A loop which runs through each leg on the tour.
607
-	 */
608
-	public function process_itineraries( $data, $id, $importable_content ) {
609
-		$day_counter = 1;
610
-		$leg_counter = 0;
611
-
612
-		delete_post_meta( $id, 'itinerary' );
613
-
614
-		if ( false !== $importable_content && in_array( 'accommodation', $importable_content ) ) {
615
-			delete_post_meta( $id, 'accommodation_to_tour' );
616
-		}
617
-
618
-		foreach ( $data['legs'] as $leg ) {
619
-
620
-			// Itinerary Accommodation.
621
-			$current_accommodation = false;
622
-			$current_destination   = false;
623
-			if ( 'Mobile' !== $leg['type'] ) {
624
-				if ( false !== $importable_content && in_array( 'accommodation', $importable_content ) ) {
625
-					$current_accommodation = $this->set_accommodation( $leg, $id );
626
-				}
627
-				if ( false !== $importable_content && in_array( 'destination', $importable_content ) ) {
628
-					$current_destination = $this->set_destination( $leg, $id, $leg_counter );
629
-				}
630
-			}
631
-
632
-			// If the Nights are the same mount of days in the array,  then it isnt "By Destination".
633
-			if ( ( 1 <= (int) $leg['nights'] && isset( $leg['periods'] ) ) || 0 === $leg['itinerary_leg_id'] ) {
634
-
635
-				foreach ( $leg['periods'] as $day_key => $day ) {
636
-					$current_day = array();
637
-
638
-					// If this is a moble tented solution.
639
-					$next_day_count = $day_counter + (int) $day['days'];
640
-
641
-					if ( ( isset( $leg['stops'] ) && 'Mobile' !== $leg['type'] ) || ( 1 < (int) $day['days'] ) ) {
642
-						$day_count_label = ' - ' . ( $next_day_count - 1 );
643
-					} else {
644
-						$day_count_label = '';
645
-					}
646
-					$current_day['title'] = esc_attr( 'Day ', 'lsx-wetu-importer' ) . $day_counter . $day_count_label;
647
-
648
-					// Description.
649
-					if ( false !== $importable_content && in_array( 'itinerary_description', $importable_content ) && isset( $day['notes'] ) ) {
650
-						$current_day['description'] = $day['notes'];
651
-					} else {
652
-						$current_day['description'] = '';
653
-					}
654
-
655
-					// Itinerary Gallery.
656
-					if ( false !== $importable_content && in_array( 'itinerary_gallery', $importable_content ) && isset( $day['images'] ) ) {
657
-						$current_day['featured_image'] = '';
658
-					} else {
659
-						$current_day['featured_image'] = '';
660
-					}
661
-
662
-					// If its a mobile safari, we need to get the destination and accommodation data from the stops.
663
-					if ( 'Mobile' === $leg['type'] ) {
664
-						$current_destination   = $this->get_mobile_destination( $day, $leg, $id );
665
-						$current_accommodation = $this->get_mobile_accommodation( $day, $leg, $id );
666
-					}
667
-
668
-					// Accommodation.
669
-					if ( false !== $current_accommodation ) {
670
-						$current_day['accommodation_to_tour'] = array( $current_accommodation );
671
-					} else {
672
-						$current_day['accommodation_to_tour'] = array();
673
-					}
674
-
675
-					// Destination.
676
-					if ( false !== $current_destination ) {
677
-						$current_day['destination_to_tour'] = array( $current_destination );
678
-					} else {
679
-						$current_day['destination_to_tour'] = array();
680
-					}
681
-
682
-					// Included.
683
-					if ( false !== $importable_content && in_array( 'itinerary_included', $importable_content ) && isset( $day['included'] ) && '' !== $day['included'] ) {
684
-						$current_day['included'] = $day['included'];
685
-					} else {
686
-						$current_day['included'] = '';
687
-					}
688
-
689
-					// Excluded.
690
-					if ( false !== $importable_content && in_array( 'itinerary_excluded', $importable_content ) && isset( $day['excluded'] ) && '' !== $day['excluded'] ) {
691
-						$current_day['excluded'] = $day['excluded'];
692
-					} else {
693
-						$current_day['excluded'] = '';
694
-					}
695
-
696
-					// Excluded.
697
-					if ( false !== $importable_content && in_array( 'room_basis', $importable_content ) && isset( $day['room_basis'] ) && '' !== $day['room_basis'] ) {
698
-						$current_day['room_basis'] = $day['room_basis'];
699
-					} else {
700
-						$current_day['room_basis'] = '';
701
-					}
702
-
703
-					// Excluded.
704
-					if ( false !== $importable_content && in_array( 'drinks_basis', $importable_content ) && isset( $day['drinks_basis'] ) && '' !== $day['drinks_basis'] ) {
705
-						$current_day['drinks_basis'] = $day['drinks_basis'];
706
-					} else {
707
-						$current_day['drinks_basis'] = '';
708
-					}
709
-
710
-					$this->set_itinerary_day( $current_day, $id );
711
-					$day_counter = $next_day_count;
712
-				}
713
-			} else {
714
-				// This is for the by destination.
715
-
716
-				$current_day     = array();
717
-				$next_day_count  = $day_counter + (int) $leg['nights'];
718
-				$day_count_label = $next_day_count - 1;
719
-
720
-				$current_day['title'] = esc_attr( 'Day ', 'lsx-wetu-importer' ) . $day_counter;
721
-
722
-				if ( 0 !== (int) $leg['nights'] ) {
723
-					$current_day['title'] .= ' - ' . $day_count_label;
724
-				}
725
-
726
-				// Description.
727
-				if ( false !== $importable_content && in_array( 'itinerary_description', $importable_content ) && isset( $leg['notes'] ) ) {
728
-					$current_day['description'] = $leg['notes'];
729
-				} else {
730
-					$current_day['description'] = '';
731
-				}
732
-
733
-				// Itinerary Gallery.
734
-				if ( false !== $importable_content && in_array( 'itinerary_gallery', $importable_content ) && isset( $leg['images'] ) ) {
735
-					$current_day['featured_image'] = '';
736
-				} else {
737
-					$current_day['featured_image'] = '';
738
-				}
739
-
740
-				// Accommodation.
741
-				if ( false !== $current_accommodation ) {
742
-					$current_day['accommodation_to_tour'] = array( $current_accommodation );
743
-				} else {
744
-					$current_day['accommodation_to_tour'] = array();
745
-				}
746
-
747
-				// Destination.
748
-				if ( false !== $current_destination ) {
749
-					$current_day['destination_to_tour'] = array( $current_destination );
750
-				} else {
751
-					$current_day['destination_to_tour'] = array();
752
-				}
753
-
754
-				// Included.
755
-				if ( false !== $importable_content && in_array( 'itinerary_included', $importable_content ) && isset( $leg['included'] ) && '' !== $leg['included'] ) {
756
-					$current_day['included'] = $leg['included'];
757
-				} else {
758
-					$current_day['included'] = '';
759
-				}
760
-
761
-				// Excluded.
762
-				if ( false !== $importable_content && in_array( 'itinerary_excluded', $importable_content ) && isset( $leg['excluded'] ) && '' !== $leg['excluded'] ) {
763
-					$current_day['excluded'] = $leg['excluded'];
764
-				} else {
765
-					$current_day['excluded'] = '';
766
-				}
767
-
768
-				// Excluded.
769
-				if ( false !== $importable_content && in_array( 'room_basis', $importable_content ) && isset( $leg['room_basis'] ) && '' !== $leg['room_basis'] ) {
770
-					$current_day['room_basis'] = $leg['room_basis'];
771
-				} else {
772
-					$current_day['room_basis'] = '';
773
-				}
774
-
775
-				// Excluded.
776
-				if ( false !== $importable_content && in_array( 'drinks_basis', $importable_content ) && isset( $leg['drinks_basis'] ) && '' !== $leg['drinks_basis'] ) {
777
-					$current_day['drinks_basis'] = $leg['drinks_basis'];
778
-				} else {
779
-					$current_day['drinks_basis'] = '';
780
-				}
781
-
782
-				$this->set_itinerary_day( $current_day, $id );
783
-				$day_counter = $next_day_count;
784
-			}
785
-			$leg_counter++;
786
-		}
787
-	}
788
-
789
-	/**
790
-	 * Sets the departs from and ends in points on the tours.
791
-	 *
792
-	 * @param array  $data
793
-	 * @param string $id
794
-	 * @return void
795
-	 */
796
-	public function set_start_end_point( $data, $id ) {
797
-		delete_post_meta( $id, 'departs_from' );
798
-		delete_post_meta( $id, 'ends_in' );
799
-		$departs_from = false;
800
-		$ends_in      = false;
801
-
802
-		$args = array(
803
-			'points'      => $data['legs'],
804
-			'start_index' => 0,
805
-			'end_index'   => count( $data['legs'] ) - 2,
806
-		);
807
-		$args = apply_filters( 'lsx_wetu_start_end_args', $args, $data );
808
-
809
-		if ( ! empty( $args['points'] ) && is_array( $args['points'] ) ) {
810
-			$leg_counter = 0;
811
-
812
-			foreach ( $args['points'] as $point ) {
813
-				// If we are in the first leg,  and the destination was attached then save it as the departure field.
814
-				if ( $leg_counter === $args['start_index'] ) {
815
-					$departs_from_destination = $this->set_country( $point['destination_content_entity_id'], $id );
816
-					if ( false !== $departs_from_destination ) {
817
-						$departs_from = $departs_from_destination;
818
-					}
819
-				}
820
-				// If its the last leg then save it as the ends in.
821
-				if ( $leg_counter === $args['end_index'] ) {
822
-					$ends_in = $point['destination_content_entity_id'];
823
-				}
824
-				$leg_counter++;
825
-			}
826
-
827
-			$departs_from = apply_filters( 'lsx_wetu_departs_from_id', $departs_from, $data, $this );
828
-			if ( false !== $departs_from ) {
829
-				add_post_meta( $id, 'departs_from', $departs_from, true );
830
-			}
831
-
832
-			if ( false !== $ends_in ) {
833
-				$ends_in             = apply_filters( 'lsx_wetu_ends_in_id', $ends_in, $data, $this );
834
-				$ends_in_destination = $this->set_country( $ends_in, $id );
835
-				if ( false !== $ends_in_destination ) {
836
-					add_post_meta( $id, 'ends_in', $ends_in_destination, true );
837
-				}
838
-			}
839
-		}
840
-	}
841
-
842
-	/**
843
-	 * Gets the destination for the mobile camp.
844
-	 *
845
-	 * @param $day
846
-	 * @param $leg
847
-	 * @return void
848
-	 */
849
-	public function get_mobile_destination( $day, $leg, $id ) {
850
-		$current_destination = false;
851
-		$current_day         = (int) $day['period_start_day'];
852
-		if ( isset( $leg['stops'] ) ) {
853
-			foreach ( $leg['stops'] as $stop ) {
854
-				$arrival_day   = (int) $stop['arrival_day'];
855
-				$departure_day = (int) $stop['departure_day'];
856
-				if ( $arrival_day <= $current_day && $current_day < $departure_day ) {
857
-					$current_destination = $this->set_destination( $stop, $id, 0 );
858
-				}
859
-			}
860
-		}
861
-		return $current_destination;
862
-	}
863
-
864
-	/**
865
-	 * Gets the accommodation for the mobile camp.
866
-	 *
867
-	 * @param $day
868
-	 * @param $leg
869
-	 * @return void
870
-	 */
871
-	public function get_mobile_accommodation( $day, $leg, $id ) {
872
-		$current_accommodation = false;
873
-		$current_day           = (int) $day['period_start_day'];
874
-		if ( isset( $leg['stops'] ) ) {
875
-			foreach ( $leg['stops'] as $stop ) {
876
-				$arrival_day   = (int) $stop['arrival_day'];
877
-				$departure_day = (int) $stop['departure_day'];
878
-				if ( $arrival_day <= $current_day && $current_day < $departure_day ) {
879
-					$current_accommodation = $this->set_accommodation( $stop, $id, 0 );
880
-				}
881
-			}
882
-		}
883
-		return $current_accommodation;
884
-	}
885
-
886
-	/**
887
-	 * Run through your routes and save the points as a KML file.
888
-	 */
889
-	public function set_map_data( $data, $id, $zoom = 9 ) {
890
-		if ( ! empty( $data['routes'] ) ) {
891
-			delete_post_meta( $id, 'wetu_map_points' );
892
-
893
-			$points = array();
894
-
895
-			foreach ( $data['routes'] as $route ) {
896
-
897
-				if ( isset( $route['points'] ) && '' !== $route['points'] ) {
898
-
899
-					$temp_points   = explode( ';', $route['points'] );
900
-					$point_counter = count( $temp_points );
901
-
902
-					for ( $x = 0; $x <= $point_counter; $x++ ) {
903
-						$y        = $x + 1;
904
-						$points[] = $temp_points[ $x ] . ',' . $temp_points[ $y ];
905
-						$x++;
906
-					}
907
-				}
908
-			}
909
-
910
-			if ( ! empty( $points ) ) {
911
-				$this->save_custom_field( implode( ' ', $points ), 'wetu_map_points', $id, false, true );
912
-			}
913
-		}
914
-
915
-	}
916
-
917
-	// CLASS SPECIFIC FUNCTIONS.
918
-
919
-	/**
920
-	 * Set the Itinerary Day.
921
-	 */
922
-	public function set_itinerary_day( $day, $id ) {
923
-		$this->save_custom_field( $day, 'itinerary', $id, false, false );
924
-	}
925
-
926
-	/**
927
-	 * Set the ref number
928
-	 */
929
-	public function set_reference_number( $data, $id ) {
930
-		if ( isset( $data['reference_number'] ) && '' !== $data['reference_number'] ) {
931
-			$this->save_custom_field( $data['reference_number'], 'lsx_wetu_ref', $id );
932
-		}
933
-	}
934
-
935
-	/**
936
-	 * Set the price.
937
-	 */
938
-	public function set_price( $data, $id ) {
939
-		// Price.
940
-		if ( isset( $data['price'] ) && '' !== $data['price'] ) {
941
-			$price = $data['price'];
942
-			if ( false === apply_filters( 'lsx_wetu_importer_disable_tour_price_filter', false ) ) {
943
-				$price = preg_replace( '/[^0-9,.]/', '', $price );
944
-			}
945
-			$meta_key = apply_filters( 'lsx_wetu_importer_price_meta_key', 'price' );
946
-			$this->save_custom_field( $price, $meta_key, $id );
947
-		}
948
-
949
-		// Price includes.
950
-		if ( isset( $data['price_includes'] ) && '' !== $data['price_includes'] ) {
951
-			$meta_key = apply_filters( 'lsx_wetu_importer_included_meta_key', 'included' );
952
-			$this->save_custom_field( $data['price_includes'], $meta_key, $id );
953
-		}
954
-
955
-		// Price Excludes.
956
-		if ( isset( $data['price_excludes'] ) && '' !== $data['price_excludes'] ) {
957
-			$meta_key = apply_filters( 'lsx_wetu_importer_not_included_meta_key', 'not_included' );
958
-			$this->save_custom_field( $data['price_excludes'], $meta_key, $id );
959
-		}
960
-	}
961
-
962
-	/**
963
-	 * Set the duration.
964
-	 */
965
-	public function set_duration( $data, $id ) {
966
-		if ( isset( $data['days'] ) && ! empty( $data['days'] ) ) {
967
-			$price = $data['days'];
968
-			$price = preg_replace( '/[^0-9,.]/', '', $price );
969
-			$this->save_custom_field( $price, 'duration', $id );
970
-		}
971
-	}
972
-
973
-	/**
974
-	 * Set the group size
975
-	 */
976
-	public function set_group_size( $data, $id ) {
977
-		if ( isset( $data['group_size'] ) && ! empty( $data['group_size'] ) ) {
978
-			$group_size = $data['group_size'];
979
-			$this->save_custom_field( $group_size, 'group_size', $id );
980
-		}
981
-	}
982
-
983
-	/**
984
-	 * Takes the WETU tags and sets the Travel Styles.
985
-	 *
986
-	 * @param string $id
987
-	 * @param array  $travel_styles
988
-	 * @return void
989
-	 */
990
-	public function set_travel_styles( $id, $data ) {
991
-		$tags = apply_filters( 'lsx_wetu_importer_tour_travel_styles', $data['tags'] );
992
-		if ( isset( $data['tags'] ) && ! empty( $tags ) ) {
993
-			foreach ( $tags as $tag ) {
994
-				$this->set_term( $id, $tag, 'travel-style' );
995
-			}
996
-		}
997
-	}
998
-
999
-	/**
1000
-	 * Connects the Accommodation if its available
1001
-	 */
1002
-	public function set_accommodation( $day, $id ) {
1003
-		$ac_id                       = false;
1004
-		$this->current_accommodation = $this->find_current_accommodation();
1005
-
1006
-		if ( isset( $day['content_entity_id'] ) && ! empty( $day['content_entity_id'] ) && ! in_array( (int) $day['content_entity_id'], array( 25862 ) ) ) {
1007
-			if ( false !== $this->current_accommodation && ! empty( $this->current_accommodation ) && array_key_exists( $day['content_entity_id'], $this->current_accommodation ) ) {
1008
-				$ac_id = $this->current_accommodation[ $day['content_entity_id'] ];
1009
-			} else {
1010
-				$ac_id = wp_insert_post(
1011
-					array(
1012
-						'post_type'   => 'accommodation',
1013
-						'post_status' => 'draft',
1014
-						'post_title'  => $day['content_entity_id'],
1015
-					)
1016
-				);
1017
-
1018
-				$this->save_custom_field( $day['content_entity_id'], 'lsx_wetu_id', $ac_id );
1019
-			}
1020
-
1021
-			if ( '' !== $ac_id && false !== $ac_id ) {
1022
-				$this->save_custom_field( $ac_id, 'accommodation_to_tour', $id, false, false );
1023
-				$this->save_custom_field( $id, 'tour_to_accommodation', $ac_id, false, false );
1024
-				$this->queue_item( $ac_id );
1025
-			}
1026
-		}
1027
-		return $ac_id;
1028
-	}
1029
-
1030
-	/**
1031
-	 * Grab all the current accommodation posts via the lsx_wetu_id field.
1032
-	 *
1033
-	 * @param $post_type string
1034
-	 * @return boolean / array
1035
-	 */
1036
-	public function find_current_accommodation( $post_type = 'accommodation' ) {
1037
-		global $wpdb;
1038
-		$accommodation = parent::find_current_accommodation( $post_type );
1039
-		$return        = false;
1040
-
1041
-		if ( ! empty( $accommodation ) ) {
1042
-			foreach ( $accommodation as $key => $acc ) {
1043
-				$return[ $acc->meta_value ] = $acc->post_id;
1044
-			}
1045
-		}
1046
-
1047
-		return $return;
1048
-	}
1049
-
1050
-	/**
1051
-	 * Grab all the current accommodation posts via the lsx_wetu_id field.
1052
-	 *
1053
-	 * @return boolean / array
1054
-	 */
1055
-	public function find_current_destinations() {
1056
-		return $this->find_current_accommodation( 'destination' );
1057
-	}
1058
-
1059
-	/**
1060
-	 * Connects the destinations post type
1061
-	 *
1062
-	 * @param $day array
1063
-	 * @param $id string
1064
-	 * @return boolean / string
1065
-	 */
1066
-	public function set_destination( $day, $id, $leg_counter ) {
1067
-		$dest_id    = false;
1068
-		$country_id = false;
1069
-
1070
-		$this->current_destinations = $this->find_current_destinations();
1071
-
1072
-		if ( isset( $day['destination_content_entity_id'] ) && ! empty( $day['destination_content_entity_id'] ) ) {
1073
-			if ( false !== $this->current_destinations && ! empty( $this->current_destinations ) && array_key_exists( $day['destination_content_entity_id'], $this->current_destinations ) ) {
1074
-				$dest_id = $this->current_destinations[ $day['destination_content_entity_id'] ];
1075
-
1076
-				// TODO Check for attachments here.
1077
-				$this->destination_images[ $id ][] = array( $dest_id, $day['destination_content_entity_id'] );
1078
-
1079
-				// Check if there is a country asigned.
1080
-				$potential_id    = wp_get_post_parent_id( $dest_id );
1081
-				$country_wetu_id = get_post_meta( $potential_id, 'lsx_wetu_id', true );
1082
-
1083
-				if ( false !== $country_wetu_id ) {
1084
-					$country_id = $this->set_country( $country_wetu_id, $id );
1085
-					// $this->destination_images[ $id ][] = array( $id, $country_wetu_id );
1086
-				}
1087
-			} else {
1088
-				$destination_json = wp_remote_get( 'https://wetu.com/API/Pins/' . $this->api_key . '/Get?ids=' . $day['destination_content_entity_id'] );
1089
-
1090
-				if ( ! is_wp_error( $destination_json ) && ! empty( $destination_json ) && isset( $destination_json['response'] ) && isset( $destination_json['response']['code'] ) && 200 === $destination_json['response']['code'] ) {
1091
-
1092
-					$destination_data = json_decode( $destination_json['body'], true );
1093
-
1094
-					if ( ! empty( $destination_data ) && ! isset( $destination_data['error'] ) ) {
1095
-						$destination_title = $day['destination_content_entity_id'];
1096
-
1097
-						if ( isset( $destination_data[0]['name'] ) ) {
1098
-							$destination_title = $destination_data[0]['name'];
1099
-						}
1100
-
1101
-						if ( isset( $destination_data[0]['map_object_id'] ) && isset( $destination_data[0]['position']['country_content_entity_id'] )
1102
-							&& $destination_data[0]['map_object_id'] !== $destination_data[0]['position']['country_content_entity_id'] ) {
1103
-
1104
-							$country_id = $this->set_country( $destination_data[0]['position']['country_content_entity_id'], $id );
1105
-							// Save the destination so we can grab the tour featured image and banner from them.
1106
-						}
1107
-
1108
-						$dest_post = array(
1109
-							'post_type'   => 'destination',
1110
-							'post_status' => 'draft',
1111
-							'post_title'  => $destination_title,
1112
-						);
1113
-
1114
-						if ( false !== $country_id ) {
1115
-							$dest_post['post_parent'] = $country_id;
1116
-						}
1117
-						$dest_id = wp_insert_post( $dest_post );
1118
-
1119
-						// Make sure we register the.
1120
-						$this->current_destinations[ $day['destination_content_entity_id'] ] = $dest_id;
1121
-
1122
-						// If there are images attached then use the destination.
1123
-						if ( isset( $destination_data[0]['content']['images'] ) && ! empty( $destination_data[0]['content']['images'] ) ) {
1124
-							$this->destination_images[ $id ][] = array( $dest_id, $day['destination_content_entity_id'] );
1125
-						}
1126
-
1127
-						$this->save_custom_field( $day['destination_content_entity_id'], 'lsx_wetu_id', $dest_id );
1128
-					}
1129
-				}
1130
-			}
1131
-
1132
-			if ( '' !== $dest_id && false !== $dest_id ) {
1133
-				$this->save_custom_field( $dest_id, 'destination_to_tour', $id, false, false );
1134
-				$this->save_custom_field( $id, 'tour_to_destination', $dest_id, false, false );
1135
-
1136
-				// Save the item to display in the queue
1137
-				$this->queue_item( $dest_id );
1138
-
1139
-				// Save the item to clean up the amount of connections.
1140
-				$this->cleanup_posts[ $dest_id ] = 'tour_to_destination';
1141
-
1142
-				// Add this relation info so we can make sure certain items are set as countries.
1143
-				if ( 0 !== $country_id && false !== $country_id ) {
1144
-					$this->relation_meta[ $dest_id ]    = $country_id;
1145
-					$this->relation_meta[ $country_id ] = 0;
1146
-				} else {
1147
-					$this->relation_meta[ $dest_id ] = 0;
1148
-				}
1149
-			}
1150
-		}
1151
-		return $dest_id;
1152
-	}
1153
-
1154
-	/**
1155
-	 * Connects the destinations post type
1156
-	 *
1157
-	 * @param $dest_id string
1158
-	 * @param $country_id array
1159
-	 * @param $id string
1160
-	 *
1161
-	 * @return string
1162
-	 */
1163
-	public function set_country( $country_wetu_id, $id ) {
1164
-		$country_id                 = false;
1165
-		$this->current_destinations = $this->find_current_destinations();
1166
-
1167
-		if ( false !== $this->current_destinations && ! empty( $this->current_destinations ) && array_key_exists( $country_wetu_id, $this->current_destinations ) ) {
1168
-			$country_id                        = $this->current_destinations[ $country_wetu_id ];
1169
-			$this->destination_images[ $id ][] = array( $country_id, $country_wetu_id );
1170
-		} else {
1171
-			$country_json = wp_remote_get( 'https://wetu.com/API/Pins/' . $this->api_key . '/Get?ids=' . $country_wetu_id );
1172
-
1173
-			if ( ! is_wp_error( $country_json ) && ! empty( $country_json ) && isset( $country_json['response'] ) && isset( $country_json['response']['code'] ) && 200 === $country_json['response']['code'] ) {
1174
-				$country_data = json_decode( $country_json['body'], true );
1175
-
1176
-				// Format the title of the destination if its available,  otherwise default to the WETU ID.
1177
-				$country_title = $country_wetu_id;
1178
-
1179
-				if ( isset( $country_data[0]['name'] ) ) {
1180
-					$country_title = $country_data[0]['name'];
1181
-				}
1182
-
1183
-				$country_id = wp_insert_post(
1184
-					array(
1185
-						'post_type'   => 'destination',
1186
-						'post_status' => 'draft',
1187
-						'post_title'  => $country_title,
1188
-					)
1189
-				);
1190
-
1191
-				// add the country to the current destination stack
1192
-				$this->current_destinations[ $country_wetu_id ] = $country_id;
1193
-
1194
-				// Check if there are images and save fore use later.
1195
-				if ( isset( $country_data[0]['content']['images'] ) && ! empty( $country_data[0]['content']['images'] ) ) {
1196
-					$this->destination_images[ $id ][] = array( $country_id, $country_wetu_id );
1197
-				}
1198
-
1199
-				// Save the wetu field
1200
-				$this->save_custom_field( $country_wetu_id, 'lsx_wetu_id', $country_id );
1201
-			}
1202
-		}
1203
-
1204
-		if ( '' !== $country_id && false !== $country_id ) {
1205
-			$this->save_custom_field( $country_id, 'destination_to_tour', $id, false, false );
1206
-			$this->save_custom_field( $id, 'tour_to_destination', $country_id, false, false );
1207
-			$this->queue_item( $country_id );
1208
-			$this->cleanup_posts[ $country_id ] = 'tour_to_destination';
1209
-
1210
-			return $country_id;
1211
-		}
1212
-	}
1213
-
1214
-	/**
1215
-	 * Connects the destinations post type
1216
-	 *
1217
-	 * @param $dest_id string
1218
-	 * @param $country_id array
1219
-	 * @param $id string
1220
-	 *
1221
-	 * @return string
1222
-	 */
1223
-	public function attach_destination_images( $importable_content = array() ) {
1224
-		if ( false !== $this->destination_images ) {
1225
-			$this->shuffle_assoc( $this->destination_images );
1226
-			foreach ( $this->destination_images as $tour => $destinations ) {
1227
-				shuffle( $destinations );
1228
-				$image_set = false;
1229
-				$forced    = false;
1230
-
1231
-				foreach ( $destinations as $destination ) {
1232
-					if ( false === $image_set && false === $forced ) {
1233
-						$url = 'https://wetu.com/API/Pins/' . $this->api_key;
1234
-
1235
-						$url_qs = '';
1236
-						$jdata  = wp_remote_get( $url . '/Get?' . $url_qs . '&ids=' . $destination[1] );
1237
-
1238
-						if ( ! is_wp_error( $jdata ) && ! empty( $jdata ) && isset( $jdata['response'] ) && isset( $jdata['response']['code'] ) && 200 === $jdata['response']['code'] ) {
1239
-							$adata = json_decode( $jdata['body'], true );
1240
-
1241
-							if ( ! empty( $adata ) && ! empty( $adata[0]['content']['images'] ) ) {
1242
-								$this->find_attachments( $destination[0] );
1243
-
1244
-								// Set the featured image.
1245
-								if ( false !== $importable_content && in_array( 'featured_image', $importable_content ) ) {
1246
-									$image_set = $this->set_featured_image( $adata, $tour );
1247
-									if ( false !== $importable_content && in_array( 'banner_image', $importable_content ) ) {
1248
-										$image_set = $this->set_banner_image( $adata, $tour );
1249
-										$forced    = true;
1250
-									}
1251
-									continue;
1252
-								}
1253
-								if ( false !== $importable_content && in_array( 'banner_image', $importable_content ) ) {
1254
-									$image_set = $this->set_banner_image( $adata, $tour );
1255
-								}
1256
-							}
1257
-						}
1258
-					} else {
1259
-						continue;
1260
-					}
1261
-				}
1262
-			}
1263
-		}
1264
-	}
1265
-
1266
-	/**
1267
-	 * Creates the main gallery data
1268
-	 */
1269
-	public function set_featured_image( $data, $id ) {
1270
-		$image_set = false;
1271
-		$counter   = 0;
1272
-
1273
-		if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) {
1274
-			$images_array = $data[0]['content']['images'];
1275
-
1276
-			if ( 'on' === $this->options['enable_tour_featured_random'] ) {
1277
-				shuffle( $images_array );
1278
-			}
1279
-
1280
-			foreach ( $images_array as $v ) {
1281
-
1282
-				if ( true === $image_set ) {
1283
-					$counter++;
1284
-					continue;
1285
-				}
1286
-
1287
-				if ( ! $this->check_if_image_is_used( $v ) ) {
1288
-					$temp_featured_image = $this->attach_image( $v, $id );
1289
-
1290
-					if ( false !== $temp_featured_image ) {
1291
-						$this->featured_image = $temp_featured_image;
1292
-						delete_post_meta( $id, '_thumbnail_id' );
1293
-						add_post_meta( $id, '_thumbnail_id', $this->featured_image, true );
1294
-						$image_set = true;
1295
-					}
1296
-				}
1297
-
1298
-				$counter++;
1299
-			}
1300
-		}
1301
-		return $image_set;
1302
-	}
1303
-
1304
-	/**
1305
-	 * Sets a banner image
1306
-	 */
1307
-	public function set_banner_image( $data, $id, $content = array( 'none' ) ) {
1308
-		$image_set = false;
1309
-		$counter   = 0;
1310
-
1311
-		if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) {
1312
-
1313
-			foreach ( $data[0]['content']['images'] as $v ) {
1314
-				/*
439
+               return $row_html;
440
+          }
441
+     }
442
+
443
+     /**
444
+      * Connect to wetu
445
+      */
446
+     public function process_ajax_import( $force = false ) {
447
+          $return = false;
448
+          check_ajax_referer( 'lsx_wetu_ajax_action', 'security' );
449
+          if ( isset( $_POST['action'] ) && 'lsx_import_items' === $_POST['action'] && isset( $_POST['type'] ) && $_POST['type'] === $this->tab_slug && isset( $_POST['wetu_id'] ) ) {
450
+
451
+               $wetu_id = sanitize_text_field( $_POST['wetu_id'] );
452
+               if ( isset( $_POST['post_id'] ) ) {
453
+                    $post_id = sanitize_text_field( $_POST['post_id'] );
454
+               } else {
455
+                    $post_id = 0;
456
+               }
457
+
458
+               delete_option( 'lsx_wetu_importer_tour_settings' );
459
+
460
+               if ( isset( $_POST['team_members'] ) ) {
461
+                    $team_members = array_map( 'sanitize_text_field', wp_unslash( $_POST['team_members'] ) );
462
+               } else {
463
+                    $team_members = false;
464
+               }
465
+
466
+               if ( isset( $_POST['content'] ) && is_array( $_POST['content'] ) && ! empty( $_POST['content'] ) ) {
467
+                    $content = array_map( 'sanitize_text_field', wp_unslash( $_POST['content'] ) );
468
+                    add_option( 'lsx_wetu_importer_tour_settings', $content );
469
+               } else {
470
+                    $content = false;
471
+               }
472
+               $jdata = wp_remote_get( 'https://wetu.com/API/Itinerary/V8/Get?id=' . $wetu_id );
473
+
474
+               if ( ! is_wp_error( $jdata ) && ! empty( $jdata ) && isset( $jdata['response'] ) && isset( $jdata['response']['code'] ) && 200 === $jdata['response']['code'] ) {
475
+                    $jdata  = json_decode( $jdata['body'], true );
476
+                    $return = $this->import_row( $jdata, $wetu_id, $post_id, $team_members, $content );
477
+                    $this->format_completed_row( $return );
478
+                    $this->save_queue();
479
+                    $this->cleanup_posts();
480
+                    $this->attach_destination_images( $content );
481
+                    $this->clean_attached_destinations( $return );
482
+               } else {
483
+                    $this->format_error( esc_html__( 'There was a problem importing your tour, please try again.', 'lsx-wetu-importer' ) );
484
+               }
485
+          }
486
+     }
487
+
488
+     /**
489
+      * Amends the tours destinations instead of replace.
490
+      *
491
+      * @param $id string
492
+      * @return void
493
+      */
494
+     public function clean_attached_destinations( $id ) {
495
+          $current_connections = get_post_meta( $id, 'destination_to_tour', false );
496
+          delete_post_meta( $id, 'destination_to_tour' );
497
+          $current_connections = array_unique( $current_connections );
498
+
499
+          foreach ( $current_connections as $connection ) {
500
+               add_post_meta( $id, 'destination_to_tour', $connection, false );
501
+          }
502
+     }
503
+
504
+     /**
505
+      * Connect to wetu
506
+      *
507
+      * @param $data array
508
+      * @param $wetu_id string
509
+      */
510
+     public function import_row( $data, $wetu_id, $id = 0, $team_members = false, $importable_content = array(), $old1 = false, $old2 = false ) {
511
+          $post_name         = '';
512
+          $data_post_content = '';
513
+          $data_post_excerpt = '';
514
+
515
+          $current_post = get_post( $id );
516
+
517
+          $post = array(
518
+               'post_type' => 'tour',
519
+          );
520
+
521
+          $content_used_general_description = false;
522
+
523
+          if ( ! empty( $importable_content ) && in_array( 'description', $importable_content ) ) {
524
+               $data_post_content = $current_post->post_content;
525
+               if ( isset( $data['summary'] ) && ! empty( $data['summary'] ) ) {
526
+                    $data_post_content = $data['summary'];
527
+               }
528
+               $post['post_content'] = $data_post_content;
529
+          }
530
+
531
+          // Create or update the post.
532
+          if ( false !== $id && '0' !== $id ) {
533
+               $post['ID']          = $id;
534
+               $post['post_status'] = 'publish';
535
+               if ( isset( $this->options ) && 'on' !== $this->options['disable_accommodation_title'] ) {
536
+                    $post['post_title'] = $data['name'];
537
+               }
538
+               $id = wp_update_post( $post );
539
+          } else {
540
+               // Set the name.
541
+               if ( isset( $data['name'] ) ) {
542
+                    $post_name = wp_unique_post_slug( sanitize_title( $data['name'] ), $id, 'draft', 'tour', 0 );
543
+               }
544
+
545
+               if ( ! isset( $post['post_content'] ) ) {
546
+                    $post['post_content'] = ' ';
547
+               }
548
+
549
+               $post['post_name']   = $post_name;
550
+               $post['post_title']  = $data['name'];
551
+               $post['post_status'] = 'publish';
552
+               $id                  = wp_insert_post( $post );
553
+
554
+               // Save the WETU ID and the Last date it was modified.
555
+               if ( false !== $id ) {
556
+                    add_post_meta( $id, 'lsx_wetu_id', $wetu_id );
557
+                    add_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data['last_modified'] ) );
558
+               }
559
+          }
560
+
561
+          // Set reference number.
562
+          $this->set_reference_number( $data, $id );
563
+
564
+          // Set the team member if it is there.
565
+          if ( post_type_exists( 'team' ) && false !== $team_members && '' !== $team_members ) {
566
+               $this->set_team_member( $id, $team_members );
567
+          }
568
+
569
+          // Set the price.
570
+          if ( false !== $importable_content && in_array( 'price', $importable_content ) ) {
571
+               $this->set_price( $data, $id );
572
+          }
573
+
574
+          // Set the Duration.
575
+          if ( false !== $importable_content && in_array( 'duration', $importable_content ) ) {
576
+               $this->set_duration( $data, $id );
577
+          }
578
+
579
+          // Set the Group Size.
580
+          if ( false !== $importable_content && in_array( 'group_size', $importable_content ) ) {
581
+               $this->set_group_size( $data, $id );
582
+          }
583
+
584
+          // Set the Group Size.
585
+          if ( false !== $importable_content && in_array( 'tags', $importable_content ) ) {
586
+               $this->set_travel_styles( $id, $data );
587
+          }
588
+
589
+          // Set the Start and End Point Destinations.
590
+          if ( false !== $importable_content && in_array( 'start_end_point', $importable_content ) ) {
591
+               $this->set_start_end_point( $data, $id );
592
+          }
593
+
594
+          if ( false !== $importable_content && in_array( 'itineraries', $importable_content ) && isset( $data['legs'] ) && ! empty( $data['legs'] ) ) {
595
+               $this->process_itineraries( $data, $id, $importable_content );
596
+          }
597
+
598
+          if ( in_array( 'map', $importable_content ) && isset( $data['routes'] ) && ! empty( $data['routes'] ) ) {
599
+               $this->set_map_data( $data, $id );
600
+          }
601
+
602
+          return $id;
603
+     }
604
+
605
+     /**
606
+      * A loop which runs through each leg on the tour.
607
+      */
608
+     public function process_itineraries( $data, $id, $importable_content ) {
609
+          $day_counter = 1;
610
+          $leg_counter = 0;
611
+
612
+          delete_post_meta( $id, 'itinerary' );
613
+
614
+          if ( false !== $importable_content && in_array( 'accommodation', $importable_content ) ) {
615
+               delete_post_meta( $id, 'accommodation_to_tour' );
616
+          }
617
+
618
+          foreach ( $data['legs'] as $leg ) {
619
+
620
+               // Itinerary Accommodation.
621
+               $current_accommodation = false;
622
+               $current_destination   = false;
623
+               if ( 'Mobile' !== $leg['type'] ) {
624
+                    if ( false !== $importable_content && in_array( 'accommodation', $importable_content ) ) {
625
+                         $current_accommodation = $this->set_accommodation( $leg, $id );
626
+                    }
627
+                    if ( false !== $importable_content && in_array( 'destination', $importable_content ) ) {
628
+                         $current_destination = $this->set_destination( $leg, $id, $leg_counter );
629
+                    }
630
+               }
631
+
632
+               // If the Nights are the same mount of days in the array,  then it isnt "By Destination".
633
+               if ( ( 1 <= (int) $leg['nights'] && isset( $leg['periods'] ) ) || 0 === $leg['itinerary_leg_id'] ) {
634
+
635
+                    foreach ( $leg['periods'] as $day_key => $day ) {
636
+                         $current_day = array();
637
+
638
+                         // If this is a moble tented solution.
639
+                         $next_day_count = $day_counter + (int) $day['days'];
640
+
641
+                         if ( ( isset( $leg['stops'] ) && 'Mobile' !== $leg['type'] ) || ( 1 < (int) $day['days'] ) ) {
642
+                              $day_count_label = ' - ' . ( $next_day_count - 1 );
643
+                         } else {
644
+                              $day_count_label = '';
645
+                         }
646
+                         $current_day['title'] = esc_attr( 'Day ', 'lsx-wetu-importer' ) . $day_counter . $day_count_label;
647
+
648
+                         // Description.
649
+                         if ( false !== $importable_content && in_array( 'itinerary_description', $importable_content ) && isset( $day['notes'] ) ) {
650
+                              $current_day['description'] = $day['notes'];
651
+                         } else {
652
+                              $current_day['description'] = '';
653
+                         }
654
+
655
+                         // Itinerary Gallery.
656
+                         if ( false !== $importable_content && in_array( 'itinerary_gallery', $importable_content ) && isset( $day['images'] ) ) {
657
+                              $current_day['featured_image'] = '';
658
+                         } else {
659
+                              $current_day['featured_image'] = '';
660
+                         }
661
+
662
+                         // If its a mobile safari, we need to get the destination and accommodation data from the stops.
663
+                         if ( 'Mobile' === $leg['type'] ) {
664
+                              $current_destination   = $this->get_mobile_destination( $day, $leg, $id );
665
+                              $current_accommodation = $this->get_mobile_accommodation( $day, $leg, $id );
666
+                         }
667
+
668
+                         // Accommodation.
669
+                         if ( false !== $current_accommodation ) {
670
+                              $current_day['accommodation_to_tour'] = array( $current_accommodation );
671
+                         } else {
672
+                              $current_day['accommodation_to_tour'] = array();
673
+                         }
674
+
675
+                         // Destination.
676
+                         if ( false !== $current_destination ) {
677
+                              $current_day['destination_to_tour'] = array( $current_destination );
678
+                         } else {
679
+                              $current_day['destination_to_tour'] = array();
680
+                         }
681
+
682
+                         // Included.
683
+                         if ( false !== $importable_content && in_array( 'itinerary_included', $importable_content ) && isset( $day['included'] ) && '' !== $day['included'] ) {
684
+                              $current_day['included'] = $day['included'];
685
+                         } else {
686
+                              $current_day['included'] = '';
687
+                         }
688
+
689
+                         // Excluded.
690
+                         if ( false !== $importable_content && in_array( 'itinerary_excluded', $importable_content ) && isset( $day['excluded'] ) && '' !== $day['excluded'] ) {
691
+                              $current_day['excluded'] = $day['excluded'];
692
+                         } else {
693
+                              $current_day['excluded'] = '';
694
+                         }
695
+
696
+                         // Excluded.
697
+                         if ( false !== $importable_content && in_array( 'room_basis', $importable_content ) && isset( $day['room_basis'] ) && '' !== $day['room_basis'] ) {
698
+                              $current_day['room_basis'] = $day['room_basis'];
699
+                         } else {
700
+                              $current_day['room_basis'] = '';
701
+                         }
702
+
703
+                         // Excluded.
704
+                         if ( false !== $importable_content && in_array( 'drinks_basis', $importable_content ) && isset( $day['drinks_basis'] ) && '' !== $day['drinks_basis'] ) {
705
+                              $current_day['drinks_basis'] = $day['drinks_basis'];
706
+                         } else {
707
+                              $current_day['drinks_basis'] = '';
708
+                         }
709
+
710
+                         $this->set_itinerary_day( $current_day, $id );
711
+                         $day_counter = $next_day_count;
712
+                    }
713
+               } else {
714
+                    // This is for the by destination.
715
+
716
+                    $current_day     = array();
717
+                    $next_day_count  = $day_counter + (int) $leg['nights'];
718
+                    $day_count_label = $next_day_count - 1;
719
+
720
+                    $current_day['title'] = esc_attr( 'Day ', 'lsx-wetu-importer' ) . $day_counter;
721
+
722
+                    if ( 0 !== (int) $leg['nights'] ) {
723
+                         $current_day['title'] .= ' - ' . $day_count_label;
724
+                    }
725
+
726
+                    // Description.
727
+                    if ( false !== $importable_content && in_array( 'itinerary_description', $importable_content ) && isset( $leg['notes'] ) ) {
728
+                         $current_day['description'] = $leg['notes'];
729
+                    } else {
730
+                         $current_day['description'] = '';
731
+                    }
732
+
733
+                    // Itinerary Gallery.
734
+                    if ( false !== $importable_content && in_array( 'itinerary_gallery', $importable_content ) && isset( $leg['images'] ) ) {
735
+                         $current_day['featured_image'] = '';
736
+                    } else {
737
+                         $current_day['featured_image'] = '';
738
+                    }
739
+
740
+                    // Accommodation.
741
+                    if ( false !== $current_accommodation ) {
742
+                         $current_day['accommodation_to_tour'] = array( $current_accommodation );
743
+                    } else {
744
+                         $current_day['accommodation_to_tour'] = array();
745
+                    }
746
+
747
+                    // Destination.
748
+                    if ( false !== $current_destination ) {
749
+                         $current_day['destination_to_tour'] = array( $current_destination );
750
+                    } else {
751
+                         $current_day['destination_to_tour'] = array();
752
+                    }
753
+
754
+                    // Included.
755
+                    if ( false !== $importable_content && in_array( 'itinerary_included', $importable_content ) && isset( $leg['included'] ) && '' !== $leg['included'] ) {
756
+                         $current_day['included'] = $leg['included'];
757
+                    } else {
758
+                         $current_day['included'] = '';
759
+                    }
760
+
761
+                    // Excluded.
762
+                    if ( false !== $importable_content && in_array( 'itinerary_excluded', $importable_content ) && isset( $leg['excluded'] ) && '' !== $leg['excluded'] ) {
763
+                         $current_day['excluded'] = $leg['excluded'];
764
+                    } else {
765
+                         $current_day['excluded'] = '';
766
+                    }
767
+
768
+                    // Excluded.
769
+                    if ( false !== $importable_content && in_array( 'room_basis', $importable_content ) && isset( $leg['room_basis'] ) && '' !== $leg['room_basis'] ) {
770
+                         $current_day['room_basis'] = $leg['room_basis'];
771
+                    } else {
772
+                         $current_day['room_basis'] = '';
773
+                    }
774
+
775
+                    // Excluded.
776
+                    if ( false !== $importable_content && in_array( 'drinks_basis', $importable_content ) && isset( $leg['drinks_basis'] ) && '' !== $leg['drinks_basis'] ) {
777
+                         $current_day['drinks_basis'] = $leg['drinks_basis'];
778
+                    } else {
779
+                         $current_day['drinks_basis'] = '';
780
+                    }
781
+
782
+                    $this->set_itinerary_day( $current_day, $id );
783
+                    $day_counter = $next_day_count;
784
+               }
785
+               $leg_counter++;
786
+          }
787
+     }
788
+
789
+     /**
790
+      * Sets the departs from and ends in points on the tours.
791
+      *
792
+      * @param array  $data
793
+      * @param string $id
794
+      * @return void
795
+      */
796
+     public function set_start_end_point( $data, $id ) {
797
+          delete_post_meta( $id, 'departs_from' );
798
+          delete_post_meta( $id, 'ends_in' );
799
+          $departs_from = false;
800
+          $ends_in      = false;
801
+
802
+          $args = array(
803
+               'points'      => $data['legs'],
804
+               'start_index' => 0,
805
+               'end_index'   => count( $data['legs'] ) - 2,
806
+          );
807
+          $args = apply_filters( 'lsx_wetu_start_end_args', $args, $data );
808
+
809
+          if ( ! empty( $args['points'] ) && is_array( $args['points'] ) ) {
810
+               $leg_counter = 0;
811
+
812
+               foreach ( $args['points'] as $point ) {
813
+                    // If we are in the first leg,  and the destination was attached then save it as the departure field.
814
+                    if ( $leg_counter === $args['start_index'] ) {
815
+                         $departs_from_destination = $this->set_country( $point['destination_content_entity_id'], $id );
816
+                         if ( false !== $departs_from_destination ) {
817
+                              $departs_from = $departs_from_destination;
818
+                         }
819
+                    }
820
+                    // If its the last leg then save it as the ends in.
821
+                    if ( $leg_counter === $args['end_index'] ) {
822
+                         $ends_in = $point['destination_content_entity_id'];
823
+                    }
824
+                    $leg_counter++;
825
+               }
826
+
827
+               $departs_from = apply_filters( 'lsx_wetu_departs_from_id', $departs_from, $data, $this );
828
+               if ( false !== $departs_from ) {
829
+                    add_post_meta( $id, 'departs_from', $departs_from, true );
830
+               }
831
+
832
+               if ( false !== $ends_in ) {
833
+                    $ends_in             = apply_filters( 'lsx_wetu_ends_in_id', $ends_in, $data, $this );
834
+                    $ends_in_destination = $this->set_country( $ends_in, $id );
835
+                    if ( false !== $ends_in_destination ) {
836
+                         add_post_meta( $id, 'ends_in', $ends_in_destination, true );
837
+                    }
838
+               }
839
+          }
840
+     }
841
+
842
+     /**
843
+      * Gets the destination for the mobile camp.
844
+      *
845
+      * @param $day
846
+      * @param $leg
847
+      * @return void
848
+      */
849
+     public function get_mobile_destination( $day, $leg, $id ) {
850
+          $current_destination = false;
851
+          $current_day         = (int) $day['period_start_day'];
852
+          if ( isset( $leg['stops'] ) ) {
853
+               foreach ( $leg['stops'] as $stop ) {
854
+                    $arrival_day   = (int) $stop['arrival_day'];
855
+                    $departure_day = (int) $stop['departure_day'];
856
+                    if ( $arrival_day <= $current_day && $current_day < $departure_day ) {
857
+                         $current_destination = $this->set_destination( $stop, $id, 0 );
858
+                    }
859
+               }
860
+          }
861
+          return $current_destination;
862
+     }
863
+
864
+     /**
865
+      * Gets the accommodation for the mobile camp.
866
+      *
867
+      * @param $day
868
+      * @param $leg
869
+      * @return void
870
+      */
871
+     public function get_mobile_accommodation( $day, $leg, $id ) {
872
+          $current_accommodation = false;
873
+          $current_day           = (int) $day['period_start_day'];
874
+          if ( isset( $leg['stops'] ) ) {
875
+               foreach ( $leg['stops'] as $stop ) {
876
+                    $arrival_day   = (int) $stop['arrival_day'];
877
+                    $departure_day = (int) $stop['departure_day'];
878
+                    if ( $arrival_day <= $current_day && $current_day < $departure_day ) {
879
+                         $current_accommodation = $this->set_accommodation( $stop, $id, 0 );
880
+                    }
881
+               }
882
+          }
883
+          return $current_accommodation;
884
+     }
885
+
886
+     /**
887
+      * Run through your routes and save the points as a KML file.
888
+      */
889
+     public function set_map_data( $data, $id, $zoom = 9 ) {
890
+          if ( ! empty( $data['routes'] ) ) {
891
+               delete_post_meta( $id, 'wetu_map_points' );
892
+
893
+               $points = array();
894
+
895
+               foreach ( $data['routes'] as $route ) {
896
+
897
+                    if ( isset( $route['points'] ) && '' !== $route['points'] ) {
898
+
899
+                         $temp_points   = explode( ';', $route['points'] );
900
+                         $point_counter = count( $temp_points );
901
+
902
+                         for ( $x = 0; $x <= $point_counter; $x++ ) {
903
+                              $y        = $x + 1;
904
+                              $points[] = $temp_points[ $x ] . ',' . $temp_points[ $y ];
905
+                              $x++;
906
+                         }
907
+                    }
908
+               }
909
+
910
+               if ( ! empty( $points ) ) {
911
+                    $this->save_custom_field( implode( ' ', $points ), 'wetu_map_points', $id, false, true );
912
+               }
913
+          }
914
+
915
+     }
916
+
917
+     // CLASS SPECIFIC FUNCTIONS.
918
+
919
+     /**
920
+      * Set the Itinerary Day.
921
+      */
922
+     public function set_itinerary_day( $day, $id ) {
923
+          $this->save_custom_field( $day, 'itinerary', $id, false, false );
924
+     }
925
+
926
+     /**
927
+      * Set the ref number
928
+      */
929
+     public function set_reference_number( $data, $id ) {
930
+          if ( isset( $data['reference_number'] ) && '' !== $data['reference_number'] ) {
931
+               $this->save_custom_field( $data['reference_number'], 'lsx_wetu_ref', $id );
932
+          }
933
+     }
934
+
935
+     /**
936
+      * Set the price.
937
+      */
938
+     public function set_price( $data, $id ) {
939
+          // Price.
940
+          if ( isset( $data['price'] ) && '' !== $data['price'] ) {
941
+               $price = $data['price'];
942
+               if ( false === apply_filters( 'lsx_wetu_importer_disable_tour_price_filter', false ) ) {
943
+                    $price = preg_replace( '/[^0-9,.]/', '', $price );
944
+               }
945
+               $meta_key = apply_filters( 'lsx_wetu_importer_price_meta_key', 'price' );
946
+               $this->save_custom_field( $price, $meta_key, $id );
947
+          }
948
+
949
+          // Price includes.
950
+          if ( isset( $data['price_includes'] ) && '' !== $data['price_includes'] ) {
951
+               $meta_key = apply_filters( 'lsx_wetu_importer_included_meta_key', 'included' );
952
+               $this->save_custom_field( $data['price_includes'], $meta_key, $id );
953
+          }
954
+
955
+          // Price Excludes.
956
+          if ( isset( $data['price_excludes'] ) && '' !== $data['price_excludes'] ) {
957
+               $meta_key = apply_filters( 'lsx_wetu_importer_not_included_meta_key', 'not_included' );
958
+               $this->save_custom_field( $data['price_excludes'], $meta_key, $id );
959
+          }
960
+     }
961
+
962
+     /**
963
+      * Set the duration.
964
+      */
965
+     public function set_duration( $data, $id ) {
966
+          if ( isset( $data['days'] ) && ! empty( $data['days'] ) ) {
967
+               $price = $data['days'];
968
+               $price = preg_replace( '/[^0-9,.]/', '', $price );
969
+               $this->save_custom_field( $price, 'duration', $id );
970
+          }
971
+     }
972
+
973
+     /**
974
+      * Set the group size
975
+      */
976
+     public function set_group_size( $data, $id ) {
977
+          if ( isset( $data['group_size'] ) && ! empty( $data['group_size'] ) ) {
978
+               $group_size = $data['group_size'];
979
+               $this->save_custom_field( $group_size, 'group_size', $id );
980
+          }
981
+     }
982
+
983
+     /**
984
+      * Takes the WETU tags and sets the Travel Styles.
985
+      *
986
+      * @param string $id
987
+      * @param array  $travel_styles
988
+      * @return void
989
+      */
990
+     public function set_travel_styles( $id, $data ) {
991
+          $tags = apply_filters( 'lsx_wetu_importer_tour_travel_styles', $data['tags'] );
992
+          if ( isset( $data['tags'] ) && ! empty( $tags ) ) {
993
+               foreach ( $tags as $tag ) {
994
+                    $this->set_term( $id, $tag, 'travel-style' );
995
+               }
996
+          }
997
+     }
998
+
999
+     /**
1000
+      * Connects the Accommodation if its available
1001
+      */
1002
+     public function set_accommodation( $day, $id ) {
1003
+          $ac_id                       = false;
1004
+          $this->current_accommodation = $this->find_current_accommodation();
1005
+
1006
+          if ( isset( $day['content_entity_id'] ) && ! empty( $day['content_entity_id'] ) && ! in_array( (int) $day['content_entity_id'], array( 25862 ) ) ) {
1007
+               if ( false !== $this->current_accommodation && ! empty( $this->current_accommodation ) && array_key_exists( $day['content_entity_id'], $this->current_accommodation ) ) {
1008
+                    $ac_id = $this->current_accommodation[ $day['content_entity_id'] ];
1009
+               } else {
1010
+                    $ac_id = wp_insert_post(
1011
+                         array(
1012
+                              'post_type'   => 'accommodation',
1013
+                              'post_status' => 'draft',
1014
+                              'post_title'  => $day['content_entity_id'],
1015
+                         )
1016
+                    );
1017
+
1018
+                    $this->save_custom_field( $day['content_entity_id'], 'lsx_wetu_id', $ac_id );
1019
+               }
1020
+
1021
+               if ( '' !== $ac_id && false !== $ac_id ) {
1022
+                    $this->save_custom_field( $ac_id, 'accommodation_to_tour', $id, false, false );
1023
+                    $this->save_custom_field( $id, 'tour_to_accommodation', $ac_id, false, false );
1024
+                    $this->queue_item( $ac_id );
1025
+               }
1026
+          }
1027
+          return $ac_id;
1028
+     }
1029
+
1030
+     /**
1031
+      * Grab all the current accommodation posts via the lsx_wetu_id field.
1032
+      *
1033
+      * @param $post_type string
1034
+      * @return boolean / array
1035
+      */
1036
+     public function find_current_accommodation( $post_type = 'accommodation' ) {
1037
+          global $wpdb;
1038
+          $accommodation = parent::find_current_accommodation( $post_type );
1039
+          $return        = false;
1040
+
1041
+          if ( ! empty( $accommodation ) ) {
1042
+               foreach ( $accommodation as $key => $acc ) {
1043
+                    $return[ $acc->meta_value ] = $acc->post_id;
1044
+               }
1045
+          }
1046
+
1047
+          return $return;
1048
+     }
1049
+
1050
+     /**
1051
+      * Grab all the current accommodation posts via the lsx_wetu_id field.
1052
+      *
1053
+      * @return boolean / array
1054
+      */
1055
+     public function find_current_destinations() {
1056
+          return $this->find_current_accommodation( 'destination' );
1057
+     }
1058
+
1059
+     /**
1060
+      * Connects the destinations post type
1061
+      *
1062
+      * @param $day array
1063
+      * @param $id string
1064
+      * @return boolean / string
1065
+      */
1066
+     public function set_destination( $day, $id, $leg_counter ) {
1067
+          $dest_id    = false;
1068
+          $country_id = false;
1069
+
1070
+          $this->current_destinations = $this->find_current_destinations();
1071
+
1072
+          if ( isset( $day['destination_content_entity_id'] ) && ! empty( $day['destination_content_entity_id'] ) ) {
1073
+               if ( false !== $this->current_destinations && ! empty( $this->current_destinations ) && array_key_exists( $day['destination_content_entity_id'], $this->current_destinations ) ) {
1074
+                    $dest_id = $this->current_destinations[ $day['destination_content_entity_id'] ];
1075
+
1076
+                    // TODO Check for attachments here.
1077
+                    $this->destination_images[ $id ][] = array( $dest_id, $day['destination_content_entity_id'] );
1078
+
1079
+                    // Check if there is a country asigned.
1080
+                    $potential_id    = wp_get_post_parent_id( $dest_id );
1081
+                    $country_wetu_id = get_post_meta( $potential_id, 'lsx_wetu_id', true );
1082
+
1083
+                    if ( false !== $country_wetu_id ) {
1084
+                         $country_id = $this->set_country( $country_wetu_id, $id );
1085
+                         // $this->destination_images[ $id ][] = array( $id, $country_wetu_id );
1086
+                    }
1087
+               } else {
1088
+                    $destination_json = wp_remote_get( 'https://wetu.com/API/Pins/' . $this->api_key . '/Get?ids=' . $day['destination_content_entity_id'] );
1089
+
1090
+                    if ( ! is_wp_error( $destination_json ) && ! empty( $destination_json ) && isset( $destination_json['response'] ) && isset( $destination_json['response']['code'] ) && 200 === $destination_json['response']['code'] ) {
1091
+
1092
+                         $destination_data = json_decode( $destination_json['body'], true );
1093
+
1094
+                         if ( ! empty( $destination_data ) && ! isset( $destination_data['error'] ) ) {
1095
+                              $destination_title = $day['destination_content_entity_id'];
1096
+
1097
+                              if ( isset( $destination_data[0]['name'] ) ) {
1098
+                                   $destination_title = $destination_data[0]['name'];
1099
+                              }
1100
+
1101
+                              if ( isset( $destination_data[0]['map_object_id'] ) && isset( $destination_data[0]['position']['country_content_entity_id'] )
1102
+                                   && $destination_data[0]['map_object_id'] !== $destination_data[0]['position']['country_content_entity_id'] ) {
1103
+
1104
+                                   $country_id = $this->set_country( $destination_data[0]['position']['country_content_entity_id'], $id );
1105
+                                   // Save the destination so we can grab the tour featured image and banner from them.
1106
+                              }
1107
+
1108
+                              $dest_post = array(
1109
+                                   'post_type'   => 'destination',
1110
+                                   'post_status' => 'draft',
1111
+                                   'post_title'  => $destination_title,
1112
+                              );
1113
+
1114
+                              if ( false !== $country_id ) {
1115
+                                   $dest_post['post_parent'] = $country_id;
1116
+                              }
1117
+                              $dest_id = wp_insert_post( $dest_post );
1118
+
1119
+                              // Make sure we register the.
1120
+                              $this->current_destinations[ $day['destination_content_entity_id'] ] = $dest_id;
1121
+
1122
+                              // If there are images attached then use the destination.
1123
+                              if ( isset( $destination_data[0]['content']['images'] ) && ! empty( $destination_data[0]['content']['images'] ) ) {
1124
+                                   $this->destination_images[ $id ][] = array( $dest_id, $day['destination_content_entity_id'] );
1125
+                              }
1126
+
1127
+                              $this->save_custom_field( $day['destination_content_entity_id'], 'lsx_wetu_id', $dest_id );
1128
+                         }
1129
+                    }
1130
+               }
1131
+
1132
+               if ( '' !== $dest_id && false !== $dest_id ) {
1133
+                    $this->save_custom_field( $dest_id, 'destination_to_tour', $id, false, false );
1134
+                    $this->save_custom_field( $id, 'tour_to_destination', $dest_id, false, false );
1135
+
1136
+                    // Save the item to display in the queue
1137
+                    $this->queue_item( $dest_id );
1138
+
1139
+                    // Save the item to clean up the amount of connections.
1140
+                    $this->cleanup_posts[ $dest_id ] = 'tour_to_destination';
1141
+
1142
+                    // Add this relation info so we can make sure certain items are set as countries.
1143
+                    if ( 0 !== $country_id && false !== $country_id ) {
1144
+                         $this->relation_meta[ $dest_id ]    = $country_id;
1145
+                         $this->relation_meta[ $country_id ] = 0;
1146
+                    } else {
1147
+                         $this->relation_meta[ $dest_id ] = 0;
1148
+                    }
1149
+               }
1150
+          }
1151
+          return $dest_id;
1152
+     }
1153
+
1154
+     /**
1155
+      * Connects the destinations post type
1156
+      *
1157
+      * @param $dest_id string
1158
+      * @param $country_id array
1159
+      * @param $id string
1160
+      *
1161
+      * @return string
1162
+      */
1163
+     public function set_country( $country_wetu_id, $id ) {
1164
+          $country_id                 = false;
1165
+          $this->current_destinations = $this->find_current_destinations();
1166
+
1167
+          if ( false !== $this->current_destinations && ! empty( $this->current_destinations ) && array_key_exists( $country_wetu_id, $this->current_destinations ) ) {
1168
+               $country_id                        = $this->current_destinations[ $country_wetu_id ];
1169
+               $this->destination_images[ $id ][] = array( $country_id, $country_wetu_id );
1170
+          } else {
1171
+               $country_json = wp_remote_get( 'https://wetu.com/API/Pins/' . $this->api_key . '/Get?ids=' . $country_wetu_id );
1172
+
1173
+               if ( ! is_wp_error( $country_json ) && ! empty( $country_json ) && isset( $country_json['response'] ) && isset( $country_json['response']['code'] ) && 200 === $country_json['response']['code'] ) {
1174
+                    $country_data = json_decode( $country_json['body'], true );
1175
+
1176
+                    // Format the title of the destination if its available,  otherwise default to the WETU ID.
1177
+                    $country_title = $country_wetu_id;
1178
+
1179
+                    if ( isset( $country_data[0]['name'] ) ) {
1180
+                         $country_title = $country_data[0]['name'];
1181
+                    }
1182
+
1183
+                    $country_id = wp_insert_post(
1184
+                         array(
1185
+                              'post_type'   => 'destination',
1186
+                              'post_status' => 'draft',
1187
+                              'post_title'  => $country_title,
1188
+                         )
1189
+                    );
1190
+
1191
+                    // add the country to the current destination stack
1192
+                    $this->current_destinations[ $country_wetu_id ] = $country_id;
1193
+
1194
+                    // Check if there are images and save fore use later.
1195
+                    if ( isset( $country_data[0]['content']['images'] ) && ! empty( $country_data[0]['content']['images'] ) ) {
1196
+                         $this->destination_images[ $id ][] = array( $country_id, $country_wetu_id );
1197
+                    }
1198
+
1199
+                    // Save the wetu field
1200
+                    $this->save_custom_field( $country_wetu_id, 'lsx_wetu_id', $country_id );
1201
+               }
1202
+          }
1203
+
1204
+          if ( '' !== $country_id && false !== $country_id ) {
1205
+               $this->save_custom_field( $country_id, 'destination_to_tour', $id, false, false );
1206
+               $this->save_custom_field( $id, 'tour_to_destination', $country_id, false, false );
1207
+               $this->queue_item( $country_id );
1208
+               $this->cleanup_posts[ $country_id ] = 'tour_to_destination';
1209
+
1210
+               return $country_id;
1211
+          }
1212
+     }
1213
+
1214
+     /**
1215
+      * Connects the destinations post type
1216
+      *
1217
+      * @param $dest_id string
1218
+      * @param $country_id array
1219
+      * @param $id string
1220
+      *
1221
+      * @return string
1222
+      */
1223
+     public function attach_destination_images( $importable_content = array() ) {
1224
+          if ( false !== $this->destination_images ) {
1225
+               $this->shuffle_assoc( $this->destination_images );
1226
+               foreach ( $this->destination_images as $tour => $destinations ) {
1227
+                    shuffle( $destinations );
1228
+                    $image_set = false;
1229
+                    $forced    = false;
1230
+
1231
+                    foreach ( $destinations as $destination ) {
1232
+                         if ( false === $image_set && false === $forced ) {
1233
+                              $url = 'https://wetu.com/API/Pins/' . $this->api_key;
1234
+
1235
+                              $url_qs = '';
1236
+                              $jdata  = wp_remote_get( $url . '/Get?' . $url_qs . '&ids=' . $destination[1] );
1237
+
1238
+                              if ( ! is_wp_error( $jdata ) && ! empty( $jdata ) && isset( $jdata['response'] ) && isset( $jdata['response']['code'] ) && 200 === $jdata['response']['code'] ) {
1239
+                                   $adata = json_decode( $jdata['body'], true );
1240
+
1241
+                                   if ( ! empty( $adata ) && ! empty( $adata[0]['content']['images'] ) ) {
1242
+                                        $this->find_attachments( $destination[0] );
1243
+
1244
+                                        // Set the featured image.
1245
+                                        if ( false !== $importable_content && in_array( 'featured_image', $importable_content ) ) {
1246
+                                             $image_set = $this->set_featured_image( $adata, $tour );
1247
+                                             if ( false !== $importable_content && in_array( 'banner_image', $importable_content ) ) {
1248
+                                                  $image_set = $this->set_banner_image( $adata, $tour );
1249
+                                                  $forced    = true;
1250
+                                             }
1251
+                                             continue;
1252
+                                        }
1253
+                                        if ( false !== $importable_content && in_array( 'banner_image', $importable_content ) ) {
1254
+                                             $image_set = $this->set_banner_image( $adata, $tour );
1255
+                                        }
1256
+                                   }
1257
+                              }
1258
+                         } else {
1259
+                              continue;
1260
+                         }
1261
+                    }
1262
+               }
1263
+          }
1264
+     }
1265
+
1266
+     /**
1267
+      * Creates the main gallery data
1268
+      */
1269
+     public function set_featured_image( $data, $id ) {
1270
+          $image_set = false;
1271
+          $counter   = 0;
1272
+
1273
+          if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) {
1274
+               $images_array = $data[0]['content']['images'];
1275
+
1276
+               if ( 'on' === $this->options['enable_tour_featured_random'] ) {
1277
+                    shuffle( $images_array );
1278
+               }
1279
+
1280
+               foreach ( $images_array as $v ) {
1281
+
1282
+                    if ( true === $image_set ) {
1283
+                         $counter++;
1284
+                         continue;
1285
+                    }
1286
+
1287
+                    if ( ! $this->check_if_image_is_used( $v ) ) {
1288
+                         $temp_featured_image = $this->attach_image( $v, $id );
1289
+
1290
+                         if ( false !== $temp_featured_image ) {
1291
+                              $this->featured_image = $temp_featured_image;
1292
+                              delete_post_meta( $id, '_thumbnail_id' );
1293
+                              add_post_meta( $id, '_thumbnail_id', $this->featured_image, true );
1294
+                              $image_set = true;
1295
+                         }
1296
+                    }
1297
+
1298
+                    $counter++;
1299
+               }
1300
+          }
1301
+          return $image_set;
1302
+     }
1303
+
1304
+     /**
1305
+      * Sets a banner image
1306
+      */
1307
+     public function set_banner_image( $data, $id, $content = array( 'none' ) ) {
1308
+          $image_set = false;
1309
+          $counter   = 0;
1310
+
1311
+          if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) {
1312
+
1313
+               foreach ( $data[0]['content']['images'] as $v ) {
1314
+                    /*
1315 1315
 				print_r('<pre>');
1316 1316
 				print_r( $v );
1317 1317
 				print_r('</pre>');*/
1318 1318
 
1319
-				if ( true === $image_set || 0 === $counter ) {
1320
-					$counter++;
1321
-					continue;
1322
-				}
1323
-
1324
-				if ( ! $this->check_if_image_is_used( $v ) ) {
1325
-					$temp_banner = $this->attach_image(
1326
-						$v,
1327
-						$id,
1328
-						array(
1329
-							'width'    => '1920',
1330
-							'height'   => '600',
1331
-							'cropping' => 'c',
1332
-						)
1333
-					);
1334
-
1335
-					if ( false !== $temp_banner ) {
1336
-						$this->banner_image = $temp_banner;
1337
-
1338
-						delete_post_meta( $id, 'image_group' );
1339
-
1340
-						$new_banner = array(
1341
-							'banner_image' => array(
1342
-								'cmb-field-0' => $this->banner_image,
1343
-							),
1344
-						);
1345
-						add_post_meta( $id, 'image_group', $new_banner, true );
1346
-						$image_set = true;
1347
-					}
1348
-				}
1349
-				$counter++;
1350
-			}
1351
-		}
1352
-
1353
-		return $image_set;
1354
-	}
1355
-
1356
-	/**
1357
-	 * Grabs all of the current used featured images on the site.
1358
-	 */
1359
-	public function check_if_image_is_used( $v ) {
1360
-		global $wpdb;
1361
-		$return = false;
1362
-
1363
-		$results        = $wpdb->get_results(
1364
-			$wpdb->prepare(
1365
-				"SELECT post_id
1319
+                    if ( true === $image_set || 0 === $counter ) {
1320
+                         $counter++;
1321
+                         continue;
1322
+                    }
1323
+
1324
+                    if ( ! $this->check_if_image_is_used( $v ) ) {
1325
+                         $temp_banner = $this->attach_image(
1326
+                              $v,
1327
+                              $id,
1328
+                              array(
1329
+                                   'width'    => '1920',
1330
+                                   'height'   => '600',
1331
+                                   'cropping' => 'c',
1332
+                              )
1333
+                         );
1334
+
1335
+                         if ( false !== $temp_banner ) {
1336
+                              $this->banner_image = $temp_banner;
1337
+
1338
+                              delete_post_meta( $id, 'image_group' );
1339
+
1340
+                              $new_banner = array(
1341
+                                   'banner_image' => array(
1342
+                                        'cmb-field-0' => $this->banner_image,
1343
+                                   ),
1344
+                              );
1345
+                              add_post_meta( $id, 'image_group', $new_banner, true );
1346
+                              $image_set = true;
1347
+                         }
1348
+                    }
1349
+                    $counter++;
1350
+               }
1351
+          }
1352
+
1353
+          return $image_set;
1354
+     }
1355
+
1356
+     /**
1357
+      * Grabs all of the current used featured images on the site.
1358
+      */
1359
+     public function check_if_image_is_used( $v ) {
1360
+          global $wpdb;
1361
+          $return = false;
1362
+
1363
+          $results        = $wpdb->get_results(
1364
+               $wpdb->prepare(
1365
+                    "SELECT post_id
1366 1366
 				 FROM {$wpdb->postmeta}
1367 1367
 				 WHERE meta_value = '%s'
1368 1368
 				 AND meta_key = 'lsx_wetu_id'
1369 1369
 				",
1370
-				array( $value )
1371
-			)
1372
-		);
1373
-		$attached_tours = array();
1374
-		if ( ! empty( $results ) ) {
1375
-			foreach ( $results as $result ) {
1376
-				if ( 'tour' === get_post_type( $result['post_id'] ) ) {
1377
-					$attached_tours[] = $result['post_id'];
1378
-				}
1379
-			}
1380
-		}
1381
-		if ( ! empty( $attached_tours ) ) {
1382
-			$return = true;
1383
-		}
1384
-		return $return;
1385
-	}
1386
-
1387
-	/**
1388
-	 * Que an item to be saved.
1389
-	 *
1390
-	 * @param   $id     int
1391
-	 */
1392
-	public function queue_item( $id ) {
1393
-		if ( is_array( $this->import_queue ) && ! in_array( $id, $this->import_queue ) ) {
1394
-			$this->import_queue[] = $id;
1395
-		} else {
1396
-			$this->import_queue[] = $id;
1397
-		}
1398
-	}
1399
-
1400
-	/**
1401
-	 * Saves the queue to the option.
1402
-	 */
1403
-	public function save_queue() {
1404
-		if ( ! empty( $this->import_queue ) ) {
1405
-			if ( ! empty( $this->queued_imports ) ) {
1406
-				$saved_imports = array_merge( $this->queued_imports, $this->import_queue );
1407
-			} else {
1408
-				$saved_imports = $this->import_queue;
1409
-			}
1410
-
1411
-			delete_option( 'lsx_wetu_importer_que' );
1412
-
1413
-			if ( ! empty( $saved_imports ) ) {
1414
-				$saved_imports = array_unique( $saved_imports );
1415
-				update_option( 'lsx_wetu_importer_que', $saved_imports );
1416
-			}
1417
-		}
1418
-	}
1419
-
1420
-	/**
1421
-	 * The header of the item list
1422
-	 */
1423
-	public function table_header() {
1424
-		?>
1370
+                    array( $value )
1371
+               )
1372
+          );
1373
+          $attached_tours = array();
1374
+          if ( ! empty( $results ) ) {
1375
+               foreach ( $results as $result ) {
1376
+                    if ( 'tour' === get_post_type( $result['post_id'] ) ) {
1377
+                         $attached_tours[] = $result['post_id'];
1378
+                    }
1379
+               }
1380
+          }
1381
+          if ( ! empty( $attached_tours ) ) {
1382
+               $return = true;
1383
+          }
1384
+          return $return;
1385
+     }
1386
+
1387
+     /**
1388
+      * Que an item to be saved.
1389
+      *
1390
+      * @param   $id     int
1391
+      */
1392
+     public function queue_item( $id ) {
1393
+          if ( is_array( $this->import_queue ) && ! in_array( $id, $this->import_queue ) ) {
1394
+               $this->import_queue[] = $id;
1395
+          } else {
1396
+               $this->import_queue[] = $id;
1397
+          }
1398
+     }
1399
+
1400
+     /**
1401
+      * Saves the queue to the option.
1402
+      */
1403
+     public function save_queue() {
1404
+          if ( ! empty( $this->import_queue ) ) {
1405
+               if ( ! empty( $this->queued_imports ) ) {
1406
+                    $saved_imports = array_merge( $this->queued_imports, $this->import_queue );
1407
+               } else {
1408
+                    $saved_imports = $this->import_queue;
1409
+               }
1410
+
1411
+               delete_option( 'lsx_wetu_importer_que' );
1412
+
1413
+               if ( ! empty( $saved_imports ) ) {
1414
+                    $saved_imports = array_unique( $saved_imports );
1415
+                    update_option( 'lsx_wetu_importer_que', $saved_imports );
1416
+               }
1417
+          }
1418
+     }
1419
+
1420
+     /**
1421
+      * The header of the item list
1422
+      */
1423
+     public function table_header() {
1424
+          ?>
1425 1425
 		<thead>
1426 1426
 		<tr>
1427 1427
 			<th class="manage-column column-cb check-column" id="cb" scope="col">
@@ -1436,13 +1436,13 @@  discard block
 block discarded – undo
1436 1436
 		</tr>
1437 1437
 		</thead>
1438 1438
 		<?php
1439
-	}
1439
+     }
1440 1440
 
1441
-	/**
1442
-	 * The footer of the item list
1443
-	 */
1444
-	public function table_footer() {
1445
-		?>
1441
+     /**
1442
+      * The footer of the item list
1443
+      */
1444
+     public function table_footer() {
1445
+          ?>
1446 1446
 		<tfoot>
1447 1447
 		<tr>
1448 1448
 			<th class="manage-column column-cb check-column" id="cb" scope="col">
@@ -1457,5 +1457,5 @@  discard block
 block discarded – undo
1457 1457
 		</tr>
1458 1458
 		</tfoot>
1459 1459
 		<?php
1460
-	}
1460
+     }
1461 1461
 }
Please login to merge, or discard this patch.
Spacing   +439 added lines, -439 removed lines patch added patch discarded remove patch
@@ -97,12 +97,12 @@  discard block
 block discarded – undo
97 97
 	 */
98 98
 	public function set_variables() {
99 99
 		parent::set_variables();
100
-		if ( false !== $this->api_key ) {
101
-			$this->url    = 'https://wetu.com/API/Itinerary/' . $this->api_key;
100
+		if (false !== $this->api_key) {
101
+			$this->url    = 'https://wetu.com/API/Itinerary/'.$this->api_key;
102 102
 			$this->url_qs = '';
103 103
 		}
104
-		$tour_options = get_option( 'lsx_wetu_importer_tour_settings', false );
105
-		if ( false !== $tour_options ) {
104
+		$tour_options = get_option('lsx_wetu_importer_tour_settings', false);
105
+		if (false !== $tour_options) {
106 106
 			$this->tour_options = $tour_options;
107 107
 		}
108 108
 	}
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 			</div>
127 127
 
128 128
 			<form method="get" action="" id="posts-filter">
129
-				<input type="hidden" name="post_type" class="post_type" value="<?php echo esc_attr( $this->tab_slug ); ?>" />
129
+				<input type="hidden" name="post_type" class="post_type" value="<?php echo esc_attr($this->tab_slug); ?>" />
130 130
 
131 131
 				<table class="wp-list-table widefat fixed posts">
132 132
 					<?php $this->table_header(); ?>
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
 						<tr class="post-0 type-tour status-none" id="post-0">
136 136
 							<td class="date column-date column-ref" colspan="5">
137 137
 								<strong>
138
-									<?php esc_html_e( 'Search for tours using the search form above', 'lsx-wetu-importer' ); ?>
138
+									<?php esc_html_e('Search for tours using the search form above', 'lsx-wetu-importer'); ?>
139 139
 								</strong>
140 140
 							</td>
141 141
 						</tr>
@@ -145,8 +145,8 @@  discard block
 block discarded – undo
145 145
 
146 146
 				</table>
147 147
 
148
-				<p><input class="button button-primary add" type="button" value="<?php esc_html_e( 'Add to List', 'lsx-wetu-importer' ); ?>" />
149
-					<input class="button button-primary clear" type="button" value="<?php esc_html_e( 'Clear', 'lsx-wetu-importer' ); ?>" />
148
+				<p><input class="button button-primary add" type="button" value="<?php esc_html_e('Add to List', 'lsx-wetu-importer'); ?>" />
149
+					<input class="button button-primary clear" type="button" value="<?php esc_html_e('Clear', 'lsx-wetu-importer'); ?>" />
150 150
 				</p>
151 151
 			</form>
152 152
 
@@ -156,53 +156,53 @@  discard block
 block discarded – undo
156 156
 
157 157
 					<div class="row">
158 158
 						<div class="settings-all" style="width:30%;display:block;float:left;">
159
-							<h3><?php esc_html_e( 'What content to Sync from WETU' ); ?></h3>
159
+							<h3><?php esc_html_e('What content to Sync from WETU'); ?></h3>
160 160
 							<ul>
161
-								<?php if ( isset( $this->options ) && isset( $this->options['disable_tour_descriptions'] ) && 'on' !== $this->options['disable_tour_descriptions'] ) { ?>
162
-									<li><input class="content" checked="checked" type="checkbox" name="content[]" value="description" /> <?php esc_html_e( 'Description', 'lsx-wetu-importer' ); ?></li>
161
+								<?php if (isset($this->options) && isset($this->options['disable_tour_descriptions']) && 'on' !== $this->options['disable_tour_descriptions']) { ?>
162
+									<li><input class="content" checked="checked" type="checkbox" name="content[]" value="description" /> <?php esc_html_e('Description', 'lsx-wetu-importer'); ?></li>
163 163
 								<?php } ?>
164 164
 
165
-								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="price" /> <?php esc_html_e( 'Price', 'lsx-wetu-importer' ); ?></li>
166
-								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="duration" /> <?php esc_html_e( 'Duration', 'lsx-wetu-importer' ); ?></li>
167
-								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="group_size" /> <?php esc_html_e( 'Group Size', 'lsx-wetu-importer' ); ?></li>
168
-								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="category" /> <?php esc_html_e( 'Category', 'lsx-wetu-importer' ); ?></li>
169
-								<?php if ( isset( $this->options ) && isset( $this->options['disable_tour_tags'] ) && 'on' !== $this->options['disable_tour_tags'] ) { ?>
170
-									<li><input class="content" checked="checked" type="checkbox" name="content[]" value="tags" /> <?php esc_html_e( 'Tags', 'lsx-wetu-importer' ); ?></li>
165
+								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="price" /> <?php esc_html_e('Price', 'lsx-wetu-importer'); ?></li>
166
+								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="duration" /> <?php esc_html_e('Duration', 'lsx-wetu-importer'); ?></li>
167
+								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="group_size" /> <?php esc_html_e('Group Size', 'lsx-wetu-importer'); ?></li>
168
+								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="category" /> <?php esc_html_e('Category', 'lsx-wetu-importer'); ?></li>
169
+								<?php if (isset($this->options) && isset($this->options['disable_tour_tags']) && 'on' !== $this->options['disable_tour_tags']) { ?>
170
+									<li><input class="content" checked="checked" type="checkbox" name="content[]" value="tags" /> <?php esc_html_e('Tags', 'lsx-wetu-importer'); ?></li>
171 171
 								<?php } ?>
172
-								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="itineraries" /> <?php esc_html_e( 'Itinerary Days', 'lsx-wetu-importer' ); ?></li>
173
-								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="start_end_point" /> <?php esc_html_e( 'Departs from / Ends in', 'lsx-wetu-importer' ); ?></li>
172
+								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="itineraries" /> <?php esc_html_e('Itinerary Days', 'lsx-wetu-importer'); ?></li>
173
+								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="start_end_point" /> <?php esc_html_e('Departs from / Ends in', 'lsx-wetu-importer'); ?></li>
174 174
 							</ul>
175 175
 						</div>
176 176
 						<div class="settings-all" style="width:30%;display:block;float:left;">
177
-							<h3><?php esc_html_e( 'Itinerary Info' ); ?></h3>
177
+							<h3><?php esc_html_e('Itinerary Info'); ?></h3>
178 178
 							<ul>
179
-								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="itinerary_description" /> <?php esc_html_e( 'Description', 'lsx-wetu-importer' ); ?></li>
180
-								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="itinerary_included" /> <?php esc_html_e( 'Included', 'lsx-wetu-importer' ); ?></li>
181
-								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="itinerary_excluded" /> <?php esc_html_e( 'Excluded', 'lsx-wetu-importer' ); ?></li>
182
-								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="room_basis" /> <?php esc_html_e( 'Room Basis', 'lsx-wetu-importer' ); ?></li>
183
-								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="drinks_basis" /> <?php esc_html_e( 'Drink Bases', 'lsx-wetu-importer' ); ?></li>
179
+								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="itinerary_description" /> <?php esc_html_e('Description', 'lsx-wetu-importer'); ?></li>
180
+								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="itinerary_included" /> <?php esc_html_e('Included', 'lsx-wetu-importer'); ?></li>
181
+								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="itinerary_excluded" /> <?php esc_html_e('Excluded', 'lsx-wetu-importer'); ?></li>
182
+								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="room_basis" /> <?php esc_html_e('Room Basis', 'lsx-wetu-importer'); ?></li>
183
+								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="drinks_basis" /> <?php esc_html_e('Drink Bases', 'lsx-wetu-importer'); ?></li>
184 184
 							</ul>
185 185
 
186
-							<h4><?php esc_html_e( 'Additional Content' ); ?></h4>
186
+							<h4><?php esc_html_e('Additional Content'); ?></h4>
187 187
 							<ul>
188
-								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="accommodation" /> <?php esc_html_e( 'Sync Accommodation', 'lsx-wetu-importer' ); ?></li>
189
-								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="destination" /> <?php esc_html_e( 'Sync Destinations', 'lsx-wetu-importer' ); ?></li>
190
-								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="featured_image" /> <?php esc_html_e( 'Featured Image', 'lsx-wetu-importer' ); ?></li>
191
-								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="banner_image" /> <?php esc_html_e( 'Banner Image', 'lsx-wetu-importer' ); ?></li>
188
+								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="accommodation" /> <?php esc_html_e('Sync Accommodation', 'lsx-wetu-importer'); ?></li>
189
+								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="destination" /> <?php esc_html_e('Sync Destinations', 'lsx-wetu-importer'); ?></li>
190
+								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="featured_image" /> <?php esc_html_e('Featured Image', 'lsx-wetu-importer'); ?></li>
191
+								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="banner_image" /> <?php esc_html_e('Banner Image', 'lsx-wetu-importer'); ?></li>
192 192
 							</ul>
193 193
 						</div>
194
-						<?php if ( class_exists( 'LSX_TO_Team' ) ) { ?>
194
+						<?php if (class_exists('LSX_TO_Team')) { ?>
195 195
 							<div style="width:30%;display:block;float:left;">
196
-								<h3><?php esc_html_e( 'Assign a Team Member' ); ?></h3>
197
-								<?php $this->team_member_checkboxes( $this->tour_options ); ?>
196
+								<h3><?php esc_html_e('Assign a Team Member'); ?></h3>
197
+								<?php $this->team_member_checkboxes($this->tour_options); ?>
198 198
 							</div>
199 199
 						<?php } ?>
200 200
 
201 201
 						<br clear="both" />
202 202
 					</div>
203 203
 
204
-					<h3><?php esc_html_e( 'Your List' ); ?></h3>
205
-					<p><input class="button button-primary" type="submit" value="<?php esc_html_e( 'Sync', 'lsx-wetu-importer' ); ?>" /></p>
204
+					<h3><?php esc_html_e('Your List'); ?></h3>
205
+					<p><input class="button button-primary" type="submit" value="<?php esc_html_e('Sync', 'lsx-wetu-importer'); ?>" /></p>
206 206
 					<table class="wp-list-table widefat fixed posts">
207 207
 						<?php $this->table_header(); ?>
208 208
 
@@ -214,12 +214,12 @@  discard block
 block discarded – undo
214 214
 
215 215
 					</table>
216 216
 
217
-					<p><input class="button button-primary" type="submit" value="<?php esc_html_e( 'Sync', 'lsx-wetu-importer' ); ?>" /></p>
217
+					<p><input class="button button-primary" type="submit" value="<?php esc_html_e('Sync', 'lsx-wetu-importer'); ?>" /></p>
218 218
 				</form>
219 219
 			</div>
220 220
 
221 221
 			<div style="display:none;" class="completed-list-wrapper">
222
-				<h3><?php esc_html_e( 'Completed', 'lsx-wetu-importer' ); ?> - <small><?php esc_html_e( 'Import your', 'lsx-wetu-importer' ); ?> <a href="<?php echo esc_attr( admin_url( 'admin.php' ) ); ?>?page=<?php echo esc_attr( $this->plugin_slug ); ?>&tab=accommodation"><?php esc_html_e( 'accommodation' ); ?></a> <?php esc_html_e( 'next', 'lsx-wetu-importer' ); ?></small></h3>
222
+				<h3><?php esc_html_e('Completed', 'lsx-wetu-importer'); ?> - <small><?php esc_html_e('Import your', 'lsx-wetu-importer'); ?> <a href="<?php echo esc_attr(admin_url('admin.php')); ?>?page=<?php echo esc_attr($this->plugin_slug); ?>&tab=accommodation"><?php esc_html_e('accommodation'); ?></a> <?php esc_html_e('next', 'lsx-wetu-importer'); ?></small></h3>
223 223
 				<ul>
224 224
 				</ul>
225 225
 			</div>
@@ -233,13 +233,13 @@  discard block
 block discarded – undo
233 233
 	 * @return void
234 234
 	 */
235 235
 	public function update_options_form() {
236
-		$form_options = get_option( 'lsx_ti_tours_api_options' );
237
-		if ( false === $form_options ) {
238
-			$form_options = array( 'sample' );
236
+		$form_options = get_option('lsx_ti_tours_api_options');
237
+		if (false === $form_options) {
238
+			$form_options = array('sample');
239 239
 		}
240 240
 		?>
241 241
 		<form method="get" class="tour-refresh-form">
242
-			<input type="hidden" name="page" value="<?php echo esc_attr( $this->plugin_slug ); ?>" />
242
+			<input type="hidden" name="page" value="<?php echo esc_attr($this->plugin_slug); ?>" />
243 243
 			<input type="hidden" name="tab" value="tour" />
244 244
 			<input type="hidden" name="refresh_tours" value="true" />
245 245
 			<input class="content" type="hidden" name="own" value="true" />
@@ -247,18 +247,18 @@  discard block
 block discarded – undo
247 247
 			<select name="type">
248 248
 				<option 
249 249
 				<?php
250
-				if ( in_array( 'personal', $form_options ) ) {
251
-					echo esc_attr( 'selected="selected"' ); }
250
+				if (in_array('personal', $form_options)) {
251
+					echo esc_attr('selected="selected"'); }
252 252
 				?>
253
-value="personal"><?php esc_html_e( 'Personal', 'lsx-wetu-importer' ); ?></option>
253
+value="personal"><?php esc_html_e('Personal', 'lsx-wetu-importer'); ?></option>
254 254
 				<option 
255 255
 				<?php
256
-				if ( in_array( 'sample', $form_options ) ) {
257
-					echo esc_attr( 'selected="selected"' ); }
256
+				if (in_array('sample', $form_options)) {
257
+					echo esc_attr('selected="selected"'); }
258 258
 				?>
259
-value="sample"><?php esc_html_e( 'Sample', 'lsx-wetu-importer' ); ?></option>
259
+value="sample"><?php esc_html_e('Sample', 'lsx-wetu-importer'); ?></option>
260 260
 			</select>
261
-			<input class="button submit" type="submit" value="<?php esc_attr_e( 'Refresh', 'lsx-wetu-importer' ); ?>" />
261
+			<input class="button submit" type="submit" value="<?php esc_attr_e('Refresh', 'lsx-wetu-importer'); ?>" />
262 262
 		</form>
263 263
 		<?php
264 264
 	}
@@ -285,9 +285,9 @@  discard block
 block discarded – undo
285 285
 		"
286 286
 		);
287 287
 
288
-		if ( null !== $current_tours && ! empty( $current_tours ) ) {
289
-			foreach ( $current_tours as $tour ) {
290
-				$return[ $tour->meta_value ] = $tour;
288
+		if (null !== $current_tours && !empty($current_tours)) {
289
+			foreach ($current_tours as $tour) {
290
+				$return[$tour->meta_value] = $tour;
291 291
 			}
292 292
 		}
293 293
 
@@ -299,45 +299,45 @@  discard block
 block discarded – undo
299 299
 	 */
300 300
 	public function process_ajax_search() {
301 301
 		$return = false;
302
-		check_ajax_referer( 'lsx_wetu_ajax_action', 'security' );
302
+		check_ajax_referer('lsx_wetu_ajax_action', 'security');
303 303
 
304
-		if ( isset( $_POST['action'] ) && 'lsx_tour_importer' === $_POST['action'] && isset( $_POST['type'] ) && $_POST['type'] === $this->tab_slug ) {
305
-			$tours = get_transient( 'lsx_ti_tours' );
304
+		if (isset($_POST['action']) && 'lsx_tour_importer' === $_POST['action'] && isset($_POST['type']) && $_POST['type'] === $this->tab_slug) {
305
+			$tours = get_transient('lsx_ti_tours');
306 306
 
307
-			if ( false !== $tours ) {
307
+			if (false !== $tours) {
308 308
 				$searched_items = false;
309
-				if ( isset( $_POST['keyword'] ) ) {
310
-					$keyphrases = array_map( 'sanitize_text_field', wp_unslash( $_POST['keyword'] ) );
311
-				} else {
312
-					$keyphrases = array( 0 );
309
+				if (isset($_POST['keyword'])) {
310
+					$keyphrases = array_map('sanitize_text_field', wp_unslash($_POST['keyword']));
311
+				}else {
312
+					$keyphrases = array(0);
313 313
 				}
314 314
 
315
-				if ( ! is_array( $keyphrases ) ) {
316
-					$keyphrases = array( $keyphrases );
315
+				if (!is_array($keyphrases)) {
316
+					$keyphrases = array($keyphrases);
317 317
 				}
318
-				foreach ( $keyphrases as &$keyword ) {
319
-					$keyword = ltrim( rtrim( $keyword ) );
318
+				foreach ($keyphrases as &$keyword) {
319
+					$keyword = ltrim(rtrim($keyword));
320 320
 				}
321 321
 
322 322
 				$post_status = false;
323
-				if ( in_array( 'publish', $keyphrases ) ) {
323
+				if (in_array('publish', $keyphrases)) {
324 324
 					$post_status = 'publish';
325 325
 				}
326
-				if ( in_array( 'pending', $keyphrases ) ) {
326
+				if (in_array('pending', $keyphrases)) {
327 327
 					$post_status = 'pending';
328 328
 				}
329
-				if ( in_array( 'draft', $keyphrases ) ) {
329
+				if (in_array('draft', $keyphrases)) {
330 330
 					$post_status = 'draft';
331 331
 				}
332
-				if ( in_array( 'import', $keyphrases ) ) {
332
+				if (in_array('import', $keyphrases)) {
333 333
 					$post_status = 'import';
334 334
 				}
335 335
 
336
-				if ( ! empty( $tours ) ) {
336
+				if (!empty($tours)) {
337 337
 					$current_tours = $this->find_current_tours();
338 338
 
339
-					foreach ( $tours as $row_key => $row ) {
340
-						if ( isset( $row['is_disabled'] ) && true === $row['is_disabled'] ) {
339
+					foreach ($tours as $row_key => $row) {
340
+						if (isset($row['is_disabled']) && true === $row['is_disabled']) {
341 341
 							continue;
342 342
 						}
343 343
 
@@ -345,60 +345,60 @@  discard block
 block discarded – undo
345 345
 						$row['post_id']    = 0;
346 346
 						$row['post_title'] = $row['name'];
347 347
 
348
-						if ( false !== $current_tours && array_key_exists( $row['identifier'], $current_tours ) ) {
349
-							$row['post_id']    = $current_tours[ $row['identifier'] ]->post_id;
350
-							$row['post_title'] = $current_tours[ $row['identifier'] ]->post_title;
348
+						if (false !== $current_tours && array_key_exists($row['identifier'], $current_tours)) {
349
+							$row['post_id']    = $current_tours[$row['identifier']]->post_id;
350
+							$row['post_title'] = $current_tours[$row['identifier']]->post_title;
351 351
 						}
352 352
 
353 353
 						// If we are searching for.
354
-						if ( false !== $post_status ) {
355
-							if ( 'import' === $post_status ) {
354
+						if (false !== $post_status) {
355
+							if ('import' === $post_status) {
356 356
 
357
-								if ( 0 !== $row['post_id'] ) {
357
+								if (0 !== $row['post_id']) {
358 358
 									continue;
359
-								} else {
360
-									$searched_items[ sanitize_title( $row['name'] ) . '-' . $row['identifier'] ] = $this->format_row( $row, $row_key );
359
+								}else {
360
+									$searched_items[sanitize_title($row['name']).'-'.$row['identifier']] = $this->format_row($row, $row_key);
361 361
 								}
362
-							} else {
363
-								if ( 0 === $row['post_id'] ) {
362
+							}else {
363
+								if (0 === $row['post_id']) {
364 364
 									continue;
365
-								} else {
366
-									$current_status = get_post_status( $row['post_id'] );
365
+								}else {
366
+									$current_status = get_post_status($row['post_id']);
367 367
 
368
-									if ( $current_status !== $post_status ) {
368
+									if ($current_status !== $post_status) {
369 369
 										continue;
370 370
 									}
371 371
 								}
372 372
 
373
-								$searched_items[ sanitize_title( $row['name'] ) . '-' . $row['identifier'] ] = $this->format_row( $row, $row_key );
373
+								$searched_items[sanitize_title($row['name']).'-'.$row['identifier']] = $this->format_row($row, $row_key);
374 374
 							}
375
-						} else {
375
+						}else {
376 376
 							// Search through each keyword.
377
-							foreach ( $keyphrases as $keyphrase ) {
377
+							foreach ($keyphrases as $keyphrase) {
378 378
 
379 379
 								// Make sure the keyphrase is turned into an array.
380
-								$keywords = explode( ' ', $keyphrase );
381
-								if ( ! is_array( $keywords ) ) {
382
-									$keywords = array( $keywords );
380
+								$keywords = explode(' ', $keyphrase);
381
+								if (!is_array($keywords)) {
382
+									$keywords = array($keywords);
383 383
 								}
384 384
 
385
-								if ( $this->multineedle_stripos( ltrim( rtrim( $row['name'] ) ), $keywords ) !== false ) {
386
-									$searched_items[ sanitize_title( $row['name'] ) . '-' . $row['identifier'] ] = $this->format_row( $row, $row_key );
387
-								} elseif ( $this->multineedle_stripos( ltrim( rtrim( $row['reference_number'] ) ), $keywords ) !== false ) {
388
-									$searched_items[ sanitize_title( $row['name'] ) . '-' . $row['identifier'] ] = $this->format_row( $row, $row_key );
389
-								} elseif ( $this->multineedle_stripos( ltrim( rtrim( $row['identifier_key'] ) ), $keywords ) !== false ) {
390
-									$searched_items[ sanitize_title( $row['name'] ) . '-' . $row['identifier'] ] = $this->format_row( $row, $row_key );
385
+								if ($this->multineedle_stripos(ltrim(rtrim($row['name'])), $keywords) !== false) {
386
+									$searched_items[sanitize_title($row['name']).'-'.$row['identifier']] = $this->format_row($row, $row_key);
387
+								} elseif ($this->multineedle_stripos(ltrim(rtrim($row['reference_number'])), $keywords) !== false) {
388
+									$searched_items[sanitize_title($row['name']).'-'.$row['identifier']] = $this->format_row($row, $row_key);
389
+								} elseif ($this->multineedle_stripos(ltrim(rtrim($row['identifier_key'])), $keywords) !== false) {
390
+									$searched_items[sanitize_title($row['name']).'-'.$row['identifier']] = $this->format_row($row, $row_key);
391 391
 								}
392 392
 							}
393 393
 						}
394 394
 					}
395 395
 				}
396 396
 
397
-				if ( false !== $searched_items ) {
398
-					$return = implode( $searched_items );
397
+				if (false !== $searched_items) {
398
+					$return = implode($searched_items);
399 399
 				}
400 400
 			}
401
-			print_r( $return );
401
+			print_r($return);
402 402
 			die();
403 403
 		}
404 404
 	}
@@ -406,34 +406,34 @@  discard block
 block discarded – undo
406 406
 	/**
407 407
 	 * Formats the row for output on the screen.
408 408
 	 */
409
-	public function format_row( $row = false, $row_key = '' ) {
410
-		if ( false !== $row ) {
409
+	public function format_row($row = false, $row_key = '') {
410
+		if (false !== $row) {
411 411
 			$status = 'import';
412 412
 
413
-			if ( 0 !== $row['post_id'] ) {
414
-				$status = '<a href="' . admin_url( '/post.php?post=' . $row['post_id'] . '&action=edit' ) . '" target="_blank">' . get_post_status( $row['post_id'] ) . '</a>';
413
+			if (0 !== $row['post_id']) {
414
+				$status = '<a href="'.admin_url('/post.php?post='.$row['post_id'].'&action=edit').'" target="_blank">'.get_post_status($row['post_id']).'</a>';
415 415
 			}
416 416
 
417 417
 			$row_html = '
418
-			<tr class="post-' . $row['post_id'] . ' type-tour" id="post-' . $row['post_id'] . '">
418
+			<tr class="post-' . $row['post_id'].' type-tour" id="post-'.$row['post_id'].'">
419 419
 				<td class="check-column">
420
-					<label for="cb-select-' . $row['identifier'] . '" class="screen-reader-text">' . $row['post_title'] . '</label>
421
-					<input type="checkbox" data-identifier="' . $row['identifier'] . '" value="' . $row['post_id'] . '" name="post[]" id="cb-select-' . $row['identifier'] . '">
420
+					<label for="cb-select-' . $row['identifier'].'" class="screen-reader-text">'.$row['post_title'].'</label>
421
+					<input type="checkbox" data-identifier="' . $row['identifier'].'" value="'.$row['post_id'].'" name="post[]" id="cb-select-'.$row['identifier'].'">
422 422
 				</td>
423 423
 				<td class="column-order">
424
-					' . ( $row_key + 1 ) . '
424
+					' . ($row_key + 1).'
425 425
 				</td>
426 426
 				<td class="post-title page-title column-title">
427
-					' . $row['post_title'] . ' - ' . $status . '
427
+					' . $row['post_title'].' - '.$status.'
428 428
 				</td>
429 429
 				<td class="date column-date">
430
-					' . $row['reference_number'] . '
430
+					' . $row['reference_number'].'
431 431
 				</td>
432 432
 				<td class="date column-date">
433
-					<abbr title="' . date( 'Y/m/d', strtotime( $row['last_modified'] ) ) . '">' . date( 'Y/m/d', strtotime( $row['last_modified'] ) ) . '</abbr><br>Last Modified
433
+					<abbr title="' . date('Y/m/d', strtotime($row['last_modified'])).'">'.date('Y/m/d', strtotime($row['last_modified'])).'</abbr><br>Last Modified
434 434
 				</td>
435 435
 				<td class="ssid column-ssid">
436
-					' . $row['identifier'] . '
436
+					' . $row['identifier'].'
437 437
 				</td>
438 438
 			</tr>';
439 439
 			return $row_html;
@@ -443,44 +443,44 @@  discard block
 block discarded – undo
443 443
 	/**
444 444
 	 * Connect to wetu
445 445
 	 */
446
-	public function process_ajax_import( $force = false ) {
446
+	public function process_ajax_import($force = false) {
447 447
 		$return = false;
448
-		check_ajax_referer( 'lsx_wetu_ajax_action', 'security' );
449
-		if ( isset( $_POST['action'] ) && 'lsx_import_items' === $_POST['action'] && isset( $_POST['type'] ) && $_POST['type'] === $this->tab_slug && isset( $_POST['wetu_id'] ) ) {
448
+		check_ajax_referer('lsx_wetu_ajax_action', 'security');
449
+		if (isset($_POST['action']) && 'lsx_import_items' === $_POST['action'] && isset($_POST['type']) && $_POST['type'] === $this->tab_slug && isset($_POST['wetu_id'])) {
450 450
 
451
-			$wetu_id = sanitize_text_field( $_POST['wetu_id'] );
452
-			if ( isset( $_POST['post_id'] ) ) {
453
-				$post_id = sanitize_text_field( $_POST['post_id'] );
454
-			} else {
451
+			$wetu_id = sanitize_text_field($_POST['wetu_id']);
452
+			if (isset($_POST['post_id'])) {
453
+				$post_id = sanitize_text_field($_POST['post_id']);
454
+			}else {
455 455
 				$post_id = 0;
456 456
 			}
457 457
 
458
-			delete_option( 'lsx_wetu_importer_tour_settings' );
458
+			delete_option('lsx_wetu_importer_tour_settings');
459 459
 
460
-			if ( isset( $_POST['team_members'] ) ) {
461
-				$team_members = array_map( 'sanitize_text_field', wp_unslash( $_POST['team_members'] ) );
462
-			} else {
460
+			if (isset($_POST['team_members'])) {
461
+				$team_members = array_map('sanitize_text_field', wp_unslash($_POST['team_members']));
462
+			}else {
463 463
 				$team_members = false;
464 464
 			}
465 465
 
466
-			if ( isset( $_POST['content'] ) && is_array( $_POST['content'] ) && ! empty( $_POST['content'] ) ) {
467
-				$content = array_map( 'sanitize_text_field', wp_unslash( $_POST['content'] ) );
468
-				add_option( 'lsx_wetu_importer_tour_settings', $content );
469
-			} else {
466
+			if (isset($_POST['content']) && is_array($_POST['content']) && !empty($_POST['content'])) {
467
+				$content = array_map('sanitize_text_field', wp_unslash($_POST['content']));
468
+				add_option('lsx_wetu_importer_tour_settings', $content);
469
+			}else {
470 470
 				$content = false;
471 471
 			}
472
-			$jdata = wp_remote_get( 'https://wetu.com/API/Itinerary/V8/Get?id=' . $wetu_id );
472
+			$jdata = wp_remote_get('https://wetu.com/API/Itinerary/V8/Get?id='.$wetu_id);
473 473
 
474
-			if ( ! is_wp_error( $jdata ) && ! empty( $jdata ) && isset( $jdata['response'] ) && isset( $jdata['response']['code'] ) && 200 === $jdata['response']['code'] ) {
475
-				$jdata  = json_decode( $jdata['body'], true );
476
-				$return = $this->import_row( $jdata, $wetu_id, $post_id, $team_members, $content );
477
-				$this->format_completed_row( $return );
474
+			if (!is_wp_error($jdata) && !empty($jdata) && isset($jdata['response']) && isset($jdata['response']['code']) && 200 === $jdata['response']['code']) {
475
+				$jdata  = json_decode($jdata['body'], true);
476
+				$return = $this->import_row($jdata, $wetu_id, $post_id, $team_members, $content);
477
+				$this->format_completed_row($return);
478 478
 				$this->save_queue();
479 479
 				$this->cleanup_posts();
480
-				$this->attach_destination_images( $content );
481
-				$this->clean_attached_destinations( $return );
482
-			} else {
483
-				$this->format_error( esc_html__( 'There was a problem importing your tour, please try again.', 'lsx-wetu-importer' ) );
480
+				$this->attach_destination_images($content);
481
+				$this->clean_attached_destinations($return);
482
+			}else {
483
+				$this->format_error(esc_html__('There was a problem importing your tour, please try again.', 'lsx-wetu-importer'));
484 484
 			}
485 485
 		}
486 486
 	}
@@ -491,13 +491,13 @@  discard block
 block discarded – undo
491 491
 	 * @param $id string
492 492
 	 * @return void
493 493
 	 */
494
-	public function clean_attached_destinations( $id ) {
495
-		$current_connections = get_post_meta( $id, 'destination_to_tour', false );
496
-		delete_post_meta( $id, 'destination_to_tour' );
497
-		$current_connections = array_unique( $current_connections );
494
+	public function clean_attached_destinations($id) {
495
+		$current_connections = get_post_meta($id, 'destination_to_tour', false);
496
+		delete_post_meta($id, 'destination_to_tour');
497
+		$current_connections = array_unique($current_connections);
498 498
 
499
-		foreach ( $current_connections as $connection ) {
500
-			add_post_meta( $id, 'destination_to_tour', $connection, false );
499
+		foreach ($current_connections as $connection) {
500
+			add_post_meta($id, 'destination_to_tour', $connection, false);
501 501
 		}
502 502
 	}
503 503
 
@@ -507,12 +507,12 @@  discard block
 block discarded – undo
507 507
 	 * @param $data array
508 508
 	 * @param $wetu_id string
509 509
 	 */
510
-	public function import_row( $data, $wetu_id, $id = 0, $team_members = false, $importable_content = array(), $old1 = false, $old2 = false ) {
510
+	public function import_row($data, $wetu_id, $id = 0, $team_members = false, $importable_content = array(), $old1 = false, $old2 = false) {
511 511
 		$post_name         = '';
512 512
 		$data_post_content = '';
513 513
 		$data_post_excerpt = '';
514 514
 
515
-		$current_post = get_post( $id );
515
+		$current_post = get_post($id);
516 516
 
517 517
 		$post = array(
518 518
 			'post_type' => 'tour',
@@ -520,83 +520,83 @@  discard block
 block discarded – undo
520 520
 
521 521
 		$content_used_general_description = false;
522 522
 
523
-		if ( ! empty( $importable_content ) && in_array( 'description', $importable_content ) ) {
523
+		if (!empty($importable_content) && in_array('description', $importable_content)) {
524 524
 			$data_post_content = $current_post->post_content;
525
-			if ( isset( $data['summary'] ) && ! empty( $data['summary'] ) ) {
525
+			if (isset($data['summary']) && !empty($data['summary'])) {
526 526
 				$data_post_content = $data['summary'];
527 527
 			}
528 528
 			$post['post_content'] = $data_post_content;
529 529
 		}
530 530
 
531 531
 		// Create or update the post.
532
-		if ( false !== $id && '0' !== $id ) {
532
+		if (false !== $id && '0' !== $id) {
533 533
 			$post['ID']          = $id;
534 534
 			$post['post_status'] = 'publish';
535
-			if ( isset( $this->options ) && 'on' !== $this->options['disable_accommodation_title'] ) {
535
+			if (isset($this->options) && 'on' !== $this->options['disable_accommodation_title']) {
536 536
 				$post['post_title'] = $data['name'];
537 537
 			}
538
-			$id = wp_update_post( $post );
539
-		} else {
538
+			$id = wp_update_post($post);
539
+		}else {
540 540
 			// Set the name.
541
-			if ( isset( $data['name'] ) ) {
542
-				$post_name = wp_unique_post_slug( sanitize_title( $data['name'] ), $id, 'draft', 'tour', 0 );
541
+			if (isset($data['name'])) {
542
+				$post_name = wp_unique_post_slug(sanitize_title($data['name']), $id, 'draft', 'tour', 0);
543 543
 			}
544 544
 
545
-			if ( ! isset( $post['post_content'] ) ) {
545
+			if (!isset($post['post_content'])) {
546 546
 				$post['post_content'] = ' ';
547 547
 			}
548 548
 
549 549
 			$post['post_name']   = $post_name;
550 550
 			$post['post_title']  = $data['name'];
551 551
 			$post['post_status'] = 'publish';
552
-			$id                  = wp_insert_post( $post );
552
+			$id                  = wp_insert_post($post);
553 553
 
554 554
 			// Save the WETU ID and the Last date it was modified.
555
-			if ( false !== $id ) {
556
-				add_post_meta( $id, 'lsx_wetu_id', $wetu_id );
557
-				add_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data['last_modified'] ) );
555
+			if (false !== $id) {
556
+				add_post_meta($id, 'lsx_wetu_id', $wetu_id);
557
+				add_post_meta($id, 'lsx_wetu_modified_date', strtotime($data['last_modified']));
558 558
 			}
559 559
 		}
560 560
 
561 561
 		// Set reference number.
562
-		$this->set_reference_number( $data, $id );
562
+		$this->set_reference_number($data, $id);
563 563
 
564 564
 		// Set the team member if it is there.
565
-		if ( post_type_exists( 'team' ) && false !== $team_members && '' !== $team_members ) {
566
-			$this->set_team_member( $id, $team_members );
565
+		if (post_type_exists('team') && false !== $team_members && '' !== $team_members) {
566
+			$this->set_team_member($id, $team_members);
567 567
 		}
568 568
 
569 569
 		// Set the price.
570
-		if ( false !== $importable_content && in_array( 'price', $importable_content ) ) {
571
-			$this->set_price( $data, $id );
570
+		if (false !== $importable_content && in_array('price', $importable_content)) {
571
+			$this->set_price($data, $id);
572 572
 		}
573 573
 
574 574
 		// Set the Duration.
575
-		if ( false !== $importable_content && in_array( 'duration', $importable_content ) ) {
576
-			$this->set_duration( $data, $id );
575
+		if (false !== $importable_content && in_array('duration', $importable_content)) {
576
+			$this->set_duration($data, $id);
577 577
 		}
578 578
 
579 579
 		// Set the Group Size.
580
-		if ( false !== $importable_content && in_array( 'group_size', $importable_content ) ) {
581
-			$this->set_group_size( $data, $id );
580
+		if (false !== $importable_content && in_array('group_size', $importable_content)) {
581
+			$this->set_group_size($data, $id);
582 582
 		}
583 583
 
584 584
 		// Set the Group Size.
585
-		if ( false !== $importable_content && in_array( 'tags', $importable_content ) ) {
586
-			$this->set_travel_styles( $id, $data );
585
+		if (false !== $importable_content && in_array('tags', $importable_content)) {
586
+			$this->set_travel_styles($id, $data);
587 587
 		}
588 588
 
589 589
 		// Set the Start and End Point Destinations.
590
-		if ( false !== $importable_content && in_array( 'start_end_point', $importable_content ) ) {
591
-			$this->set_start_end_point( $data, $id );
590
+		if (false !== $importable_content && in_array('start_end_point', $importable_content)) {
591
+			$this->set_start_end_point($data, $id);
592 592
 		}
593 593
 
594
-		if ( false !== $importable_content && in_array( 'itineraries', $importable_content ) && isset( $data['legs'] ) && ! empty( $data['legs'] ) ) {
595
-			$this->process_itineraries( $data, $id, $importable_content );
594
+		if (false !== $importable_content && in_array('itineraries', $importable_content) && isset($data['legs']) && !empty($data['legs'])) {
595
+			$this->process_itineraries($data, $id, $importable_content);
596 596
 		}
597 597
 
598
-		if ( in_array( 'map', $importable_content ) && isset( $data['routes'] ) && ! empty( $data['routes'] ) ) {
599
-			$this->set_map_data( $data, $id );
598
+		if (in_array('map', $importable_content) && isset($data['routes']) && !empty($data['routes'])) {
599
+			$this->set_map_data($data, $id);
600 600
 		}
601 601
 
602 602
 		return $id;
@@ -605,181 +605,181 @@  discard block
 block discarded – undo
605 605
 	/**
606 606
 	 * A loop which runs through each leg on the tour.
607 607
 	 */
608
-	public function process_itineraries( $data, $id, $importable_content ) {
608
+	public function process_itineraries($data, $id, $importable_content) {
609 609
 		$day_counter = 1;
610 610
 		$leg_counter = 0;
611 611
 
612
-		delete_post_meta( $id, 'itinerary' );
612
+		delete_post_meta($id, 'itinerary');
613 613
 
614
-		if ( false !== $importable_content && in_array( 'accommodation', $importable_content ) ) {
615
-			delete_post_meta( $id, 'accommodation_to_tour' );
614
+		if (false !== $importable_content && in_array('accommodation', $importable_content)) {
615
+			delete_post_meta($id, 'accommodation_to_tour');
616 616
 		}
617 617
 
618
-		foreach ( $data['legs'] as $leg ) {
618
+		foreach ($data['legs'] as $leg) {
619 619
 
620 620
 			// Itinerary Accommodation.
621 621
 			$current_accommodation = false;
622 622
 			$current_destination   = false;
623
-			if ( 'Mobile' !== $leg['type'] ) {
624
-				if ( false !== $importable_content && in_array( 'accommodation', $importable_content ) ) {
625
-					$current_accommodation = $this->set_accommodation( $leg, $id );
623
+			if ('Mobile' !== $leg['type']) {
624
+				if (false !== $importable_content && in_array('accommodation', $importable_content)) {
625
+					$current_accommodation = $this->set_accommodation($leg, $id);
626 626
 				}
627
-				if ( false !== $importable_content && in_array( 'destination', $importable_content ) ) {
628
-					$current_destination = $this->set_destination( $leg, $id, $leg_counter );
627
+				if (false !== $importable_content && in_array('destination', $importable_content)) {
628
+					$current_destination = $this->set_destination($leg, $id, $leg_counter);
629 629
 				}
630 630
 			}
631 631
 
632 632
 			// If the Nights are the same mount of days in the array,  then it isnt "By Destination".
633
-			if ( ( 1 <= (int) $leg['nights'] && isset( $leg['periods'] ) ) || 0 === $leg['itinerary_leg_id'] ) {
633
+			if ((1 <= (int) $leg['nights'] && isset($leg['periods'])) || 0 === $leg['itinerary_leg_id']) {
634 634
 
635
-				foreach ( $leg['periods'] as $day_key => $day ) {
635
+				foreach ($leg['periods'] as $day_key => $day) {
636 636
 					$current_day = array();
637 637
 
638 638
 					// If this is a moble tented solution.
639 639
 					$next_day_count = $day_counter + (int) $day['days'];
640 640
 
641
-					if ( ( isset( $leg['stops'] ) && 'Mobile' !== $leg['type'] ) || ( 1 < (int) $day['days'] ) ) {
642
-						$day_count_label = ' - ' . ( $next_day_count - 1 );
643
-					} else {
641
+					if ((isset($leg['stops']) && 'Mobile' !== $leg['type']) || (1 < (int) $day['days'])) {
642
+						$day_count_label = ' - '.($next_day_count - 1);
643
+					}else {
644 644
 						$day_count_label = '';
645 645
 					}
646
-					$current_day['title'] = esc_attr( 'Day ', 'lsx-wetu-importer' ) . $day_counter . $day_count_label;
646
+					$current_day['title'] = esc_attr('Day ', 'lsx-wetu-importer').$day_counter.$day_count_label;
647 647
 
648 648
 					// Description.
649
-					if ( false !== $importable_content && in_array( 'itinerary_description', $importable_content ) && isset( $day['notes'] ) ) {
649
+					if (false !== $importable_content && in_array('itinerary_description', $importable_content) && isset($day['notes'])) {
650 650
 						$current_day['description'] = $day['notes'];
651
-					} else {
651
+					}else {
652 652
 						$current_day['description'] = '';
653 653
 					}
654 654
 
655 655
 					// Itinerary Gallery.
656
-					if ( false !== $importable_content && in_array( 'itinerary_gallery', $importable_content ) && isset( $day['images'] ) ) {
656
+					if (false !== $importable_content && in_array('itinerary_gallery', $importable_content) && isset($day['images'])) {
657 657
 						$current_day['featured_image'] = '';
658
-					} else {
658
+					}else {
659 659
 						$current_day['featured_image'] = '';
660 660
 					}
661 661
 
662 662
 					// If its a mobile safari, we need to get the destination and accommodation data from the stops.
663
-					if ( 'Mobile' === $leg['type'] ) {
664
-						$current_destination   = $this->get_mobile_destination( $day, $leg, $id );
665
-						$current_accommodation = $this->get_mobile_accommodation( $day, $leg, $id );
663
+					if ('Mobile' === $leg['type']) {
664
+						$current_destination   = $this->get_mobile_destination($day, $leg, $id);
665
+						$current_accommodation = $this->get_mobile_accommodation($day, $leg, $id);
666 666
 					}
667 667
 
668 668
 					// Accommodation.
669
-					if ( false !== $current_accommodation ) {
670
-						$current_day['accommodation_to_tour'] = array( $current_accommodation );
671
-					} else {
669
+					if (false !== $current_accommodation) {
670
+						$current_day['accommodation_to_tour'] = array($current_accommodation);
671
+					}else {
672 672
 						$current_day['accommodation_to_tour'] = array();
673 673
 					}
674 674
 
675 675
 					// Destination.
676
-					if ( false !== $current_destination ) {
677
-						$current_day['destination_to_tour'] = array( $current_destination );
678
-					} else {
676
+					if (false !== $current_destination) {
677
+						$current_day['destination_to_tour'] = array($current_destination);
678
+					}else {
679 679
 						$current_day['destination_to_tour'] = array();
680 680
 					}
681 681
 
682 682
 					// Included.
683
-					if ( false !== $importable_content && in_array( 'itinerary_included', $importable_content ) && isset( $day['included'] ) && '' !== $day['included'] ) {
683
+					if (false !== $importable_content && in_array('itinerary_included', $importable_content) && isset($day['included']) && '' !== $day['included']) {
684 684
 						$current_day['included'] = $day['included'];
685
-					} else {
685
+					}else {
686 686
 						$current_day['included'] = '';
687 687
 					}
688 688
 
689 689
 					// Excluded.
690
-					if ( false !== $importable_content && in_array( 'itinerary_excluded', $importable_content ) && isset( $day['excluded'] ) && '' !== $day['excluded'] ) {
690
+					if (false !== $importable_content && in_array('itinerary_excluded', $importable_content) && isset($day['excluded']) && '' !== $day['excluded']) {
691 691
 						$current_day['excluded'] = $day['excluded'];
692
-					} else {
692
+					}else {
693 693
 						$current_day['excluded'] = '';
694 694
 					}
695 695
 
696 696
 					// Excluded.
697
-					if ( false !== $importable_content && in_array( 'room_basis', $importable_content ) && isset( $day['room_basis'] ) && '' !== $day['room_basis'] ) {
697
+					if (false !== $importable_content && in_array('room_basis', $importable_content) && isset($day['room_basis']) && '' !== $day['room_basis']) {
698 698
 						$current_day['room_basis'] = $day['room_basis'];
699
-					} else {
699
+					}else {
700 700
 						$current_day['room_basis'] = '';
701 701
 					}
702 702
 
703 703
 					// Excluded.
704
-					if ( false !== $importable_content && in_array( 'drinks_basis', $importable_content ) && isset( $day['drinks_basis'] ) && '' !== $day['drinks_basis'] ) {
704
+					if (false !== $importable_content && in_array('drinks_basis', $importable_content) && isset($day['drinks_basis']) && '' !== $day['drinks_basis']) {
705 705
 						$current_day['drinks_basis'] = $day['drinks_basis'];
706
-					} else {
706
+					}else {
707 707
 						$current_day['drinks_basis'] = '';
708 708
 					}
709 709
 
710
-					$this->set_itinerary_day( $current_day, $id );
710
+					$this->set_itinerary_day($current_day, $id);
711 711
 					$day_counter = $next_day_count;
712 712
 				}
713
-			} else {
713
+			}else {
714 714
 				// This is for the by destination.
715 715
 
716 716
 				$current_day     = array();
717 717
 				$next_day_count  = $day_counter + (int) $leg['nights'];
718 718
 				$day_count_label = $next_day_count - 1;
719 719
 
720
-				$current_day['title'] = esc_attr( 'Day ', 'lsx-wetu-importer' ) . $day_counter;
720
+				$current_day['title'] = esc_attr('Day ', 'lsx-wetu-importer').$day_counter;
721 721
 
722
-				if ( 0 !== (int) $leg['nights'] ) {
723
-					$current_day['title'] .= ' - ' . $day_count_label;
722
+				if (0 !== (int) $leg['nights']) {
723
+					$current_day['title'] .= ' - '.$day_count_label;
724 724
 				}
725 725
 
726 726
 				// Description.
727
-				if ( false !== $importable_content && in_array( 'itinerary_description', $importable_content ) && isset( $leg['notes'] ) ) {
727
+				if (false !== $importable_content && in_array('itinerary_description', $importable_content) && isset($leg['notes'])) {
728 728
 					$current_day['description'] = $leg['notes'];
729
-				} else {
729
+				}else {
730 730
 					$current_day['description'] = '';
731 731
 				}
732 732
 
733 733
 				// Itinerary Gallery.
734
-				if ( false !== $importable_content && in_array( 'itinerary_gallery', $importable_content ) && isset( $leg['images'] ) ) {
734
+				if (false !== $importable_content && in_array('itinerary_gallery', $importable_content) && isset($leg['images'])) {
735 735
 					$current_day['featured_image'] = '';
736
-				} else {
736
+				}else {
737 737
 					$current_day['featured_image'] = '';
738 738
 				}
739 739
 
740 740
 				// Accommodation.
741
-				if ( false !== $current_accommodation ) {
742
-					$current_day['accommodation_to_tour'] = array( $current_accommodation );
743
-				} else {
741
+				if (false !== $current_accommodation) {
742
+					$current_day['accommodation_to_tour'] = array($current_accommodation);
743
+				}else {
744 744
 					$current_day['accommodation_to_tour'] = array();
745 745
 				}
746 746
 
747 747
 				// Destination.
748
-				if ( false !== $current_destination ) {
749
-					$current_day['destination_to_tour'] = array( $current_destination );
750
-				} else {
748
+				if (false !== $current_destination) {
749
+					$current_day['destination_to_tour'] = array($current_destination);
750
+				}else {
751 751
 					$current_day['destination_to_tour'] = array();
752 752
 				}
753 753
 
754 754
 				// Included.
755
-				if ( false !== $importable_content && in_array( 'itinerary_included', $importable_content ) && isset( $leg['included'] ) && '' !== $leg['included'] ) {
755
+				if (false !== $importable_content && in_array('itinerary_included', $importable_content) && isset($leg['included']) && '' !== $leg['included']) {
756 756
 					$current_day['included'] = $leg['included'];
757
-				} else {
757
+				}else {
758 758
 					$current_day['included'] = '';
759 759
 				}
760 760
 
761 761
 				// Excluded.
762
-				if ( false !== $importable_content && in_array( 'itinerary_excluded', $importable_content ) && isset( $leg['excluded'] ) && '' !== $leg['excluded'] ) {
762
+				if (false !== $importable_content && in_array('itinerary_excluded', $importable_content) && isset($leg['excluded']) && '' !== $leg['excluded']) {
763 763
 					$current_day['excluded'] = $leg['excluded'];
764
-				} else {
764
+				}else {
765 765
 					$current_day['excluded'] = '';
766 766
 				}
767 767
 
768 768
 				// Excluded.
769
-				if ( false !== $importable_content && in_array( 'room_basis', $importable_content ) && isset( $leg['room_basis'] ) && '' !== $leg['room_basis'] ) {
769
+				if (false !== $importable_content && in_array('room_basis', $importable_content) && isset($leg['room_basis']) && '' !== $leg['room_basis']) {
770 770
 					$current_day['room_basis'] = $leg['room_basis'];
771
-				} else {
771
+				}else {
772 772
 					$current_day['room_basis'] = '';
773 773
 				}
774 774
 
775 775
 				// Excluded.
776
-				if ( false !== $importable_content && in_array( 'drinks_basis', $importable_content ) && isset( $leg['drinks_basis'] ) && '' !== $leg['drinks_basis'] ) {
776
+				if (false !== $importable_content && in_array('drinks_basis', $importable_content) && isset($leg['drinks_basis']) && '' !== $leg['drinks_basis']) {
777 777
 					$current_day['drinks_basis'] = $leg['drinks_basis'];
778
-				} else {
778
+				}else {
779 779
 					$current_day['drinks_basis'] = '';
780 780
 				}
781 781
 
782
-				$this->set_itinerary_day( $current_day, $id );
782
+				$this->set_itinerary_day($current_day, $id);
783 783
 				$day_counter = $next_day_count;
784 784
 			}
785 785
 			$leg_counter++;
@@ -793,47 +793,47 @@  discard block
 block discarded – undo
793 793
 	 * @param string $id
794 794
 	 * @return void
795 795
 	 */
796
-	public function set_start_end_point( $data, $id ) {
797
-		delete_post_meta( $id, 'departs_from' );
798
-		delete_post_meta( $id, 'ends_in' );
796
+	public function set_start_end_point($data, $id) {
797
+		delete_post_meta($id, 'departs_from');
798
+		delete_post_meta($id, 'ends_in');
799 799
 		$departs_from = false;
800 800
 		$ends_in      = false;
801 801
 
802 802
 		$args = array(
803 803
 			'points'      => $data['legs'],
804 804
 			'start_index' => 0,
805
-			'end_index'   => count( $data['legs'] ) - 2,
805
+			'end_index'   => count($data['legs']) - 2,
806 806
 		);
807
-		$args = apply_filters( 'lsx_wetu_start_end_args', $args, $data );
807
+		$args = apply_filters('lsx_wetu_start_end_args', $args, $data);
808 808
 
809
-		if ( ! empty( $args['points'] ) && is_array( $args['points'] ) ) {
809
+		if (!empty($args['points']) && is_array($args['points'])) {
810 810
 			$leg_counter = 0;
811 811
 
812
-			foreach ( $args['points'] as $point ) {
812
+			foreach ($args['points'] as $point) {
813 813
 				// If we are in the first leg,  and the destination was attached then save it as the departure field.
814
-				if ( $leg_counter === $args['start_index'] ) {
815
-					$departs_from_destination = $this->set_country( $point['destination_content_entity_id'], $id );
816
-					if ( false !== $departs_from_destination ) {
814
+				if ($leg_counter === $args['start_index']) {
815
+					$departs_from_destination = $this->set_country($point['destination_content_entity_id'], $id);
816
+					if (false !== $departs_from_destination) {
817 817
 						$departs_from = $departs_from_destination;
818 818
 					}
819 819
 				}
820 820
 				// If its the last leg then save it as the ends in.
821
-				if ( $leg_counter === $args['end_index'] ) {
821
+				if ($leg_counter === $args['end_index']) {
822 822
 					$ends_in = $point['destination_content_entity_id'];
823 823
 				}
824 824
 				$leg_counter++;
825 825
 			}
826 826
 
827
-			$departs_from = apply_filters( 'lsx_wetu_departs_from_id', $departs_from, $data, $this );
828
-			if ( false !== $departs_from ) {
829
-				add_post_meta( $id, 'departs_from', $departs_from, true );
827
+			$departs_from = apply_filters('lsx_wetu_departs_from_id', $departs_from, $data, $this);
828
+			if (false !== $departs_from) {
829
+				add_post_meta($id, 'departs_from', $departs_from, true);
830 830
 			}
831 831
 
832
-			if ( false !== $ends_in ) {
833
-				$ends_in             = apply_filters( 'lsx_wetu_ends_in_id', $ends_in, $data, $this );
834
-				$ends_in_destination = $this->set_country( $ends_in, $id );
835
-				if ( false !== $ends_in_destination ) {
836
-					add_post_meta( $id, 'ends_in', $ends_in_destination, true );
832
+			if (false !== $ends_in) {
833
+				$ends_in             = apply_filters('lsx_wetu_ends_in_id', $ends_in, $data, $this);
834
+				$ends_in_destination = $this->set_country($ends_in, $id);
835
+				if (false !== $ends_in_destination) {
836
+					add_post_meta($id, 'ends_in', $ends_in_destination, true);
837 837
 				}
838 838
 			}
839 839
 		}
@@ -846,15 +846,15 @@  discard block
 block discarded – undo
846 846
 	 * @param $leg
847 847
 	 * @return void
848 848
 	 */
849
-	public function get_mobile_destination( $day, $leg, $id ) {
849
+	public function get_mobile_destination($day, $leg, $id) {
850 850
 		$current_destination = false;
851 851
 		$current_day         = (int) $day['period_start_day'];
852
-		if ( isset( $leg['stops'] ) ) {
853
-			foreach ( $leg['stops'] as $stop ) {
852
+		if (isset($leg['stops'])) {
853
+			foreach ($leg['stops'] as $stop) {
854 854
 				$arrival_day   = (int) $stop['arrival_day'];
855 855
 				$departure_day = (int) $stop['departure_day'];
856
-				if ( $arrival_day <= $current_day && $current_day < $departure_day ) {
857
-					$current_destination = $this->set_destination( $stop, $id, 0 );
856
+				if ($arrival_day <= $current_day && $current_day < $departure_day) {
857
+					$current_destination = $this->set_destination($stop, $id, 0);
858 858
 				}
859 859
 			}
860 860
 		}
@@ -868,15 +868,15 @@  discard block
 block discarded – undo
868 868
 	 * @param $leg
869 869
 	 * @return void
870 870
 	 */
871
-	public function get_mobile_accommodation( $day, $leg, $id ) {
871
+	public function get_mobile_accommodation($day, $leg, $id) {
872 872
 		$current_accommodation = false;
873 873
 		$current_day           = (int) $day['period_start_day'];
874
-		if ( isset( $leg['stops'] ) ) {
875
-			foreach ( $leg['stops'] as $stop ) {
874
+		if (isset($leg['stops'])) {
875
+			foreach ($leg['stops'] as $stop) {
876 876
 				$arrival_day   = (int) $stop['arrival_day'];
877 877
 				$departure_day = (int) $stop['departure_day'];
878
-				if ( $arrival_day <= $current_day && $current_day < $departure_day ) {
879
-					$current_accommodation = $this->set_accommodation( $stop, $id, 0 );
878
+				if ($arrival_day <= $current_day && $current_day < $departure_day) {
879
+					$current_accommodation = $this->set_accommodation($stop, $id, 0);
880 880
 				}
881 881
 			}
882 882
 		}
@@ -886,29 +886,29 @@  discard block
 block discarded – undo
886 886
 	/**
887 887
 	 * Run through your routes and save the points as a KML file.
888 888
 	 */
889
-	public function set_map_data( $data, $id, $zoom = 9 ) {
890
-		if ( ! empty( $data['routes'] ) ) {
891
-			delete_post_meta( $id, 'wetu_map_points' );
889
+	public function set_map_data($data, $id, $zoom = 9) {
890
+		if (!empty($data['routes'])) {
891
+			delete_post_meta($id, 'wetu_map_points');
892 892
 
893 893
 			$points = array();
894 894
 
895
-			foreach ( $data['routes'] as $route ) {
895
+			foreach ($data['routes'] as $route) {
896 896
 
897
-				if ( isset( $route['points'] ) && '' !== $route['points'] ) {
897
+				if (isset($route['points']) && '' !== $route['points']) {
898 898
 
899
-					$temp_points   = explode( ';', $route['points'] );
900
-					$point_counter = count( $temp_points );
899
+					$temp_points   = explode(';', $route['points']);
900
+					$point_counter = count($temp_points);
901 901
 
902
-					for ( $x = 0; $x <= $point_counter; $x++ ) {
902
+					for ($x = 0; $x <= $point_counter; $x++) {
903 903
 						$y        = $x + 1;
904
-						$points[] = $temp_points[ $x ] . ',' . $temp_points[ $y ];
904
+						$points[] = $temp_points[$x].','.$temp_points[$y];
905 905
 						$x++;
906 906
 					}
907 907
 				}
908 908
 			}
909 909
 
910
-			if ( ! empty( $points ) ) {
911
-				$this->save_custom_field( implode( ' ', $points ), 'wetu_map_points', $id, false, true );
910
+			if (!empty($points)) {
911
+				$this->save_custom_field(implode(' ', $points), 'wetu_map_points', $id, false, true);
912 912
 			}
913 913
 		}
914 914
 
@@ -919,64 +919,64 @@  discard block
 block discarded – undo
919 919
 	/**
920 920
 	 * Set the Itinerary Day.
921 921
 	 */
922
-	public function set_itinerary_day( $day, $id ) {
923
-		$this->save_custom_field( $day, 'itinerary', $id, false, false );
922
+	public function set_itinerary_day($day, $id) {
923
+		$this->save_custom_field($day, 'itinerary', $id, false, false);
924 924
 	}
925 925
 
926 926
 	/**
927 927
 	 * Set the ref number
928 928
 	 */
929
-	public function set_reference_number( $data, $id ) {
930
-		if ( isset( $data['reference_number'] ) && '' !== $data['reference_number'] ) {
931
-			$this->save_custom_field( $data['reference_number'], 'lsx_wetu_ref', $id );
929
+	public function set_reference_number($data, $id) {
930
+		if (isset($data['reference_number']) && '' !== $data['reference_number']) {
931
+			$this->save_custom_field($data['reference_number'], 'lsx_wetu_ref', $id);
932 932
 		}
933 933
 	}
934 934
 
935 935
 	/**
936 936
 	 * Set the price.
937 937
 	 */
938
-	public function set_price( $data, $id ) {
938
+	public function set_price($data, $id) {
939 939
 		// Price.
940
-		if ( isset( $data['price'] ) && '' !== $data['price'] ) {
940
+		if (isset($data['price']) && '' !== $data['price']) {
941 941
 			$price = $data['price'];
942
-			if ( false === apply_filters( 'lsx_wetu_importer_disable_tour_price_filter', false ) ) {
943
-				$price = preg_replace( '/[^0-9,.]/', '', $price );
942
+			if (false === apply_filters('lsx_wetu_importer_disable_tour_price_filter', false)) {
943
+				$price = preg_replace('/[^0-9,.]/', '', $price);
944 944
 			}
945
-			$meta_key = apply_filters( 'lsx_wetu_importer_price_meta_key', 'price' );
946
-			$this->save_custom_field( $price, $meta_key, $id );
945
+			$meta_key = apply_filters('lsx_wetu_importer_price_meta_key', 'price');
946
+			$this->save_custom_field($price, $meta_key, $id);
947 947
 		}
948 948
 
949 949
 		// Price includes.
950
-		if ( isset( $data['price_includes'] ) && '' !== $data['price_includes'] ) {
951
-			$meta_key = apply_filters( 'lsx_wetu_importer_included_meta_key', 'included' );
952
-			$this->save_custom_field( $data['price_includes'], $meta_key, $id );
950
+		if (isset($data['price_includes']) && '' !== $data['price_includes']) {
951
+			$meta_key = apply_filters('lsx_wetu_importer_included_meta_key', 'included');
952
+			$this->save_custom_field($data['price_includes'], $meta_key, $id);
953 953
 		}
954 954
 
955 955
 		// Price Excludes.
956
-		if ( isset( $data['price_excludes'] ) && '' !== $data['price_excludes'] ) {
957
-			$meta_key = apply_filters( 'lsx_wetu_importer_not_included_meta_key', 'not_included' );
958
-			$this->save_custom_field( $data['price_excludes'], $meta_key, $id );
956
+		if (isset($data['price_excludes']) && '' !== $data['price_excludes']) {
957
+			$meta_key = apply_filters('lsx_wetu_importer_not_included_meta_key', 'not_included');
958
+			$this->save_custom_field($data['price_excludes'], $meta_key, $id);
959 959
 		}
960 960
 	}
961 961
 
962 962
 	/**
963 963
 	 * Set the duration.
964 964
 	 */
965
-	public function set_duration( $data, $id ) {
966
-		if ( isset( $data['days'] ) && ! empty( $data['days'] ) ) {
965
+	public function set_duration($data, $id) {
966
+		if (isset($data['days']) && !empty($data['days'])) {
967 967
 			$price = $data['days'];
968
-			$price = preg_replace( '/[^0-9,.]/', '', $price );
969
-			$this->save_custom_field( $price, 'duration', $id );
968
+			$price = preg_replace('/[^0-9,.]/', '', $price);
969
+			$this->save_custom_field($price, 'duration', $id);
970 970
 		}
971 971
 	}
972 972
 
973 973
 	/**
974 974
 	 * Set the group size
975 975
 	 */
976
-	public function set_group_size( $data, $id ) {
977
-		if ( isset( $data['group_size'] ) && ! empty( $data['group_size'] ) ) {
976
+	public function set_group_size($data, $id) {
977
+		if (isset($data['group_size']) && !empty($data['group_size'])) {
978 978
 			$group_size = $data['group_size'];
979
-			$this->save_custom_field( $group_size, 'group_size', $id );
979
+			$this->save_custom_field($group_size, 'group_size', $id);
980 980
 		}
981 981
 	}
982 982
 
@@ -987,11 +987,11 @@  discard block
 block discarded – undo
987 987
 	 * @param array  $travel_styles
988 988
 	 * @return void
989 989
 	 */
990
-	public function set_travel_styles( $id, $data ) {
991
-		$tags = apply_filters( 'lsx_wetu_importer_tour_travel_styles', $data['tags'] );
992
-		if ( isset( $data['tags'] ) && ! empty( $tags ) ) {
993
-			foreach ( $tags as $tag ) {
994
-				$this->set_term( $id, $tag, 'travel-style' );
990
+	public function set_travel_styles($id, $data) {
991
+		$tags = apply_filters('lsx_wetu_importer_tour_travel_styles', $data['tags']);
992
+		if (isset($data['tags']) && !empty($tags)) {
993
+			foreach ($tags as $tag) {
994
+				$this->set_term($id, $tag, 'travel-style');
995 995
 			}
996 996
 		}
997 997
 	}
@@ -999,14 +999,14 @@  discard block
 block discarded – undo
999 999
 	/**
1000 1000
 	 * Connects the Accommodation if its available
1001 1001
 	 */
1002
-	public function set_accommodation( $day, $id ) {
1002
+	public function set_accommodation($day, $id) {
1003 1003
 		$ac_id                       = false;
1004 1004
 		$this->current_accommodation = $this->find_current_accommodation();
1005 1005
 
1006
-		if ( isset( $day['content_entity_id'] ) && ! empty( $day['content_entity_id'] ) && ! in_array( (int) $day['content_entity_id'], array( 25862 ) ) ) {
1007
-			if ( false !== $this->current_accommodation && ! empty( $this->current_accommodation ) && array_key_exists( $day['content_entity_id'], $this->current_accommodation ) ) {
1008
-				$ac_id = $this->current_accommodation[ $day['content_entity_id'] ];
1009
-			} else {
1006
+		if (isset($day['content_entity_id']) && !empty($day['content_entity_id']) && !in_array((int) $day['content_entity_id'], array(25862))) {
1007
+			if (false !== $this->current_accommodation && !empty($this->current_accommodation) && array_key_exists($day['content_entity_id'], $this->current_accommodation)) {
1008
+				$ac_id = $this->current_accommodation[$day['content_entity_id']];
1009
+			}else {
1010 1010
 				$ac_id = wp_insert_post(
1011 1011
 					array(
1012 1012
 						'post_type'   => 'accommodation',
@@ -1015,13 +1015,13 @@  discard block
 block discarded – undo
1015 1015
 					)
1016 1016
 				);
1017 1017
 
1018
-				$this->save_custom_field( $day['content_entity_id'], 'lsx_wetu_id', $ac_id );
1018
+				$this->save_custom_field($day['content_entity_id'], 'lsx_wetu_id', $ac_id);
1019 1019
 			}
1020 1020
 
1021
-			if ( '' !== $ac_id && false !== $ac_id ) {
1022
-				$this->save_custom_field( $ac_id, 'accommodation_to_tour', $id, false, false );
1023
-				$this->save_custom_field( $id, 'tour_to_accommodation', $ac_id, false, false );
1024
-				$this->queue_item( $ac_id );
1021
+			if ('' !== $ac_id && false !== $ac_id) {
1022
+				$this->save_custom_field($ac_id, 'accommodation_to_tour', $id, false, false);
1023
+				$this->save_custom_field($id, 'tour_to_accommodation', $ac_id, false, false);
1024
+				$this->queue_item($ac_id);
1025 1025
 			}
1026 1026
 		}
1027 1027
 		return $ac_id;
@@ -1033,14 +1033,14 @@  discard block
 block discarded – undo
1033 1033
 	 * @param $post_type string
1034 1034
 	 * @return boolean / array
1035 1035
 	 */
1036
-	public function find_current_accommodation( $post_type = 'accommodation' ) {
1036
+	public function find_current_accommodation($post_type = 'accommodation') {
1037 1037
 		global $wpdb;
1038
-		$accommodation = parent::find_current_accommodation( $post_type );
1038
+		$accommodation = parent::find_current_accommodation($post_type);
1039 1039
 		$return        = false;
1040 1040
 
1041
-		if ( ! empty( $accommodation ) ) {
1042
-			foreach ( $accommodation as $key => $acc ) {
1043
-				$return[ $acc->meta_value ] = $acc->post_id;
1041
+		if (!empty($accommodation)) {
1042
+			foreach ($accommodation as $key => $acc) {
1043
+				$return[$acc->meta_value] = $acc->post_id;
1044 1044
 			}
1045 1045
 		}
1046 1046
 
@@ -1053,7 +1053,7 @@  discard block
 block discarded – undo
1053 1053
 	 * @return boolean / array
1054 1054
 	 */
1055 1055
 	public function find_current_destinations() {
1056
-		return $this->find_current_accommodation( 'destination' );
1056
+		return $this->find_current_accommodation('destination');
1057 1057
 	}
1058 1058
 
1059 1059
 	/**
@@ -1063,45 +1063,45 @@  discard block
 block discarded – undo
1063 1063
 	 * @param $id string
1064 1064
 	 * @return boolean / string
1065 1065
 	 */
1066
-	public function set_destination( $day, $id, $leg_counter ) {
1066
+	public function set_destination($day, $id, $leg_counter) {
1067 1067
 		$dest_id    = false;
1068 1068
 		$country_id = false;
1069 1069
 
1070 1070
 		$this->current_destinations = $this->find_current_destinations();
1071 1071
 
1072
-		if ( isset( $day['destination_content_entity_id'] ) && ! empty( $day['destination_content_entity_id'] ) ) {
1073
-			if ( false !== $this->current_destinations && ! empty( $this->current_destinations ) && array_key_exists( $day['destination_content_entity_id'], $this->current_destinations ) ) {
1074
-				$dest_id = $this->current_destinations[ $day['destination_content_entity_id'] ];
1072
+		if (isset($day['destination_content_entity_id']) && !empty($day['destination_content_entity_id'])) {
1073
+			if (false !== $this->current_destinations && !empty($this->current_destinations) && array_key_exists($day['destination_content_entity_id'], $this->current_destinations)) {
1074
+				$dest_id = $this->current_destinations[$day['destination_content_entity_id']];
1075 1075
 
1076 1076
 				// TODO Check for attachments here.
1077
-				$this->destination_images[ $id ][] = array( $dest_id, $day['destination_content_entity_id'] );
1077
+				$this->destination_images[$id][] = array($dest_id, $day['destination_content_entity_id']);
1078 1078
 
1079 1079
 				// Check if there is a country asigned.
1080
-				$potential_id    = wp_get_post_parent_id( $dest_id );
1081
-				$country_wetu_id = get_post_meta( $potential_id, 'lsx_wetu_id', true );
1080
+				$potential_id    = wp_get_post_parent_id($dest_id);
1081
+				$country_wetu_id = get_post_meta($potential_id, 'lsx_wetu_id', true);
1082 1082
 
1083
-				if ( false !== $country_wetu_id ) {
1084
-					$country_id = $this->set_country( $country_wetu_id, $id );
1083
+				if (false !== $country_wetu_id) {
1084
+					$country_id = $this->set_country($country_wetu_id, $id);
1085 1085
 					// $this->destination_images[ $id ][] = array( $id, $country_wetu_id );
1086 1086
 				}
1087
-			} else {
1088
-				$destination_json = wp_remote_get( 'https://wetu.com/API/Pins/' . $this->api_key . '/Get?ids=' . $day['destination_content_entity_id'] );
1087
+			}else {
1088
+				$destination_json = wp_remote_get('https://wetu.com/API/Pins/'.$this->api_key.'/Get?ids='.$day['destination_content_entity_id']);
1089 1089
 
1090
-				if ( ! is_wp_error( $destination_json ) && ! empty( $destination_json ) && isset( $destination_json['response'] ) && isset( $destination_json['response']['code'] ) && 200 === $destination_json['response']['code'] ) {
1090
+				if (!is_wp_error($destination_json) && !empty($destination_json) && isset($destination_json['response']) && isset($destination_json['response']['code']) && 200 === $destination_json['response']['code']) {
1091 1091
 
1092
-					$destination_data = json_decode( $destination_json['body'], true );
1092
+					$destination_data = json_decode($destination_json['body'], true);
1093 1093
 
1094
-					if ( ! empty( $destination_data ) && ! isset( $destination_data['error'] ) ) {
1094
+					if (!empty($destination_data) && !isset($destination_data['error'])) {
1095 1095
 						$destination_title = $day['destination_content_entity_id'];
1096 1096
 
1097
-						if ( isset( $destination_data[0]['name'] ) ) {
1097
+						if (isset($destination_data[0]['name'])) {
1098 1098
 							$destination_title = $destination_data[0]['name'];
1099 1099
 						}
1100 1100
 
1101
-						if ( isset( $destination_data[0]['map_object_id'] ) && isset( $destination_data[0]['position']['country_content_entity_id'] )
1102
-							&& $destination_data[0]['map_object_id'] !== $destination_data[0]['position']['country_content_entity_id'] ) {
1101
+						if (isset($destination_data[0]['map_object_id']) && isset($destination_data[0]['position']['country_content_entity_id'])
1102
+							&& $destination_data[0]['map_object_id'] !== $destination_data[0]['position']['country_content_entity_id']) {
1103 1103
 
1104
-							$country_id = $this->set_country( $destination_data[0]['position']['country_content_entity_id'], $id );
1104
+							$country_id = $this->set_country($destination_data[0]['position']['country_content_entity_id'], $id);
1105 1105
 							// Save the destination so we can grab the tour featured image and banner from them.
1106 1106
 						}
1107 1107
 
@@ -1111,40 +1111,40 @@  discard block
 block discarded – undo
1111 1111
 							'post_title'  => $destination_title,
1112 1112
 						);
1113 1113
 
1114
-						if ( false !== $country_id ) {
1114
+						if (false !== $country_id) {
1115 1115
 							$dest_post['post_parent'] = $country_id;
1116 1116
 						}
1117
-						$dest_id = wp_insert_post( $dest_post );
1117
+						$dest_id = wp_insert_post($dest_post);
1118 1118
 
1119 1119
 						// Make sure we register the.
1120
-						$this->current_destinations[ $day['destination_content_entity_id'] ] = $dest_id;
1120
+						$this->current_destinations[$day['destination_content_entity_id']] = $dest_id;
1121 1121
 
1122 1122
 						// If there are images attached then use the destination.
1123
-						if ( isset( $destination_data[0]['content']['images'] ) && ! empty( $destination_data[0]['content']['images'] ) ) {
1124
-							$this->destination_images[ $id ][] = array( $dest_id, $day['destination_content_entity_id'] );
1123
+						if (isset($destination_data[0]['content']['images']) && !empty($destination_data[0]['content']['images'])) {
1124
+							$this->destination_images[$id][] = array($dest_id, $day['destination_content_entity_id']);
1125 1125
 						}
1126 1126
 
1127
-						$this->save_custom_field( $day['destination_content_entity_id'], 'lsx_wetu_id', $dest_id );
1127
+						$this->save_custom_field($day['destination_content_entity_id'], 'lsx_wetu_id', $dest_id);
1128 1128
 					}
1129 1129
 				}
1130 1130
 			}
1131 1131
 
1132
-			if ( '' !== $dest_id && false !== $dest_id ) {
1133
-				$this->save_custom_field( $dest_id, 'destination_to_tour', $id, false, false );
1134
-				$this->save_custom_field( $id, 'tour_to_destination', $dest_id, false, false );
1132
+			if ('' !== $dest_id && false !== $dest_id) {
1133
+				$this->save_custom_field($dest_id, 'destination_to_tour', $id, false, false);
1134
+				$this->save_custom_field($id, 'tour_to_destination', $dest_id, false, false);
1135 1135
 
1136 1136
 				// Save the item to display in the queue
1137
-				$this->queue_item( $dest_id );
1137
+				$this->queue_item($dest_id);
1138 1138
 
1139 1139
 				// Save the item to clean up the amount of connections.
1140
-				$this->cleanup_posts[ $dest_id ] = 'tour_to_destination';
1140
+				$this->cleanup_posts[$dest_id] = 'tour_to_destination';
1141 1141
 
1142 1142
 				// Add this relation info so we can make sure certain items are set as countries.
1143
-				if ( 0 !== $country_id && false !== $country_id ) {
1144
-					$this->relation_meta[ $dest_id ]    = $country_id;
1145
-					$this->relation_meta[ $country_id ] = 0;
1146
-				} else {
1147
-					$this->relation_meta[ $dest_id ] = 0;
1143
+				if (0 !== $country_id && false !== $country_id) {
1144
+					$this->relation_meta[$dest_id]    = $country_id;
1145
+					$this->relation_meta[$country_id] = 0;
1146
+				}else {
1147
+					$this->relation_meta[$dest_id] = 0;
1148 1148
 				}
1149 1149
 			}
1150 1150
 		}
@@ -1160,23 +1160,23 @@  discard block
 block discarded – undo
1160 1160
 	 *
1161 1161
 	 * @return string
1162 1162
 	 */
1163
-	public function set_country( $country_wetu_id, $id ) {
1163
+	public function set_country($country_wetu_id, $id) {
1164 1164
 		$country_id                 = false;
1165 1165
 		$this->current_destinations = $this->find_current_destinations();
1166 1166
 
1167
-		if ( false !== $this->current_destinations && ! empty( $this->current_destinations ) && array_key_exists( $country_wetu_id, $this->current_destinations ) ) {
1168
-			$country_id                        = $this->current_destinations[ $country_wetu_id ];
1169
-			$this->destination_images[ $id ][] = array( $country_id, $country_wetu_id );
1170
-		} else {
1171
-			$country_json = wp_remote_get( 'https://wetu.com/API/Pins/' . $this->api_key . '/Get?ids=' . $country_wetu_id );
1167
+		if (false !== $this->current_destinations && !empty($this->current_destinations) && array_key_exists($country_wetu_id, $this->current_destinations)) {
1168
+			$country_id                        = $this->current_destinations[$country_wetu_id];
1169
+			$this->destination_images[$id][] = array($country_id, $country_wetu_id);
1170
+		}else {
1171
+			$country_json = wp_remote_get('https://wetu.com/API/Pins/'.$this->api_key.'/Get?ids='.$country_wetu_id);
1172 1172
 
1173
-			if ( ! is_wp_error( $country_json ) && ! empty( $country_json ) && isset( $country_json['response'] ) && isset( $country_json['response']['code'] ) && 200 === $country_json['response']['code'] ) {
1174
-				$country_data = json_decode( $country_json['body'], true );
1173
+			if (!is_wp_error($country_json) && !empty($country_json) && isset($country_json['response']) && isset($country_json['response']['code']) && 200 === $country_json['response']['code']) {
1174
+				$country_data = json_decode($country_json['body'], true);
1175 1175
 
1176 1176
 				// Format the title of the destination if its available,  otherwise default to the WETU ID.
1177 1177
 				$country_title = $country_wetu_id;
1178 1178
 
1179
-				if ( isset( $country_data[0]['name'] ) ) {
1179
+				if (isset($country_data[0]['name'])) {
1180 1180
 					$country_title = $country_data[0]['name'];
1181 1181
 				}
1182 1182
 
@@ -1189,23 +1189,23 @@  discard block
 block discarded – undo
1189 1189
 				);
1190 1190
 
1191 1191
 				// add the country to the current destination stack
1192
-				$this->current_destinations[ $country_wetu_id ] = $country_id;
1192
+				$this->current_destinations[$country_wetu_id] = $country_id;
1193 1193
 
1194 1194
 				// Check if there are images and save fore use later.
1195
-				if ( isset( $country_data[0]['content']['images'] ) && ! empty( $country_data[0]['content']['images'] ) ) {
1196
-					$this->destination_images[ $id ][] = array( $country_id, $country_wetu_id );
1195
+				if (isset($country_data[0]['content']['images']) && !empty($country_data[0]['content']['images'])) {
1196
+					$this->destination_images[$id][] = array($country_id, $country_wetu_id);
1197 1197
 				}
1198 1198
 
1199 1199
 				// Save the wetu field
1200
-				$this->save_custom_field( $country_wetu_id, 'lsx_wetu_id', $country_id );
1200
+				$this->save_custom_field($country_wetu_id, 'lsx_wetu_id', $country_id);
1201 1201
 			}
1202 1202
 		}
1203 1203
 
1204
-		if ( '' !== $country_id && false !== $country_id ) {
1205
-			$this->save_custom_field( $country_id, 'destination_to_tour', $id, false, false );
1206
-			$this->save_custom_field( $id, 'tour_to_destination', $country_id, false, false );
1207
-			$this->queue_item( $country_id );
1208
-			$this->cleanup_posts[ $country_id ] = 'tour_to_destination';
1204
+		if ('' !== $country_id && false !== $country_id) {
1205
+			$this->save_custom_field($country_id, 'destination_to_tour', $id, false, false);
1206
+			$this->save_custom_field($id, 'tour_to_destination', $country_id, false, false);
1207
+			$this->queue_item($country_id);
1208
+			$this->cleanup_posts[$country_id] = 'tour_to_destination';
1209 1209
 
1210 1210
 			return $country_id;
1211 1211
 		}
@@ -1220,42 +1220,42 @@  discard block
 block discarded – undo
1220 1220
 	 *
1221 1221
 	 * @return string
1222 1222
 	 */
1223
-	public function attach_destination_images( $importable_content = array() ) {
1224
-		if ( false !== $this->destination_images ) {
1225
-			$this->shuffle_assoc( $this->destination_images );
1226
-			foreach ( $this->destination_images as $tour => $destinations ) {
1227
-				shuffle( $destinations );
1223
+	public function attach_destination_images($importable_content = array()) {
1224
+		if (false !== $this->destination_images) {
1225
+			$this->shuffle_assoc($this->destination_images);
1226
+			foreach ($this->destination_images as $tour => $destinations) {
1227
+				shuffle($destinations);
1228 1228
 				$image_set = false;
1229 1229
 				$forced    = false;
1230 1230
 
1231
-				foreach ( $destinations as $destination ) {
1232
-					if ( false === $image_set && false === $forced ) {
1233
-						$url = 'https://wetu.com/API/Pins/' . $this->api_key;
1231
+				foreach ($destinations as $destination) {
1232
+					if (false === $image_set && false === $forced) {
1233
+						$url = 'https://wetu.com/API/Pins/'.$this->api_key;
1234 1234
 
1235 1235
 						$url_qs = '';
1236
-						$jdata  = wp_remote_get( $url . '/Get?' . $url_qs . '&ids=' . $destination[1] );
1236
+						$jdata  = wp_remote_get($url.'/Get?'.$url_qs.'&ids='.$destination[1]);
1237 1237
 
1238
-						if ( ! is_wp_error( $jdata ) && ! empty( $jdata ) && isset( $jdata['response'] ) && isset( $jdata['response']['code'] ) && 200 === $jdata['response']['code'] ) {
1239
-							$adata = json_decode( $jdata['body'], true );
1238
+						if (!is_wp_error($jdata) && !empty($jdata) && isset($jdata['response']) && isset($jdata['response']['code']) && 200 === $jdata['response']['code']) {
1239
+							$adata = json_decode($jdata['body'], true);
1240 1240
 
1241
-							if ( ! empty( $adata ) && ! empty( $adata[0]['content']['images'] ) ) {
1242
-								$this->find_attachments( $destination[0] );
1241
+							if (!empty($adata) && !empty($adata[0]['content']['images'])) {
1242
+								$this->find_attachments($destination[0]);
1243 1243
 
1244 1244
 								// Set the featured image.
1245
-								if ( false !== $importable_content && in_array( 'featured_image', $importable_content ) ) {
1246
-									$image_set = $this->set_featured_image( $adata, $tour );
1247
-									if ( false !== $importable_content && in_array( 'banner_image', $importable_content ) ) {
1248
-										$image_set = $this->set_banner_image( $adata, $tour );
1245
+								if (false !== $importable_content && in_array('featured_image', $importable_content)) {
1246
+									$image_set = $this->set_featured_image($adata, $tour);
1247
+									if (false !== $importable_content && in_array('banner_image', $importable_content)) {
1248
+										$image_set = $this->set_banner_image($adata, $tour);
1249 1249
 										$forced    = true;
1250 1250
 									}
1251 1251
 									continue;
1252 1252
 								}
1253
-								if ( false !== $importable_content && in_array( 'banner_image', $importable_content ) ) {
1254
-									$image_set = $this->set_banner_image( $adata, $tour );
1253
+								if (false !== $importable_content && in_array('banner_image', $importable_content)) {
1254
+									$image_set = $this->set_banner_image($adata, $tour);
1255 1255
 								}
1256 1256
 							}
1257 1257
 						}
1258
-					} else {
1258
+					}else {
1259 1259
 						continue;
1260 1260
 					}
1261 1261
 				}
@@ -1266,31 +1266,31 @@  discard block
 block discarded – undo
1266 1266
 	/**
1267 1267
 	 * Creates the main gallery data
1268 1268
 	 */
1269
-	public function set_featured_image( $data, $id ) {
1269
+	public function set_featured_image($data, $id) {
1270 1270
 		$image_set = false;
1271 1271
 		$counter   = 0;
1272 1272
 
1273
-		if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) {
1273
+		if (is_array($data[0]['content']['images']) && !empty($data[0]['content']['images'])) {
1274 1274
 			$images_array = $data[0]['content']['images'];
1275 1275
 
1276
-			if ( 'on' === $this->options['enable_tour_featured_random'] ) {
1277
-				shuffle( $images_array );
1276
+			if ('on' === $this->options['enable_tour_featured_random']) {
1277
+				shuffle($images_array);
1278 1278
 			}
1279 1279
 
1280
-			foreach ( $images_array as $v ) {
1280
+			foreach ($images_array as $v) {
1281 1281
 
1282
-				if ( true === $image_set ) {
1282
+				if (true === $image_set) {
1283 1283
 					$counter++;
1284 1284
 					continue;
1285 1285
 				}
1286 1286
 
1287
-				if ( ! $this->check_if_image_is_used( $v ) ) {
1288
-					$temp_featured_image = $this->attach_image( $v, $id );
1287
+				if (!$this->check_if_image_is_used($v)) {
1288
+					$temp_featured_image = $this->attach_image($v, $id);
1289 1289
 
1290
-					if ( false !== $temp_featured_image ) {
1290
+					if (false !== $temp_featured_image) {
1291 1291
 						$this->featured_image = $temp_featured_image;
1292
-						delete_post_meta( $id, '_thumbnail_id' );
1293
-						add_post_meta( $id, '_thumbnail_id', $this->featured_image, true );
1292
+						delete_post_meta($id, '_thumbnail_id');
1293
+						add_post_meta($id, '_thumbnail_id', $this->featured_image, true);
1294 1294
 						$image_set = true;
1295 1295
 					}
1296 1296
 				}
@@ -1304,24 +1304,24 @@  discard block
 block discarded – undo
1304 1304
 	/**
1305 1305
 	 * Sets a banner image
1306 1306
 	 */
1307
-	public function set_banner_image( $data, $id, $content = array( 'none' ) ) {
1307
+	public function set_banner_image($data, $id, $content = array('none')) {
1308 1308
 		$image_set = false;
1309 1309
 		$counter   = 0;
1310 1310
 
1311
-		if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) {
1311
+		if (is_array($data[0]['content']['images']) && !empty($data[0]['content']['images'])) {
1312 1312
 
1313
-			foreach ( $data[0]['content']['images'] as $v ) {
1313
+			foreach ($data[0]['content']['images'] as $v) {
1314 1314
 				/*
1315 1315
 				print_r('<pre>');
1316 1316
 				print_r( $v );
1317 1317
 				print_r('</pre>');*/
1318 1318
 
1319
-				if ( true === $image_set || 0 === $counter ) {
1319
+				if (true === $image_set || 0 === $counter) {
1320 1320
 					$counter++;
1321 1321
 					continue;
1322 1322
 				}
1323 1323
 
1324
-				if ( ! $this->check_if_image_is_used( $v ) ) {
1324
+				if (!$this->check_if_image_is_used($v)) {
1325 1325
 					$temp_banner = $this->attach_image(
1326 1326
 						$v,
1327 1327
 						$id,
@@ -1332,17 +1332,17 @@  discard block
 block discarded – undo
1332 1332
 						)
1333 1333
 					);
1334 1334
 
1335
-					if ( false !== $temp_banner ) {
1335
+					if (false !== $temp_banner) {
1336 1336
 						$this->banner_image = $temp_banner;
1337 1337
 
1338
-						delete_post_meta( $id, 'image_group' );
1338
+						delete_post_meta($id, 'image_group');
1339 1339
 
1340 1340
 						$new_banner = array(
1341 1341
 							'banner_image' => array(
1342 1342
 								'cmb-field-0' => $this->banner_image,
1343 1343
 							),
1344 1344
 						);
1345
-						add_post_meta( $id, 'image_group', $new_banner, true );
1345
+						add_post_meta($id, 'image_group', $new_banner, true);
1346 1346
 						$image_set = true;
1347 1347
 					}
1348 1348
 				}
@@ -1356,29 +1356,29 @@  discard block
 block discarded – undo
1356 1356
 	/**
1357 1357
 	 * Grabs all of the current used featured images on the site.
1358 1358
 	 */
1359
-	public function check_if_image_is_used( $v ) {
1359
+	public function check_if_image_is_used($v) {
1360 1360
 		global $wpdb;
1361 1361
 		$return = false;
1362 1362
 
1363
-		$results        = $wpdb->get_results(
1363
+		$results = $wpdb->get_results(
1364 1364
 			$wpdb->prepare(
1365 1365
 				"SELECT post_id
1366 1366
 				 FROM {$wpdb->postmeta}
1367 1367
 				 WHERE meta_value = '%s'
1368 1368
 				 AND meta_key = 'lsx_wetu_id'
1369 1369
 				",
1370
-				array( $value )
1370
+				array($value)
1371 1371
 			)
1372 1372
 		);
1373 1373
 		$attached_tours = array();
1374
-		if ( ! empty( $results ) ) {
1375
-			foreach ( $results as $result ) {
1376
-				if ( 'tour' === get_post_type( $result['post_id'] ) ) {
1374
+		if (!empty($results)) {
1375
+			foreach ($results as $result) {
1376
+				if ('tour' === get_post_type($result['post_id'])) {
1377 1377
 					$attached_tours[] = $result['post_id'];
1378 1378
 				}
1379 1379
 			}
1380 1380
 		}
1381
-		if ( ! empty( $attached_tours ) ) {
1381
+		if (!empty($attached_tours)) {
1382 1382
 			$return = true;
1383 1383
 		}
1384 1384
 		return $return;
@@ -1389,10 +1389,10 @@  discard block
 block discarded – undo
1389 1389
 	 *
1390 1390
 	 * @param   $id     int
1391 1391
 	 */
1392
-	public function queue_item( $id ) {
1393
-		if ( is_array( $this->import_queue ) && ! in_array( $id, $this->import_queue ) ) {
1392
+	public function queue_item($id) {
1393
+		if (is_array($this->import_queue) && !in_array($id, $this->import_queue)) {
1394 1394
 			$this->import_queue[] = $id;
1395
-		} else {
1395
+		}else {
1396 1396
 			$this->import_queue[] = $id;
1397 1397
 		}
1398 1398
 	}
@@ -1401,18 +1401,18 @@  discard block
 block discarded – undo
1401 1401
 	 * Saves the queue to the option.
1402 1402
 	 */
1403 1403
 	public function save_queue() {
1404
-		if ( ! empty( $this->import_queue ) ) {
1405
-			if ( ! empty( $this->queued_imports ) ) {
1406
-				$saved_imports = array_merge( $this->queued_imports, $this->import_queue );
1407
-			} else {
1404
+		if (!empty($this->import_queue)) {
1405
+			if (!empty($this->queued_imports)) {
1406
+				$saved_imports = array_merge($this->queued_imports, $this->import_queue);
1407
+			}else {
1408 1408
 				$saved_imports = $this->import_queue;
1409 1409
 			}
1410 1410
 
1411
-			delete_option( 'lsx_wetu_importer_que' );
1411
+			delete_option('lsx_wetu_importer_que');
1412 1412
 
1413
-			if ( ! empty( $saved_imports ) ) {
1414
-				$saved_imports = array_unique( $saved_imports );
1415
-				update_option( 'lsx_wetu_importer_que', $saved_imports );
1413
+			if (!empty($saved_imports)) {
1414
+				$saved_imports = array_unique($saved_imports);
1415
+				update_option('lsx_wetu_importer_que', $saved_imports);
1416 1416
 			}
1417 1417
 		}
1418 1418
 	}
@@ -1425,14 +1425,14 @@  discard block
 block discarded – undo
1425 1425
 		<thead>
1426 1426
 		<tr>
1427 1427
 			<th class="manage-column column-cb check-column" id="cb" scope="col">
1428
-				<label for="cb-select-all-1" class="screen-reader-text"><?php esc_attr_e( 'Select All', 'lsx-wetu-importer' ); ?></label>
1428
+				<label for="cb-select-all-1" class="screen-reader-text"><?php esc_attr_e('Select All', 'lsx-wetu-importer'); ?></label>
1429 1429
 				<input type="checkbox" id="cb-select-all-1">
1430 1430
 			</th>
1431
-			<th class="manage-column column-order " id="order" scope="col"><?php esc_attr_e( 'Order', 'lsx-wetu-importer' ); ?></th>
1432
-			<th class="manage-column column-title " id="title" scope="col"><?php esc_attr_e( 'Title', 'lsx-wetu-importer' ); ?></th>
1433
-			<th class="manage-column column-date" id="ref" scope="col"><?php esc_attr_e( 'Ref', 'lsx-wetu-importer' ); ?></th>
1434
-			<th class="manage-column column-date" id="date" scope="col"><?php esc_attr_e( 'Date', 'lsx-wetu-importer' ); ?></th>
1435
-			<th class="manage-column column-ssid" id="ssid" scope="col"><?php esc_attr_e( 'WETU ID', 'lsx-wetu-importer' ); ?></th>
1431
+			<th class="manage-column column-order " id="order" scope="col"><?php esc_attr_e('Order', 'lsx-wetu-importer'); ?></th>
1432
+			<th class="manage-column column-title " id="title" scope="col"><?php esc_attr_e('Title', 'lsx-wetu-importer'); ?></th>
1433
+			<th class="manage-column column-date" id="ref" scope="col"><?php esc_attr_e('Ref', 'lsx-wetu-importer'); ?></th>
1434
+			<th class="manage-column column-date" id="date" scope="col"><?php esc_attr_e('Date', 'lsx-wetu-importer'); ?></th>
1435
+			<th class="manage-column column-ssid" id="ssid" scope="col"><?php esc_attr_e('WETU ID', 'lsx-wetu-importer'); ?></th>
1436 1436
 		</tr>
1437 1437
 		</thead>
1438 1438
 		<?php
@@ -1446,14 +1446,14 @@  discard block
 block discarded – undo
1446 1446
 		<tfoot>
1447 1447
 		<tr>
1448 1448
 			<th class="manage-column column-cb check-column" id="cb" scope="col">
1449
-				<label for="cb-select-all-1" class="screen-reader-text"><?php esc_attr_e( 'Select All', 'lsx-wetu-importer' ); ?></label>
1449
+				<label for="cb-select-all-1" class="screen-reader-text"><?php esc_attr_e('Select All', 'lsx-wetu-importer'); ?></label>
1450 1450
 				<input type="checkbox" id="cb-select-all-1">
1451 1451
 			</th>
1452
-			<th class="manage-column column-order " id="order" scope="col"><?php esc_attr_e( 'Order', 'lsx-wetu-importer' ); ?></th>
1453
-			<th class="manage-column column-title" scope="col"><?php esc_attr_e( 'Title', 'lsx-wetu-importer' ); ?></th>
1454
-			<th class="manage-column column-date" id="ref" scope="col"><?php esc_attr_e( 'Ref', 'lsx-wetu-importer' ); ?></th>
1455
-			<th class="manage-column column-date" scope="col"><?php esc_attr_e( 'Date', 'lsx-wetu-importer' ); ?></th>
1456
-			<th class="manage-column column-ssid" scope="col"><?php esc_attr_e( 'WETU ID', 'lsx-wetu-importer' ); ?></th>
1452
+			<th class="manage-column column-order " id="order" scope="col"><?php esc_attr_e('Order', 'lsx-wetu-importer'); ?></th>
1453
+			<th class="manage-column column-title" scope="col"><?php esc_attr_e('Title', 'lsx-wetu-importer'); ?></th>
1454
+			<th class="manage-column column-date" id="ref" scope="col"><?php esc_attr_e('Ref', 'lsx-wetu-importer'); ?></th>
1455
+			<th class="manage-column column-date" scope="col"><?php esc_attr_e('Date', 'lsx-wetu-importer'); ?></th>
1456
+			<th class="manage-column column-ssid" scope="col"><?php esc_attr_e('WETU ID', 'lsx-wetu-importer'); ?></th>
1457 1457
 		</tr>
1458 1458
 		</tfoot>
1459 1459
 		<?php
Please login to merge, or discard this patch.
lsx-importer-for-wetu.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -11,13 +11,13 @@
 block discarded – undo
11 11
  * Domain Path: /languages/
12 12
  */
13 13
 
14
-define( 'LSX_WETU_IMPORTER_PATH', plugin_dir_path( __FILE__ ) );
15
-define( 'LSX_WETU_IMPORTER_CORE', __FILE__ );
16
-define( 'LSX_WETU_IMPORTER_URL', plugin_dir_url( __FILE__ ) );
17
-define( 'LSX_WETU_IMPORTER_VER', '1.3.7' );
14
+define('LSX_WETU_IMPORTER_PATH', plugin_dir_path(__FILE__));
15
+define('LSX_WETU_IMPORTER_CORE', __FILE__);
16
+define('LSX_WETU_IMPORTER_URL', plugin_dir_url(__FILE__));
17
+define('LSX_WETU_IMPORTER_VER', '1.3.7');
18 18
 
19
-register_activation_hook( LSX_WETU_IMPORTER_CORE, array( 'LSX_WETU_Importer', 'register_activation_hook' ) );
19
+register_activation_hook(LSX_WETU_IMPORTER_CORE, array('LSX_WETU_Importer', 'register_activation_hook'));
20 20
 
21 21
 /* ======================= Below is the Plugin Class init ========================= */
22 22
 
23
-require_once LSX_WETU_IMPORTER_PATH . 'classes/class-lsx-wetu-importer.php';
23
+require_once LSX_WETU_IMPORTER_PATH.'classes/class-lsx-wetu-importer.php';
Please login to merge, or discard this patch.