Passed
Push — dependabot/npm_and_yarn/jshint... ( dd9a84 )
by
unknown
08:54
created
classes/class-lsx-wetu-importer-welcome.php 2 patches
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 	 */
39 39
 	public static function get_instance() {
40 40
 		// If the single instance hasn't been set, set it now.
41
-		if ( ! isset( self::$instance ) ) {
41
+		if (!isset(self::$instance)) {
42 42
 			self::$instance = new self();
43 43
 		}
44 44
 		return self::$instance;
@@ -50,8 +50,8 @@  discard block
 block discarded – undo
50 50
 	public function display_page() {
51 51
 		?>
52 52
 		<div class="row section">
53
-			<h1><?php esc_html_e( 'Welcome to the LSX Importer for Wetu', 'lsx-wetu-importer' ); ?></h1>
54
-			<p><?php esc_html_e( 'If this is the first time running the import, please follow the steps below.', 'lsx-wetu-importer' ); ?></p>
53
+			<h1><?php esc_html_e('Welcome to the LSX Importer for Wetu', 'lsx-wetu-importer'); ?></h1>
54
+			<p><?php esc_html_e('If this is the first time running the import, please follow the steps below.', 'lsx-wetu-importer'); ?></p>
55 55
 		</div>
56 56
 		<?php
57 57
 		$this->importer_steps();
@@ -67,19 +67,19 @@  discard block
 block discarded – undo
67 67
 		?>
68 68
 		<div class="row section postbox">
69 69
 			<div class="welcome-block-header">
70
-				<p class="heading"><a href="<?php echo esc_attr( admin_url( 'admin.php' ) . '?page=lsx-wetu-importer&tab=tour' ); ?>"><?php esc_html_e( 'Import your tours', 'lsx-wetu-importer' ); ?></a></p>
71
-				<p class="value"><a href="<?php echo esc_attr( admin_url( 'admin.php' ) . '?page=lsx-wetu-importer&tab=tour' ); ?>"><span>1</span></a></p>
70
+				<p class="heading"><a href="<?php echo esc_attr(admin_url('admin.php').'?page=lsx-wetu-importer&tab=tour'); ?>"><?php esc_html_e('Import your tours', 'lsx-wetu-importer'); ?></a></p>
71
+				<p class="value"><a href="<?php echo esc_attr(admin_url('admin.php').'?page=lsx-wetu-importer&tab=tour'); ?>"><span>1</span></a></p>
72 72
 			</div>
73 73
 			<div class="welcome-block-header">
74
-				<p class="heading"><a href="<?php echo esc_attr( admin_url( 'admin.php' ) . '?page=lsx-wetu-importer&tab=accommodation' ); ?>"><?php esc_html_e( 'Import accommodation', 'lsx-wetu-importer' ); ?></a></p>
75
-				<p class="value"><a href="<?php echo esc_attr( admin_url( 'admin.php' ) . '?page=lsx-wetu-importer&tab=accommodation' ); ?>"><span>2</span></a></p>
74
+				<p class="heading"><a href="<?php echo esc_attr(admin_url('admin.php').'?page=lsx-wetu-importer&tab=accommodation'); ?>"><?php esc_html_e('Import accommodation', 'lsx-wetu-importer'); ?></a></p>
75
+				<p class="value"><a href="<?php echo esc_attr(admin_url('admin.php').'?page=lsx-wetu-importer&tab=accommodation'); ?>"><span>2</span></a></p>
76 76
 			</div>
77 77
 			<div class="welcome-block-header">
78
-				<p class="heading"><a href="<?php echo esc_attr( admin_url( 'admin.php' ) . '?page=lsx-wetu-importer&tab=destination' ); ?>"><?php esc_html_e( 'Import destination', 'lsx-wetu-importer' ); ?></a></p>
79
-				<p class="value"><a href="<?php echo esc_attr( admin_url( 'admin.php' ) . '?page=lsx-wetu-importer&tab=destination' ); ?>"><span>3</span></a></p>
78
+				<p class="heading"><a href="<?php echo esc_attr(admin_url('admin.php').'?page=lsx-wetu-importer&tab=destination'); ?>"><?php esc_html_e('Import destination', 'lsx-wetu-importer'); ?></a></p>
79
+				<p class="value"><a href="<?php echo esc_attr(admin_url('admin.php').'?page=lsx-wetu-importer&tab=destination'); ?>"><span>3</span></a></p>
80 80
 			</div>
81 81
 			<div class="welcome-block-header">
82
-				<p class="heading"><?php esc_html_e( 'Done', 'lsx-wetu-importer' ); ?></p>
82
+				<p class="heading"><?php esc_html_e('Done', 'lsx-wetu-importer'); ?></p>
83 83
 				<p class="value"><span class="dashicons dashicons-yes"></span></p>
84 84
 			</div>
85 85
 			<div class="spacer"></div>
@@ -118,14 +118,14 @@  discard block
 block discarded – undo
118 118
 	 */
119 119
 	public function tour_block() {
120 120
 		?>
121
-			<h2 class="title"><?php esc_html_e( 'Importing tours', 'lsx-wetu-importer' ); ?></h2>
122
-			<p class="excerpt"><?php esc_html_e( 'Search for tours, select the ones you want to import and choose the data you want to sync on import. All connected accommodadtions will be imported as drafts to be pubished after completing the tour import.', 'lsx-wetu-importer' ); ?></p>
123
-			<p><a href="<?php echo esc_attr( admin_url( 'admin.php' ) . '?page=lsx-wetu-importer&tab=tour' ); ?>" class="button button-primary"><?php esc_html_e( 'Import Tours', 'lsx-wetu-importer' ); ?></a></p>
121
+			<h2 class="title"><?php esc_html_e('Importing tours', 'lsx-wetu-importer'); ?></h2>
122
+			<p class="excerpt"><?php esc_html_e('Search for tours, select the ones you want to import and choose the data you want to sync on import. All connected accommodadtions will be imported as drafts to be pubished after completing the tour import.', 'lsx-wetu-importer'); ?></p>
123
+			<p><a href="<?php echo esc_attr(admin_url('admin.php').'?page=lsx-wetu-importer&tab=tour'); ?>" class="button button-primary"><?php esc_html_e('Import Tours', 'lsx-wetu-importer'); ?></a></p>
124 124
 			<p>
125 125
 				<ul class="link-list">
126
-					<li><a href="<?php echo esc_attr( admin_url( 'admin.php' ) . '?page=lsx-wetu-importer&tab=tour' ); ?>#publish"><?php esc_html_e( 'Published', 'lsx-wetu-importer' ); ?>  (<?php echo esc_attr( lsx_wetu_get_post_count( 'tour', 'publish ' ) ); ?>)</a></li>
127
-					<li><a href="<?php echo esc_attr( admin_url( 'admin.php' ) . '?page=lsx-wetu-importer&tab=tour' ); ?>#pending"><?php esc_html_e( 'Pending', 'lsx-wetu-importer' ); ?>  (<?php echo esc_attr( lsx_wetu_get_post_count( 'tour', 'pending ' ) ); ?>)</a></li>
128
-					<li><a href="<?php echo esc_attr( admin_url( 'admin.php' ) . '?page=lsx-wetu-importer&tab=tour' ); ?>#draft"><?php esc_html_e( 'Draft', 'lsx-wetu-importer' ); ?>  (<?php echo esc_attr( lsx_wetu_get_post_count( 'tour', 'draft ' ) ); ?>)</a></li>
126
+					<li><a href="<?php echo esc_attr(admin_url('admin.php').'?page=lsx-wetu-importer&tab=tour'); ?>#publish"><?php esc_html_e('Published', 'lsx-wetu-importer'); ?>  (<?php echo esc_attr(lsx_wetu_get_post_count('tour', 'publish ')); ?>)</a></li>
127
+					<li><a href="<?php echo esc_attr(admin_url('admin.php').'?page=lsx-wetu-importer&tab=tour'); ?>#pending"><?php esc_html_e('Pending', 'lsx-wetu-importer'); ?>  (<?php echo esc_attr(lsx_wetu_get_post_count('tour', 'pending ')); ?>)</a></li>
128
+					<li><a href="<?php echo esc_attr(admin_url('admin.php').'?page=lsx-wetu-importer&tab=tour'); ?>#draft"><?php esc_html_e('Draft', 'lsx-wetu-importer'); ?>  (<?php echo esc_attr(lsx_wetu_get_post_count('tour', 'draft ')); ?>)</a></li>
129 129
 				</ul>
130 130
 			</p>			
131 131
 		<?php
@@ -137,16 +137,16 @@  discard block
 block discarded – undo
137 137
 	 */
138 138
 	public function accommodation_block() {
139 139
 		?>
140
-			<h2 class="title"><?php esc_html_e( 'Import and publish accommodation', 'lsx-wetu-importer' ); ?></h2>
141
-			<p class="excerpt"><?php esc_html_e( 'All accommodations connnected to your tours have been imported as drafts. Review the imported accommodations, sync selected data and publish.', 'lsx-wetu-importer' ); ?></p>
142
-			<p><a href="<?php echo esc_attr( admin_url( 'admin.php' ) . '?page=lsx-wetu-importer&tab=accommodation' ); ?>" class="button button-primary"><?php esc_html_e( 'Sync accommodation', 'lsx-wetu-importer' ); ?></a></p>
140
+			<h2 class="title"><?php esc_html_e('Import and publish accommodation', 'lsx-wetu-importer'); ?></h2>
141
+			<p class="excerpt"><?php esc_html_e('All accommodations connnected to your tours have been imported as drafts. Review the imported accommodations, sync selected data and publish.', 'lsx-wetu-importer'); ?></p>
142
+			<p><a href="<?php echo esc_attr(admin_url('admin.php').'?page=lsx-wetu-importer&tab=accommodation'); ?>" class="button button-primary"><?php esc_html_e('Sync accommodation', 'lsx-wetu-importer'); ?></a></p>
143 143
 
144 144
 			<p>
145 145
 				<ul class="link-list">
146
-					<li><a href="<?php echo esc_attr( admin_url( 'admin.php' ) . '?page=lsx-wetu-importer&tab=accommodation' ); ?>#publish"><?php esc_html_e( 'Published', 'lsx-wetu-importer' ); ?> (<?php echo esc_attr( lsx_wetu_get_post_count( 'accommodation', 'publish ' ) ); ?>)</a></li>
147
-					<li><a href="<?php echo esc_attr( admin_url( 'admin.php' ) . '?page=lsx-wetu-importer&tab=accommodation' ); ?>#pending"><?php esc_html_e( 'Pending', 'lsx-wetu-importer' ); ?> (<?php echo esc_attr( lsx_wetu_get_post_count( 'accommodation', 'pending ' ) ); ?>)</a></li>
148
-					<li><a href="<?php echo esc_attr( admin_url( 'admin.php' ) . '?page=lsx-wetu-importer&tab=accommodation' ); ?>#draft"><?php esc_html_e( 'Draft', 'lsx-wetu-importer' ); ?> (<?php echo esc_attr( lsx_wetu_get_post_count( 'accommodation', 'draft ' ) ); ?>)</a></li>
149
-					<li><a href="<?php echo esc_attr( admin_url( 'admin.php' ) . '?page=lsx-wetu-importer&tab=accommodation' ); ?>#import"><?php esc_html_e( 'Wetu Queue', 'lsx-wetu-importer' ); ?>  (<?php echo esc_attr( lsx_wetu_get_queue_count( 'accommodation' ) ); ?>)</a></li>
146
+					<li><a href="<?php echo esc_attr(admin_url('admin.php').'?page=lsx-wetu-importer&tab=accommodation'); ?>#publish"><?php esc_html_e('Published', 'lsx-wetu-importer'); ?> (<?php echo esc_attr(lsx_wetu_get_post_count('accommodation', 'publish ')); ?>)</a></li>
147
+					<li><a href="<?php echo esc_attr(admin_url('admin.php').'?page=lsx-wetu-importer&tab=accommodation'); ?>#pending"><?php esc_html_e('Pending', 'lsx-wetu-importer'); ?> (<?php echo esc_attr(lsx_wetu_get_post_count('accommodation', 'pending ')); ?>)</a></li>
148
+					<li><a href="<?php echo esc_attr(admin_url('admin.php').'?page=lsx-wetu-importer&tab=accommodation'); ?>#draft"><?php esc_html_e('Draft', 'lsx-wetu-importer'); ?> (<?php echo esc_attr(lsx_wetu_get_post_count('accommodation', 'draft ')); ?>)</a></li>
149
+					<li><a href="<?php echo esc_attr(admin_url('admin.php').'?page=lsx-wetu-importer&tab=accommodation'); ?>#import"><?php esc_html_e('Wetu Queue', 'lsx-wetu-importer'); ?>  (<?php echo esc_attr(lsx_wetu_get_queue_count('accommodation')); ?>)</a></li>
150 150
 				</ul>
151 151
 			</p>			
152 152
 		<?php
@@ -158,15 +158,15 @@  discard block
 block discarded – undo
158 158
 	 */
159 159
 	public function destination_block() {
160 160
 		?>
161
-			<h2 class="title"><?php esc_html_e( 'Import and publish destinations', 'lsx-wetu-importer' ); ?></h2>
162
-			<p class="excerpt"><?php esc_html_e( 'All destinations and regions connnected to your tours & accommodations have been imported as drafts. Review the imported accommodations, sync selected data and publish.', 'lsx-wetu-importer' ); ?></p>
163
-			<p><a href="<?php echo esc_attr( admin_url( 'admin.php' ) . '?page=lsx-wetu-importer&tab=destination' ); ?>" class="button button-primary"><?php esc_html_e( 'Sync destinations', 'lsx-wetu-importer' ); ?></a></p>
161
+			<h2 class="title"><?php esc_html_e('Import and publish destinations', 'lsx-wetu-importer'); ?></h2>
162
+			<p class="excerpt"><?php esc_html_e('All destinations and regions connnected to your tours & accommodations have been imported as drafts. Review the imported accommodations, sync selected data and publish.', 'lsx-wetu-importer'); ?></p>
163
+			<p><a href="<?php echo esc_attr(admin_url('admin.php').'?page=lsx-wetu-importer&tab=destination'); ?>" class="button button-primary"><?php esc_html_e('Sync destinations', 'lsx-wetu-importer'); ?></a></p>
164 164
 			<p>
165 165
 				<ul class="link-list">
166
-					<li><a href="<?php echo esc_attr( admin_url( 'admin.php' ) . '?page=lsx-wetu-importer&tab=destination' ); ?>#publish"><?php esc_html_e( 'Published', 'lsx-wetu-importer' ); ?> (<?php echo esc_attr( lsx_wetu_get_post_count( 'destination', 'publish ' ) ); ?>)</a></li>
167
-					<li><a href="<?php echo esc_attr( admin_url( 'admin.php' ) . '?page=lsx-wetu-importer&tab=destination' ); ?>#pending"><?php esc_html_e( 'Pending', 'lsx-wetu-importer' ); ?> (<?php echo esc_attr( lsx_wetu_get_post_count( 'destination', 'pending ' ) ); ?>)</a></li>
168
-					<li><a href="<?php echo esc_attr( admin_url( 'admin.php' ) . '?page=lsx-wetu-importer&tab=destination' ); ?>#draft"><?php esc_html_e( 'Draft', 'lsx-wetu-importer' ); ?> (<?php echo esc_attr( lsx_wetu_get_post_count( 'destination', 'draft ' ) ); ?>)</a></li>
169
-					<li><a href="<?php echo esc_attr( admin_url( 'admin.php' ) . '?page=lsx-wetu-importer&tab=destination' ); ?>#import"><?php esc_html_e( 'Wetu Queue', 'lsx-wetu-importer' ); ?>  (<?php echo esc_attr( lsx_wetu_get_queue_count( 'destination' ) ); ?>)</a></li>
166
+					<li><a href="<?php echo esc_attr(admin_url('admin.php').'?page=lsx-wetu-importer&tab=destination'); ?>#publish"><?php esc_html_e('Published', 'lsx-wetu-importer'); ?> (<?php echo esc_attr(lsx_wetu_get_post_count('destination', 'publish ')); ?>)</a></li>
167
+					<li><a href="<?php echo esc_attr(admin_url('admin.php').'?page=lsx-wetu-importer&tab=destination'); ?>#pending"><?php esc_html_e('Pending', 'lsx-wetu-importer'); ?> (<?php echo esc_attr(lsx_wetu_get_post_count('destination', 'pending ')); ?>)</a></li>
168
+					<li><a href="<?php echo esc_attr(admin_url('admin.php').'?page=lsx-wetu-importer&tab=destination'); ?>#draft"><?php esc_html_e('Draft', 'lsx-wetu-importer'); ?> (<?php echo esc_attr(lsx_wetu_get_post_count('destination', 'draft ')); ?>)</a></li>
169
+					<li><a href="<?php echo esc_attr(admin_url('admin.php').'?page=lsx-wetu-importer&tab=destination'); ?>#import"><?php esc_html_e('Wetu Queue', 'lsx-wetu-importer'); ?>  (<?php echo esc_attr(lsx_wetu_get_queue_count('destination')); ?>)</a></li>
170 170
 				</ul>
171 171
 			</p>
172 172
 		<?php
@@ -178,8 +178,8 @@  discard block
 block discarded – undo
178 178
 	 */
179 179
 	public function end_block() {
180 180
 		?>
181
-			<h2 class="title"><?php esc_html_e( 'Done! Check out your imported content', 'lsx-wetu-importer' ); ?></h2>
182
-			<p><?php esc_html_e( 'If you’ve updated your content on Wetu then you can return to these steps at any stage to import and re-sync any updates', 'lsx-wetu-importer' ); ?></p>
181
+			<h2 class="title"><?php esc_html_e('Done! Check out your imported content', 'lsx-wetu-importer'); ?></h2>
182
+			<p><?php esc_html_e('If you’ve updated your content on Wetu then you can return to these steps at any stage to import and re-sync any updates', 'lsx-wetu-importer'); ?></p>
183 183
 		<?php
184 184
 	}
185 185
 }
Please login to merge, or discard this patch.
Indentation   +83 added lines, -83 removed lines patch added patch discarded remove patch
@@ -14,57 +14,57 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class LSX_WETU_Importer_Welcome {
16 16
 
17
-	/**
18
-	 * Holds instance of the class
19
-	 *
20
-	 * @var object
21
-	 */
22
-	private static $instance;
17
+     /**
18
+      * Holds instance of the class
19
+      *
20
+      * @var object
21
+      */
22
+     private static $instance;
23 23
 
24
-	/**
25
-	 * Initialize the plugin by setting localization, filters, and administration functions.
26
-	 *
27
-	 * @since 1.0.0
28
-	 *
29
-	 * @access private
30
-	 */
31
-	public function __construct() {
32
-	}
24
+     /**
25
+      * Initialize the plugin by setting localization, filters, and administration functions.
26
+      *
27
+      * @since 1.0.0
28
+      *
29
+      * @access private
30
+      */
31
+     public function __construct() {
32
+     }
33 33
 
34
-	/**
35
-	 * Return an instance of this class.
36
-	 *
37
-	 * @return  object
38
-	 */
39
-	public static function get_instance() {
40
-		// If the single instance hasn't been set, set it now.
41
-		if ( ! isset( self::$instance ) ) {
42
-			self::$instance = new self();
43
-		}
44
-		return self::$instance;
45
-	}
34
+     /**
35
+      * Return an instance of this class.
36
+      *
37
+      * @return  object
38
+      */
39
+     public static function get_instance() {
40
+          // If the single instance hasn't been set, set it now.
41
+          if ( ! isset( self::$instance ) ) {
42
+               self::$instance = new self();
43
+          }
44
+          return self::$instance;
45
+     }
46 46
 
47
-	/**
48
-	 * Display the importer welcome screen
49
-	 */
50
-	public function display_page() {
51
-		?>
47
+     /**
48
+      * Display the importer welcome screen
49
+      */
50
+     public function display_page() {
51
+          ?>
52 52
 		<div class="row section">
53 53
 			<h1><?php esc_html_e( 'Welcome to the LSX Importer for Wetu', 'lsx-wetu-importer' ); ?></h1>
54 54
 			<p><?php esc_html_e( 'If this is the first time running the import, please follow the steps below.', 'lsx-wetu-importer' ); ?></p>
55 55
 		</div>
56 56
 		<?php
57
-		$this->importer_steps();
58
-		$this->welcome_blocks();
59
-	}
57
+          $this->importer_steps();
58
+          $this->welcome_blocks();
59
+     }
60 60
 
61
-	/**
62
-	 * Undocumented function
63
-	 *
64
-	 * @return void
65
-	 */
66
-	public function importer_steps() {
67
-		?>
61
+     /**
62
+      * Undocumented function
63
+      *
64
+      * @return void
65
+      */
66
+     public function importer_steps() {
67
+          ?>
68 68
 		<div class="row section postbox">
69 69
 			<div class="welcome-block-header">
70 70
 				<p class="heading"><a href="<?php echo esc_attr( admin_url( 'admin.php' ) . '?page=lsx-wetu-importer&tab=tour' ); ?>"><?php esc_html_e( 'Import your tours', 'lsx-wetu-importer' ); ?></a></p>
@@ -85,15 +85,15 @@  discard block
 block discarded – undo
85 85
 			<div class="spacer"></div>
86 86
 		</div>
87 87
 		<?php
88
-	}
88
+     }
89 89
 
90
-	/**
91
-	 * Outputs the welcome blocks on the welcome screen
92
-	 *
93
-	 * @return void
94
-	 */
95
-	public function welcome_blocks() {
96
-		?>
90
+     /**
91
+      * Outputs the welcome blocks on the welcome screen
92
+      *
93
+      * @return void
94
+      */
95
+     public function welcome_blocks() {
96
+          ?>
97 97
 		<div class="row section">
98 98
 			<div class="welcome-block postbox">
99 99
 				<?php $this->tour_block(); ?>
@@ -109,15 +109,15 @@  discard block
 block discarded – undo
109 109
 			</div>
110 110
 		</div>
111 111
 		<?php
112
-	}
112
+     }
113 113
 
114
-	/**
115
-	 * Outputs the Tour Block.
116
-	 *
117
-	 * @return void
118
-	 */
119
-	public function tour_block() {
120
-		?>
114
+     /**
115
+      * Outputs the Tour Block.
116
+      *
117
+      * @return void
118
+      */
119
+     public function tour_block() {
120
+          ?>
121 121
 			<h2 class="title"><?php esc_html_e( 'Importing tours', 'lsx-wetu-importer' ); ?></h2>
122 122
 			<p class="excerpt"><?php esc_html_e( 'Search for tours, select the ones you want to import and choose the data you want to sync on import. All connected accommodadtions will be imported as drafts to be pubished after completing the tour import.', 'lsx-wetu-importer' ); ?></p>
123 123
 			<p><a href="<?php echo esc_attr( admin_url( 'admin.php' ) . '?page=lsx-wetu-importer&tab=tour' ); ?>" class="button button-primary"><?php esc_html_e( 'Import Tours', 'lsx-wetu-importer' ); ?></a></p>
@@ -129,14 +129,14 @@  discard block
 block discarded – undo
129 129
 				</ul>
130 130
 			</p>			
131 131
 		<?php
132
-	}
133
-	/**
134
-	 * Outputs the Accommodation Block.
135
-	 *
136
-	 * @return void
137
-	 */
138
-	public function accommodation_block() {
139
-		?>
132
+     }
133
+     /**
134
+      * Outputs the Accommodation Block.
135
+      *
136
+      * @return void
137
+      */
138
+     public function accommodation_block() {
139
+          ?>
140 140
 			<h2 class="title"><?php esc_html_e( 'Import and publish accommodation', 'lsx-wetu-importer' ); ?></h2>
141 141
 			<p class="excerpt"><?php esc_html_e( 'All accommodations connnected to your tours have been imported as drafts. Review the imported accommodations, sync selected data and publish.', 'lsx-wetu-importer' ); ?></p>
142 142
 			<p><a href="<?php echo esc_attr( admin_url( 'admin.php' ) . '?page=lsx-wetu-importer&tab=accommodation' ); ?>" class="button button-primary"><?php esc_html_e( 'Sync accommodation', 'lsx-wetu-importer' ); ?></a></p>
@@ -150,14 +150,14 @@  discard block
 block discarded – undo
150 150
 				</ul>
151 151
 			</p>			
152 152
 		<?php
153
-	}
154
-	/**
155
-	 * Outputs the Destination Block.
156
-	 *
157
-	 * @return void
158
-	 */
159
-	public function destination_block() {
160
-		?>
153
+     }
154
+     /**
155
+      * Outputs the Destination Block.
156
+      *
157
+      * @return void
158
+      */
159
+     public function destination_block() {
160
+          ?>
161 161
 			<h2 class="title"><?php esc_html_e( 'Import and publish destinations', 'lsx-wetu-importer' ); ?></h2>
162 162
 			<p class="excerpt"><?php esc_html_e( 'All destinations and regions connnected to your tours & accommodations have been imported as drafts. Review the imported accommodations, sync selected data and publish.', 'lsx-wetu-importer' ); ?></p>
163 163
 			<p><a href="<?php echo esc_attr( admin_url( 'admin.php' ) . '?page=lsx-wetu-importer&tab=destination' ); ?>" class="button button-primary"><?php esc_html_e( 'Sync destinations', 'lsx-wetu-importer' ); ?></a></p>
@@ -170,16 +170,16 @@  discard block
 block discarded – undo
170 170
 				</ul>
171 171
 			</p>
172 172
 		<?php
173
-	}
174
-	/**
175
-	 * Outputs the last welcome block
176
-	 *
177
-	 * @return void
178
-	 */
179
-	public function end_block() {
180
-		?>
173
+     }
174
+     /**
175
+      * Outputs the last welcome block
176
+      *
177
+      * @return void
178
+      */
179
+     public function end_block() {
180
+          ?>
181 181
 			<h2 class="title"><?php esc_html_e( 'Done! Check out your imported content', 'lsx-wetu-importer' ); ?></h2>
182 182
 			<p><?php esc_html_e( 'If you’ve updated your content on Wetu then you can return to these steps at any stage to import and re-sync any updates', 'lsx-wetu-importer' ); ?></p>
183 183
 		<?php
184
-	}
184
+     }
185 185
 }
Please login to merge, or discard this patch.
includes/helpers.php 2 patches
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -15,14 +15,14 @@  discard block
 block discarded – undo
15 15
  * @return array
16 16
  */
17 17
 function lsx_wetu_get_options() {
18
-	$options = get_option( 'lsx_wetu_importer_settings', array() );
19
-	if ( empty( $options ) ) {
18
+	$options = get_option('lsx_wetu_importer_settings', array());
19
+	if (empty($options)) {
20 20
 		// Check for any previous options.
21
-		$temp_options = get_option( '_lsx-to_settings', false );
22
-		if ( false !== $temp_options && isset( $temp_options['lsx-wetu-importer'] ) && ! empty( $temp_options['lsx-wetu-importer'] ) ) {
21
+		$temp_options = get_option('_lsx-to_settings', false);
22
+		if (false !== $temp_options && isset($temp_options['lsx-wetu-importer']) && !empty($temp_options['lsx-wetu-importer'])) {
23 23
 			$options = $temp_options['lsx-wetu-importer'];
24 24
 		}
25
-		if ( false !== $temp_options && isset( $temp_options['api']['wetu_api_key'] ) && '' !== $temp_options['api']['wetu_api_key'] ) {
25
+		if (false !== $temp_options && isset($temp_options['api']['wetu_api_key']) && '' !== $temp_options['api']['wetu_api_key']) {
26 26
 			$options['api_key'] = $temp_options['api']['wetu_api_key'];
27 27
 		}
28 28
 	}
@@ -36,32 +36,32 @@  discard block
 block discarded – undo
36 36
  * @param string $post_status
37 37
  * @return void
38 38
  */
39
-function lsx_wetu_get_post_count( $post_type = '', $post_status = '' ) {
39
+function lsx_wetu_get_post_count($post_type = '', $post_status = '') {
40 40
 	global $wpdb;
41 41
 	$count = '0';
42
-	if ( '' !== $post_type && '' !== $post_status ) {
43
-		$result = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(`ID`) FROM $wpdb->posts WHERE `post_status` = '%s' AND `post_type` = '%s'", array( trim( $post_status ), $post_type ) ) );
44
-		if ( false !== $result && '' !== $result ) {
45
-			if ( 'tour' === $post_type ) {
46
-				$wetu_tours = get_transient( 'lsx_ti_tours' );
47
-				if ( false !== $wetu_tours ) {
48
-					$results = $wpdb->get_results( $wpdb->prepare( "SELECT `ID` FROM $wpdb->posts WHERE `post_status` = '%s' AND `post_type` = '%s'", array( trim( $post_status ), $post_type ) ) );
42
+	if ('' !== $post_type && '' !== $post_status) {
43
+		$result = $wpdb->get_var($wpdb->prepare("SELECT COUNT(`ID`) FROM $wpdb->posts WHERE `post_status` = '%s' AND `post_type` = '%s'", array(trim($post_status), $post_type)));
44
+		if (false !== $result && '' !== $result) {
45
+			if ('tour' === $post_type) {
46
+				$wetu_tours = get_transient('lsx_ti_tours');
47
+				if (false !== $wetu_tours) {
48
+					$results = $wpdb->get_results($wpdb->prepare("SELECT `ID` FROM $wpdb->posts WHERE `post_status` = '%s' AND `post_type` = '%s'", array(trim($post_status), $post_type)));
49 49
 					$result_count = 0;
50 50
 					$tour_wetu_ids = array();
51
-					foreach ( $wetu_tours as $wetu_tour ) {
51
+					foreach ($wetu_tours as $wetu_tour) {
52 52
 						$tour_wetu_ids[] = $wetu_tour['identifier'];
53 53
 					}
54 54
 
55
-					if ( ! empty( $results ) ) {
56
-						foreach ( $results as $tour ) {
57
-							$current_wetu_id = get_post_meta( $tour->ID, 'lsx_wetu_id', true );
58
-							if ( in_array( $current_wetu_id, $tour_wetu_ids ) ) {
55
+					if (!empty($results)) {
56
+						foreach ($results as $tour) {
57
+							$current_wetu_id = get_post_meta($tour->ID, 'lsx_wetu_id', true);
58
+							if (in_array($current_wetu_id, $tour_wetu_ids)) {
59 59
 								$result_count++;
60 60
 							}
61 61
 						}
62 62
 					}
63 63
 					$result = $result_count;
64
-				} else {
64
+				}else {
65 65
 					$result = 0;
66 66
 				}
67 67
 			}
@@ -77,11 +77,11 @@  discard block
 block discarded – undo
77 77
  * @param string $post_type
78 78
  * @return void
79 79
  */
80
-function lsx_wetu_get_queue_count( $post_type = '' ) {
80
+function lsx_wetu_get_queue_count($post_type = '') {
81 81
 	$count = '0';
82
-	$queued_imports = get_option( 'lsx_wetu_importer_que', array() );
83
-	if ( isset( $queued_imports[ $post_type ] ) ) {
84
-		$count = count( $queued_imports[ $post_type ] );
82
+	$queued_imports = get_option('lsx_wetu_importer_que', array());
83
+	if (isset($queued_imports[$post_type])) {
84
+		$count = count($queued_imports[$post_type]);
85 85
 	}
86 86
 	return $count;
87 87
 }
@@ -92,11 +92,11 @@  discard block
 block discarded – undo
92 92
  * @param string $post_type
93 93
  * @return void
94 94
  */
95
-function lsx_wetu_get_tour_count( $post_type = '' ) {
95
+function lsx_wetu_get_tour_count($post_type = '') {
96 96
 	$count = '0';
97
-	$wetu_tours = get_transient( 'lsx_ti_tours', array() );
98
-	if ( ! empty( $wetu_tours ) ) {
99
-		$count = count( $wetu_tours );
97
+	$wetu_tours = get_transient('lsx_ti_tours', array());
98
+	if (!empty($wetu_tours)) {
99
+		$count = count($wetu_tours);
100 100
 	}
101 101
 	return $count;
102 102
 }
Please login to merge, or discard this patch.
Indentation   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -15,18 +15,18 @@  discard block
 block discarded – undo
15 15
  * @return array
16 16
  */
17 17
 function lsx_wetu_get_options() {
18
-	$options = get_option( 'lsx_wetu_importer_settings', array() );
19
-	if ( empty( $options ) ) {
20
-		// Check for any previous options.
21
-		$temp_options = get_option( '_lsx-to_settings', false );
22
-		if ( false !== $temp_options && isset( $temp_options['lsx-wetu-importer'] ) && ! empty( $temp_options['lsx-wetu-importer'] ) ) {
23
-			$options = $temp_options['lsx-wetu-importer'];
24
-		}
25
-		if ( false !== $temp_options && isset( $temp_options['api']['wetu_api_key'] ) && '' !== $temp_options['api']['wetu_api_key'] ) {
26
-			$options['api_key'] = $temp_options['api']['wetu_api_key'];
27
-		}
28
-	}
29
-	return $options;
18
+     $options = get_option( 'lsx_wetu_importer_settings', array() );
19
+     if ( empty( $options ) ) {
20
+          // Check for any previous options.
21
+          $temp_options = get_option( '_lsx-to_settings', false );
22
+          if ( false !== $temp_options && isset( $temp_options['lsx-wetu-importer'] ) && ! empty( $temp_options['lsx-wetu-importer'] ) ) {
23
+               $options = $temp_options['lsx-wetu-importer'];
24
+          }
25
+          if ( false !== $temp_options && isset( $temp_options['api']['wetu_api_key'] ) && '' !== $temp_options['api']['wetu_api_key'] ) {
26
+               $options['api_key'] = $temp_options['api']['wetu_api_key'];
27
+          }
28
+     }
29
+     return $options;
30 30
 }
31 31
 
32 32
 /**
@@ -37,38 +37,38 @@  discard block
 block discarded – undo
37 37
  * @return void
38 38
  */
39 39
 function lsx_wetu_get_post_count( $post_type = '', $post_status = '' ) {
40
-	global $wpdb;
41
-	$count = '0';
42
-	if ( '' !== $post_type && '' !== $post_status ) {
43
-		$result = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(`ID`) FROM $wpdb->posts WHERE `post_status` = '%s' AND `post_type` = '%s'", array( trim( $post_status ), $post_type ) ) );
44
-		if ( false !== $result && '' !== $result ) {
45
-			if ( 'tour' === $post_type ) {
46
-				$wetu_tours = get_transient( 'lsx_ti_tours' );
47
-				if ( false !== $wetu_tours ) {
48
-					$results = $wpdb->get_results( $wpdb->prepare( "SELECT `ID` FROM $wpdb->posts WHERE `post_status` = '%s' AND `post_type` = '%s'", array( trim( $post_status ), $post_type ) ) );
49
-					$result_count = 0;
50
-					$tour_wetu_ids = array();
51
-					foreach ( $wetu_tours as $wetu_tour ) {
52
-						$tour_wetu_ids[] = $wetu_tour['identifier'];
53
-					}
40
+     global $wpdb;
41
+     $count = '0';
42
+     if ( '' !== $post_type && '' !== $post_status ) {
43
+          $result = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(`ID`) FROM $wpdb->posts WHERE `post_status` = '%s' AND `post_type` = '%s'", array( trim( $post_status ), $post_type ) ) );
44
+          if ( false !== $result && '' !== $result ) {
45
+               if ( 'tour' === $post_type ) {
46
+                    $wetu_tours = get_transient( 'lsx_ti_tours' );
47
+                    if ( false !== $wetu_tours ) {
48
+                         $results = $wpdb->get_results( $wpdb->prepare( "SELECT `ID` FROM $wpdb->posts WHERE `post_status` = '%s' AND `post_type` = '%s'", array( trim( $post_status ), $post_type ) ) );
49
+                         $result_count = 0;
50
+                         $tour_wetu_ids = array();
51
+                         foreach ( $wetu_tours as $wetu_tour ) {
52
+                              $tour_wetu_ids[] = $wetu_tour['identifier'];
53
+                         }
54 54
 
55
-					if ( ! empty( $results ) ) {
56
-						foreach ( $results as $tour ) {
57
-							$current_wetu_id = get_post_meta( $tour->ID, 'lsx_wetu_id', true );
58
-							if ( in_array( $current_wetu_id, $tour_wetu_ids ) ) {
59
-								$result_count++;
60
-							}
61
-						}
62
-					}
63
-					$result = $result_count;
64
-				} else {
65
-					$result = 0;
66
-				}
67
-			}
68
-			$count = $result;
69
-		}
70
-	}
71
-	return $count;
55
+                         if ( ! empty( $results ) ) {
56
+                              foreach ( $results as $tour ) {
57
+                                   $current_wetu_id = get_post_meta( $tour->ID, 'lsx_wetu_id', true );
58
+                                   if ( in_array( $current_wetu_id, $tour_wetu_ids ) ) {
59
+                                        $result_count++;
60
+                                   }
61
+                              }
62
+                         }
63
+                         $result = $result_count;
64
+                    } else {
65
+                         $result = 0;
66
+                    }
67
+               }
68
+               $count = $result;
69
+          }
70
+     }
71
+     return $count;
72 72
 }
73 73
 
74 74
 /**
@@ -78,12 +78,12 @@  discard block
 block discarded – undo
78 78
  * @return void
79 79
  */
80 80
 function lsx_wetu_get_queue_count( $post_type = '' ) {
81
-	$count = '0';
82
-	$queued_imports = get_option( 'lsx_wetu_importer_que', array() );
83
-	if ( isset( $queued_imports[ $post_type ] ) ) {
84
-		$count = count( $queued_imports[ $post_type ] );
85
-	}
86
-	return $count;
81
+     $count = '0';
82
+     $queued_imports = get_option( 'lsx_wetu_importer_que', array() );
83
+     if ( isset( $queued_imports[ $post_type ] ) ) {
84
+          $count = count( $queued_imports[ $post_type ] );
85
+     }
86
+     return $count;
87 87
 }
88 88
 
89 89
 /**
@@ -93,10 +93,10 @@  discard block
 block discarded – undo
93 93
  * @return void
94 94
  */
95 95
 function lsx_wetu_get_tour_count( $post_type = '' ) {
96
-	$count = '0';
97
-	$wetu_tours = get_transient( 'lsx_ti_tours', array() );
98
-	if ( ! empty( $wetu_tours ) ) {
99
-		$count = count( $wetu_tours );
100
-	}
101
-	return $count;
96
+     $count = '0';
97
+     $wetu_tours = get_transient( 'lsx_ti_tours', array() );
98
+     if ( ! empty( $wetu_tours ) ) {
99
+          $count = count( $wetu_tours );
100
+     }
101
+     return $count;
102 102
 }
Please login to merge, or discard this patch.
classes/class-lsx-wetu-importer-accommodation.php 2 patches
Indentation   +680 added lines, -680 removed lines patch added patch discarded remove patch
@@ -9,95 +9,95 @@  discard block
 block discarded – undo
9 9
 
10 10
 class LSX_WETU_Importer_Accommodation 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 = 'accommodation';
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
-	 * Options
41
-	 *
42
-	 * @since 0.0.1
43
-	 *
44
-	 * @var      string
45
-	 */
46
-	public $options = false;
47
-
48
-	/**
49
-	 * The fields you wish to import
50
-	 *
51
-	 * @since 0.0.1
52
-	 *
53
-	 * @var      string
54
-	 */
55
-	public $accommodation_options = false;
56
-
57
-	/**
58
-	 * Initialize the plugin by setting localization, filters, and administration functions.
59
-	 *
60
-	 * @since 1.0.0
61
-	 *
62
-	 * @access private
63
-	 */
64
-	public function __construct() {
65
-		$this->set_variables();
66
-	}
67
-
68
-	/**
69
-	 * Sets the variables used throughout the plugin.
70
-	 */
71
-	public function set_variables() {
72
-		parent::set_variables();
73
-
74
-		// ** This request only works with API KEY **
75
-		// if ( false !== $this->api_username && false !== $this->api_password ) {
76
-		// $this->url    = 'https://wetu.com/API/Pins/';
77
-		// $this->url_qs = 'username=' . $this->api_username . '&password=' . $this->api_password;
78
-		// } elseif ( false !== $this->api_key ) {
79
-			$this->url    = 'https://wetu.com/API/Pins/' . $this->api_key;
80
-			$this->url_qs = 'all=include';
81
-		// }
82
-
83
-		$temp_options = get_option( '_lsx-to_settings', false );
84
-
85
-		if ( false !== $temp_options && isset( $temp_options[ $this->plugin_slug ] ) && ! empty( $temp_options[ $this->plugin_slug ] ) ) {
86
-			$this->options = $temp_options[ $this->plugin_slug ];
87
-		}
88
-
89
-		$accommodation_options = get_option( 'lsx_wetu_importer_accommodation_settings', false );
90
-
91
-		if ( false !== $accommodation_options ) {
92
-			$this->accommodation_options = $accommodation_options;
93
-		}
94
-	}
95
-
96
-	/**
97
-	 * Display the importer administration screen
98
-	 */
99
-	public function display_page() {
100
-		?>
12
+     /**
13
+      * The url to list items from WETU
14
+      *
15
+      * @since 0.0.1
16
+      *
17
+      * @var      string
18
+      */
19
+     public $tab_slug = 'accommodation';
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
+      * Options
41
+      *
42
+      * @since 0.0.1
43
+      *
44
+      * @var      string
45
+      */
46
+     public $options = false;
47
+
48
+     /**
49
+      * The fields you wish to import
50
+      *
51
+      * @since 0.0.1
52
+      *
53
+      * @var      string
54
+      */
55
+     public $accommodation_options = false;
56
+
57
+     /**
58
+      * Initialize the plugin by setting localization, filters, and administration functions.
59
+      *
60
+      * @since 1.0.0
61
+      *
62
+      * @access private
63
+      */
64
+     public function __construct() {
65
+          $this->set_variables();
66
+     }
67
+
68
+     /**
69
+      * Sets the variables used throughout the plugin.
70
+      */
71
+     public function set_variables() {
72
+          parent::set_variables();
73
+
74
+          // ** This request only works with API KEY **
75
+          // if ( false !== $this->api_username && false !== $this->api_password ) {
76
+          // $this->url    = 'https://wetu.com/API/Pins/';
77
+          // $this->url_qs = 'username=' . $this->api_username . '&password=' . $this->api_password;
78
+          // } elseif ( false !== $this->api_key ) {
79
+               $this->url    = 'https://wetu.com/API/Pins/' . $this->api_key;
80
+               $this->url_qs = 'all=include';
81
+          // }
82
+
83
+          $temp_options = get_option( '_lsx-to_settings', false );
84
+
85
+          if ( false !== $temp_options && isset( $temp_options[ $this->plugin_slug ] ) && ! empty( $temp_options[ $this->plugin_slug ] ) ) {
86
+               $this->options = $temp_options[ $this->plugin_slug ];
87
+          }
88
+
89
+          $accommodation_options = get_option( 'lsx_wetu_importer_accommodation_settings', false );
90
+
91
+          if ( false !== $accommodation_options ) {
92
+               $this->accommodation_options = $accommodation_options;
93
+          }
94
+     }
95
+
96
+     /**
97
+      * Display the importer administration screen
98
+      */
99
+     public function display_page() {
100
+          ?>
101 101
 		<div class="wrap">
102 102
 
103 103
 			<div class="tablenav top">
@@ -187,8 +187,8 @@  discard block
 block discarded – undo
187 187
 						<div style="width:30%;display:block;float:left;">
188 188
 							<h3><?php esc_html_e( 'Assign a Safari Brand' ); ?></h3>
189 189
 							<?php
190
-								echo wp_kses_post( $this->taxonomy_checkboxes( 'accommodation-brand', $this->accommodation_options ) );
191
-							?>
190
+                                        echo wp_kses_post( $this->taxonomy_checkboxes( 'accommodation-brand', $this->accommodation_options ) );
191
+                                   ?>
192 192
 						</div>
193 193
 
194 194
 						<br clear="both" />
@@ -218,142 +218,142 @@  discard block
 block discarded – undo
218 218
 			</div>
219 219
 		</div>
220 220
 		<?php
221
-	}
222
-
223
-	/**
224
-	 * Run through the accommodation grabbed from the DB.
225
-	 */
226
-	public function process_ajax_search() {
227
-		$return = false;
228
-		check_ajax_referer( 'lsx_wetu_ajax_action', 'security' );
229
-		if ( isset( $_POST['action'] ) && 'lsx_tour_importer' === $_POST['action'] && isset( $_POST['type'] ) && 'accommodation' === $_POST['type'] ) {
230
-
231
-			$searched_items = false;
232
-			if ( isset( $_POST['keyword'] ) ) {
233
-				$keyphrases = array_map( 'sanitize_text_field', wp_unslash( $_POST['keyword'] ) );
234
-			} else {
235
-				$keyphrases = array( 0 );
236
-			}
237
-
238
-			if ( ! is_array( $keyphrases ) ) {
239
-				$keyphrases = array( $keyphrases );
240
-			}
241
-			foreach ( $keyphrases as &$keyword ) {
242
-				$keyword = ltrim( rtrim( $keyword ) );
243
-			}
244
-
245
-			$post_status = false;
246
-
247
-			if ( in_array( 'publish', $keyphrases ) ) {
248
-				$post_status = 'publish';
249
-			}
250
-			if ( in_array( 'pending', $keyphrases ) ) {
251
-				$post_status = 'pending';
252
-			}
253
-			if ( in_array( 'draft', $keyphrases ) ) {
254
-				$post_status = 'draft';
255
-			}
256
-			if ( in_array( 'import', $keyphrases ) ) {
257
-				$post_status = 'import';
258
-			}
259
-
260
-			// If there is a post status use it.
261
-			if ( false !== $post_status ) {
262
-
263
-				$accommodation         = array();
264
-				$current_accommodation = $this->find_current_accommodation();
265
-				if ( ! empty( $current_accommodation ) ) {
266
-					foreach ( $current_accommodation as $cs_key => $ccs_id ) {
267
-						$accommodation[] = $this->prepare_row_attributes( $cs_key, $ccs_id->post_id );
268
-					}
269
-				}
270
-
271
-				// Run through each accommodation and use it.
272
-				if ( ! empty( $accommodation ) ) {
273
-					foreach ( $accommodation as $row_key => $row ) {
274
-						$row['post_title'] = $row['name'];
275
-						if ( 'import' === $post_status ) {
276
-							if ( is_array( $this->queued_imports ) && in_array( $row['post_id'], $this->queued_imports ) ) {
277
-								$current_status = get_post_status( $row['post_id'] );
278
-								if ( 'draft' === $current_status ) {
279
-									$searched_items[ sanitize_title( $row['name'] ) . '-' . $row['id'] ] = $this->format_row( $row );
280
-								}
281
-							} else {
282
-								continue;
283
-							}
284
-						} else {
285
-							if ( 0 === $row['post_id'] ) {
286
-								continue;
287
-							} else {
288
-								$current_status = get_post_status( $row['post_id'] );
289
-								if ( $current_status !== $post_status ) {
290
-									continue;
291
-								}
292
-							}
293
-							$searched_items[ sanitize_title( $row['name'] ) . '-' . $row['id'] ] = $this->format_row( $row, $row_key );
294
-						}
295
-					}
296
-				}
297
-			} else {
298
-				$key_string_search = implode( '+', $keyphrases );
299
-				$search_data       = wp_remote_get( $this->url . '/Search/' . $key_string_search );
300
-				if ( ! empty( $search_data ) && isset( $search_data['response'] ) && isset( $search_data['response']['code'] ) && 200 === $search_data['response']['code'] ) {
301
-
302
-					$search_data = json_decode( $search_data['body'], true );
303
-					foreach ( $search_data as $sdata_key => $sdata ) {
304
-
305
-						if ( 'Destination' === trim( $sdata['type'] ) || 'Activity' === trim( $sdata['type'] ) || 'Restaurant' === trim( $sdata['type'] ) || 'None' === trim( $sdata['type'] ) || 'Site / Attraction' === trim( $sdata['type'] ) || '' === trim( $sdata['type'] ) ) {
306
-							continue;
307
-						}
308
-
309
-						$temp_id = $this->get_post_id_by_key_value( $sdata['id'] );
310
-						if ( false === $temp_id ) {
311
-							$sdata['post_id']    = 0;
312
-							$sdata['post_title'] = $sdata['name'];
313
-						} else {
314
-							$sdata['post_id']    = $temp_id;
315
-							$sdata['post_title'] = get_the_title( $temp_id );
316
-						}
317
-						$searched_items[ sanitize_title( $sdata['name'] ) . '-' . $sdata['id'] ] = $this->format_row( $sdata, $sdata_key );
318
-					}
319
-				}
320
-			}
321
-
322
-			if ( false !== $searched_items ) {
323
-				$return = implode( $searched_items );
324
-			}
325
-			print_r( $return );
326
-		}
327
-
328
-		die();
329
-	}
330
-
331
-	public function prepare_row_attributes( $cs_key, $ccs_id ) {
332
-		$row_item = array(
333
-			'id'            => $cs_key,
334
-			'type'          => 'Accommodation',
335
-			'name'          => get_the_title( $ccs_id ),
336
-			'last_modified' => date( 'Y-m-d', strtotime( 'now' ) ),
337
-			'post_id'       => $ccs_id,
338
-		);
339
-		return $row_item;
340
-	}
341
-
342
-	/**
343
-	 * Formats the row for output on the screen.
344
-	 *
345
-	 * @param boolean $row the current row to format.
346
-	 * @return void
347
-	 */
348
-	public function format_row( $row = false, $row_key = '' ) {
349
-		if ( false !== $row ) {
350
-
351
-			$status = 'import';
352
-			if ( 0 !== $row['post_id'] ) {
353
-				$status = '<a href="' . admin_url( '/post.php?post=' . $row['post_id'] . '&action=edit' ) . '" target="_blank">' . get_post_status( $row['post_id'] ) . '</a>';
354
-			}
355
-
356
-			$row_html = '
221
+     }
222
+
223
+     /**
224
+      * Run through the accommodation grabbed from the DB.
225
+      */
226
+     public function process_ajax_search() {
227
+          $return = false;
228
+          check_ajax_referer( 'lsx_wetu_ajax_action', 'security' );
229
+          if ( isset( $_POST['action'] ) && 'lsx_tour_importer' === $_POST['action'] && isset( $_POST['type'] ) && 'accommodation' === $_POST['type'] ) {
230
+
231
+               $searched_items = false;
232
+               if ( isset( $_POST['keyword'] ) ) {
233
+                    $keyphrases = array_map( 'sanitize_text_field', wp_unslash( $_POST['keyword'] ) );
234
+               } else {
235
+                    $keyphrases = array( 0 );
236
+               }
237
+
238
+               if ( ! is_array( $keyphrases ) ) {
239
+                    $keyphrases = array( $keyphrases );
240
+               }
241
+               foreach ( $keyphrases as &$keyword ) {
242
+                    $keyword = ltrim( rtrim( $keyword ) );
243
+               }
244
+
245
+               $post_status = false;
246
+
247
+               if ( in_array( 'publish', $keyphrases ) ) {
248
+                    $post_status = 'publish';
249
+               }
250
+               if ( in_array( 'pending', $keyphrases ) ) {
251
+                    $post_status = 'pending';
252
+               }
253
+               if ( in_array( 'draft', $keyphrases ) ) {
254
+                    $post_status = 'draft';
255
+               }
256
+               if ( in_array( 'import', $keyphrases ) ) {
257
+                    $post_status = 'import';
258
+               }
259
+
260
+               // If there is a post status use it.
261
+               if ( false !== $post_status ) {
262
+
263
+                    $accommodation         = array();
264
+                    $current_accommodation = $this->find_current_accommodation();
265
+                    if ( ! empty( $current_accommodation ) ) {
266
+                         foreach ( $current_accommodation as $cs_key => $ccs_id ) {
267
+                              $accommodation[] = $this->prepare_row_attributes( $cs_key, $ccs_id->post_id );
268
+                         }
269
+                    }
270
+
271
+                    // Run through each accommodation and use it.
272
+                    if ( ! empty( $accommodation ) ) {
273
+                         foreach ( $accommodation as $row_key => $row ) {
274
+                              $row['post_title'] = $row['name'];
275
+                              if ( 'import' === $post_status ) {
276
+                                   if ( is_array( $this->queued_imports ) && in_array( $row['post_id'], $this->queued_imports ) ) {
277
+                                        $current_status = get_post_status( $row['post_id'] );
278
+                                        if ( 'draft' === $current_status ) {
279
+                                             $searched_items[ sanitize_title( $row['name'] ) . '-' . $row['id'] ] = $this->format_row( $row );
280
+                                        }
281
+                                   } else {
282
+                                        continue;
283
+                                   }
284
+                              } else {
285
+                                   if ( 0 === $row['post_id'] ) {
286
+                                        continue;
287
+                                   } else {
288
+                                        $current_status = get_post_status( $row['post_id'] );
289
+                                        if ( $current_status !== $post_status ) {
290
+                                             continue;
291
+                                        }
292
+                                   }
293
+                                   $searched_items[ sanitize_title( $row['name'] ) . '-' . $row['id'] ] = $this->format_row( $row, $row_key );
294
+                              }
295
+                         }
296
+                    }
297
+               } else {
298
+                    $key_string_search = implode( '+', $keyphrases );
299
+                    $search_data       = wp_remote_get( $this->url . '/Search/' . $key_string_search );
300
+                    if ( ! empty( $search_data ) && isset( $search_data['response'] ) && isset( $search_data['response']['code'] ) && 200 === $search_data['response']['code'] ) {
301
+
302
+                         $search_data = json_decode( $search_data['body'], true );
303
+                         foreach ( $search_data as $sdata_key => $sdata ) {
304
+
305
+                              if ( 'Destination' === trim( $sdata['type'] ) || 'Activity' === trim( $sdata['type'] ) || 'Restaurant' === trim( $sdata['type'] ) || 'None' === trim( $sdata['type'] ) || 'Site / Attraction' === trim( $sdata['type'] ) || '' === trim( $sdata['type'] ) ) {
306
+                                   continue;
307
+                              }
308
+
309
+                              $temp_id = $this->get_post_id_by_key_value( $sdata['id'] );
310
+                              if ( false === $temp_id ) {
311
+                                   $sdata['post_id']    = 0;
312
+                                   $sdata['post_title'] = $sdata['name'];
313
+                              } else {
314
+                                   $sdata['post_id']    = $temp_id;
315
+                                   $sdata['post_title'] = get_the_title( $temp_id );
316
+                              }
317
+                              $searched_items[ sanitize_title( $sdata['name'] ) . '-' . $sdata['id'] ] = $this->format_row( $sdata, $sdata_key );
318
+                         }
319
+                    }
320
+               }
321
+
322
+               if ( false !== $searched_items ) {
323
+                    $return = implode( $searched_items );
324
+               }
325
+               print_r( $return );
326
+          }
327
+
328
+          die();
329
+     }
330
+
331
+     public function prepare_row_attributes( $cs_key, $ccs_id ) {
332
+          $row_item = array(
333
+               'id'            => $cs_key,
334
+               'type'          => 'Accommodation',
335
+               'name'          => get_the_title( $ccs_id ),
336
+               'last_modified' => date( 'Y-m-d', strtotime( 'now' ) ),
337
+               'post_id'       => $ccs_id,
338
+          );
339
+          return $row_item;
340
+     }
341
+
342
+     /**
343
+      * Formats the row for output on the screen.
344
+      *
345
+      * @param boolean $row the current row to format.
346
+      * @return void
347
+      */
348
+     public function format_row( $row = false, $row_key = '' ) {
349
+          if ( false !== $row ) {
350
+
351
+               $status = 'import';
352
+               if ( 0 !== $row['post_id'] ) {
353
+                    $status = '<a href="' . admin_url( '/post.php?post=' . $row['post_id'] . '&action=edit' ) . '" target="_blank">' . get_post_status( $row['post_id'] ) . '</a>';
354
+               }
355
+
356
+               $row_html = '
357 357
 			<tr class="post-' . $row['post_id'] . ' type-tour" id="post-' . $row['post_id'] . '">
358 358
 				<th class="check-column" scope="row">
359 359
 					<label for="cb-select-' . $row['id'] . '" class="screen-reader-text">' . $row['name'] . '</label>
@@ -372,457 +372,457 @@  discard block
 block discarded – undo
372 372
 					' . $row['id'] . '
373 373
 				</td>
374 374
 			</tr>';
375
-			return $row_html;
376
-		}
377
-	}
378
-
379
-	/**
380
-	 * Saves the queue to the option.
381
-	 */
382
-	public function remove_from_queue( $id ) {
383
-		if ( ! empty( $this->queued_imports ) ) {
384
-			$key = array_search( $id, $this->queued_imports );
385
-			if ( false !== $key ) {
386
-				unset( $this->queued_imports[ $key ] );
387
-
388
-				delete_option( 'lsx_wetu_importer_que' );
389
-				update_option( 'lsx_wetu_importer_que', $this->queued_imports );
390
-			}
391
-		}
392
-	}
393
-
394
-	/**
395
-	 * Connect to wetu
396
-	 */
397
-	public function process_ajax_import() {
398
-		$return = false;
399
-		check_ajax_referer( 'lsx_wetu_ajax_action', 'security' );
400
-
401
-		if ( isset( $_POST['action'] ) && 'lsx_import_items' === $_POST['action'] && isset( $_POST['type'] ) && 'accommodation' === $_POST['type'] && isset( $_POST['wetu_id'] ) ) {
402
-
403
-			$wetu_id = sanitize_text_field( $_POST['wetu_id'] );
404
-			if ( isset( $_POST['post_id'] ) ) {
405
-				$post_id = sanitize_text_field( $_POST['post_id'] );
406
-			} else {
407
-				$post_id = 0;
408
-			}
409
-
410
-			if ( isset( $_POST['team_members'] ) ) {
411
-				$team_members = array_map( 'sanitize_text_field', wp_unslash( $_POST['team_members'] ) );
412
-			} else {
413
-				$team_members = false;
414
-			}
415
-
416
-			if ( isset( $_POST['safari_brands'] ) ) {
417
-				$safari_brands = array_map( 'sanitize_text_field', wp_unslash( $_POST['safari_brands'] ) );
418
-			} else {
419
-				$safari_brands = false;
420
-			}
421
-			delete_option( 'lsx_wetu_importer_accommodation_settings' );
422
-
423
-			if ( isset( $_POST['content'] ) && is_array( $_POST['content'] ) && ! empty( $_POST['content'] ) ) {
424
-				$content = array_map( 'sanitize_text_field', wp_unslash( $_POST['content'] ) );
425
-				add_option( 'lsx_wetu_importer_accommodation_settings', $content );
426
-			} else {
427
-				$content = false;
428
-			}
429
-
430
-			$jdata = wp_remote_get( $this->url . '/Get?' . $this->url_qs . '&ids=' . $wetu_id );
431
-
432
-			if ( ! empty( $jdata ) && isset( $jdata['response'] ) && isset( $jdata['response']['code'] ) && 200 === $jdata['response']['code'] ) {
433
-				$adata  = json_decode( $jdata['body'], true );
434
-				$return = $this->import_row( $adata, $wetu_id, $post_id, $team_members, $content, $safari_brands );
435
-				$this->format_completed_row( $return );
436
-				$this->remove_from_queue( $return );
437
-				$this->cleanup_posts();
438
-			} else {
439
-				$this->format_error( esc_html__( 'There was a problem importing your accommodation, please try refreshing the page.', 'lsx-wetu-importer' ) );
440
-			}
441
-		}
442
-	}
443
-
444
-	/**
445
-	 * Connect to wetu
446
-	 */
447
-	public function import_row( $data, $wetu_id, $id = 0, $team_members = false, $importable_content = array(), $safari_brands = false ) {
448
-		$post_name         = '';
449
-		$data_post_content = '';
450
-		$data_post_excerpt = '';
451
-
452
-		$post                             = array(
453
-			'post_type' => 'accommodation',
454
-		);
455
-		$content_used_general_description = false;
456
-
457
-		// Set the post_content.
458
-		if ( ! empty( $importable_content ) && in_array( 'description', $importable_content ) ) {
459
-			if ( isset( $data[0]['content']['extended_description'] ) ) {
460
-				$data_post_content = $data[0]['content']['extended_description'];
461
-			} elseif ( isset( $data[0]['content']['general_description'] ) ) {
462
-				$data_post_content                = $data[0]['content']['general_description'];
463
-				$content_used_general_description = true;
464
-			} elseif ( isset( $data[0]['content']['teaser_description'] ) ) {
465
-				$data_post_content = $data[0]['content']['teaser_description'];
466
-			}
467
-
468
-			if ( isset( $this->options['disable_accommodation_filtering'] ) && 'on' === $this->options['disable_accommodation_filtering'] ) {
469
-				$post['post_content'] = $data_post_content;
470
-			} else {
471
-				$post['post_content'] = wp_strip_all_tags( $data_post_content );
472
-			}
473
-		}
474
-
475
-		// set the post_excerpt.
476
-		if ( ! empty( $importable_content ) && in_array( 'excerpt', $importable_content ) ) {
477
-			if ( isset( $data[0]['content']['teaser_description'] ) ) {
478
-				$data_post_excerpt = $data[0]['content']['teaser_description'];
479
-			} elseif ( isset( $data[0]['content']['general_description'] ) && false === $content_used_general_description ) {
480
-				$data_post_excerpt = $data[0]['content']['general_description'];
481
-			}
482
-
483
-			$post['post_excerpt'] = $data_post_excerpt;
484
-		}
485
-
486
-		if ( false !== $id && '0' !== $id ) {
487
-			$post['ID'] = $id;
488
-
489
-			if ( isset( $this->options ) && 'on' !== $this->options['disable_accommodation_title'] && isset( $data[0]['name'] ) ) {
490
-				$post['post_title'] = $data[0]['name'];
491
-				$post['post_name']  = wp_unique_post_slug( sanitize_title( $data[0]['name'] ), $id, 'draft', 'accommodation', 0 );
492
-			}
493
-
494
-			$post['post_status'] = 'publish';
495
-
496
-			$id        = wp_update_post( $post );
497
-			$prev_date = get_post_meta( $id, 'lsx_wetu_modified_date', true );
498
-			update_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data[0]['last_modified'] ), $prev_date );
499
-		} else {
500
-			// Set the name.
501
-			if ( isset( $data[0]['name'] ) ) {
502
-				$post_name = wp_unique_post_slug( sanitize_title( $data[0]['name'] ), $id, 'draft', 'accommodation', 0 );
503
-			}
504
-
505
-			$post['post_name']   = $post_name;
506
-			$post['post_title']  = $data[0]['name'];
507
-			$post['post_status'] = 'publish';
508
-			$id                  = wp_insert_post( $post );
509
-
510
-			// Save the WETU ID and the Last date it was modified.
511
-			if ( false !== $id ) {
512
-				add_post_meta( $id, 'lsx_wetu_id', $wetu_id );
513
-				add_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data[0]['last_modified'] ) );
514
-			}
515
-		}
516
-
517
-		// Setup some default for use in the import.
518
-		if ( false !== $importable_content && ( in_array( 'gallery', $importable_content ) || in_array( 'banner_image', $importable_content ) || in_array( 'featured_image', $importable_content ) ) ) {
519
-			$this->find_attachments( $id );
520
-		}
521
-
522
-		// Set the team member if it is there.
523
-		if ( post_type_exists( 'team' ) && false !== $team_members && '' !== $team_members ) {
524
-			$this->set_team_member( $id, $team_members );
525
-		}
526
-
527
-		// Set the safari brand.
528
-		if ( false !== $safari_brands && '' !== $safari_brands ) {
529
-			$this->set_safari_brands( $id, $safari_brands );
530
-		}
531
-
532
-		$this->set_map_data( $data, $id, 9 );
533
-
534
-		if ( post_type_exists( 'destination' ) && false !== $importable_content && in_array( 'destination', $importable_content ) ) {
535
-			$this->connect_destinations( $data, $id );
536
-		}
537
-
538
-		if ( false !== $importable_content && in_array( 'category', $importable_content ) ) {
539
-			$this->set_taxonomy_style( $data, $id );
540
-		}
541
-
542
-		// Set the Room Data.
543
-		if ( false !== $importable_content && in_array( 'rooms', $importable_content ) ) {
544
-			$this->set_room_data( $data, $id );
545
-		}
546
-
547
-		// Set the rating.
548
-		if ( false !== $importable_content && in_array( 'rating', $importable_content ) ) {
549
-			$this->set_rating( $data, $id );
550
-		}
551
-
552
-		// Set the checkin checkout data.
553
-		if ( false !== $importable_content && in_array( 'checkin', $importable_content ) ) {
554
-			$this->set_checkin_checkout( $data, $id );
555
-		}
556
-
557
-		// Set the Spoken Languages.
558
-		if ( false !== $importable_content && in_array( 'spoken_languages', $importable_content ) ) {
559
-			$this->set_spoken_languages( $data, $id );
560
-		}
561
-
562
-		// Set the friendly options.
563
-		if ( false !== $importable_content && in_array( 'friendly', $importable_content ) ) {
564
-			$this->set_friendly( $data, $id );
565
-		}
566
-
567
-		// Set the special_interests.
568
-		if ( false !== $importable_content && in_array( 'special_interests', $importable_content ) ) {
569
-			$this->set_special_interests( $data, $id );
570
-		}
571
-
572
-		// Import the videos.
573
-		if ( false !== $importable_content && in_array( 'videos', $importable_content ) ) {
574
-			$this->set_video_data( $data, $id );
575
-		}
576
-
577
-		// Import the facilities.
578
-		if ( false !== $importable_content && in_array( 'facilities', $importable_content ) ) {
579
-			$this->set_facilities( $data, $id );
580
-		}
581
-
582
-		// Set the featured image.
583
-		if ( false !== $importable_content && in_array( 'featured_image', $importable_content ) ) {
584
-			$this->set_featured_image( $data, $id );
585
-		}
586
-
587
-		if ( false !== $importable_content && in_array( 'banner_image', $importable_content ) ) {
588
-			$this->set_banner_image( $data, $id );
589
-		}
590
-
591
-		// Import the main gallery.
592
-		if ( false !== $importable_content && in_array( 'gallery', $importable_content ) ) {
593
-			$this->create_main_gallery( $data, $id );
594
-		}
595
-
596
-		return $id;
597
-	}
598
-
599
-	/**
600
-	 * Set the safari brand
601
-	 */
602
-	public function set_safari_brands( $id, $safari_brands ) {
603
-		foreach ( $safari_brands as $safari_brand ) {
604
-			wp_set_object_terms( $id, intval( $safari_brand ), 'accommodation-brand', true );
605
-		}
606
-	}
607
-
608
-	/**
609
-	 * Connects the destinations post type
610
-	 */
611
-	public function connect_destinations( $data, $id ) {
612
-		if ( isset( $data[0]['position'] ) ) {
613
-			$destinations = false;
614
-
615
-			if ( isset( $data[0]['position']['country'] ) ) {
616
-				$destinations['country'] = $data[0]['position']['country'];
617
-			}
618
-
619
-			if ( isset( $data[0]['position']['destination'] ) ) {
620
-				$destinations['destination'] = $data[0]['position']['destination'];
621
-			}
622
-
623
-			if ( false !== $destinations ) {
624
-				$prev_values = get_post_meta( $id, 'destination_to_accommodation', false );
625
-
626
-				if ( false === $prev_values || ! is_array( $prev_values ) ) {
627
-					$prev_values = array();
628
-				}
629
-
630
-				delete_post_meta( $id, 'destination_to_accommodation', $prev_values );
631
-				$destinations = array_unique( $destinations );
632
-
633
-				foreach ( $destinations as $key => $value ) {
634
-					$destination = get_page_by_title( ltrim( rtrim( $value ) ), 'OBJECT', 'destination' );
635
-					if ( null !== $destination ) {
636
-						if ( ! in_array( $destination->ID, $prev_values ) ) {
637
-							add_post_meta( $id, 'destination_to_accommodation', $destination->ID, false );
638
-							add_post_meta( $destination->ID, 'accommodation_to_destination', $id, false );
639
-							$this->cleanup_posts[ $destination->ID ] = 'accommodation_to_destination';
640
-						}
641
-					}
642
-				}
643
-			}
644
-		}
645
-	}
646
-
647
-	/**
648
-	 * Set the Travel Style
649
-	 */
650
-	public function set_taxonomy_style( $data, $id ) {
651
-		$terms = false;
652
-
653
-		if ( isset( $data[0]['category'] ) ) {
654
-			$term = term_exists( trim( $data[0]['category'] ), 'accommodation-type' );
655
-			if ( ! $term ) {
656
-				$term = wp_insert_term( trim( $data[0]['category'] ), 'accommodation-type' );
657
-
658
-				if ( is_wp_error( $term ) ) {
659
-					echo wp_kses_post( $term->get_error_message() );
660
-				}
661
-			} else {
662
-				wp_set_object_terms( $id, intval( $term['term_id'] ), 'accommodation-type', true );
663
-			}
664
-		} else {
665
-			wp_set_object_terms( $id, intval( $term['term_id'] ), 'accommodation-type', true );
666
-		}
667
-	}
668
-
669
-	/**
670
-	 * Saves the room data
671
-	 */
672
-	public function set_room_data( $data, $id ) {
673
-		if ( ! empty( $data[0]['rooms'] ) && is_array( $data[0]['rooms'] ) ) {
674
-			$rooms = false;
675
-
676
-			foreach ( $data[0]['rooms'] as $room ) {
677
-				$temp_room = array();
678
-
679
-				if ( isset( $room['name'] ) ) {
680
-					$temp_room['title'] = $room['name'];
681
-				}
682
-
683
-				if ( isset( $room['description'] ) ) {
684
-					$temp_room['description'] = strip_tags( $room['description'] );
685
-				}
686
-
687
-				$temp_room['price'] = 0;
688
-				$temp_room['type']  = 'room';
689
-
690
-				if ( ! empty( $room['images'] ) && is_array( $room['images'] ) ) {
691
-					$temp_room['gallery']   = array();
692
-					$temp_room['gallery'][] = $this->attach_image( $room['images'][0], $id );
693
-				}
694
-				$rooms[] = $temp_room;
695
-			}
696
-
697
-			if ( false !== $id && '0' !== $id ) {
698
-				delete_post_meta( $id, 'units' );
699
-			}
700
-
701
-			foreach ( $rooms as $room ) {
702
-				add_post_meta( $id, 'units', $room, false );
703
-			}
704
-
705
-			if ( isset( $data[0]['features'] ) && isset( $data[0]['features']['rooms'] ) ) {
706
-				$room_count = $data[0]['features']['rooms'];
707
-			} else {
708
-				$room_count = count( $data[0]['rooms'] );
709
-			}
710
-
711
-			if ( false !== $id && '0' !== $id ) {
712
-				$prev_rooms = get_post_meta( $id, 'number_of_rooms', true );
713
-				update_post_meta( $id, 'number_of_rooms', $room_count, $prev_rooms );
714
-			} else {
715
-				add_post_meta( $id, 'number_of_rooms', $room_count, true );
716
-			}
717
-		}
718
-	}
719
-
720
-	/**
721
-	 * Set the ratings
722
-	 */
723
-	public function set_rating( $data, $id ) {
724
-		if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['star_authority'] ) ) {
725
-			$rating_type = $data[0]['features']['star_authority'];
726
-		} else {
727
-			$rating_type = 'Unspecified2';
728
-		}
729
-
730
-		$this->save_custom_field( $rating_type, 'rating_type', $id );
731
-
732
-		if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['stars'] ) ) {
733
-			$this->save_custom_field( $data[0]['features']['stars'], 'rating', $id, true );
734
-		}
735
-	}
736
-
737
-	/**
738
-	 * Set the spoken_languages
739
-	 */
740
-	public function set_spoken_languages( $data, $id ) {
741
-		if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['spoken_languages'] ) && ! empty( $data[0]['features']['spoken_languages'] ) ) {
742
-			$languages = false;
743
-
744
-			foreach ( $data[0]['features']['spoken_languages'] as $spoken_language ) {
745
-				$languages[] = sanitize_title( $spoken_language );
746
-			}
747
-
748
-			if ( false !== $languages ) {
749
-				$this->save_custom_field( $languages, 'spoken_languages', $id );
750
-			}
751
-		}
752
-	}
753
-
754
-	/**
755
-	 * Set the friendly
756
-	 */
757
-	public function set_friendly( $data, $id ) {
758
-		if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['suggested_visitor_types'] ) && ! empty( $data[0]['features']['suggested_visitor_types'] ) ) {
759
-			$friendly_options = false;
760
-
761
-			foreach ( $data[0]['features']['suggested_visitor_types'] as $visitor_type ) {
762
-				$friendly_options[] = sanitize_title( $visitor_type );
763
-			}
764
-
765
-			if ( false !== $friendly_options ) {
766
-				$this->save_custom_field( $friendly_options, 'suggested_visitor_types', $id );
767
-			}
768
-		}
769
-	}
770
-
771
-	/**
772
-	 * Set the special interests
773
-	 */
774
-	public function set_special_interests( $data, $id ) {
775
-		if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['special_interests'] ) && ! empty( $data[0]['features']['special_interests'] ) ) {
776
-			$interests = false;
777
-
778
-			foreach ( $data[0]['features']['special_interests'] as $special_interest ) {
779
-				$interests[] = sanitize_title( $special_interest );
780
-			}
781
-
782
-			if ( false !== $interests ) {
783
-				$this->save_custom_field( $interests, 'special_interests', $id );
784
-			}
785
-		}
786
-	}
787
-
788
-	/**
789
-	 * Set the Check in and Check out Date
790
-	 */
791
-	public function set_checkin_checkout( $data, $id ) {
792
-		if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['check_in_time'] ) ) {
793
-			$time = str_replace( 'h', ':', $data[0]['features']['check_in_time'] );
794
-			$time = date( 'h:ia', strtotime( $time ) );
795
-			$this->save_custom_field( $time, 'checkin_time', $id );
796
-		}
797
-
798
-		if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['check_out_time'] ) ) {
799
-			$time = str_replace( 'h', ':', $data[0]['features']['check_out_time'] );
800
-			$time = date( 'h:ia', strtotime( $time ) );
801
-			$this->save_custom_field( $time, 'checkout_time', $id );
802
-		}
803
-	}
804
-
805
-	/**
806
-	 * Set the Facilities
807
-	 */
808
-	public function set_facilities( $data, $id ) {
809
-		$parent_facilities = array(
810
-			'available_services'  => 'Available Services',
811
-			'property_facilities' => 'Property Facilities',
812
-			'room_facilities'     => 'Room Facilities',
813
-			'activities_on_site'  => 'Activities on Site',
814
-		);
815
-
816
-		foreach ( $parent_facilities as $key => $label ) {
817
-			$terms = false;
818
-
819
-			if ( isset( $data[0]['features'] ) && isset( $data[0]['features'][ $key ] ) ) {
820
-				$parent_id = $this->set_term( $id, $label, 'facility' );
821
-			}
822
-
823
-			foreach ( $data[0]['features'][ $key ] as $child_facility ) {
824
-				$this->set_term( $id, $child_facility, 'facility', $parent_id );
825
-			}
826
-		}
827
-	}
375
+               return $row_html;
376
+          }
377
+     }
378
+
379
+     /**
380
+      * Saves the queue to the option.
381
+      */
382
+     public function remove_from_queue( $id ) {
383
+          if ( ! empty( $this->queued_imports ) ) {
384
+               $key = array_search( $id, $this->queued_imports );
385
+               if ( false !== $key ) {
386
+                    unset( $this->queued_imports[ $key ] );
387
+
388
+                    delete_option( 'lsx_wetu_importer_que' );
389
+                    update_option( 'lsx_wetu_importer_que', $this->queued_imports );
390
+               }
391
+          }
392
+     }
393
+
394
+     /**
395
+      * Connect to wetu
396
+      */
397
+     public function process_ajax_import() {
398
+          $return = false;
399
+          check_ajax_referer( 'lsx_wetu_ajax_action', 'security' );
400
+
401
+          if ( isset( $_POST['action'] ) && 'lsx_import_items' === $_POST['action'] && isset( $_POST['type'] ) && 'accommodation' === $_POST['type'] && isset( $_POST['wetu_id'] ) ) {
402
+
403
+               $wetu_id = sanitize_text_field( $_POST['wetu_id'] );
404
+               if ( isset( $_POST['post_id'] ) ) {
405
+                    $post_id = sanitize_text_field( $_POST['post_id'] );
406
+               } else {
407
+                    $post_id = 0;
408
+               }
409
+
410
+               if ( isset( $_POST['team_members'] ) ) {
411
+                    $team_members = array_map( 'sanitize_text_field', wp_unslash( $_POST['team_members'] ) );
412
+               } else {
413
+                    $team_members = false;
414
+               }
415
+
416
+               if ( isset( $_POST['safari_brands'] ) ) {
417
+                    $safari_brands = array_map( 'sanitize_text_field', wp_unslash( $_POST['safari_brands'] ) );
418
+               } else {
419
+                    $safari_brands = false;
420
+               }
421
+               delete_option( 'lsx_wetu_importer_accommodation_settings' );
422
+
423
+               if ( isset( $_POST['content'] ) && is_array( $_POST['content'] ) && ! empty( $_POST['content'] ) ) {
424
+                    $content = array_map( 'sanitize_text_field', wp_unslash( $_POST['content'] ) );
425
+                    add_option( 'lsx_wetu_importer_accommodation_settings', $content );
426
+               } else {
427
+                    $content = false;
428
+               }
429
+
430
+               $jdata = wp_remote_get( $this->url . '/Get?' . $this->url_qs . '&ids=' . $wetu_id );
431
+
432
+               if ( ! empty( $jdata ) && isset( $jdata['response'] ) && isset( $jdata['response']['code'] ) && 200 === $jdata['response']['code'] ) {
433
+                    $adata  = json_decode( $jdata['body'], true );
434
+                    $return = $this->import_row( $adata, $wetu_id, $post_id, $team_members, $content, $safari_brands );
435
+                    $this->format_completed_row( $return );
436
+                    $this->remove_from_queue( $return );
437
+                    $this->cleanup_posts();
438
+               } else {
439
+                    $this->format_error( esc_html__( 'There was a problem importing your accommodation, please try refreshing the page.', 'lsx-wetu-importer' ) );
440
+               }
441
+          }
442
+     }
443
+
444
+     /**
445
+      * Connect to wetu
446
+      */
447
+     public function import_row( $data, $wetu_id, $id = 0, $team_members = false, $importable_content = array(), $safari_brands = false ) {
448
+          $post_name         = '';
449
+          $data_post_content = '';
450
+          $data_post_excerpt = '';
451
+
452
+          $post                             = array(
453
+               'post_type' => 'accommodation',
454
+          );
455
+          $content_used_general_description = false;
456
+
457
+          // Set the post_content.
458
+          if ( ! empty( $importable_content ) && in_array( 'description', $importable_content ) ) {
459
+               if ( isset( $data[0]['content']['extended_description'] ) ) {
460
+                    $data_post_content = $data[0]['content']['extended_description'];
461
+               } elseif ( isset( $data[0]['content']['general_description'] ) ) {
462
+                    $data_post_content                = $data[0]['content']['general_description'];
463
+                    $content_used_general_description = true;
464
+               } elseif ( isset( $data[0]['content']['teaser_description'] ) ) {
465
+                    $data_post_content = $data[0]['content']['teaser_description'];
466
+               }
467
+
468
+               if ( isset( $this->options['disable_accommodation_filtering'] ) && 'on' === $this->options['disable_accommodation_filtering'] ) {
469
+                    $post['post_content'] = $data_post_content;
470
+               } else {
471
+                    $post['post_content'] = wp_strip_all_tags( $data_post_content );
472
+               }
473
+          }
474
+
475
+          // set the post_excerpt.
476
+          if ( ! empty( $importable_content ) && in_array( 'excerpt', $importable_content ) ) {
477
+               if ( isset( $data[0]['content']['teaser_description'] ) ) {
478
+                    $data_post_excerpt = $data[0]['content']['teaser_description'];
479
+               } elseif ( isset( $data[0]['content']['general_description'] ) && false === $content_used_general_description ) {
480
+                    $data_post_excerpt = $data[0]['content']['general_description'];
481
+               }
482
+
483
+               $post['post_excerpt'] = $data_post_excerpt;
484
+          }
485
+
486
+          if ( false !== $id && '0' !== $id ) {
487
+               $post['ID'] = $id;
488
+
489
+               if ( isset( $this->options ) && 'on' !== $this->options['disable_accommodation_title'] && isset( $data[0]['name'] ) ) {
490
+                    $post['post_title'] = $data[0]['name'];
491
+                    $post['post_name']  = wp_unique_post_slug( sanitize_title( $data[0]['name'] ), $id, 'draft', 'accommodation', 0 );
492
+               }
493
+
494
+               $post['post_status'] = 'publish';
495
+
496
+               $id        = wp_update_post( $post );
497
+               $prev_date = get_post_meta( $id, 'lsx_wetu_modified_date', true );
498
+               update_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data[0]['last_modified'] ), $prev_date );
499
+          } else {
500
+               // Set the name.
501
+               if ( isset( $data[0]['name'] ) ) {
502
+                    $post_name = wp_unique_post_slug( sanitize_title( $data[0]['name'] ), $id, 'draft', 'accommodation', 0 );
503
+               }
504
+
505
+               $post['post_name']   = $post_name;
506
+               $post['post_title']  = $data[0]['name'];
507
+               $post['post_status'] = 'publish';
508
+               $id                  = wp_insert_post( $post );
509
+
510
+               // Save the WETU ID and the Last date it was modified.
511
+               if ( false !== $id ) {
512
+                    add_post_meta( $id, 'lsx_wetu_id', $wetu_id );
513
+                    add_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data[0]['last_modified'] ) );
514
+               }
515
+          }
516
+
517
+          // Setup some default for use in the import.
518
+          if ( false !== $importable_content && ( in_array( 'gallery', $importable_content ) || in_array( 'banner_image', $importable_content ) || in_array( 'featured_image', $importable_content ) ) ) {
519
+               $this->find_attachments( $id );
520
+          }
521
+
522
+          // Set the team member if it is there.
523
+          if ( post_type_exists( 'team' ) && false !== $team_members && '' !== $team_members ) {
524
+               $this->set_team_member( $id, $team_members );
525
+          }
526
+
527
+          // Set the safari brand.
528
+          if ( false !== $safari_brands && '' !== $safari_brands ) {
529
+               $this->set_safari_brands( $id, $safari_brands );
530
+          }
531
+
532
+          $this->set_map_data( $data, $id, 9 );
533
+
534
+          if ( post_type_exists( 'destination' ) && false !== $importable_content && in_array( 'destination', $importable_content ) ) {
535
+               $this->connect_destinations( $data, $id );
536
+          }
537
+
538
+          if ( false !== $importable_content && in_array( 'category', $importable_content ) ) {
539
+               $this->set_taxonomy_style( $data, $id );
540
+          }
541
+
542
+          // Set the Room Data.
543
+          if ( false !== $importable_content && in_array( 'rooms', $importable_content ) ) {
544
+               $this->set_room_data( $data, $id );
545
+          }
546
+
547
+          // Set the rating.
548
+          if ( false !== $importable_content && in_array( 'rating', $importable_content ) ) {
549
+               $this->set_rating( $data, $id );
550
+          }
551
+
552
+          // Set the checkin checkout data.
553
+          if ( false !== $importable_content && in_array( 'checkin', $importable_content ) ) {
554
+               $this->set_checkin_checkout( $data, $id );
555
+          }
556
+
557
+          // Set the Spoken Languages.
558
+          if ( false !== $importable_content && in_array( 'spoken_languages', $importable_content ) ) {
559
+               $this->set_spoken_languages( $data, $id );
560
+          }
561
+
562
+          // Set the friendly options.
563
+          if ( false !== $importable_content && in_array( 'friendly', $importable_content ) ) {
564
+               $this->set_friendly( $data, $id );
565
+          }
566
+
567
+          // Set the special_interests.
568
+          if ( false !== $importable_content && in_array( 'special_interests', $importable_content ) ) {
569
+               $this->set_special_interests( $data, $id );
570
+          }
571
+
572
+          // Import the videos.
573
+          if ( false !== $importable_content && in_array( 'videos', $importable_content ) ) {
574
+               $this->set_video_data( $data, $id );
575
+          }
576
+
577
+          // Import the facilities.
578
+          if ( false !== $importable_content && in_array( 'facilities', $importable_content ) ) {
579
+               $this->set_facilities( $data, $id );
580
+          }
581
+
582
+          // Set the featured image.
583
+          if ( false !== $importable_content && in_array( 'featured_image', $importable_content ) ) {
584
+               $this->set_featured_image( $data, $id );
585
+          }
586
+
587
+          if ( false !== $importable_content && in_array( 'banner_image', $importable_content ) ) {
588
+               $this->set_banner_image( $data, $id );
589
+          }
590
+
591
+          // Import the main gallery.
592
+          if ( false !== $importable_content && in_array( 'gallery', $importable_content ) ) {
593
+               $this->create_main_gallery( $data, $id );
594
+          }
595
+
596
+          return $id;
597
+     }
598
+
599
+     /**
600
+      * Set the safari brand
601
+      */
602
+     public function set_safari_brands( $id, $safari_brands ) {
603
+          foreach ( $safari_brands as $safari_brand ) {
604
+               wp_set_object_terms( $id, intval( $safari_brand ), 'accommodation-brand', true );
605
+          }
606
+     }
607
+
608
+     /**
609
+      * Connects the destinations post type
610
+      */
611
+     public function connect_destinations( $data, $id ) {
612
+          if ( isset( $data[0]['position'] ) ) {
613
+               $destinations = false;
614
+
615
+               if ( isset( $data[0]['position']['country'] ) ) {
616
+                    $destinations['country'] = $data[0]['position']['country'];
617
+               }
618
+
619
+               if ( isset( $data[0]['position']['destination'] ) ) {
620
+                    $destinations['destination'] = $data[0]['position']['destination'];
621
+               }
622
+
623
+               if ( false !== $destinations ) {
624
+                    $prev_values = get_post_meta( $id, 'destination_to_accommodation', false );
625
+
626
+                    if ( false === $prev_values || ! is_array( $prev_values ) ) {
627
+                         $prev_values = array();
628
+                    }
629
+
630
+                    delete_post_meta( $id, 'destination_to_accommodation', $prev_values );
631
+                    $destinations = array_unique( $destinations );
632
+
633
+                    foreach ( $destinations as $key => $value ) {
634
+                         $destination = get_page_by_title( ltrim( rtrim( $value ) ), 'OBJECT', 'destination' );
635
+                         if ( null !== $destination ) {
636
+                              if ( ! in_array( $destination->ID, $prev_values ) ) {
637
+                                   add_post_meta( $id, 'destination_to_accommodation', $destination->ID, false );
638
+                                   add_post_meta( $destination->ID, 'accommodation_to_destination', $id, false );
639
+                                   $this->cleanup_posts[ $destination->ID ] = 'accommodation_to_destination';
640
+                              }
641
+                         }
642
+                    }
643
+               }
644
+          }
645
+     }
646
+
647
+     /**
648
+      * Set the Travel Style
649
+      */
650
+     public function set_taxonomy_style( $data, $id ) {
651
+          $terms = false;
652
+
653
+          if ( isset( $data[0]['category'] ) ) {
654
+               $term = term_exists( trim( $data[0]['category'] ), 'accommodation-type' );
655
+               if ( ! $term ) {
656
+                    $term = wp_insert_term( trim( $data[0]['category'] ), 'accommodation-type' );
657
+
658
+                    if ( is_wp_error( $term ) ) {
659
+                         echo wp_kses_post( $term->get_error_message() );
660
+                    }
661
+               } else {
662
+                    wp_set_object_terms( $id, intval( $term['term_id'] ), 'accommodation-type', true );
663
+               }
664
+          } else {
665
+               wp_set_object_terms( $id, intval( $term['term_id'] ), 'accommodation-type', true );
666
+          }
667
+     }
668
+
669
+     /**
670
+      * Saves the room data
671
+      */
672
+     public function set_room_data( $data, $id ) {
673
+          if ( ! empty( $data[0]['rooms'] ) && is_array( $data[0]['rooms'] ) ) {
674
+               $rooms = false;
675
+
676
+               foreach ( $data[0]['rooms'] as $room ) {
677
+                    $temp_room = array();
678
+
679
+                    if ( isset( $room['name'] ) ) {
680
+                         $temp_room['title'] = $room['name'];
681
+                    }
682
+
683
+                    if ( isset( $room['description'] ) ) {
684
+                         $temp_room['description'] = strip_tags( $room['description'] );
685
+                    }
686
+
687
+                    $temp_room['price'] = 0;
688
+                    $temp_room['type']  = 'room';
689
+
690
+                    if ( ! empty( $room['images'] ) && is_array( $room['images'] ) ) {
691
+                         $temp_room['gallery']   = array();
692
+                         $temp_room['gallery'][] = $this->attach_image( $room['images'][0], $id );
693
+                    }
694
+                    $rooms[] = $temp_room;
695
+               }
696
+
697
+               if ( false !== $id && '0' !== $id ) {
698
+                    delete_post_meta( $id, 'units' );
699
+               }
700
+
701
+               foreach ( $rooms as $room ) {
702
+                    add_post_meta( $id, 'units', $room, false );
703
+               }
704
+
705
+               if ( isset( $data[0]['features'] ) && isset( $data[0]['features']['rooms'] ) ) {
706
+                    $room_count = $data[0]['features']['rooms'];
707
+               } else {
708
+                    $room_count = count( $data[0]['rooms'] );
709
+               }
710
+
711
+               if ( false !== $id && '0' !== $id ) {
712
+                    $prev_rooms = get_post_meta( $id, 'number_of_rooms', true );
713
+                    update_post_meta( $id, 'number_of_rooms', $room_count, $prev_rooms );
714
+               } else {
715
+                    add_post_meta( $id, 'number_of_rooms', $room_count, true );
716
+               }
717
+          }
718
+     }
719
+
720
+     /**
721
+      * Set the ratings
722
+      */
723
+     public function set_rating( $data, $id ) {
724
+          if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['star_authority'] ) ) {
725
+               $rating_type = $data[0]['features']['star_authority'];
726
+          } else {
727
+               $rating_type = 'Unspecified2';
728
+          }
729
+
730
+          $this->save_custom_field( $rating_type, 'rating_type', $id );
731
+
732
+          if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['stars'] ) ) {
733
+               $this->save_custom_field( $data[0]['features']['stars'], 'rating', $id, true );
734
+          }
735
+     }
736
+
737
+     /**
738
+      * Set the spoken_languages
739
+      */
740
+     public function set_spoken_languages( $data, $id ) {
741
+          if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['spoken_languages'] ) && ! empty( $data[0]['features']['spoken_languages'] ) ) {
742
+               $languages = false;
743
+
744
+               foreach ( $data[0]['features']['spoken_languages'] as $spoken_language ) {
745
+                    $languages[] = sanitize_title( $spoken_language );
746
+               }
747
+
748
+               if ( false !== $languages ) {
749
+                    $this->save_custom_field( $languages, 'spoken_languages', $id );
750
+               }
751
+          }
752
+     }
753
+
754
+     /**
755
+      * Set the friendly
756
+      */
757
+     public function set_friendly( $data, $id ) {
758
+          if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['suggested_visitor_types'] ) && ! empty( $data[0]['features']['suggested_visitor_types'] ) ) {
759
+               $friendly_options = false;
760
+
761
+               foreach ( $data[0]['features']['suggested_visitor_types'] as $visitor_type ) {
762
+                    $friendly_options[] = sanitize_title( $visitor_type );
763
+               }
764
+
765
+               if ( false !== $friendly_options ) {
766
+                    $this->save_custom_field( $friendly_options, 'suggested_visitor_types', $id );
767
+               }
768
+          }
769
+     }
770
+
771
+     /**
772
+      * Set the special interests
773
+      */
774
+     public function set_special_interests( $data, $id ) {
775
+          if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['special_interests'] ) && ! empty( $data[0]['features']['special_interests'] ) ) {
776
+               $interests = false;
777
+
778
+               foreach ( $data[0]['features']['special_interests'] as $special_interest ) {
779
+                    $interests[] = sanitize_title( $special_interest );
780
+               }
781
+
782
+               if ( false !== $interests ) {
783
+                    $this->save_custom_field( $interests, 'special_interests', $id );
784
+               }
785
+          }
786
+     }
787
+
788
+     /**
789
+      * Set the Check in and Check out Date
790
+      */
791
+     public function set_checkin_checkout( $data, $id ) {
792
+          if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['check_in_time'] ) ) {
793
+               $time = str_replace( 'h', ':', $data[0]['features']['check_in_time'] );
794
+               $time = date( 'h:ia', strtotime( $time ) );
795
+               $this->save_custom_field( $time, 'checkin_time', $id );
796
+          }
797
+
798
+          if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['check_out_time'] ) ) {
799
+               $time = str_replace( 'h', ':', $data[0]['features']['check_out_time'] );
800
+               $time = date( 'h:ia', strtotime( $time ) );
801
+               $this->save_custom_field( $time, 'checkout_time', $id );
802
+          }
803
+     }
804
+
805
+     /**
806
+      * Set the Facilities
807
+      */
808
+     public function set_facilities( $data, $id ) {
809
+          $parent_facilities = array(
810
+               'available_services'  => 'Available Services',
811
+               'property_facilities' => 'Property Facilities',
812
+               'room_facilities'     => 'Room Facilities',
813
+               'activities_on_site'  => 'Activities on Site',
814
+          );
815
+
816
+          foreach ( $parent_facilities as $key => $label ) {
817
+               $terms = false;
818
+
819
+               if ( isset( $data[0]['features'] ) && isset( $data[0]['features'][ $key ] ) ) {
820
+                    $parent_id = $this->set_term( $id, $label, 'facility' );
821
+               }
822
+
823
+               foreach ( $data[0]['features'][ $key ] as $child_facility ) {
824
+                    $this->set_term( $id, $child_facility, 'facility', $parent_id );
825
+               }
826
+          }
827
+     }
828 828
 }
Please login to merge, or discard this patch.
Spacing   +279 added lines, -279 removed lines patch added patch discarded remove patch
@@ -76,19 +76,19 @@  discard block
 block discarded – undo
76 76
 		// $this->url    = 'https://wetu.com/API/Pins/';
77 77
 		// $this->url_qs = 'username=' . $this->api_username . '&password=' . $this->api_password;
78 78
 		// } elseif ( false !== $this->api_key ) {
79
-			$this->url    = 'https://wetu.com/API/Pins/' . $this->api_key;
79
+			$this->url    = 'https://wetu.com/API/Pins/'.$this->api_key;
80 80
 			$this->url_qs = 'all=include';
81 81
 		// }
82 82
 
83
-		$temp_options = get_option( '_lsx-to_settings', false );
83
+		$temp_options = get_option('_lsx-to_settings', false);
84 84
 
85
-		if ( false !== $temp_options && isset( $temp_options[ $this->plugin_slug ] ) && ! empty( $temp_options[ $this->plugin_slug ] ) ) {
86
-			$this->options = $temp_options[ $this->plugin_slug ];
85
+		if (false !== $temp_options && isset($temp_options[$this->plugin_slug]) && !empty($temp_options[$this->plugin_slug])) {
86
+			$this->options = $temp_options[$this->plugin_slug];
87 87
 		}
88 88
 
89
-		$accommodation_options = get_option( 'lsx_wetu_importer_accommodation_settings', false );
89
+		$accommodation_options = get_option('lsx_wetu_importer_accommodation_settings', false);
90 90
 
91
-		if ( false !== $accommodation_options ) {
91
+		if (false !== $accommodation_options) {
92 92
 			$this->accommodation_options = $accommodation_options;
93 93
 		}
94 94
 	}
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
 			</div>
108 108
 
109 109
 			<form method="get" action="" id="posts-filter">
110
-				<input type="hidden" name="post_type" class="post_type" value="<?php echo esc_attr( $this->tab_slug ); ?>" />
110
+				<input type="hidden" name="post_type" class="post_type" value="<?php echo esc_attr($this->tab_slug); ?>" />
111 111
 
112 112
 				<table class="wp-list-table widefat fixed posts">
113 113
 					<?php $this->table_header(); ?>
@@ -115,11 +115,11 @@  discard block
 block discarded – undo
115 115
 					<tbody id="the-list">
116 116
 						<tr class="post-0 type-tour status-none" id="post-0">
117 117
 							<th class="check-column" scope="row">
118
-								<label for="cb-select-0" class="screen-reader-text"><?php esc_html_e( 'Enter a title to search for and press enter', 'lsx-wetu-importer' ); ?></label>
118
+								<label for="cb-select-0" class="screen-reader-text"><?php esc_html_e('Enter a title to search for and press enter', 'lsx-wetu-importer'); ?></label>
119 119
 							</th>
120 120
 							<td class="post-title page-title column-title">
121 121
 								<strong>
122
-									<?php esc_html_e( 'Enter a title to search for', 'lsx-wetu-importer' ); ?>
122
+									<?php esc_html_e('Enter a title to search for', 'lsx-wetu-importer'); ?>
123 123
 								</strong>
124 124
 							</td>
125 125
 							<td class="date column-date">
@@ -133,8 +133,8 @@  discard block
 block discarded – undo
133 133
 
134 134
 				</table>
135 135
 
136
-				<p><input class="button button-primary add" type="button" value="<?php esc_attr_e( 'Add to List', 'lsx-wetu-importer' ); ?>" />
137
-					<input class="button button-primary clear" type="button" value="<?php esc_attr_e( 'Clear', 'lsx-wetu-importer' ); ?>" />
136
+				<p><input class="button button-primary add" type="button" value="<?php esc_attr_e('Add to List', 'lsx-wetu-importer'); ?>" />
137
+					<input class="button button-primary clear" type="button" value="<?php esc_attr_e('Clear', 'lsx-wetu-importer'); ?>" />
138 138
 				</p>
139 139
 			</form>
140 140
 
@@ -144,58 +144,58 @@  discard block
 block discarded – undo
144 144
 
145 145
 					<div class="row">
146 146
 						<div class="settings-all" style="width:30%;display:block;float:left;">
147
-							<h3><?php esc_html_e( 'What content to Sync from WETU' ); ?></h3>
147
+							<h3><?php esc_html_e('What content to Sync from WETU'); ?></h3>
148 148
 							<ul>
149
-								<?php if ( isset( $this->options['disable_accommodation_descriptions'] ) && 'on' !== $this->options['disable_accommodation_descriptions'] ) { ?>
150
-									<li><input class="content" checked="checked" type="checkbox" name="content[]" value="description" /> <?php esc_html_e( 'Description', 'lsx-wetu-importer' ); ?></li>
149
+								<?php if (isset($this->options['disable_accommodation_descriptions']) && 'on' !== $this->options['disable_accommodation_descriptions']) { ?>
150
+									<li><input class="content" checked="checked" type="checkbox" name="content[]" value="description" /> <?php esc_html_e('Description', 'lsx-wetu-importer'); ?></li>
151 151
 								<?php } ?>
152
-								<?php if ( isset( $this->options['disable_accommodation_excerpts'] ) && 'on' !== $this->options['disable_accommodation_excerpts'] ) { ?>
153
-									<li><input class="content" checked="checked" type="checkbox" name="content[]" value="excerpt" /> <?php esc_html_e( 'Excerpt', 'lsx-wetu-importer' ); ?></li>
152
+								<?php if (isset($this->options['disable_accommodation_excerpts']) && 'on' !== $this->options['disable_accommodation_excerpts']) { ?>
153
+									<li><input class="content" checked="checked" type="checkbox" name="content[]" value="excerpt" /> <?php esc_html_e('Excerpt', 'lsx-wetu-importer'); ?></li>
154 154
 								<?php } ?>
155 155
 
156
-								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="gallery" /> <?php esc_html_e( 'Main Gallery', 'lsx-wetu-importer' ); ?></li>
157
-								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="category" /> <?php esc_html_e( 'Category', 'lsx-wetu-importer' ); ?></li>
158
-								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="location" /> <?php esc_html_e( 'Location', 'lsx-wetu-importer' ); ?></li>
156
+								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="gallery" /> <?php esc_html_e('Main Gallery', 'lsx-wetu-importer'); ?></li>
157
+								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="category" /> <?php esc_html_e('Category', 'lsx-wetu-importer'); ?></li>
158
+								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="location" /> <?php esc_html_e('Location', 'lsx-wetu-importer'); ?></li>
159 159
 
160
-								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="destination" /> <?php esc_html_e( 'Connect Destinations', 'lsx-wetu-importer' ); ?></li>
161
-								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="rating" /> <?php esc_html_e( 'Rating', 'lsx-wetu-importer' ); ?></li>
162
-								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="rooms" /> <?php esc_html_e( 'Rooms', 'lsx-wetu-importer' ); ?></li>
160
+								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="destination" /> <?php esc_html_e('Connect Destinations', 'lsx-wetu-importer'); ?></li>
161
+								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="rating" /> <?php esc_html_e('Rating', 'lsx-wetu-importer'); ?></li>
162
+								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="rooms" /> <?php esc_html_e('Rooms', 'lsx-wetu-importer'); ?></li>
163 163
 
164
-								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="checkin" /> <?php esc_html_e( 'Check In / Check Out', 'lsx-wetu-importer' ); ?></li>
165
-								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="facilities" /> <?php esc_html_e( 'Facilities', 'lsx-wetu-importer' ); ?></li>
166
-								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="friendly" /> <?php esc_html_e( 'Friendly', 'lsx-wetu-importer' ); ?></li>
164
+								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="checkin" /> <?php esc_html_e('Check In / Check Out', 'lsx-wetu-importer'); ?></li>
165
+								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="facilities" /> <?php esc_html_e('Facilities', 'lsx-wetu-importer'); ?></li>
166
+								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="friendly" /> <?php esc_html_e('Friendly', 'lsx-wetu-importer'); ?></li>
167 167
 
168 168
 
169
-								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="special_interests" /> <?php esc_html_e( 'Special Interests', 'lsx-wetu-importer' ); ?></li>
170
-								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="spoken_languages" /> <?php esc_html_e( 'Spoken Languages', 'lsx-wetu-importer' ); ?></li>
169
+								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="special_interests" /> <?php esc_html_e('Special Interests', 'lsx-wetu-importer'); ?></li>
170
+								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="spoken_languages" /> <?php esc_html_e('Spoken Languages', 'lsx-wetu-importer'); ?></li>
171 171
 
172
-								<?php if ( class_exists( 'LSX_TO_Videos' ) ) { ?>
173
-									<li><input class="content" checked="checked" type="checkbox" name="content[]" value="videos" /> <?php esc_html_e( 'Videos', 'lsx-wetu-importer' ); ?></li>
172
+								<?php if (class_exists('LSX_TO_Videos')) { ?>
173
+									<li><input class="content" checked="checked" type="checkbox" name="content[]" value="videos" /> <?php esc_html_e('Videos', 'lsx-wetu-importer'); ?></li>
174 174
 								<?php } ?>
175 175
 							</ul>
176
-							<h4><?php esc_html_e( 'Additional Content' ); ?></h4>
176
+							<h4><?php esc_html_e('Additional Content'); ?></h4>
177 177
 							<ul>
178
-								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="featured_image" /> <?php esc_html_e( 'Set Featured Image', 'lsx-wetu-importer' ); ?></li>
179
-								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="banner_image" /> <?php esc_html_e( 'Set Banner Image', 'lsx-wetu-importer' ); ?></li>
178
+								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="featured_image" /> <?php esc_html_e('Set Featured Image', 'lsx-wetu-importer'); ?></li>
179
+								<li><input class="content" checked="checked" type="checkbox" name="content[]" value="banner_image" /> <?php esc_html_e('Set Banner Image', 'lsx-wetu-importer'); ?></li>
180 180
 							</ul>
181 181
 						</div>
182 182
 						<div style="width:30%;display:block;float:left;">
183
-							<h3><?php esc_html_e( 'Assign a Team Member' ); ?></h3>
184
-							<?php $this->team_member_checkboxes( $this->accommodation_options ); ?>
183
+							<h3><?php esc_html_e('Assign a Team Member'); ?></h3>
184
+							<?php $this->team_member_checkboxes($this->accommodation_options); ?>
185 185
 						</div>
186 186
 
187 187
 						<div style="width:30%;display:block;float:left;">
188
-							<h3><?php esc_html_e( 'Assign a Safari Brand' ); ?></h3>
188
+							<h3><?php esc_html_e('Assign a Safari Brand'); ?></h3>
189 189
 							<?php
190
-								echo wp_kses_post( $this->taxonomy_checkboxes( 'accommodation-brand', $this->accommodation_options ) );
190
+								echo wp_kses_post($this->taxonomy_checkboxes('accommodation-brand', $this->accommodation_options));
191 191
 							?>
192 192
 						</div>
193 193
 
194 194
 						<br clear="both" />
195 195
 					</div>
196 196
 
197
-					<h3><?php esc_html_e( 'Your List' ); ?></h3>
198
-					<p><input class="button button-primary" type="submit" value="<?php esc_attr_e( 'Sync', 'lsx-wetu-importer' ); ?>" /></p>
197
+					<h3><?php esc_html_e('Your List'); ?></h3>
198
+					<p><input class="button button-primary" type="submit" value="<?php esc_attr_e('Sync', 'lsx-wetu-importer'); ?>" /></p>
199 199
 					<table class="wp-list-table widefat fixed posts">
200 200
 						<?php $this->table_header(); ?>
201 201
 
@@ -207,12 +207,12 @@  discard block
 block discarded – undo
207 207
 
208 208
 					</table>
209 209
 
210
-					<p><input class="button button-primary" type="submit" value="<?php esc_attr_e( 'Sync', 'lsx-wetu-importer' ); ?>" /></p>
210
+					<p><input class="button button-primary" type="submit" value="<?php esc_attr_e('Sync', 'lsx-wetu-importer'); ?>" /></p>
211 211
 				</form>
212 212
 			</div>
213 213
 
214 214
 			<div style="display:none;" class="completed-list-wrapper">
215
-				<h3><?php esc_html_e( 'Completed' ); ?> - <small><?php esc_html_e( 'Import your', 'lsx-wetu-importer' ); ?> <a href="<?php echo esc_url( admin_url( 'admin.php' ) ); ?>?page=<?php echo esc_attr( $this->plugin_slug ); ?>&tab=destination"><?php esc_html_e( 'destinations' ); ?></a> <?php esc_html_e( 'next', 'lsx-wetu-importer' ); ?></small></h3>
215
+				<h3><?php esc_html_e('Completed'); ?> - <small><?php esc_html_e('Import your', 'lsx-wetu-importer'); ?> <a href="<?php echo esc_url(admin_url('admin.php')); ?>?page=<?php echo esc_attr($this->plugin_slug); ?>&tab=destination"><?php esc_html_e('destinations'); ?></a> <?php esc_html_e('next', 'lsx-wetu-importer'); ?></small></h3>
216 216
 				<ul>
217 217
 				</ul>
218 218
 			</div>
@@ -225,115 +225,115 @@  discard block
 block discarded – undo
225 225
 	 */
226 226
 	public function process_ajax_search() {
227 227
 		$return = false;
228
-		check_ajax_referer( 'lsx_wetu_ajax_action', 'security' );
229
-		if ( isset( $_POST['action'] ) && 'lsx_tour_importer' === $_POST['action'] && isset( $_POST['type'] ) && 'accommodation' === $_POST['type'] ) {
228
+		check_ajax_referer('lsx_wetu_ajax_action', 'security');
229
+		if (isset($_POST['action']) && 'lsx_tour_importer' === $_POST['action'] && isset($_POST['type']) && 'accommodation' === $_POST['type']) {
230 230
 
231 231
 			$searched_items = false;
232
-			if ( isset( $_POST['keyword'] ) ) {
233
-				$keyphrases = array_map( 'sanitize_text_field', wp_unslash( $_POST['keyword'] ) );
234
-			} else {
235
-				$keyphrases = array( 0 );
232
+			if (isset($_POST['keyword'])) {
233
+				$keyphrases = array_map('sanitize_text_field', wp_unslash($_POST['keyword']));
234
+			}else {
235
+				$keyphrases = array(0);
236 236
 			}
237 237
 
238
-			if ( ! is_array( $keyphrases ) ) {
239
-				$keyphrases = array( $keyphrases );
238
+			if (!is_array($keyphrases)) {
239
+				$keyphrases = array($keyphrases);
240 240
 			}
241
-			foreach ( $keyphrases as &$keyword ) {
242
-				$keyword = ltrim( rtrim( $keyword ) );
241
+			foreach ($keyphrases as &$keyword) {
242
+				$keyword = ltrim(rtrim($keyword));
243 243
 			}
244 244
 
245 245
 			$post_status = false;
246 246
 
247
-			if ( in_array( 'publish', $keyphrases ) ) {
247
+			if (in_array('publish', $keyphrases)) {
248 248
 				$post_status = 'publish';
249 249
 			}
250
-			if ( in_array( 'pending', $keyphrases ) ) {
250
+			if (in_array('pending', $keyphrases)) {
251 251
 				$post_status = 'pending';
252 252
 			}
253
-			if ( in_array( 'draft', $keyphrases ) ) {
253
+			if (in_array('draft', $keyphrases)) {
254 254
 				$post_status = 'draft';
255 255
 			}
256
-			if ( in_array( 'import', $keyphrases ) ) {
256
+			if (in_array('import', $keyphrases)) {
257 257
 				$post_status = 'import';
258 258
 			}
259 259
 
260 260
 			// If there is a post status use it.
261
-			if ( false !== $post_status ) {
261
+			if (false !== $post_status) {
262 262
 
263 263
 				$accommodation         = array();
264 264
 				$current_accommodation = $this->find_current_accommodation();
265
-				if ( ! empty( $current_accommodation ) ) {
266
-					foreach ( $current_accommodation as $cs_key => $ccs_id ) {
267
-						$accommodation[] = $this->prepare_row_attributes( $cs_key, $ccs_id->post_id );
265
+				if (!empty($current_accommodation)) {
266
+					foreach ($current_accommodation as $cs_key => $ccs_id) {
267
+						$accommodation[] = $this->prepare_row_attributes($cs_key, $ccs_id->post_id);
268 268
 					}
269 269
 				}
270 270
 
271 271
 				// Run through each accommodation and use it.
272
-				if ( ! empty( $accommodation ) ) {
273
-					foreach ( $accommodation as $row_key => $row ) {
272
+				if (!empty($accommodation)) {
273
+					foreach ($accommodation as $row_key => $row) {
274 274
 						$row['post_title'] = $row['name'];
275
-						if ( 'import' === $post_status ) {
276
-							if ( is_array( $this->queued_imports ) && in_array( $row['post_id'], $this->queued_imports ) ) {
277
-								$current_status = get_post_status( $row['post_id'] );
278
-								if ( 'draft' === $current_status ) {
279
-									$searched_items[ sanitize_title( $row['name'] ) . '-' . $row['id'] ] = $this->format_row( $row );
275
+						if ('import' === $post_status) {
276
+							if (is_array($this->queued_imports) && in_array($row['post_id'], $this->queued_imports)) {
277
+								$current_status = get_post_status($row['post_id']);
278
+								if ('draft' === $current_status) {
279
+									$searched_items[sanitize_title($row['name']).'-'.$row['id']] = $this->format_row($row);
280 280
 								}
281
-							} else {
281
+							}else {
282 282
 								continue;
283 283
 							}
284
-						} else {
285
-							if ( 0 === $row['post_id'] ) {
284
+						}else {
285
+							if (0 === $row['post_id']) {
286 286
 								continue;
287
-							} else {
288
-								$current_status = get_post_status( $row['post_id'] );
289
-								if ( $current_status !== $post_status ) {
287
+							}else {
288
+								$current_status = get_post_status($row['post_id']);
289
+								if ($current_status !== $post_status) {
290 290
 									continue;
291 291
 								}
292 292
 							}
293
-							$searched_items[ sanitize_title( $row['name'] ) . '-' . $row['id'] ] = $this->format_row( $row, $row_key );
293
+							$searched_items[sanitize_title($row['name']).'-'.$row['id']] = $this->format_row($row, $row_key);
294 294
 						}
295 295
 					}
296 296
 				}
297
-			} else {
298
-				$key_string_search = implode( '+', $keyphrases );
299
-				$search_data       = wp_remote_get( $this->url . '/Search/' . $key_string_search );
300
-				if ( ! empty( $search_data ) && isset( $search_data['response'] ) && isset( $search_data['response']['code'] ) && 200 === $search_data['response']['code'] ) {
297
+			}else {
298
+				$key_string_search = implode('+', $keyphrases);
299
+				$search_data       = wp_remote_get($this->url.'/Search/'.$key_string_search);
300
+				if (!empty($search_data) && isset($search_data['response']) && isset($search_data['response']['code']) && 200 === $search_data['response']['code']) {
301 301
 
302
-					$search_data = json_decode( $search_data['body'], true );
303
-					foreach ( $search_data as $sdata_key => $sdata ) {
302
+					$search_data = json_decode($search_data['body'], true);
303
+					foreach ($search_data as $sdata_key => $sdata) {
304 304
 
305
-						if ( 'Destination' === trim( $sdata['type'] ) || 'Activity' === trim( $sdata['type'] ) || 'Restaurant' === trim( $sdata['type'] ) || 'None' === trim( $sdata['type'] ) || 'Site / Attraction' === trim( $sdata['type'] ) || '' === trim( $sdata['type'] ) ) {
305
+						if ('Destination' === trim($sdata['type']) || 'Activity' === trim($sdata['type']) || 'Restaurant' === trim($sdata['type']) || 'None' === trim($sdata['type']) || 'Site / Attraction' === trim($sdata['type']) || '' === trim($sdata['type'])) {
306 306
 							continue;
307 307
 						}
308 308
 
309
-						$temp_id = $this->get_post_id_by_key_value( $sdata['id'] );
310
-						if ( false === $temp_id ) {
309
+						$temp_id = $this->get_post_id_by_key_value($sdata['id']);
310
+						if (false === $temp_id) {
311 311
 							$sdata['post_id']    = 0;
312 312
 							$sdata['post_title'] = $sdata['name'];
313
-						} else {
313
+						}else {
314 314
 							$sdata['post_id']    = $temp_id;
315
-							$sdata['post_title'] = get_the_title( $temp_id );
315
+							$sdata['post_title'] = get_the_title($temp_id);
316 316
 						}
317
-						$searched_items[ sanitize_title( $sdata['name'] ) . '-' . $sdata['id'] ] = $this->format_row( $sdata, $sdata_key );
317
+						$searched_items[sanitize_title($sdata['name']).'-'.$sdata['id']] = $this->format_row($sdata, $sdata_key);
318 318
 					}
319 319
 				}
320 320
 			}
321 321
 
322
-			if ( false !== $searched_items ) {
323
-				$return = implode( $searched_items );
322
+			if (false !== $searched_items) {
323
+				$return = implode($searched_items);
324 324
 			}
325
-			print_r( $return );
325
+			print_r($return);
326 326
 		}
327 327
 
328 328
 		die();
329 329
 	}
330 330
 
331
-	public function prepare_row_attributes( $cs_key, $ccs_id ) {
331
+	public function prepare_row_attributes($cs_key, $ccs_id) {
332 332
 		$row_item = array(
333 333
 			'id'            => $cs_key,
334 334
 			'type'          => 'Accommodation',
335
-			'name'          => get_the_title( $ccs_id ),
336
-			'last_modified' => date( 'Y-m-d', strtotime( 'now' ) ),
335
+			'name'          => get_the_title($ccs_id),
336
+			'last_modified' => date('Y-m-d', strtotime('now')),
337 337
 			'post_id'       => $ccs_id,
338 338
 		);
339 339
 		return $row_item;
@@ -345,31 +345,31 @@  discard block
 block discarded – undo
345 345
 	 * @param boolean $row the current row to format.
346 346
 	 * @return void
347 347
 	 */
348
-	public function format_row( $row = false, $row_key = '' ) {
349
-		if ( false !== $row ) {
348
+	public function format_row($row = false, $row_key = '') {
349
+		if (false !== $row) {
350 350
 
351 351
 			$status = 'import';
352
-			if ( 0 !== $row['post_id'] ) {
353
-				$status = '<a href="' . admin_url( '/post.php?post=' . $row['post_id'] . '&action=edit' ) . '" target="_blank">' . get_post_status( $row['post_id'] ) . '</a>';
352
+			if (0 !== $row['post_id']) {
353
+				$status = '<a href="'.admin_url('/post.php?post='.$row['post_id'].'&action=edit').'" target="_blank">'.get_post_status($row['post_id']).'</a>';
354 354
 			}
355 355
 
356 356
 			$row_html = '
357
-			<tr class="post-' . $row['post_id'] . ' type-tour" id="post-' . $row['post_id'] . '">
357
+			<tr class="post-' . $row['post_id'].' type-tour" id="post-'.$row['post_id'].'">
358 358
 				<th class="check-column" scope="row">
359
-					<label for="cb-select-' . $row['id'] . '" class="screen-reader-text">' . $row['name'] . '</label>
360
-					<input type="checkbox" data-identifier="' . $row['id'] . '" value="' . $row['post_id'] . '" name="post[]" id="cb-select-' . $row['id'] . '">
359
+					<label for="cb-select-' . $row['id'].'" class="screen-reader-text">'.$row['name'].'</label>
360
+					<input type="checkbox" data-identifier="' . $row['id'].'" value="'.$row['post_id'].'" name="post[]" id="cb-select-'.$row['id'].'">
361 361
 				</th>
362 362
 				<td class="column-order">
363
-					' . ( $row_key + 1 ) . '
363
+					' . ($row_key + 1).'
364 364
 				</td>
365 365
 				<td class="post-title page-title column-title">
366
-					<strong>' . $row['post_title'] . '</strong> - ' . $status . '
366
+					<strong>' . $row['post_title'].'</strong> - '.$status.'
367 367
 				</td>
368 368
 				<td class="date column-date">
369
-					<abbr title="' . date( 'Y/m/d', strtotime( $row['last_modified'] ) ) . '">' . date( 'Y/m/d', strtotime( $row['last_modified'] ) ) . '</abbr><br>Last Modified
369
+					<abbr title="' . date('Y/m/d', strtotime($row['last_modified'])).'">'.date('Y/m/d', strtotime($row['last_modified'])).'</abbr><br>Last Modified
370 370
 				</td>
371 371
 				<td class="ssid column-ssid">
372
-					' . $row['id'] . '
372
+					' . $row['id'].'
373 373
 				</td>
374 374
 			</tr>';
375 375
 			return $row_html;
@@ -379,14 +379,14 @@  discard block
 block discarded – undo
379 379
 	/**
380 380
 	 * Saves the queue to the option.
381 381
 	 */
382
-	public function remove_from_queue( $id ) {
383
-		if ( ! empty( $this->queued_imports ) ) {
384
-			$key = array_search( $id, $this->queued_imports );
385
-			if ( false !== $key ) {
386
-				unset( $this->queued_imports[ $key ] );
382
+	public function remove_from_queue($id) {
383
+		if (!empty($this->queued_imports)) {
384
+			$key = array_search($id, $this->queued_imports);
385
+			if (false !== $key) {
386
+				unset($this->queued_imports[$key]);
387 387
 
388
-				delete_option( 'lsx_wetu_importer_que' );
389
-				update_option( 'lsx_wetu_importer_que', $this->queued_imports );
388
+				delete_option('lsx_wetu_importer_que');
389
+				update_option('lsx_wetu_importer_que', $this->queued_imports);
390 390
 			}
391 391
 		}
392 392
 	}
@@ -396,47 +396,47 @@  discard block
 block discarded – undo
396 396
 	 */
397 397
 	public function process_ajax_import() {
398 398
 		$return = false;
399
-		check_ajax_referer( 'lsx_wetu_ajax_action', 'security' );
399
+		check_ajax_referer('lsx_wetu_ajax_action', 'security');
400 400
 
401
-		if ( isset( $_POST['action'] ) && 'lsx_import_items' === $_POST['action'] && isset( $_POST['type'] ) && 'accommodation' === $_POST['type'] && isset( $_POST['wetu_id'] ) ) {
401
+		if (isset($_POST['action']) && 'lsx_import_items' === $_POST['action'] && isset($_POST['type']) && 'accommodation' === $_POST['type'] && isset($_POST['wetu_id'])) {
402 402
 
403
-			$wetu_id = sanitize_text_field( $_POST['wetu_id'] );
404
-			if ( isset( $_POST['post_id'] ) ) {
405
-				$post_id = sanitize_text_field( $_POST['post_id'] );
406
-			} else {
403
+			$wetu_id = sanitize_text_field($_POST['wetu_id']);
404
+			if (isset($_POST['post_id'])) {
405
+				$post_id = sanitize_text_field($_POST['post_id']);
406
+			}else {
407 407
 				$post_id = 0;
408 408
 			}
409 409
 
410
-			if ( isset( $_POST['team_members'] ) ) {
411
-				$team_members = array_map( 'sanitize_text_field', wp_unslash( $_POST['team_members'] ) );
412
-			} else {
410
+			if (isset($_POST['team_members'])) {
411
+				$team_members = array_map('sanitize_text_field', wp_unslash($_POST['team_members']));
412
+			}else {
413 413
 				$team_members = false;
414 414
 			}
415 415
 
416
-			if ( isset( $_POST['safari_brands'] ) ) {
417
-				$safari_brands = array_map( 'sanitize_text_field', wp_unslash( $_POST['safari_brands'] ) );
418
-			} else {
416
+			if (isset($_POST['safari_brands'])) {
417
+				$safari_brands = array_map('sanitize_text_field', wp_unslash($_POST['safari_brands']));
418
+			}else {
419 419
 				$safari_brands = false;
420 420
 			}
421
-			delete_option( 'lsx_wetu_importer_accommodation_settings' );
421
+			delete_option('lsx_wetu_importer_accommodation_settings');
422 422
 
423
-			if ( isset( $_POST['content'] ) && is_array( $_POST['content'] ) && ! empty( $_POST['content'] ) ) {
424
-				$content = array_map( 'sanitize_text_field', wp_unslash( $_POST['content'] ) );
425
-				add_option( 'lsx_wetu_importer_accommodation_settings', $content );
426
-			} else {
423
+			if (isset($_POST['content']) && is_array($_POST['content']) && !empty($_POST['content'])) {
424
+				$content = array_map('sanitize_text_field', wp_unslash($_POST['content']));
425
+				add_option('lsx_wetu_importer_accommodation_settings', $content);
426
+			}else {
427 427
 				$content = false;
428 428
 			}
429 429
 
430
-			$jdata = wp_remote_get( $this->url . '/Get?' . $this->url_qs . '&ids=' . $wetu_id );
430
+			$jdata = wp_remote_get($this->url.'/Get?'.$this->url_qs.'&ids='.$wetu_id);
431 431
 
432
-			if ( ! empty( $jdata ) && isset( $jdata['response'] ) && isset( $jdata['response']['code'] ) && 200 === $jdata['response']['code'] ) {
433
-				$adata  = json_decode( $jdata['body'], true );
434
-				$return = $this->import_row( $adata, $wetu_id, $post_id, $team_members, $content, $safari_brands );
435
-				$this->format_completed_row( $return );
436
-				$this->remove_from_queue( $return );
432
+			if (!empty($jdata) && isset($jdata['response']) && isset($jdata['response']['code']) && 200 === $jdata['response']['code']) {
433
+				$adata  = json_decode($jdata['body'], true);
434
+				$return = $this->import_row($adata, $wetu_id, $post_id, $team_members, $content, $safari_brands);
435
+				$this->format_completed_row($return);
436
+				$this->remove_from_queue($return);
437 437
 				$this->cleanup_posts();
438
-			} else {
439
-				$this->format_error( esc_html__( 'There was a problem importing your accommodation, please try refreshing the page.', 'lsx-wetu-importer' ) );
438
+			}else {
439
+				$this->format_error(esc_html__('There was a problem importing your accommodation, please try refreshing the page.', 'lsx-wetu-importer'));
440 440
 			}
441 441
 		}
442 442
 	}
@@ -444,7 +444,7 @@  discard block
 block discarded – undo
444 444
 	/**
445 445
 	 * Connect to wetu
446 446
 	 */
447
-	public function import_row( $data, $wetu_id, $id = 0, $team_members = false, $importable_content = array(), $safari_brands = false ) {
447
+	public function import_row($data, $wetu_id, $id = 0, $team_members = false, $importable_content = array(), $safari_brands = false) {
448 448
 		$post_name         = '';
449 449
 		$data_post_content = '';
450 450
 		$data_post_excerpt = '';
@@ -455,142 +455,142 @@  discard block
 block discarded – undo
455 455
 		$content_used_general_description = false;
456 456
 
457 457
 		// Set the post_content.
458
-		if ( ! empty( $importable_content ) && in_array( 'description', $importable_content ) ) {
459
-			if ( isset( $data[0]['content']['extended_description'] ) ) {
458
+		if (!empty($importable_content) && in_array('description', $importable_content)) {
459
+			if (isset($data[0]['content']['extended_description'])) {
460 460
 				$data_post_content = $data[0]['content']['extended_description'];
461
-			} elseif ( isset( $data[0]['content']['general_description'] ) ) {
461
+			} elseif (isset($data[0]['content']['general_description'])) {
462 462
 				$data_post_content                = $data[0]['content']['general_description'];
463 463
 				$content_used_general_description = true;
464
-			} elseif ( isset( $data[0]['content']['teaser_description'] ) ) {
464
+			} elseif (isset($data[0]['content']['teaser_description'])) {
465 465
 				$data_post_content = $data[0]['content']['teaser_description'];
466 466
 			}
467 467
 
468
-			if ( isset( $this->options['disable_accommodation_filtering'] ) && 'on' === $this->options['disable_accommodation_filtering'] ) {
468
+			if (isset($this->options['disable_accommodation_filtering']) && 'on' === $this->options['disable_accommodation_filtering']) {
469 469
 				$post['post_content'] = $data_post_content;
470
-			} else {
471
-				$post['post_content'] = wp_strip_all_tags( $data_post_content );
470
+			}else {
471
+				$post['post_content'] = wp_strip_all_tags($data_post_content);
472 472
 			}
473 473
 		}
474 474
 
475 475
 		// set the post_excerpt.
476
-		if ( ! empty( $importable_content ) && in_array( 'excerpt', $importable_content ) ) {
477
-			if ( isset( $data[0]['content']['teaser_description'] ) ) {
476
+		if (!empty($importable_content) && in_array('excerpt', $importable_content)) {
477
+			if (isset($data[0]['content']['teaser_description'])) {
478 478
 				$data_post_excerpt = $data[0]['content']['teaser_description'];
479
-			} elseif ( isset( $data[0]['content']['general_description'] ) && false === $content_used_general_description ) {
479
+			} elseif (isset($data[0]['content']['general_description']) && false === $content_used_general_description) {
480 480
 				$data_post_excerpt = $data[0]['content']['general_description'];
481 481
 			}
482 482
 
483 483
 			$post['post_excerpt'] = $data_post_excerpt;
484 484
 		}
485 485
 
486
-		if ( false !== $id && '0' !== $id ) {
486
+		if (false !== $id && '0' !== $id) {
487 487
 			$post['ID'] = $id;
488 488
 
489
-			if ( isset( $this->options ) && 'on' !== $this->options['disable_accommodation_title'] && isset( $data[0]['name'] ) ) {
489
+			if (isset($this->options) && 'on' !== $this->options['disable_accommodation_title'] && isset($data[0]['name'])) {
490 490
 				$post['post_title'] = $data[0]['name'];
491
-				$post['post_name']  = wp_unique_post_slug( sanitize_title( $data[0]['name'] ), $id, 'draft', 'accommodation', 0 );
491
+				$post['post_name']  = wp_unique_post_slug(sanitize_title($data[0]['name']), $id, 'draft', 'accommodation', 0);
492 492
 			}
493 493
 
494 494
 			$post['post_status'] = 'publish';
495 495
 
496
-			$id        = wp_update_post( $post );
497
-			$prev_date = get_post_meta( $id, 'lsx_wetu_modified_date', true );
498
-			update_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data[0]['last_modified'] ), $prev_date );
499
-		} else {
496
+			$id        = wp_update_post($post);
497
+			$prev_date = get_post_meta($id, 'lsx_wetu_modified_date', true);
498
+			update_post_meta($id, 'lsx_wetu_modified_date', strtotime($data[0]['last_modified']), $prev_date);
499
+		}else {
500 500
 			// Set the name.
501
-			if ( isset( $data[0]['name'] ) ) {
502
-				$post_name = wp_unique_post_slug( sanitize_title( $data[0]['name'] ), $id, 'draft', 'accommodation', 0 );
501
+			if (isset($data[0]['name'])) {
502
+				$post_name = wp_unique_post_slug(sanitize_title($data[0]['name']), $id, 'draft', 'accommodation', 0);
503 503
 			}
504 504
 
505 505
 			$post['post_name']   = $post_name;
506 506
 			$post['post_title']  = $data[0]['name'];
507 507
 			$post['post_status'] = 'publish';
508
-			$id                  = wp_insert_post( $post );
508
+			$id                  = wp_insert_post($post);
509 509
 
510 510
 			// Save the WETU ID and the Last date it was modified.
511
-			if ( false !== $id ) {
512
-				add_post_meta( $id, 'lsx_wetu_id', $wetu_id );
513
-				add_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data[0]['last_modified'] ) );
511
+			if (false !== $id) {
512
+				add_post_meta($id, 'lsx_wetu_id', $wetu_id);
513
+				add_post_meta($id, 'lsx_wetu_modified_date', strtotime($data[0]['last_modified']));
514 514
 			}
515 515
 		}
516 516
 
517 517
 		// Setup some default for use in the import.
518
-		if ( false !== $importable_content && ( in_array( 'gallery', $importable_content ) || in_array( 'banner_image', $importable_content ) || in_array( 'featured_image', $importable_content ) ) ) {
519
-			$this->find_attachments( $id );
518
+		if (false !== $importable_content && (in_array('gallery', $importable_content) || in_array('banner_image', $importable_content) || in_array('featured_image', $importable_content))) {
519
+			$this->find_attachments($id);
520 520
 		}
521 521
 
522 522
 		// Set the team member if it is there.
523
-		if ( post_type_exists( 'team' ) && false !== $team_members && '' !== $team_members ) {
524
-			$this->set_team_member( $id, $team_members );
523
+		if (post_type_exists('team') && false !== $team_members && '' !== $team_members) {
524
+			$this->set_team_member($id, $team_members);
525 525
 		}
526 526
 
527 527
 		// Set the safari brand.
528
-		if ( false !== $safari_brands && '' !== $safari_brands ) {
529
-			$this->set_safari_brands( $id, $safari_brands );
528
+		if (false !== $safari_brands && '' !== $safari_brands) {
529
+			$this->set_safari_brands($id, $safari_brands);
530 530
 		}
531 531
 
532
-		$this->set_map_data( $data, $id, 9 );
532
+		$this->set_map_data($data, $id, 9);
533 533
 
534
-		if ( post_type_exists( 'destination' ) && false !== $importable_content && in_array( 'destination', $importable_content ) ) {
535
-			$this->connect_destinations( $data, $id );
534
+		if (post_type_exists('destination') && false !== $importable_content && in_array('destination', $importable_content)) {
535
+			$this->connect_destinations($data, $id);
536 536
 		}
537 537
 
538
-		if ( false !== $importable_content && in_array( 'category', $importable_content ) ) {
539
-			$this->set_taxonomy_style( $data, $id );
538
+		if (false !== $importable_content && in_array('category', $importable_content)) {
539
+			$this->set_taxonomy_style($data, $id);
540 540
 		}
541 541
 
542 542
 		// Set the Room Data.
543
-		if ( false !== $importable_content && in_array( 'rooms', $importable_content ) ) {
544
-			$this->set_room_data( $data, $id );
543
+		if (false !== $importable_content && in_array('rooms', $importable_content)) {
544
+			$this->set_room_data($data, $id);
545 545
 		}
546 546
 
547 547
 		// Set the rating.
548
-		if ( false !== $importable_content && in_array( 'rating', $importable_content ) ) {
549
-			$this->set_rating( $data, $id );
548
+		if (false !== $importable_content && in_array('rating', $importable_content)) {
549
+			$this->set_rating($data, $id);
550 550
 		}
551 551
 
552 552
 		// Set the checkin checkout data.
553
-		if ( false !== $importable_content && in_array( 'checkin', $importable_content ) ) {
554
-			$this->set_checkin_checkout( $data, $id );
553
+		if (false !== $importable_content && in_array('checkin', $importable_content)) {
554
+			$this->set_checkin_checkout($data, $id);
555 555
 		}
556 556
 
557 557
 		// Set the Spoken Languages.
558
-		if ( false !== $importable_content && in_array( 'spoken_languages', $importable_content ) ) {
559
-			$this->set_spoken_languages( $data, $id );
558
+		if (false !== $importable_content && in_array('spoken_languages', $importable_content)) {
559
+			$this->set_spoken_languages($data, $id);
560 560
 		}
561 561
 
562 562
 		// Set the friendly options.
563
-		if ( false !== $importable_content && in_array( 'friendly', $importable_content ) ) {
564
-			$this->set_friendly( $data, $id );
563
+		if (false !== $importable_content && in_array('friendly', $importable_content)) {
564
+			$this->set_friendly($data, $id);
565 565
 		}
566 566
 
567 567
 		// Set the special_interests.
568
-		if ( false !== $importable_content && in_array( 'special_interests', $importable_content ) ) {
569
-			$this->set_special_interests( $data, $id );
568
+		if (false !== $importable_content && in_array('special_interests', $importable_content)) {
569
+			$this->set_special_interests($data, $id);
570 570
 		}
571 571
 
572 572
 		// Import the videos.
573
-		if ( false !== $importable_content && in_array( 'videos', $importable_content ) ) {
574
-			$this->set_video_data( $data, $id );
573
+		if (false !== $importable_content && in_array('videos', $importable_content)) {
574
+			$this->set_video_data($data, $id);
575 575
 		}
576 576
 
577 577
 		// Import the facilities.
578
-		if ( false !== $importable_content && in_array( 'facilities', $importable_content ) ) {
579
-			$this->set_facilities( $data, $id );
578
+		if (false !== $importable_content && in_array('facilities', $importable_content)) {
579
+			$this->set_facilities($data, $id);
580 580
 		}
581 581
 
582 582
 		// Set the featured image.
583
-		if ( false !== $importable_content && in_array( 'featured_image', $importable_content ) ) {
584
-			$this->set_featured_image( $data, $id );
583
+		if (false !== $importable_content && in_array('featured_image', $importable_content)) {
584
+			$this->set_featured_image($data, $id);
585 585
 		}
586 586
 
587
-		if ( false !== $importable_content && in_array( 'banner_image', $importable_content ) ) {
588
-			$this->set_banner_image( $data, $id );
587
+		if (false !== $importable_content && in_array('banner_image', $importable_content)) {
588
+			$this->set_banner_image($data, $id);
589 589
 		}
590 590
 
591 591
 		// Import the main gallery.
592
-		if ( false !== $importable_content && in_array( 'gallery', $importable_content ) ) {
593
-			$this->create_main_gallery( $data, $id );
592
+		if (false !== $importable_content && in_array('gallery', $importable_content)) {
593
+			$this->create_main_gallery($data, $id);
594 594
 		}
595 595
 
596 596
 		return $id;
@@ -599,44 +599,44 @@  discard block
 block discarded – undo
599 599
 	/**
600 600
 	 * Set the safari brand
601 601
 	 */
602
-	public function set_safari_brands( $id, $safari_brands ) {
603
-		foreach ( $safari_brands as $safari_brand ) {
604
-			wp_set_object_terms( $id, intval( $safari_brand ), 'accommodation-brand', true );
602
+	public function set_safari_brands($id, $safari_brands) {
603
+		foreach ($safari_brands as $safari_brand) {
604
+			wp_set_object_terms($id, intval($safari_brand), 'accommodation-brand', true);
605 605
 		}
606 606
 	}
607 607
 
608 608
 	/**
609 609
 	 * Connects the destinations post type
610 610
 	 */
611
-	public function connect_destinations( $data, $id ) {
612
-		if ( isset( $data[0]['position'] ) ) {
611
+	public function connect_destinations($data, $id) {
612
+		if (isset($data[0]['position'])) {
613 613
 			$destinations = false;
614 614
 
615
-			if ( isset( $data[0]['position']['country'] ) ) {
615
+			if (isset($data[0]['position']['country'])) {
616 616
 				$destinations['country'] = $data[0]['position']['country'];
617 617
 			}
618 618
 
619
-			if ( isset( $data[0]['position']['destination'] ) ) {
619
+			if (isset($data[0]['position']['destination'])) {
620 620
 				$destinations['destination'] = $data[0]['position']['destination'];
621 621
 			}
622 622
 
623
-			if ( false !== $destinations ) {
624
-				$prev_values = get_post_meta( $id, 'destination_to_accommodation', false );
623
+			if (false !== $destinations) {
624
+				$prev_values = get_post_meta($id, 'destination_to_accommodation', false);
625 625
 
626
-				if ( false === $prev_values || ! is_array( $prev_values ) ) {
626
+				if (false === $prev_values || !is_array($prev_values)) {
627 627
 					$prev_values = array();
628 628
 				}
629 629
 
630
-				delete_post_meta( $id, 'destination_to_accommodation', $prev_values );
631
-				$destinations = array_unique( $destinations );
630
+				delete_post_meta($id, 'destination_to_accommodation', $prev_values);
631
+				$destinations = array_unique($destinations);
632 632
 
633
-				foreach ( $destinations as $key => $value ) {
634
-					$destination = get_page_by_title( ltrim( rtrim( $value ) ), 'OBJECT', 'destination' );
635
-					if ( null !== $destination ) {
636
-						if ( ! in_array( $destination->ID, $prev_values ) ) {
637
-							add_post_meta( $id, 'destination_to_accommodation', $destination->ID, false );
638
-							add_post_meta( $destination->ID, 'accommodation_to_destination', $id, false );
639
-							$this->cleanup_posts[ $destination->ID ] = 'accommodation_to_destination';
633
+				foreach ($destinations as $key => $value) {
634
+					$destination = get_page_by_title(ltrim(rtrim($value)), 'OBJECT', 'destination');
635
+					if (null !== $destination) {
636
+						if (!in_array($destination->ID, $prev_values)) {
637
+							add_post_meta($id, 'destination_to_accommodation', $destination->ID, false);
638
+							add_post_meta($destination->ID, 'accommodation_to_destination', $id, false);
639
+							$this->cleanup_posts[$destination->ID] = 'accommodation_to_destination';
640 640
 						}
641 641
 					}
642 642
 				}
@@ -647,72 +647,72 @@  discard block
 block discarded – undo
647 647
 	/**
648 648
 	 * Set the Travel Style
649 649
 	 */
650
-	public function set_taxonomy_style( $data, $id ) {
650
+	public function set_taxonomy_style($data, $id) {
651 651
 		$terms = false;
652 652
 
653
-		if ( isset( $data[0]['category'] ) ) {
654
-			$term = term_exists( trim( $data[0]['category'] ), 'accommodation-type' );
655
-			if ( ! $term ) {
656
-				$term = wp_insert_term( trim( $data[0]['category'] ), 'accommodation-type' );
653
+		if (isset($data[0]['category'])) {
654
+			$term = term_exists(trim($data[0]['category']), 'accommodation-type');
655
+			if (!$term) {
656
+				$term = wp_insert_term(trim($data[0]['category']), 'accommodation-type');
657 657
 
658
-				if ( is_wp_error( $term ) ) {
659
-					echo wp_kses_post( $term->get_error_message() );
658
+				if (is_wp_error($term)) {
659
+					echo wp_kses_post($term->get_error_message());
660 660
 				}
661
-			} else {
662
-				wp_set_object_terms( $id, intval( $term['term_id'] ), 'accommodation-type', true );
661
+			}else {
662
+				wp_set_object_terms($id, intval($term['term_id']), 'accommodation-type', true);
663 663
 			}
664
-		} else {
665
-			wp_set_object_terms( $id, intval( $term['term_id'] ), 'accommodation-type', true );
664
+		}else {
665
+			wp_set_object_terms($id, intval($term['term_id']), 'accommodation-type', true);
666 666
 		}
667 667
 	}
668 668
 
669 669
 	/**
670 670
 	 * Saves the room data
671 671
 	 */
672
-	public function set_room_data( $data, $id ) {
673
-		if ( ! empty( $data[0]['rooms'] ) && is_array( $data[0]['rooms'] ) ) {
672
+	public function set_room_data($data, $id) {
673
+		if (!empty($data[0]['rooms']) && is_array($data[0]['rooms'])) {
674 674
 			$rooms = false;
675 675
 
676
-			foreach ( $data[0]['rooms'] as $room ) {
676
+			foreach ($data[0]['rooms'] as $room) {
677 677
 				$temp_room = array();
678 678
 
679
-				if ( isset( $room['name'] ) ) {
679
+				if (isset($room['name'])) {
680 680
 					$temp_room['title'] = $room['name'];
681 681
 				}
682 682
 
683
-				if ( isset( $room['description'] ) ) {
684
-					$temp_room['description'] = strip_tags( $room['description'] );
683
+				if (isset($room['description'])) {
684
+					$temp_room['description'] = strip_tags($room['description']);
685 685
 				}
686 686
 
687 687
 				$temp_room['price'] = 0;
688 688
 				$temp_room['type']  = 'room';
689 689
 
690
-				if ( ! empty( $room['images'] ) && is_array( $room['images'] ) ) {
690
+				if (!empty($room['images']) && is_array($room['images'])) {
691 691
 					$temp_room['gallery']   = array();
692
-					$temp_room['gallery'][] = $this->attach_image( $room['images'][0], $id );
692
+					$temp_room['gallery'][] = $this->attach_image($room['images'][0], $id);
693 693
 				}
694 694
 				$rooms[] = $temp_room;
695 695
 			}
696 696
 
697
-			if ( false !== $id && '0' !== $id ) {
698
-				delete_post_meta( $id, 'units' );
697
+			if (false !== $id && '0' !== $id) {
698
+				delete_post_meta($id, 'units');
699 699
 			}
700 700
 
701
-			foreach ( $rooms as $room ) {
702
-				add_post_meta( $id, 'units', $room, false );
701
+			foreach ($rooms as $room) {
702
+				add_post_meta($id, 'units', $room, false);
703 703
 			}
704 704
 
705
-			if ( isset( $data[0]['features'] ) && isset( $data[0]['features']['rooms'] ) ) {
705
+			if (isset($data[0]['features']) && isset($data[0]['features']['rooms'])) {
706 706
 				$room_count = $data[0]['features']['rooms'];
707
-			} else {
708
-				$room_count = count( $data[0]['rooms'] );
707
+			}else {
708
+				$room_count = count($data[0]['rooms']);
709 709
 			}
710 710
 
711
-			if ( false !== $id && '0' !== $id ) {
712
-				$prev_rooms = get_post_meta( $id, 'number_of_rooms', true );
713
-				update_post_meta( $id, 'number_of_rooms', $room_count, $prev_rooms );
714
-			} else {
715
-				add_post_meta( $id, 'number_of_rooms', $room_count, true );
711
+			if (false !== $id && '0' !== $id) {
712
+				$prev_rooms = get_post_meta($id, 'number_of_rooms', true);
713
+				update_post_meta($id, 'number_of_rooms', $room_count, $prev_rooms);
714
+			}else {
715
+				add_post_meta($id, 'number_of_rooms', $room_count, true);
716 716
 			}
717 717
 		}
718 718
 	}
@@ -720,33 +720,33 @@  discard block
 block discarded – undo
720 720
 	/**
721 721
 	 * Set the ratings
722 722
 	 */
723
-	public function set_rating( $data, $id ) {
724
-		if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['star_authority'] ) ) {
723
+	public function set_rating($data, $id) {
724
+		if (!empty($data[0]['features']) && isset($data[0]['features']['star_authority'])) {
725 725
 			$rating_type = $data[0]['features']['star_authority'];
726
-		} else {
726
+		}else {
727 727
 			$rating_type = 'Unspecified2';
728 728
 		}
729 729
 
730
-		$this->save_custom_field( $rating_type, 'rating_type', $id );
730
+		$this->save_custom_field($rating_type, 'rating_type', $id);
731 731
 
732
-		if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['stars'] ) ) {
733
-			$this->save_custom_field( $data[0]['features']['stars'], 'rating', $id, true );
732
+		if (!empty($data[0]['features']) && isset($data[0]['features']['stars'])) {
733
+			$this->save_custom_field($data[0]['features']['stars'], 'rating', $id, true);
734 734
 		}
735 735
 	}
736 736
 
737 737
 	/**
738 738
 	 * Set the spoken_languages
739 739
 	 */
740
-	public function set_spoken_languages( $data, $id ) {
741
-		if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['spoken_languages'] ) && ! empty( $data[0]['features']['spoken_languages'] ) ) {
740
+	public function set_spoken_languages($data, $id) {
741
+		if (!empty($data[0]['features']) && isset($data[0]['features']['spoken_languages']) && !empty($data[0]['features']['spoken_languages'])) {
742 742
 			$languages = false;
743 743
 
744
-			foreach ( $data[0]['features']['spoken_languages'] as $spoken_language ) {
745
-				$languages[] = sanitize_title( $spoken_language );
744
+			foreach ($data[0]['features']['spoken_languages'] as $spoken_language) {
745
+				$languages[] = sanitize_title($spoken_language);
746 746
 			}
747 747
 
748
-			if ( false !== $languages ) {
749
-				$this->save_custom_field( $languages, 'spoken_languages', $id );
748
+			if (false !== $languages) {
749
+				$this->save_custom_field($languages, 'spoken_languages', $id);
750 750
 			}
751 751
 		}
752 752
 	}
@@ -754,16 +754,16 @@  discard block
 block discarded – undo
754 754
 	/**
755 755
 	 * Set the friendly
756 756
 	 */
757
-	public function set_friendly( $data, $id ) {
758
-		if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['suggested_visitor_types'] ) && ! empty( $data[0]['features']['suggested_visitor_types'] ) ) {
757
+	public function set_friendly($data, $id) {
758
+		if (!empty($data[0]['features']) && isset($data[0]['features']['suggested_visitor_types']) && !empty($data[0]['features']['suggested_visitor_types'])) {
759 759
 			$friendly_options = false;
760 760
 
761
-			foreach ( $data[0]['features']['suggested_visitor_types'] as $visitor_type ) {
762
-				$friendly_options[] = sanitize_title( $visitor_type );
761
+			foreach ($data[0]['features']['suggested_visitor_types'] as $visitor_type) {
762
+				$friendly_options[] = sanitize_title($visitor_type);
763 763
 			}
764 764
 
765
-			if ( false !== $friendly_options ) {
766
-				$this->save_custom_field( $friendly_options, 'suggested_visitor_types', $id );
765
+			if (false !== $friendly_options) {
766
+				$this->save_custom_field($friendly_options, 'suggested_visitor_types', $id);
767 767
 			}
768 768
 		}
769 769
 	}
@@ -771,16 +771,16 @@  discard block
 block discarded – undo
771 771
 	/**
772 772
 	 * Set the special interests
773 773
 	 */
774
-	public function set_special_interests( $data, $id ) {
775
-		if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['special_interests'] ) && ! empty( $data[0]['features']['special_interests'] ) ) {
774
+	public function set_special_interests($data, $id) {
775
+		if (!empty($data[0]['features']) && isset($data[0]['features']['special_interests']) && !empty($data[0]['features']['special_interests'])) {
776 776
 			$interests = false;
777 777
 
778
-			foreach ( $data[0]['features']['special_interests'] as $special_interest ) {
779
-				$interests[] = sanitize_title( $special_interest );
778
+			foreach ($data[0]['features']['special_interests'] as $special_interest) {
779
+				$interests[] = sanitize_title($special_interest);
780 780
 			}
781 781
 
782
-			if ( false !== $interests ) {
783
-				$this->save_custom_field( $interests, 'special_interests', $id );
782
+			if (false !== $interests) {
783
+				$this->save_custom_field($interests, 'special_interests', $id);
784 784
 			}
785 785
 		}
786 786
 	}
@@ -788,24 +788,24 @@  discard block
 block discarded – undo
788 788
 	/**
789 789
 	 * Set the Check in and Check out Date
790 790
 	 */
791
-	public function set_checkin_checkout( $data, $id ) {
792
-		if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['check_in_time'] ) ) {
793
-			$time = str_replace( 'h', ':', $data[0]['features']['check_in_time'] );
794
-			$time = date( 'h:ia', strtotime( $time ) );
795
-			$this->save_custom_field( $time, 'checkin_time', $id );
791
+	public function set_checkin_checkout($data, $id) {
792
+		if (!empty($data[0]['features']) && isset($data[0]['features']['check_in_time'])) {
793
+			$time = str_replace('h', ':', $data[0]['features']['check_in_time']);
794
+			$time = date('h:ia', strtotime($time));
795
+			$this->save_custom_field($time, 'checkin_time', $id);
796 796
 		}
797 797
 
798
-		if ( ! empty( $data[0]['features'] ) && isset( $data[0]['features']['check_out_time'] ) ) {
799
-			$time = str_replace( 'h', ':', $data[0]['features']['check_out_time'] );
800
-			$time = date( 'h:ia', strtotime( $time ) );
801
-			$this->save_custom_field( $time, 'checkout_time', $id );
798
+		if (!empty($data[0]['features']) && isset($data[0]['features']['check_out_time'])) {
799
+			$time = str_replace('h', ':', $data[0]['features']['check_out_time']);
800
+			$time = date('h:ia', strtotime($time));
801
+			$this->save_custom_field($time, 'checkout_time', $id);
802 802
 		}
803 803
 	}
804 804
 
805 805
 	/**
806 806
 	 * Set the Facilities
807 807
 	 */
808
-	public function set_facilities( $data, $id ) {
808
+	public function set_facilities($data, $id) {
809 809
 		$parent_facilities = array(
810 810
 			'available_services'  => 'Available Services',
811 811
 			'property_facilities' => 'Property Facilities',
@@ -813,15 +813,15 @@  discard block
 block discarded – undo
813 813
 			'activities_on_site'  => 'Activities on Site',
814 814
 		);
815 815
 
816
-		foreach ( $parent_facilities as $key => $label ) {
816
+		foreach ($parent_facilities as $key => $label) {
817 817
 			$terms = false;
818 818
 
819
-			if ( isset( $data[0]['features'] ) && isset( $data[0]['features'][ $key ] ) ) {
820
-				$parent_id = $this->set_term( $id, $label, 'facility' );
819
+			if (isset($data[0]['features']) && isset($data[0]['features'][$key])) {
820
+				$parent_id = $this->set_term($id, $label, 'facility');
821 821
 			}
822 822
 
823
-			foreach ( $data[0]['features'][ $key ] as $child_facility ) {
824
-				$this->set_term( $id, $child_facility, 'facility', $parent_id );
823
+			foreach ($data[0]['features'][$key] as $child_facility) {
824
+				$this->set_term($id, $child_facility, 'facility', $parent_id);
825 825
 			}
826 826
 		}
827 827
 	}
Please login to merge, or discard this patch.
classes/class-lsx-wetu-importer-connect-accommodation.php 2 patches
Indentation   +151 added lines, -151 removed lines patch added patch discarded remove patch
@@ -9,51 +9,51 @@  discard block
 block discarded – undo
9 9
 
10 10
 class LSX_WETU_Importer_Connect_Accommodation extends LSX_WETU_Importer_Admin {
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 = 'connect_accommodation';
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
-	 * Initialize the plugin by setting localization, filters, and administration functions.
32
-	 *
33
-	 * @since 1.0.0
34
-	 *
35
-	 * @access private
36
-	 */
37
-	public function __construct() {
38
-		$temp_options = get_option( '_lsx-to_settings', false );
39
-
40
-		if ( false !== $temp_options && isset( $temp_options[ $this->plugin_slug ] ) && ! empty( $temp_options[ $this->plugin_slug ] ) ) {
41
-			$this->options = $temp_options[ $this->plugin_slug ];
42
-		}
43
-
44
-		$this->url = 'http://wetu.com/API/Pins/' . $this->options['api_key'] . '/List';
45
-
46
-		add_action( 'lsx_tour_importer_admin_tab_' . $this->tab_slug, array( $this, 'display_page' ) );
47
-		add_action( 'wp_ajax_lsx_import_connect_accommodation', array( $this, 'process_connection' ) );
48
-		add_action( 'wp_ajax_nopriv_lsx_import_connect_accommodation', array( $this, 'process_connection' ) );
49
-	}
50
-
51
-	/**
52
-	 * Display the importer administration screen
53
-	 */
54
-	public function display_page() {
55
-		global $post;
56
-		?>
12
+     /**
13
+      * The url to list items from WETU
14
+      *
15
+      * @since 0.0.1
16
+      *
17
+      * @var      string
18
+      */
19
+     public $tab_slug = 'connect_accommodation';
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
+      * Initialize the plugin by setting localization, filters, and administration functions.
32
+      *
33
+      * @since 1.0.0
34
+      *
35
+      * @access private
36
+      */
37
+     public function __construct() {
38
+          $temp_options = get_option( '_lsx-to_settings', false );
39
+
40
+          if ( false !== $temp_options && isset( $temp_options[ $this->plugin_slug ] ) && ! empty( $temp_options[ $this->plugin_slug ] ) ) {
41
+               $this->options = $temp_options[ $this->plugin_slug ];
42
+          }
43
+
44
+          $this->url = 'http://wetu.com/API/Pins/' . $this->options['api_key'] . '/List';
45
+
46
+          add_action( 'lsx_tour_importer_admin_tab_' . $this->tab_slug, array( $this, 'display_page' ) );
47
+          add_action( 'wp_ajax_lsx_import_connect_accommodation', array( $this, 'process_connection' ) );
48
+          add_action( 'wp_ajax_nopriv_lsx_import_connect_accommodation', array( $this, 'process_connection' ) );
49
+     }
50
+
51
+     /**
52
+      * Display the importer administration screen
53
+      */
54
+     public function display_page() {
55
+          global $post;
56
+          ?>
57 57
 		<div class="wrap">
58 58
 			<h3><span class="dashicons dashicons-admin-multisite"></span> <?php esc_html_e( 'Connect your Accommodation', 'lsx-wetu-importer' ); ?></h3>
59 59
 
@@ -67,38 +67,38 @@  discard block
 block discarded – undo
67 67
 				</div>
68 68
 
69 69
 				<?php
70
-					$loose_accommodation = $this->find_current_accommodation();
71
-				?>
70
+                         $loose_accommodation = $this->find_current_accommodation();
71
+                    ?>
72 72
 				<p><input class="button button-primary connect" type="button" value="<?php esc_html_e( 'Connect', 'lsx-wetu-importer' ); ?>" /></p>
73 73
 				<table class="wp-list-table widefat fixed posts">
74 74
 					<?php $this->table_header(); ?>
75 75
 
76 76
 					<tbody>
77 77
 						<?php
78
-						if ( false !== $loose_accommodation ) {
79
-
80
-							$loose_args                = array(
81
-								'post_type'   => 'accommodation',
82
-								'post_status' => array( 'publish', 'pending' ),
83
-								'nopagin'     => true,
84
-								'post__in'    => $loose_accommodation,
85
-							);
86
-							$loose_accommodation_query = new WP_Query( $loose_args );
87
-							$accommodation             = get_transient( 'lsx_ti_accommodation' );
88
-							$identifier                = '';
89
-
90
-							if ( $loose_accommodation_query->have_posts() && false !== $accommodation ) {
91
-								while ( $loose_accommodation_query->have_posts() ) {
92
-									$loose_accommodation_query->the_post();
93
-
94
-									foreach ( $accommodation as $row_key => $row ) {
95
-										if ( stripos( ltrim( rtrim( $row->name ) ), $post->post_title ) !== false ) {
96
-											$identifier = $row->id;
97
-										} else {
98
-											continue;
99
-										}
100
-									}
101
-									?>
78
+                              if ( false !== $loose_accommodation ) {
79
+
80
+                                   $loose_args                = array(
81
+                                        'post_type'   => 'accommodation',
82
+                                        'post_status' => array( 'publish', 'pending' ),
83
+                                        'nopagin'     => true,
84
+                                        'post__in'    => $loose_accommodation,
85
+                                   );
86
+                                   $loose_accommodation_query = new WP_Query( $loose_args );
87
+                                   $accommodation             = get_transient( 'lsx_ti_accommodation' );
88
+                                   $identifier                = '';
89
+
90
+                                   if ( $loose_accommodation_query->have_posts() && false !== $accommodation ) {
91
+                                        while ( $loose_accommodation_query->have_posts() ) {
92
+                                             $loose_accommodation_query->the_post();
93
+
94
+                                             foreach ( $accommodation as $row_key => $row ) {
95
+                                                  if ( stripos( ltrim( rtrim( $row->name ) ), $post->post_title ) !== false ) {
96
+                                                       $identifier = $row->id;
97
+                                                  } else {
98
+                                                       continue;
99
+                                                  }
100
+                                             }
101
+                                             ?>
102 102
 									<tr class="post-<?php the_ID(); ?> type-accommodation status-none" id="post-<?php the_ID(); ?>">
103 103
 										<th class="check-column" scope="row">
104 104
 											<label for="cb-select-<?php the_ID(); ?>" class="screen-reader-text"><?php the_title(); ?></label>
@@ -109,15 +109,15 @@  discard block
 block discarded – undo
109 109
 										</td>
110 110
 										<td class="excerpt column-excerpt">
111 111
 											<?php
112
-												echo wp_kses_post( strip_tags( get_the_excerpt() ) );
113
-											?>
112
+                                                            echo wp_kses_post( strip_tags( get_the_excerpt() ) );
113
+                                                       ?>
114 114
 										</td>
115 115
 									</tr>
116 116
 									<?php
117
-								}
118
-							}
119
-						}
120
-						?>
117
+                                        }
118
+                                   }
119
+                              }
120
+                              ?>
121 121
 					</tbody>
122 122
 
123 123
 					<?php $this->table_footer(); ?>
@@ -135,13 +135,13 @@  discard block
 block discarded – undo
135 135
 			</div>
136 136
 		</div>
137 137
 		<?php
138
-	}
138
+     }
139 139
 
140
-	/**
141
-	 * The header of the item list
142
-	 */
143
-	public function table_header() {
144
-		?>
140
+     /**
141
+      * The header of the item list
142
+      */
143
+     public function table_header() {
144
+          ?>
145 145
 		<thead>
146 146
 			<tr>
147 147
 				<th style="" class="manage-column column-cb check-column" id="cb" scope="col">
@@ -153,13 +153,13 @@  discard block
 block discarded – undo
153 153
 			</tr>
154 154
 		</thead>
155 155
 		<?php
156
-	}
156
+     }
157 157
 
158
-	/**
159
-	 * The footer of the item list
160
-	 */
161
-	public function table_footer() {
162
-		?>
158
+     /**
159
+      * The footer of the item list
160
+      */
161
+     public function table_footer() {
162
+          ?>
163 163
 		<tfoot>
164 164
 			<tr>
165 165
 				<th style="" class="manage-column column-cb check-column" id="cb" scope="col">
@@ -171,27 +171,27 @@  discard block
 block discarded – undo
171 171
 			</tr>
172 172
 		</tfoot>
173 173
 		<?php
174
-	}
174
+     }
175 175
 
176
-	/**
177
-	 * Grab all the current accommodation posts via the lsx_wetu_id field.
178
-	 */
179
-	public function find_current_accommodation() {
180
-		global $wpdb;
181
-		$return = false;
176
+     /**
177
+      * Grab all the current accommodation posts via the lsx_wetu_id field.
178
+      */
179
+     public function find_current_accommodation() {
180
+          global $wpdb;
181
+          $return = false;
182 182
 
183
-		$all_accommodation = $wpdb->get_results(
184
-			"
183
+          $all_accommodation = $wpdb->get_results(
184
+               "
185 185
 			SELECT ID
186 186
 			FROM {$wpdb->posts}
187 187
 			WHERE post_type = 'accommodation'
188 188
 			LIMIT 0,500
189 189
 		",
190
-			ARRAY_A
191
-		);
190
+               ARRAY_A
191
+          );
192 192
 
193
-		$current_accommodation = $wpdb->get_results(
194
-			"
193
+          $current_accommodation = $wpdb->get_results(
194
+               "
195 195
 			SELECT key1.post_id
196 196
 			FROM {$wpdb->postmeta} key1
197 197
 
@@ -203,55 +203,55 @@  discard block
 block discarded – undo
203 203
 
204 204
 			LIMIT 0,500
205 205
 		",
206
-			ARRAY_A
207
-		);
208
-
209
-		if ( null !== $all_accommodation && ! empty( $all_accommodation ) ) {
210
-			// remove the extra accommodation
211
-			if ( null !== $current_accommodation && ! empty( $current_accommodation ) ) {
212
-				$all_accommodation = array_diff( $this->format_array( $all_accommodation, 'ID' ), $this->format_array( $current_accommodation, 'post_id' ) );
213
-			} elseif ( null !== $current_accommodation && empty( $current_accommodation ) ) {
214
-				$all_accommodation = $this->format_array( $current_accommodation, 'post_id' );
215
-			}
216
-
217
-			$return = $all_accommodation;
218
-		}
219
-
220
-		return $return;
221
-	}
222
-
223
-	/**
224
-	 * format the array
225
-	 */
226
-	public function format_array( $array, $key ) {
227
-		$new_array = array();
228
-
229
-		foreach ( $array as $value ) {
230
-			$new_array[] = $value[ $key ];
231
-		}
232
-
233
-		return $new_array;
234
-	}
235
-
236
-	/**
237
-	 * Run through the accommodation an connect them.
238
-	 */
239
-	public function process_connection() {
240
-		$return = false;
241
-		check_ajax_referer( 'lsx_wetu_ajax_action', 'security' );
242
-		if ( isset( $_POST['action'] ) && 'lsx_import_connect_accommodation' === $_POST['action'] && isset( $_POST['type'] ) && $_POST['type'] === $this->tab_slug && isset( $_POST['post_id'] ) && isset( $_POST['wetu_id'] ) ) {
243
-			$post_id     = false;
244
-			$matching_id = false;
245
-			$post_id     = sanitize_text_field( $_POST['post_id'] );
246
-			$matching_id = sanitize_text_field( $_POST['wetu_id'] );
247
-
248
-			add_post_meta( $post_id, 'lsx_wetu_id', $matching_id );
249
-			$return = '<li class="post-' . $post_id . '"><span class="dashicons dashicons-yes"></span> <a target="_blank" href="' . get_permalink( $post_id ) . '">' . get_the_title( $post_id ) . '</a></li>';
250
-		}
251
-
252
-		print_r( $return );
253
-		die();
254
-	}
206
+               ARRAY_A
207
+          );
208
+
209
+          if ( null !== $all_accommodation && ! empty( $all_accommodation ) ) {
210
+               // remove the extra accommodation
211
+               if ( null !== $current_accommodation && ! empty( $current_accommodation ) ) {
212
+                    $all_accommodation = array_diff( $this->format_array( $all_accommodation, 'ID' ), $this->format_array( $current_accommodation, 'post_id' ) );
213
+               } elseif ( null !== $current_accommodation && empty( $current_accommodation ) ) {
214
+                    $all_accommodation = $this->format_array( $current_accommodation, 'post_id' );
215
+               }
216
+
217
+               $return = $all_accommodation;
218
+          }
219
+
220
+          return $return;
221
+     }
222
+
223
+     /**
224
+      * format the array
225
+      */
226
+     public function format_array( $array, $key ) {
227
+          $new_array = array();
228
+
229
+          foreach ( $array as $value ) {
230
+               $new_array[] = $value[ $key ];
231
+          }
232
+
233
+          return $new_array;
234
+     }
235
+
236
+     /**
237
+      * Run through the accommodation an connect them.
238
+      */
239
+     public function process_connection() {
240
+          $return = false;
241
+          check_ajax_referer( 'lsx_wetu_ajax_action', 'security' );
242
+          if ( isset( $_POST['action'] ) && 'lsx_import_connect_accommodation' === $_POST['action'] && isset( $_POST['type'] ) && $_POST['type'] === $this->tab_slug && isset( $_POST['post_id'] ) && isset( $_POST['wetu_id'] ) ) {
243
+               $post_id     = false;
244
+               $matching_id = false;
245
+               $post_id     = sanitize_text_field( $_POST['post_id'] );
246
+               $matching_id = sanitize_text_field( $_POST['wetu_id'] );
247
+
248
+               add_post_meta( $post_id, 'lsx_wetu_id', $matching_id );
249
+               $return = '<li class="post-' . $post_id . '"><span class="dashicons dashicons-yes"></span> <a target="_blank" href="' . get_permalink( $post_id ) . '">' . get_the_title( $post_id ) . '</a></li>';
250
+          }
251
+
252
+          print_r( $return );
253
+          die();
254
+     }
255 255
 
256 256
 }
257 257
 
Please login to merge, or discard this patch.
Spacing   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -35,17 +35,17 @@  discard block
 block discarded – undo
35 35
 	 * @access private
36 36
 	 */
37 37
 	public function __construct() {
38
-		$temp_options = get_option( '_lsx-to_settings', false );
38
+		$temp_options = get_option('_lsx-to_settings', false);
39 39
 
40
-		if ( false !== $temp_options && isset( $temp_options[ $this->plugin_slug ] ) && ! empty( $temp_options[ $this->plugin_slug ] ) ) {
41
-			$this->options = $temp_options[ $this->plugin_slug ];
40
+		if (false !== $temp_options && isset($temp_options[$this->plugin_slug]) && !empty($temp_options[$this->plugin_slug])) {
41
+			$this->options = $temp_options[$this->plugin_slug];
42 42
 		}
43 43
 
44
-		$this->url = 'http://wetu.com/API/Pins/' . $this->options['api_key'] . '/List';
44
+		$this->url = 'http://wetu.com/API/Pins/'.$this->options['api_key'].'/List';
45 45
 
46
-		add_action( 'lsx_tour_importer_admin_tab_' . $this->tab_slug, array( $this, 'display_page' ) );
47
-		add_action( 'wp_ajax_lsx_import_connect_accommodation', array( $this, 'process_connection' ) );
48
-		add_action( 'wp_ajax_nopriv_lsx_import_connect_accommodation', array( $this, 'process_connection' ) );
46
+		add_action('lsx_tour_importer_admin_tab_'.$this->tab_slug, array($this, 'display_page'));
47
+		add_action('wp_ajax_lsx_import_connect_accommodation', array($this, 'process_connection'));
48
+		add_action('wp_ajax_nopriv_lsx_import_connect_accommodation', array($this, 'process_connection'));
49 49
 	}
50 50
 
51 51
 	/**
@@ -55,46 +55,46 @@  discard block
 block discarded – undo
55 55
 		global $post;
56 56
 		?>
57 57
 		<div class="wrap">
58
-			<h3><span class="dashicons dashicons-admin-multisite"></span> <?php esc_html_e( 'Connect your Accommodation', 'lsx-wetu-importer' ); ?></h3>
58
+			<h3><span class="dashicons dashicons-admin-multisite"></span> <?php esc_html_e('Connect your Accommodation', 'lsx-wetu-importer'); ?></h3>
59 59
 
60 60
 			<form method="get" action="" id="connect-accommodation-filter">
61
-				<input type="hidden" name="post_type" class="post_type" value="<?php echo esc_attr( $this->tab_slug ); ?>" />
61
+				<input type="hidden" name="post_type" class="post_type" value="<?php echo esc_attr($this->tab_slug); ?>" />
62 62
 
63
-				<p><?php esc_html_e( 'Below is a list of your accommodation that does not contain a WETU ID, but its Title matches a name in the WETU DB. Connecting it will all you to pull through information from WETU.', 'lsx-wetu-importer' ); ?></p>
63
+				<p><?php esc_html_e('Below is a list of your accommodation that does not contain a WETU ID, but its Title matches a name in the WETU DB. Connecting it will all you to pull through information from WETU.', 'lsx-wetu-importer'); ?></p>
64 64
 
65 65
 				<div class="ajax-loader-small" style="display:none;width:100%;text-align:center;">
66
-					<img style="width:32px;" src="<?php echo esc_url( LSX_WETU_IMPORTER_URL . 'assets/images/ajaxloader.gif' ); ?>" />
66
+					<img style="width:32px;" src="<?php echo esc_url(LSX_WETU_IMPORTER_URL.'assets/images/ajaxloader.gif'); ?>" />
67 67
 				</div>
68 68
 
69 69
 				<?php
70 70
 					$loose_accommodation = $this->find_current_accommodation();
71 71
 				?>
72
-				<p><input class="button button-primary connect" type="button" value="<?php esc_html_e( 'Connect', 'lsx-wetu-importer' ); ?>" /></p>
72
+				<p><input class="button button-primary connect" type="button" value="<?php esc_html_e('Connect', 'lsx-wetu-importer'); ?>" /></p>
73 73
 				<table class="wp-list-table widefat fixed posts">
74 74
 					<?php $this->table_header(); ?>
75 75
 
76 76
 					<tbody>
77 77
 						<?php
78
-						if ( false !== $loose_accommodation ) {
78
+						if (false !== $loose_accommodation) {
79 79
 
80
-							$loose_args                = array(
80
+							$loose_args = array(
81 81
 								'post_type'   => 'accommodation',
82
-								'post_status' => array( 'publish', 'pending' ),
82
+								'post_status' => array('publish', 'pending'),
83 83
 								'nopagin'     => true,
84 84
 								'post__in'    => $loose_accommodation,
85 85
 							);
86
-							$loose_accommodation_query = new WP_Query( $loose_args );
87
-							$accommodation             = get_transient( 'lsx_ti_accommodation' );
86
+							$loose_accommodation_query = new WP_Query($loose_args);
87
+							$accommodation             = get_transient('lsx_ti_accommodation');
88 88
 							$identifier                = '';
89 89
 
90
-							if ( $loose_accommodation_query->have_posts() && false !== $accommodation ) {
91
-								while ( $loose_accommodation_query->have_posts() ) {
90
+							if ($loose_accommodation_query->have_posts() && false !== $accommodation) {
91
+								while ($loose_accommodation_query->have_posts()) {
92 92
 									$loose_accommodation_query->the_post();
93 93
 
94
-									foreach ( $accommodation as $row_key => $row ) {
95
-										if ( stripos( ltrim( rtrim( $row->name ) ), $post->post_title ) !== false ) {
94
+									foreach ($accommodation as $row_key => $row) {
95
+										if (stripos(ltrim(rtrim($row->name)), $post->post_title) !== false) {
96 96
 											$identifier = $row->id;
97
-										} else {
97
+										}else {
98 98
 											continue;
99 99
 										}
100 100
 									}
@@ -102,14 +102,14 @@  discard block
 block discarded – undo
102 102
 									<tr class="post-<?php the_ID(); ?> type-accommodation status-none" id="post-<?php the_ID(); ?>">
103 103
 										<th class="check-column" scope="row">
104 104
 											<label for="cb-select-<?php the_ID(); ?>" class="screen-reader-text"><?php the_title(); ?></label>
105
-											<input type="checkbox" data-identifier="<?php echo esc_attr( $identifier ); ?>" value="<?php the_ID(); ?>" name="post[]" id="cb-select-<?php the_ID(); ?>">
105
+											<input type="checkbox" data-identifier="<?php echo esc_attr($identifier); ?>" value="<?php the_ID(); ?>" name="post[]" id="cb-select-<?php the_ID(); ?>">
106 106
 										</th>
107 107
 										<td class="post-title page-title column-title">
108
-											<strong><?php the_title(); ?></strong> - <a href="<?php echo esc_url( admin_url( '/post.php?post=' . $post->ID . '&action=edit' ) ); ?>" target="_blank"><?php echo esc_html( $post->post_status ); ?></a>
108
+											<strong><?php the_title(); ?></strong> - <a href="<?php echo esc_url(admin_url('/post.php?post='.$post->ID.'&action=edit')); ?>" target="_blank"><?php echo esc_html($post->post_status); ?></a>
109 109
 										</td>
110 110
 										<td class="excerpt column-excerpt">
111 111
 											<?php
112
-												echo wp_kses_post( strip_tags( get_the_excerpt() ) );
112
+												echo wp_kses_post(strip_tags(get_the_excerpt()));
113 113
 											?>
114 114
 										</td>
115 115
 									</tr>
@@ -124,12 +124,12 @@  discard block
 block discarded – undo
124 124
 
125 125
 				</table>
126 126
 
127
-				<p><input class="button button-primary connect" type="button" value="<?php esc_html_e( 'Connect', 'lsx-wetu-importer' ); ?>" /></p>
127
+				<p><input class="button button-primary connect" type="button" value="<?php esc_html_e('Connect', 'lsx-wetu-importer'); ?>" /></p>
128 128
 
129 129
 			</form>
130 130
 
131 131
 			<div style="display:none;" class="completed-list-wrapper">
132
-				<h3><?php esc_html_e( 'Completed' ); ?></h3>
132
+				<h3><?php esc_html_e('Completed'); ?></h3>
133 133
 				<ul>
134 134
 				</ul>
135 135
 			</div>
@@ -206,12 +206,12 @@  discard block
 block discarded – undo
206 206
 			ARRAY_A
207 207
 		);
208 208
 
209
-		if ( null !== $all_accommodation && ! empty( $all_accommodation ) ) {
209
+		if (null !== $all_accommodation && !empty($all_accommodation)) {
210 210
 			// remove the extra accommodation
211
-			if ( null !== $current_accommodation && ! empty( $current_accommodation ) ) {
212
-				$all_accommodation = array_diff( $this->format_array( $all_accommodation, 'ID' ), $this->format_array( $current_accommodation, 'post_id' ) );
213
-			} elseif ( null !== $current_accommodation && empty( $current_accommodation ) ) {
214
-				$all_accommodation = $this->format_array( $current_accommodation, 'post_id' );
211
+			if (null !== $current_accommodation && !empty($current_accommodation)) {
212
+				$all_accommodation = array_diff($this->format_array($all_accommodation, 'ID'), $this->format_array($current_accommodation, 'post_id'));
213
+			} elseif (null !== $current_accommodation && empty($current_accommodation)) {
214
+				$all_accommodation = $this->format_array($current_accommodation, 'post_id');
215 215
 			}
216 216
 
217 217
 			$return = $all_accommodation;
@@ -223,11 +223,11 @@  discard block
 block discarded – undo
223 223
 	/**
224 224
 	 * format the array
225 225
 	 */
226
-	public function format_array( $array, $key ) {
226
+	public function format_array($array, $key) {
227 227
 		$new_array = array();
228 228
 
229
-		foreach ( $array as $value ) {
230
-			$new_array[] = $value[ $key ];
229
+		foreach ($array as $value) {
230
+			$new_array[] = $value[$key];
231 231
 		}
232 232
 
233 233
 		return $new_array;
@@ -238,18 +238,18 @@  discard block
 block discarded – undo
238 238
 	 */
239 239
 	public function process_connection() {
240 240
 		$return = false;
241
-		check_ajax_referer( 'lsx_wetu_ajax_action', 'security' );
242
-		if ( isset( $_POST['action'] ) && 'lsx_import_connect_accommodation' === $_POST['action'] && isset( $_POST['type'] ) && $_POST['type'] === $this->tab_slug && isset( $_POST['post_id'] ) && isset( $_POST['wetu_id'] ) ) {
241
+		check_ajax_referer('lsx_wetu_ajax_action', 'security');
242
+		if (isset($_POST['action']) && 'lsx_import_connect_accommodation' === $_POST['action'] && isset($_POST['type']) && $_POST['type'] === $this->tab_slug && isset($_POST['post_id']) && isset($_POST['wetu_id'])) {
243 243
 			$post_id     = false;
244 244
 			$matching_id = false;
245
-			$post_id     = sanitize_text_field( $_POST['post_id'] );
246
-			$matching_id = sanitize_text_field( $_POST['wetu_id'] );
245
+			$post_id     = sanitize_text_field($_POST['post_id']);
246
+			$matching_id = sanitize_text_field($_POST['wetu_id']);
247 247
 
248
-			add_post_meta( $post_id, 'lsx_wetu_id', $matching_id );
249
-			$return = '<li class="post-' . $post_id . '"><span class="dashicons dashicons-yes"></span> <a target="_blank" href="' . get_permalink( $post_id ) . '">' . get_the_title( $post_id ) . '</a></li>';
248
+			add_post_meta($post_id, 'lsx_wetu_id', $matching_id);
249
+			$return = '<li class="post-'.$post_id.'"><span class="dashicons dashicons-yes"></span> <a target="_blank" href="'.get_permalink($post_id).'">'.get_the_title($post_id).'</a></li>';
250 250
 		}
251 251
 
252
-		print_r( $return );
252
+		print_r($return);
253 253
 		die();
254 254
 	}
255 255
 
Please login to merge, or discard this patch.
classes/class-lsx-wetu-importer-post-columns.php 2 patches
Indentation   +95 added lines, -95 removed lines patch added patch discarded remove patch
@@ -14,109 +14,109 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class LSX_WETU_Importer_Post_Columns {
16 16
 
17
-	/**
18
-	 * Holds instance of the class
19
-	 *
20
-	 * @var object
21
-	 */
22
-	private static $instance;
17
+     /**
18
+      * Holds instance of the class
19
+      *
20
+      * @var object
21
+      */
22
+     private static $instance;
23 23
 
24
-	/**
25
-	 * Initialize the plugin by setting localization, filters, and administration functions.
26
-	 *
27
-	 * @since 1.0.0
28
-	 *
29
-	 * @access private
30
-	 */
31
-	public function __construct() {
32
-		add_filter( 'manage_tour_posts_columns', array( $this, 'register_tour_columns' ) );
33
-		add_action( 'manage_tour_posts_custom_column', array( $this, 'output_tour_ref_column' ), 10, 2 );
24
+     /**
25
+      * Initialize the plugin by setting localization, filters, and administration functions.
26
+      *
27
+      * @since 1.0.0
28
+      *
29
+      * @access private
30
+      */
31
+     public function __construct() {
32
+          add_filter( 'manage_tour_posts_columns', array( $this, 'register_tour_columns' ) );
33
+          add_action( 'manage_tour_posts_custom_column', array( $this, 'output_tour_ref_column' ), 10, 2 );
34 34
 
35
-		// Sortables Columns, sorting needs to be fixed
36
-		// add_filter( 'manage_edit-tour_sortable_columns', array( $this, 'register_sortable_columns' ) );
37
-		// add_action( 'pre_get_posts', array( $this, 'columns_posts_orderby' ) );
38
-	}
35
+          // Sortables Columns, sorting needs to be fixed
36
+          // add_filter( 'manage_edit-tour_sortable_columns', array( $this, 'register_sortable_columns' ) );
37
+          // add_action( 'pre_get_posts', array( $this, 'columns_posts_orderby' ) );
38
+     }
39 39
 
40
-	/**
41
-	 * Return an instance of this class.
42
-	 *
43
-	 * @return  object
44
-	 */
45
-	public static function get_instance() {
46
-		// If the single instance hasn't been set, set it now.
47
-		if ( ! isset( self::$instance ) ) {
48
-			self::$instance = new self();
49
-		}
50
-		return self::$instance;
51
-	}
40
+     /**
41
+      * Return an instance of this class.
42
+      *
43
+      * @return  object
44
+      */
45
+     public static function get_instance() {
46
+          // If the single instance hasn't been set, set it now.
47
+          if ( ! isset( self::$instance ) ) {
48
+               self::$instance = new self();
49
+          }
50
+          return self::$instance;
51
+     }
52 52
 
53
-	/**
54
-	 * Display the importer welcome screen
55
-	 */
56
-	public function display_page() {
53
+     /**
54
+      * Display the importer welcome screen
55
+      */
56
+     public function display_page() {
57 57
 
58
-	}
58
+     }
59 59
 
60
-	/**
61
-	 * Registers the tour ref column
62
-	 *
63
-	 * @param array $columns
64
-	 * @return array
65
-	 */
66
-	public function register_tour_columns( $columns ) {
67
-		$new_columns = array(
68
-			'cb'       => $columns['cb'],
69
-			'title'    => $columns['title'],
70
-			'wetu_ref' => __( 'Ref', 'lsx-wetu-importer' ),
71
-		);
72
-		unset( $columns['cb'] );
73
-		unset( $columns['title'] );
74
-		foreach ( $columns as $column_key => $column_label ) {
75
-			$new_columns[ $column_key ] = $column_label;
76
-		}
77
-		$columns = $new_columns;
78
-		return $columns;
79
-	}
60
+     /**
61
+      * Registers the tour ref column
62
+      *
63
+      * @param array $columns
64
+      * @return array
65
+      */
66
+     public function register_tour_columns( $columns ) {
67
+          $new_columns = array(
68
+               'cb'       => $columns['cb'],
69
+               'title'    => $columns['title'],
70
+               'wetu_ref' => __( 'Ref', 'lsx-wetu-importer' ),
71
+          );
72
+          unset( $columns['cb'] );
73
+          unset( $columns['title'] );
74
+          foreach ( $columns as $column_key => $column_label ) {
75
+               $new_columns[ $column_key ] = $column_label;
76
+          }
77
+          $columns = $new_columns;
78
+          return $columns;
79
+     }
80 80
 
81
-	/**
82
-	 * Outputs the tour reference column
83
-	 *
84
-	 * @param string $column
85
-	 * @param string $post_id
86
-	 * @return void
87
-	 */
88
-	public function output_tour_ref_column( $column, $post_id ) {
89
-		if ( 'wetu_ref' === $column ) {
90
-			echo esc_attr( get_post_meta( $post_id, 'lsx_wetu_ref', true ) );
91
-		}
92
-	}
81
+     /**
82
+      * Outputs the tour reference column
83
+      *
84
+      * @param string $column
85
+      * @param string $post_id
86
+      * @return void
87
+      */
88
+     public function output_tour_ref_column( $column, $post_id ) {
89
+          if ( 'wetu_ref' === $column ) {
90
+               echo esc_attr( get_post_meta( $post_id, 'lsx_wetu_ref', true ) );
91
+          }
92
+     }
93 93
 
94
-	/**
95
-	 * Register the columns that will be sortable
96
-	 *
97
-	 * @param array $columns
98
-	 * @return array
99
-	 */
100
-	public function register_sortable_columns( $columns = array() ) {
101
-		$columns['wetu_ref'] = 'price_per_month';
102
-		return $columns;
103
-	}
94
+     /**
95
+      * Register the columns that will be sortable
96
+      *
97
+      * @param array $columns
98
+      * @return array
99
+      */
100
+     public function register_sortable_columns( $columns = array() ) {
101
+          $columns['wetu_ref'] = 'price_per_month';
102
+          return $columns;
103
+     }
104 104
 
105
-	/**
106
-	 * Sort the columns
107
-	 *
108
-	 * @param object $query WP_Query()
109
-	 * @return void
110
-	 */
111
-	public function columns_posts_orderby( $query ) {
112
-		if ( ! is_admin() || ! $query->is_main_query() ) {
113
-			return;
114
-		}
115
-		if ( 'wetu_ref' === $query->get( 'orderby' ) ) {
116
-			$query->set( 'orderby', 'meta_value' );
117
-			$query->set( 'meta_key', 'lsx_wetu_reference' );
118
-		}
119
-		/*
105
+     /**
106
+      * Sort the columns
107
+      *
108
+      * @param object $query WP_Query()
109
+      * @return void
110
+      */
111
+     public function columns_posts_orderby( $query ) {
112
+          if ( ! is_admin() || ! $query->is_main_query() ) {
113
+               return;
114
+          }
115
+          if ( 'wetu_ref' === $query->get( 'orderby' ) ) {
116
+               $query->set( 'orderby', 'meta_value' );
117
+               $query->set( 'meta_key', 'lsx_wetu_reference' );
118
+          }
119
+          /*
120 120
 		if ( $query->is_search() && 'tour' === $query->get( 'post_type' ) ) {
121 121
 			$meta_query = array(
122 122
 				'relation' => 'OR',
@@ -128,5 +128,5 @@  discard block
 block discarded – undo
128 128
 			);
129 129
 			$query->set( 'meta_query', $meta_query );
130 130
 		}*/
131
-	}
131
+     }
132 132
 }
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -29,8 +29,8 @@  discard block
 block discarded – undo
29 29
 	 * @access private
30 30
 	 */
31 31
 	public function __construct() {
32
-		add_filter( 'manage_tour_posts_columns', array( $this, 'register_tour_columns' ) );
33
-		add_action( 'manage_tour_posts_custom_column', array( $this, 'output_tour_ref_column' ), 10, 2 );
32
+		add_filter('manage_tour_posts_columns', array($this, 'register_tour_columns'));
33
+		add_action('manage_tour_posts_custom_column', array($this, 'output_tour_ref_column'), 10, 2);
34 34
 
35 35
 		// Sortables Columns, sorting needs to be fixed
36 36
 		// add_filter( 'manage_edit-tour_sortable_columns', array( $this, 'register_sortable_columns' ) );
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
 	 */
45 45
 	public static function get_instance() {
46 46
 		// If the single instance hasn't been set, set it now.
47
-		if ( ! isset( self::$instance ) ) {
47
+		if (!isset(self::$instance)) {
48 48
 			self::$instance = new self();
49 49
 		}
50 50
 		return self::$instance;
@@ -63,16 +63,16 @@  discard block
 block discarded – undo
63 63
 	 * @param array $columns
64 64
 	 * @return array
65 65
 	 */
66
-	public function register_tour_columns( $columns ) {
66
+	public function register_tour_columns($columns) {
67 67
 		$new_columns = array(
68 68
 			'cb'       => $columns['cb'],
69 69
 			'title'    => $columns['title'],
70
-			'wetu_ref' => __( 'Ref', 'lsx-wetu-importer' ),
70
+			'wetu_ref' => __('Ref', 'lsx-wetu-importer'),
71 71
 		);
72
-		unset( $columns['cb'] );
73
-		unset( $columns['title'] );
74
-		foreach ( $columns as $column_key => $column_label ) {
75
-			$new_columns[ $column_key ] = $column_label;
72
+		unset($columns['cb']);
73
+		unset($columns['title']);
74
+		foreach ($columns as $column_key => $column_label) {
75
+			$new_columns[$column_key] = $column_label;
76 76
 		}
77 77
 		$columns = $new_columns;
78 78
 		return $columns;
@@ -85,9 +85,9 @@  discard block
 block discarded – undo
85 85
 	 * @param string $post_id
86 86
 	 * @return void
87 87
 	 */
88
-	public function output_tour_ref_column( $column, $post_id ) {
89
-		if ( 'wetu_ref' === $column ) {
90
-			echo esc_attr( get_post_meta( $post_id, 'lsx_wetu_ref', true ) );
88
+	public function output_tour_ref_column($column, $post_id) {
89
+		if ('wetu_ref' === $column) {
90
+			echo esc_attr(get_post_meta($post_id, 'lsx_wetu_ref', true));
91 91
 		}
92 92
 	}
93 93
 
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 	 * @param array $columns
98 98
 	 * @return array
99 99
 	 */
100
-	public function register_sortable_columns( $columns = array() ) {
100
+	public function register_sortable_columns($columns = array()) {
101 101
 		$columns['wetu_ref'] = 'price_per_month';
102 102
 		return $columns;
103 103
 	}
@@ -108,13 +108,13 @@  discard block
 block discarded – undo
108 108
 	 * @param object $query WP_Query()
109 109
 	 * @return void
110 110
 	 */
111
-	public function columns_posts_orderby( $query ) {
112
-		if ( ! is_admin() || ! $query->is_main_query() ) {
111
+	public function columns_posts_orderby($query) {
112
+		if (!is_admin() || !$query->is_main_query()) {
113 113
 			return;
114 114
 		}
115
-		if ( 'wetu_ref' === $query->get( 'orderby' ) ) {
116
-			$query->set( 'orderby', 'meta_value' );
117
-			$query->set( 'meta_key', 'lsx_wetu_reference' );
115
+		if ('wetu_ref' === $query->get('orderby')) {
116
+			$query->set('orderby', 'meta_value');
117
+			$query->set('meta_key', 'lsx_wetu_reference');
118 118
 		}
119 119
 		/*
120 120
 		if ( $query->is_search() && 'tour' === $query->get( 'post_type' ) ) {
Please login to merge, or discard this patch.
classes/class-lsx-wetu-importer.php 2 patches
Indentation   +1305 added lines, -1305 removed lines patch added patch discarded remove patch
@@ -13,465 +13,465 @@  discard block
 block discarded – undo
13 13
  */
14 14
 class LSX_WETU_Importer {
15 15
 
16
-	/**
17
-	 * Holds class instance
18
-	 *
19
-	 * @since 1.0.0
20
-	 *
21
-	 * @var      object|Module_Template
22
-	 */
23
-	protected static $instance = null;
24
-
25
-	/**
26
-	 * The slug for this plugin
27
-	 *
28
-	 * @since 0.0.1
29
-	 *
30
-	 * @var      string
31
-	 */
32
-	public $plugin_slug = 'lsx-wetu-importer';
33
-
34
-	/**
35
-	 * The url to list items from WETU
36
-	 *
37
-	 * @since 0.0.1
38
-	 *
39
-	 * @var      string
40
-	 */
41
-	public $tab_slug = 'default';
42
-
43
-	/**
44
-	 * The options for the plugin
45
-	 *
46
-	 * @since 0.0.1
47
-	 *
48
-	 * @var      string
49
-	 */
50
-	public $options = false;
51
-
52
-	/**
53
-	 * The url to import images from WETU
54
-	 *
55
-	 * @since 0.0.1
56
-	 *
57
-	 * @var      string
58
-	 */
59
-	public $import_scaling_url = false;
60
-
61
-	/**
62
-	 * scale the images on import or not
63
-	 *
64
-	 * @since 0.0.1
65
-	 *
66
-	 * @var      boolean
67
-	 */
68
-	public $scale_images = false;
69
-
70
-	/**
71
-	 * The WETU API Key
72
-	 */
73
-	public $api_key = false;
74
-
75
-	/**
76
-	 * The post types this works with.
77
-	 */
78
-	public $post_types = array();
79
-
80
-	/**
81
-	 * The previously attached images
82
-	 *
83
-	 * @var      array()
84
-	 */
85
-	public $found_attachments = array();
86
-
87
-	/**
88
-	 * The gallery ids for the found attachements
89
-	 *
90
-	 * @var      array()
91
-	 */
92
-	public $gallery_meta = array();
93
-
94
-	/**
95
-	 * The post ids to clean up (make sure the connected items are only singular)
96
-	 *
97
-	 * @var      array()
98
-	 */
99
-	public $cleanup_posts = array();
100
-
101
-	/**
102
-	 * A post => parent relationship array.
103
-	 *
104
-	 * @var      array()
105
-	 */
106
-	public $relation_meta = array();
107
-
108
-	/**
109
-	 * Image Limit
110
-	 *
111
-	 * @var      int
112
-	 */
113
-	public $image_limit = false;
114
-
115
-	/**
116
-	 * the featured image id
117
-	 *
118
-	 * @var      int
119
-	 */
120
-	public $featured_image = false;
121
-
122
-	/**
123
-	 * the banner image
124
-	 *
125
-	 * @var      int
126
-	 */
127
-	public $banner_image = false;
128
-
129
-	/**
130
-	 * Holds the current import to display
131
-	 *
132
-	 * @var      int
133
-	 */
134
-	public $current_importer = false;
135
-
136
-	/**
137
-	 * if you ran a tour import then you will have accommodation and destination queued to sync as well.
138
-	 *
139
-	 * @var      int
140
-	 */
141
-	public $queued_imports = array();
142
-
143
-	/**
144
-	 * An Array to hold the items to queue
145
-	 *
146
-	 * @var      int
147
-	 */
148
-	public $import_queue = array();
149
-
150
-	/**
151
-	 * Holds the current post that is being imported. Use to check the content and excerpt.
152
-	 *
153
-	 * @var      int
154
-	 */
155
-	public $current_post = false;
156
-
157
-	/**
158
-	 * Holds the accommodation settings
159
-	 *
160
-	 * @var      int
161
-	 */
162
-	public $accommodation_settings = false;
163
-
164
-	/**
165
-	 * Holds the tour settings
166
-	 *
167
-	 * @var      int
168
-	 */
169
-	public $tour_settings = false;
170
-
171
-	/**
172
-	 * Holds the destination settings
173
-	 *
174
-	 * @var      int
175
-	 */
176
-	public $destination_settings = false;
177
-
178
-	/**
179
-	 * Hold the flag to let you know if the debug is enabled or not.
180
-	 *
181
-	 * @var      int
182
-	 */
183
-	public $debug_enabled = false;
184
-
185
-	/**
186
-	 * Hold the post columns object
187
-	 *
188
-	 * @var object LSX_WETU_Importer_Post_Columns()
189
-	 */
190
-	public $post_columns = false;
191
-
192
-	/**
193
-	 * Initialize the plugin by setting localization, filters, and administration functions.
194
-	 *
195
-	 * @since 1.0.0
196
-	 *
197
-	 * @access private
198
-	 */
199
-	public function __construct() {
200
-		add_action( 'admin_init', array( $this, 'compatible_version_check' ) );
201
-		require_once LSX_WETU_IMPORTER_PATH . 'includes/helpers.php';
202
-
203
-		// Don't run anything else in the plugin, if we're on an incompatible PHP version.
204
-		if ( ! self::compatible_version() ) {
205
-			return;
206
-		}
207
-
208
-		$this->set_variables();
209
-
210
-		add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
211
-		add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ), 11 );
212
-		add_action( 'admin_menu', array( $this, 'register_importer_page' ), 20 );
213
-
214
-		require_once LSX_WETU_IMPORTER_PATH . 'classes/class-lsx-wetu-importer-welcome.php';
215
-		require_once LSX_WETU_IMPORTER_PATH . 'classes/class-lsx-wetu-importer-accommodation.php';
216
-		require_once LSX_WETU_IMPORTER_PATH . 'classes/class-lsx-wetu-importer-destination.php';
217
-		require_once LSX_WETU_IMPORTER_PATH . 'classes/class-lsx-wetu-importer-tours.php';
218
-		require_once LSX_WETU_IMPORTER_PATH . 'classes/class-lsx-wetu-importer-settings.php';
219
-		require_once LSX_WETU_IMPORTER_PATH . 'classes/class-cron.php';
220
-
221
-		if ( isset( $this->options ) && isset( $this->options['enable_tour_ref_column'] ) && '' !== $this->options['enable_tour_ref_column'] ) {
222
-			require_once LSX_WETU_IMPORTER_PATH . 'classes/class-lsx-wetu-importer-post-columns.php';
223
-			$this->post_columns = LSX_WETU_Importer_Post_Columns::get_instance();
224
-		}
225
-
226
-		add_action( 'init', array( $this, 'load_class' ) );
227
-
228
-		if ( 'default' !== $this->tab_slug ) {
229
-			add_action( 'wp_ajax_lsx_tour_importer', array( $this, 'process_ajax_search' ) );
230
-			add_action( 'wp_ajax_nopriv_lsx_tour_importer', array( $this, 'process_ajax_search' ) );
231
-
232
-			add_action( 'wp_ajax_lsx_import_items', array( $this, 'process_ajax_import' ) );
233
-			add_action( 'wp_ajax_nopriv_lsx_import_items', array( $this, 'process_ajax_import' ) );
234
-		}
235
-	}
236
-
237
-	/**
238
-	 * Load the plugin text domain for translation.
239
-	 *
240
-	 * @since 1.0.0
241
-	 */
242
-	public function load_plugin_textdomain() {
243
-		load_plugin_textdomain( 'lsx-wetu-importer', false, basename( LSX_WETU_IMPORTER_PATH ) . '/languages' );
244
-	}
245
-
246
-	/**
247
-	 * Sets the variables used throughout the plugin.
248
-	 */
249
-	public function set_variables() {
250
-		$this->post_types = array( 'accommodation', 'destination', 'tour' );
251
-		$options          = lsx_wetu_get_options();
252
-
253
-		// Set the options.
254
-		$this->options = $options;
255
-
256
-		$temp_options = get_option( '_lsx-to_settings', false );
257
-		if ( false !== $temp_options ) {
258
-			$this->accommodation_settings = $temp_options['accommodation'];
259
-			$this->tour_settings          = $temp_options['tour'];
260
-			$this->destination_settings   = $temp_options['destination'];
261
-		}
262
-
263
-		$this->api_key = false;
264
-
265
-		if ( ! defined( 'WETU_API_KEY' ) ) {
266
-			if ( isset( $options['api_key'] ) && '' !== $options['api_key'] ) {
267
-				$this->api_key = $options['api_key'];
268
-			}
269
-		} else {
270
-			$this->api_key = WETU_API_KEY;
271
-		}
272
-
273
-		// Set the tab slug.
274
-		// @codingStandardsIgnoreLine
275
-		if ( isset( $_GET['tab'] ) || ( defined( 'DOING_AJAX' ) && isset( $_POST['type'] ) ) ) {
276
-			if ( isset( $_GET['tab'] ) ) {
277
-				$this->tab_slug = sanitize_text_field( $_GET['tab'] );
278
-			} else {
279
-				// @codingStandardsIgnoreLine
280
-				$this->tab_slug = sanitize_text_field( $_POST['type'] );
281
-			}
282
-		}
283
-
284
-		// If any tours were queued.
285
-		$this->queued_imports = get_option( 'lsx_wetu_importer_que', array() );
286
-
287
-		// Set the scaling options.
288
-		if ( isset( $this->options ) && isset( $this->options['image_scaling'] ) ) {
289
-			$this->scale_images = true;
290
-
291
-			$width = '1024';
292
-			if ( isset( $this->options['width'] ) && '' !== $this->options['width'] ) {
293
-				$width = $this->options['width'];
294
-			}
295
-
296
-			$height = '768';
297
-			if ( isset( $this->options['height'] ) && '' !== $this->options['height'] ) {
298
-				$height = $this->options['height'];
299
-			}
300
-
301
-			$cropping = 'w';
302
-			if ( isset( $this->options['cropping'] ) && '' !== $this->options['cropping'] ) {
303
-				$cropping = $this->options['cropping'];
304
-			}
305
-
306
-			$this->image_scaling_url = 'https://wetu.com/ImageHandler/' . $cropping . $width . 'x' . $height . '/';
307
-		}
308
-
309
-		if ( isset( $this->options ) && isset( $this->options['image_limit'] ) && '' !== $this->options['image_limit'] ) {
310
-			$this->image_limit = $this->options['image_limit'];
311
-		}
312
-	}
313
-
314
-	// COMPATABILITY FUNCTIONS.
315
-
316
-	/**
317
-	 * On plugin activation
318
-	 *
319
-	 * @since 1.0.0
320
-	 */
321
-	public static function register_activation_hook() {
322
-		self::compatible_version_check_on_activation();
323
-	}
324
-
325
-	/**
326
-	 * Check if the PHP version is compatible.
327
-	 *
328
-	 * @since 1.0.0
329
-	 */
330
-	public static function compatible_version() {
331
-		if ( version_compare( PHP_VERSION, '5.6', '<' ) ) {
332
-			return false;
333
-		}
334
-
335
-		return true;
336
-	}
337
-
338
-	/**
339
-	 * The backup sanity check, in case the plugin is activated in a weird way,
340
-	 * or the versions change after activation.
341
-	 *
342
-	 * @since 1.0.0
343
-	 */
344
-	public function compatible_version_check() {
345
-		if ( ! self::compatible_version() ) {
346
-			if ( is_plugin_active( plugin_basename( LSX_WETU_IMPORTER_CORE ) ) ) {
347
-				deactivate_plugins( plugin_basename( LSX_WETU_IMPORTER_CORE ) );
348
-				add_action( 'admin_notices', array( $this, 'compatible_version_notice' ) );
349
-
350
-				if ( isset( $_GET['activate'] ) ) {
351
-					unset( $_GET['activate'] );
352
-				}
353
-			}
354
-		}
355
-	}
356
-
357
-	/**
358
-	 * Display the notice related with the older version from PHP.
359
-	 *
360
-	 * @since 1.0.0
361
-	 */
362
-	public function compatible_version_notice() {
363
-		$class   = 'notice notice-error';
364
-		$message = esc_html__( 'LSX Importer for Wetu Plugin requires PHP 5.6 or higher.', 'lsx-wetu-importer' );
365
-		printf( '<div class="%1$s"><p>%2$s</p></div>', esc_html( $class ), esc_html( $message ) );
366
-	}
367
-
368
-	/**
369
-	 * The primary sanity check, automatically disable the plugin on activation if it doesn't
370
-	 * meet minimum requirements.
371
-	 *
372
-	 * @since 1.0.0
373
-	 */
374
-	public static function compatible_version_check_on_activation() {
375
-		if ( ! self::compatible_version() ) {
376
-			deactivate_plugins( plugin_basename( LSX_WETU_IMPORTER_CORE ) );
377
-			wp_die( esc_html__( 'LSX Importer for Wetu Plugin requires PHP 5.6 or higher.', 'lsx-wetu-importer' ) );
378
-		}
379
-	}
380
-
381
-	// DISPLAY FUNCTIONS.
382
-
383
-	/**
384
-	 * Load the importer class you want to use
385
-	 */
386
-	public function load_class() {
387
-		switch ( $this->tab_slug ) {
388
-			case 'accommodation':
389
-				$this->current_importer = new LSX_WETU_Importer_Accommodation();
390
-				break;
391
-
392
-			case 'destination':
393
-				$this->current_importer = new LSX_WETU_Importer_Destination();
394
-				break;
395
-
396
-			case 'tour':
397
-				$this->current_importer = new LSX_WETU_Importer_Tours();
398
-				break;
399
-
400
-			case 'settings':
401
-				$this->current_importer = LSX_WETU_Importer_Settings::get_instance();
402
-				break;
403
-
404
-			default:
405
-				$this->current_importer = LSX_WETU_Importer_Welcome::get_instance();
406
-				break;
407
-		}
408
-	}
409
-
410
-	/**
411
-	 * Registers the admin page which will house the importer form.
412
-	 */
413
-	public function register_importer_page() {
414
-		add_submenu_page( 'tour-operator', esc_html__( 'Importer', 'tour-operator' ), esc_html__( 'Importer', 'tour-operator' ), 'manage_options', 'lsx-wetu-importer', array( $this, 'display_page' ) );
415
-	}
416
-
417
-	/**
418
-	 * Enqueue the JS needed to contact wetu and return your result.
419
-	 */
420
-	public function admin_scripts() {
421
-		if ( defined( 'WP_DEBUG' ) && true === WP_DEBUG ) {
422
-			$min = '';
423
-		} else {
424
-			$min = '.min';
425
-		}
426
-
427
-		$min = '';
428
-
429
-		if ( is_admin() && isset( $_GET['page'] ) && $this->plugin_slug === $_GET['page'] ) {
430
-
431
-			// wp_enqueue_style( 'datatables', LSX_WETU_IMPORTER_URL . 'assets/css/datatables' . $min . '.css', LSX_WETU_IMPORTER_VER, true );
432
-			wp_enqueue_style( 'lsx-wetu-importer-style', LSX_WETU_IMPORTER_URL . 'assets/css/lsx-wetu-importer.css', LSX_WETU_IMPORTER_VER, true );
433
-
434
-			if ( isset( $_GET['tab'] ) ) {
435
-				wp_enqueue_script( 'datatables', LSX_WETU_IMPORTER_URL . 'assets/js/datatables' . $min . '.js', array( 'jquery' ), LSX_WETU_IMPORTER_VER, true );
436
-				wp_enqueue_script( 'lsx-wetu-importers-script', LSX_WETU_IMPORTER_URL . 'assets/js/lsx-wetu-importer' . $min . '.js', array( 'jquery', 'datatables' ), LSX_WETU_IMPORTER_VER, true );
437
-
438
-				wp_localize_script(
439
-					'lsx-wetu-importers-script',
440
-					'lsx_tour_importer_params',
441
-					array(
442
-						'ajax_url'   => admin_url( 'admin-ajax.php' ),
443
-						'ajax_nonce' => wp_create_nonce( 'lsx_wetu_ajax_action' ),
444
-					)
445
-				);
446
-			}
447
-		}
448
-	}
449
-
450
-	/**
451
-	 * Display the importer administration screen
452
-	 */
453
-	public function display_page() {
454
-		?>
16
+     /**
17
+      * Holds class instance
18
+      *
19
+      * @since 1.0.0
20
+      *
21
+      * @var      object|Module_Template
22
+      */
23
+     protected static $instance = null;
24
+
25
+     /**
26
+      * The slug for this plugin
27
+      *
28
+      * @since 0.0.1
29
+      *
30
+      * @var      string
31
+      */
32
+     public $plugin_slug = 'lsx-wetu-importer';
33
+
34
+     /**
35
+      * The url to list items from WETU
36
+      *
37
+      * @since 0.0.1
38
+      *
39
+      * @var      string
40
+      */
41
+     public $tab_slug = 'default';
42
+
43
+     /**
44
+      * The options for the plugin
45
+      *
46
+      * @since 0.0.1
47
+      *
48
+      * @var      string
49
+      */
50
+     public $options = false;
51
+
52
+     /**
53
+      * The url to import images from WETU
54
+      *
55
+      * @since 0.0.1
56
+      *
57
+      * @var      string
58
+      */
59
+     public $import_scaling_url = false;
60
+
61
+     /**
62
+      * scale the images on import or not
63
+      *
64
+      * @since 0.0.1
65
+      *
66
+      * @var      boolean
67
+      */
68
+     public $scale_images = false;
69
+
70
+     /**
71
+      * The WETU API Key
72
+      */
73
+     public $api_key = false;
74
+
75
+     /**
76
+      * The post types this works with.
77
+      */
78
+     public $post_types = array();
79
+
80
+     /**
81
+      * The previously attached images
82
+      *
83
+      * @var      array()
84
+      */
85
+     public $found_attachments = array();
86
+
87
+     /**
88
+      * The gallery ids for the found attachements
89
+      *
90
+      * @var      array()
91
+      */
92
+     public $gallery_meta = array();
93
+
94
+     /**
95
+      * The post ids to clean up (make sure the connected items are only singular)
96
+      *
97
+      * @var      array()
98
+      */
99
+     public $cleanup_posts = array();
100
+
101
+     /**
102
+      * A post => parent relationship array.
103
+      *
104
+      * @var      array()
105
+      */
106
+     public $relation_meta = array();
107
+
108
+     /**
109
+      * Image Limit
110
+      *
111
+      * @var      int
112
+      */
113
+     public $image_limit = false;
114
+
115
+     /**
116
+      * the featured image id
117
+      *
118
+      * @var      int
119
+      */
120
+     public $featured_image = false;
121
+
122
+     /**
123
+      * the banner image
124
+      *
125
+      * @var      int
126
+      */
127
+     public $banner_image = false;
128
+
129
+     /**
130
+      * Holds the current import to display
131
+      *
132
+      * @var      int
133
+      */
134
+     public $current_importer = false;
135
+
136
+     /**
137
+      * if you ran a tour import then you will have accommodation and destination queued to sync as well.
138
+      *
139
+      * @var      int
140
+      */
141
+     public $queued_imports = array();
142
+
143
+     /**
144
+      * An Array to hold the items to queue
145
+      *
146
+      * @var      int
147
+      */
148
+     public $import_queue = array();
149
+
150
+     /**
151
+      * Holds the current post that is being imported. Use to check the content and excerpt.
152
+      *
153
+      * @var      int
154
+      */
155
+     public $current_post = false;
156
+
157
+     /**
158
+      * Holds the accommodation settings
159
+      *
160
+      * @var      int
161
+      */
162
+     public $accommodation_settings = false;
163
+
164
+     /**
165
+      * Holds the tour settings
166
+      *
167
+      * @var      int
168
+      */
169
+     public $tour_settings = false;
170
+
171
+     /**
172
+      * Holds the destination settings
173
+      *
174
+      * @var      int
175
+      */
176
+     public $destination_settings = false;
177
+
178
+     /**
179
+      * Hold the flag to let you know if the debug is enabled or not.
180
+      *
181
+      * @var      int
182
+      */
183
+     public $debug_enabled = false;
184
+
185
+     /**
186
+      * Hold the post columns object
187
+      *
188
+      * @var object LSX_WETU_Importer_Post_Columns()
189
+      */
190
+     public $post_columns = false;
191
+
192
+     /**
193
+      * Initialize the plugin by setting localization, filters, and administration functions.
194
+      *
195
+      * @since 1.0.0
196
+      *
197
+      * @access private
198
+      */
199
+     public function __construct() {
200
+          add_action( 'admin_init', array( $this, 'compatible_version_check' ) );
201
+          require_once LSX_WETU_IMPORTER_PATH . 'includes/helpers.php';
202
+
203
+          // Don't run anything else in the plugin, if we're on an incompatible PHP version.
204
+          if ( ! self::compatible_version() ) {
205
+               return;
206
+          }
207
+
208
+          $this->set_variables();
209
+
210
+          add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
211
+          add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ), 11 );
212
+          add_action( 'admin_menu', array( $this, 'register_importer_page' ), 20 );
213
+
214
+          require_once LSX_WETU_IMPORTER_PATH . 'classes/class-lsx-wetu-importer-welcome.php';
215
+          require_once LSX_WETU_IMPORTER_PATH . 'classes/class-lsx-wetu-importer-accommodation.php';
216
+          require_once LSX_WETU_IMPORTER_PATH . 'classes/class-lsx-wetu-importer-destination.php';
217
+          require_once LSX_WETU_IMPORTER_PATH . 'classes/class-lsx-wetu-importer-tours.php';
218
+          require_once LSX_WETU_IMPORTER_PATH . 'classes/class-lsx-wetu-importer-settings.php';
219
+          require_once LSX_WETU_IMPORTER_PATH . 'classes/class-cron.php';
220
+
221
+          if ( isset( $this->options ) && isset( $this->options['enable_tour_ref_column'] ) && '' !== $this->options['enable_tour_ref_column'] ) {
222
+               require_once LSX_WETU_IMPORTER_PATH . 'classes/class-lsx-wetu-importer-post-columns.php';
223
+               $this->post_columns = LSX_WETU_Importer_Post_Columns::get_instance();
224
+          }
225
+
226
+          add_action( 'init', array( $this, 'load_class' ) );
227
+
228
+          if ( 'default' !== $this->tab_slug ) {
229
+               add_action( 'wp_ajax_lsx_tour_importer', array( $this, 'process_ajax_search' ) );
230
+               add_action( 'wp_ajax_nopriv_lsx_tour_importer', array( $this, 'process_ajax_search' ) );
231
+
232
+               add_action( 'wp_ajax_lsx_import_items', array( $this, 'process_ajax_import' ) );
233
+               add_action( 'wp_ajax_nopriv_lsx_import_items', array( $this, 'process_ajax_import' ) );
234
+          }
235
+     }
236
+
237
+     /**
238
+      * Load the plugin text domain for translation.
239
+      *
240
+      * @since 1.0.0
241
+      */
242
+     public function load_plugin_textdomain() {
243
+          load_plugin_textdomain( 'lsx-wetu-importer', false, basename( LSX_WETU_IMPORTER_PATH ) . '/languages' );
244
+     }
245
+
246
+     /**
247
+      * Sets the variables used throughout the plugin.
248
+      */
249
+     public function set_variables() {
250
+          $this->post_types = array( 'accommodation', 'destination', 'tour' );
251
+          $options          = lsx_wetu_get_options();
252
+
253
+          // Set the options.
254
+          $this->options = $options;
255
+
256
+          $temp_options = get_option( '_lsx-to_settings', false );
257
+          if ( false !== $temp_options ) {
258
+               $this->accommodation_settings = $temp_options['accommodation'];
259
+               $this->tour_settings          = $temp_options['tour'];
260
+               $this->destination_settings   = $temp_options['destination'];
261
+          }
262
+
263
+          $this->api_key = false;
264
+
265
+          if ( ! defined( 'WETU_API_KEY' ) ) {
266
+               if ( isset( $options['api_key'] ) && '' !== $options['api_key'] ) {
267
+                    $this->api_key = $options['api_key'];
268
+               }
269
+          } else {
270
+               $this->api_key = WETU_API_KEY;
271
+          }
272
+
273
+          // Set the tab slug.
274
+          // @codingStandardsIgnoreLine
275
+          if ( isset( $_GET['tab'] ) || ( defined( 'DOING_AJAX' ) && isset( $_POST['type'] ) ) ) {
276
+               if ( isset( $_GET['tab'] ) ) {
277
+                    $this->tab_slug = sanitize_text_field( $_GET['tab'] );
278
+               } else {
279
+                    // @codingStandardsIgnoreLine
280
+                    $this->tab_slug = sanitize_text_field( $_POST['type'] );
281
+               }
282
+          }
283
+
284
+          // If any tours were queued.
285
+          $this->queued_imports = get_option( 'lsx_wetu_importer_que', array() );
286
+
287
+          // Set the scaling options.
288
+          if ( isset( $this->options ) && isset( $this->options['image_scaling'] ) ) {
289
+               $this->scale_images = true;
290
+
291
+               $width = '1024';
292
+               if ( isset( $this->options['width'] ) && '' !== $this->options['width'] ) {
293
+                    $width = $this->options['width'];
294
+               }
295
+
296
+               $height = '768';
297
+               if ( isset( $this->options['height'] ) && '' !== $this->options['height'] ) {
298
+                    $height = $this->options['height'];
299
+               }
300
+
301
+               $cropping = 'w';
302
+               if ( isset( $this->options['cropping'] ) && '' !== $this->options['cropping'] ) {
303
+                    $cropping = $this->options['cropping'];
304
+               }
305
+
306
+               $this->image_scaling_url = 'https://wetu.com/ImageHandler/' . $cropping . $width . 'x' . $height . '/';
307
+          }
308
+
309
+          if ( isset( $this->options ) && isset( $this->options['image_limit'] ) && '' !== $this->options['image_limit'] ) {
310
+               $this->image_limit = $this->options['image_limit'];
311
+          }
312
+     }
313
+
314
+     // COMPATABILITY FUNCTIONS.
315
+
316
+     /**
317
+      * On plugin activation
318
+      *
319
+      * @since 1.0.0
320
+      */
321
+     public static function register_activation_hook() {
322
+          self::compatible_version_check_on_activation();
323
+     }
324
+
325
+     /**
326
+      * Check if the PHP version is compatible.
327
+      *
328
+      * @since 1.0.0
329
+      */
330
+     public static function compatible_version() {
331
+          if ( version_compare( PHP_VERSION, '5.6', '<' ) ) {
332
+               return false;
333
+          }
334
+
335
+          return true;
336
+     }
337
+
338
+     /**
339
+      * The backup sanity check, in case the plugin is activated in a weird way,
340
+      * or the versions change after activation.
341
+      *
342
+      * @since 1.0.0
343
+      */
344
+     public function compatible_version_check() {
345
+          if ( ! self::compatible_version() ) {
346
+               if ( is_plugin_active( plugin_basename( LSX_WETU_IMPORTER_CORE ) ) ) {
347
+                    deactivate_plugins( plugin_basename( LSX_WETU_IMPORTER_CORE ) );
348
+                    add_action( 'admin_notices', array( $this, 'compatible_version_notice' ) );
349
+
350
+                    if ( isset( $_GET['activate'] ) ) {
351
+                         unset( $_GET['activate'] );
352
+                    }
353
+               }
354
+          }
355
+     }
356
+
357
+     /**
358
+      * Display the notice related with the older version from PHP.
359
+      *
360
+      * @since 1.0.0
361
+      */
362
+     public function compatible_version_notice() {
363
+          $class   = 'notice notice-error';
364
+          $message = esc_html__( 'LSX Importer for Wetu Plugin requires PHP 5.6 or higher.', 'lsx-wetu-importer' );
365
+          printf( '<div class="%1$s"><p>%2$s</p></div>', esc_html( $class ), esc_html( $message ) );
366
+     }
367
+
368
+     /**
369
+      * The primary sanity check, automatically disable the plugin on activation if it doesn't
370
+      * meet minimum requirements.
371
+      *
372
+      * @since 1.0.0
373
+      */
374
+     public static function compatible_version_check_on_activation() {
375
+          if ( ! self::compatible_version() ) {
376
+               deactivate_plugins( plugin_basename( LSX_WETU_IMPORTER_CORE ) );
377
+               wp_die( esc_html__( 'LSX Importer for Wetu Plugin requires PHP 5.6 or higher.', 'lsx-wetu-importer' ) );
378
+          }
379
+     }
380
+
381
+     // DISPLAY FUNCTIONS.
382
+
383
+     /**
384
+      * Load the importer class you want to use
385
+      */
386
+     public function load_class() {
387
+          switch ( $this->tab_slug ) {
388
+               case 'accommodation':
389
+                    $this->current_importer = new LSX_WETU_Importer_Accommodation();
390
+                    break;
391
+
392
+               case 'destination':
393
+                    $this->current_importer = new LSX_WETU_Importer_Destination();
394
+                    break;
395
+
396
+               case 'tour':
397
+                    $this->current_importer = new LSX_WETU_Importer_Tours();
398
+                    break;
399
+
400
+               case 'settings':
401
+                    $this->current_importer = LSX_WETU_Importer_Settings::get_instance();
402
+                    break;
403
+
404
+               default:
405
+                    $this->current_importer = LSX_WETU_Importer_Welcome::get_instance();
406
+                    break;
407
+          }
408
+     }
409
+
410
+     /**
411
+      * Registers the admin page which will house the importer form.
412
+      */
413
+     public function register_importer_page() {
414
+          add_submenu_page( 'tour-operator', esc_html__( 'Importer', 'tour-operator' ), esc_html__( 'Importer', 'tour-operator' ), 'manage_options', 'lsx-wetu-importer', array( $this, 'display_page' ) );
415
+     }
416
+
417
+     /**
418
+      * Enqueue the JS needed to contact wetu and return your result.
419
+      */
420
+     public function admin_scripts() {
421
+          if ( defined( 'WP_DEBUG' ) && true === WP_DEBUG ) {
422
+               $min = '';
423
+          } else {
424
+               $min = '.min';
425
+          }
426
+
427
+          $min = '';
428
+
429
+          if ( is_admin() && isset( $_GET['page'] ) && $this->plugin_slug === $_GET['page'] ) {
430
+
431
+               // wp_enqueue_style( 'datatables', LSX_WETU_IMPORTER_URL . 'assets/css/datatables' . $min . '.css', LSX_WETU_IMPORTER_VER, true );
432
+               wp_enqueue_style( 'lsx-wetu-importer-style', LSX_WETU_IMPORTER_URL . 'assets/css/lsx-wetu-importer.css', LSX_WETU_IMPORTER_VER, true );
433
+
434
+               if ( isset( $_GET['tab'] ) ) {
435
+                    wp_enqueue_script( 'datatables', LSX_WETU_IMPORTER_URL . 'assets/js/datatables' . $min . '.js', array( 'jquery' ), LSX_WETU_IMPORTER_VER, true );
436
+                    wp_enqueue_script( 'lsx-wetu-importers-script', LSX_WETU_IMPORTER_URL . 'assets/js/lsx-wetu-importer' . $min . '.js', array( 'jquery', 'datatables' ), LSX_WETU_IMPORTER_VER, true );
437
+
438
+                    wp_localize_script(
439
+                         'lsx-wetu-importers-script',
440
+                         'lsx_tour_importer_params',
441
+                         array(
442
+                              'ajax_url'   => admin_url( 'admin-ajax.php' ),
443
+                              'ajax_nonce' => wp_create_nonce( 'lsx_wetu_ajax_action' ),
444
+                         )
445
+                    );
446
+               }
447
+          }
448
+     }
449
+
450
+     /**
451
+      * Display the importer administration screen
452
+      */
453
+     public function display_page() {
454
+          ?>
455 455
 		<div class="wrap">
456 456
 			<?php
457
-			$this->navigation( $this->tab_slug );
458
-			if ( 'default' !== $this->tab_slug && 'settings' !== $this->tab_slug ) {
459
-				$this->wetu_status();
460
-				$this->post_status_navigation();
461
-			}
462
-			$this->current_importer->display_page();
463
-			?>
457
+               $this->navigation( $this->tab_slug );
458
+               if ( 'default' !== $this->tab_slug && 'settings' !== $this->tab_slug ) {
459
+                    $this->wetu_status();
460
+                    $this->post_status_navigation();
461
+               }
462
+               $this->current_importer->display_page();
463
+               ?>
464 464
 		</div>
465 465
 		<?php
466
-	}
467
-
468
-	/**
469
-	 * Outputs the post status navigation
470
-	 *
471
-	 * @return void
472
-	 */
473
-	public function post_status_navigation() {
474
-		?>
466
+     }
467
+
468
+     /**
469
+      * Outputs the post status navigation
470
+      *
471
+      * @return void
472
+      */
473
+     public function post_status_navigation() {
474
+          ?>
475 475
 		<ul class="subsubsub">
476 476
 			<li class="searchform"><a class="current" href="#search"><?php esc_attr_e( 'Search', 'lsx-wetu-importer' ); ?></a> | </li>
477 477
 			<li class="publish"><a href="#publish"><?php esc_attr_e( 'Published', 'lsx-wetu-importer' ); ?> <span class="count"> (<?php echo esc_attr( lsx_wetu_get_post_count( $this->tab_slug, 'publish ' ) ); ?>)</span></a> | </li>
@@ -486,13 +486,13 @@  discard block
 block discarded – undo
486 486
 		</ul>
487 487
 		<a class="documentation" target="_blank"href="https://tour-operator.lsdev.biz/documentation/extension/wetu-importer/"><?php esc_attr_e( 'Documentation', 'lsx-wetu-importer' ); ?></a>
488 488
 		<?php
489
-	}
489
+     }
490 490
 
491
-	/**
492
-	 * Search Form
493
-	 */
494
-	public function search_form() {
495
-		?>
491
+     /**
492
+      * Search Form
493
+      */
494
+     public function search_form() {
495
+          ?>
496 496
 		<form class="ajax-form" id="<?php echo esc_attr( $this->plugin_slug ); ?>-search-form" method="get" action="tools.php" data-type="<?php echo esc_attr( $this->tab_slug ); ?>">
497 497
 			<input type="hidden" name="page" value="<?php echo esc_attr( $this->tab_slug ); ?>" />
498 498
 
@@ -518,13 +518,13 @@  discard block
 block discarded – undo
518 518
 			<a class="button advanced-search-toggle" href="#"><?php esc_html_e( 'Bulk Search', 'lsx-wetu-importer' ); ?></a>
519 519
 		</form>
520 520
 		<?php
521
-	}
521
+     }
522 522
 
523
-	/**
524
-	 * The header of the item list
525
-	 */
526
-	public function table_header() {
527
-		?>
523
+     /**
524
+      * The header of the item list
525
+      */
526
+     public function table_header() {
527
+          ?>
528 528
 		<thead>
529 529
 		<tr>
530 530
 			<th style="" class="manage-column column-cb check-column no-sort" id="cb" scope="col">
@@ -538,13 +538,13 @@  discard block
 block discarded – undo
538 538
 		</tr>
539 539
 		</thead>
540 540
 		<?php
541
-	}
541
+     }
542 542
 
543
-	/**
544
-	 * The footer of the item list
545
-	 */
546
-	public function table_footer() {
547
-		?>
543
+     /**
544
+      * The footer of the item list
545
+      */
546
+     public function table_footer() {
547
+          ?>
548 548
 		<tfoot>
549 549
 		<tr>
550 550
 			<th style="" class="manage-column column-cb check-column" id="cb" scope="col">
@@ -558,724 +558,724 @@  discard block
 block discarded – undo
558 558
 		</tr>
559 559
 		</tfoot>
560 560
 		<?php
561
-	}
562
-
563
-	/**
564
-	 * Displays the importers navigation.
565
-	 *
566
-	 * @param $tab string
567
-	 */
568
-	public function navigation( $tab = '' ) {
569
-		$post_types = array(
570
-			'tour'          => esc_attr( 'Tours', 'lsx-wetu-importer' ),
571
-			'accommodation' => esc_attr( 'Accommodation', 'lsx-wetu-importer' ),
572
-			'destination'   => esc_attr( 'Destinations', 'lsx-wetu-importer' ),
573
-		);
574
-
575
-		echo wp_kses_post( '<div class="wp-filter">' );
576
-		echo wp_kses_post( '<ul class="filter-links">' );
577
-		echo wp_kses_post( '<li><a class="' . $this->itemd( $tab, 'default', 'current', false ) . '" href="' . admin_url( 'admin.php' ) . '?page=' . $this->plugin_slug . '">' . esc_attr__( 'Home', 'lsx-wetu-importer' ) . '</a></li>' );
578
-
579
-		foreach ( $post_types as $post_type => $label ) {
580
-			echo wp_kses_post( ' | <li><a class="' . $this->itemd( $tab, $post_type, 'current', false ) . '" href="' . admin_url( 'admin.php' ) . '?page=' . $this->plugin_slug . '&tab=' . $post_type . '">' . $label . '</a></li>' );
581
-		}
582
-
583
-		echo wp_kses_post( ' | <li><a class="' . $this->itemd( $tab, 'settings', 'current', false ) . '" href="' . admin_url( 'admin.php' ) . '?page=' . $this->plugin_slug . '&tab=settings">' . esc_attr__( 'Settings', 'lsx-wetu-importer' ) . '</a></li>' );
584
-		echo wp_kses_post( '</ul> </div>' );
585
-	}
586
-
587
-	/**
588
-	 * Wetu Status Bar.
589
-	 */
590
-	public function wetu_status() {
591
-		$tours = get_transient( 'lsx_ti_tours' );
592
-		echo '<div class="wetu-status tour-wetu-status"><h3>' . esc_html__( 'Wetu Status', 'lsx-wetu-importer' ) . ' - ';
593
-
594
-		if ( '' === $tours || false === $tours || isset( $_GET['refresh_tours'] ) ) {
595
-			$result = $this->update_options();
596
-			if ( true === $result ) {
597
-				echo '<span style="color:green;">' . esc_attr( 'Connected', 'lsx-wetu-importer' ) . '</span>';
598
-				echo ' - <small><a href="#">' . esc_attr( 'Refresh', 'lsx-wetu-importer' ) . '</a></small>';
599
-			} else {
600
-				echo '<span style="color:red;">' . wp_kses_post( $result ) . '</span>';
601
-			}
602
-		} else {
603
-			echo '<span style="color:green;">' . esc_attr( 'Connected', 'lsx-wetu-importer' ) . '</span> - <small><a href="#">' . esc_attr( 'Refresh', 'lsx-wetu-importer' ) . '</a></small>';
604
-		}
605
-		echo '</h3>';
606
-		echo '</div>';
607
-	}
608
-
609
-	/**
610
-	 * Set_taxonomy with some terms
611
-	 */
612
-	public function team_member_checkboxes( $selected = array() ) {
613
-		if ( post_type_exists( 'team' ) ) {
614
-			?>
561
+     }
562
+
563
+     /**
564
+      * Displays the importers navigation.
565
+      *
566
+      * @param $tab string
567
+      */
568
+     public function navigation( $tab = '' ) {
569
+          $post_types = array(
570
+               'tour'          => esc_attr( 'Tours', 'lsx-wetu-importer' ),
571
+               'accommodation' => esc_attr( 'Accommodation', 'lsx-wetu-importer' ),
572
+               'destination'   => esc_attr( 'Destinations', 'lsx-wetu-importer' ),
573
+          );
574
+
575
+          echo wp_kses_post( '<div class="wp-filter">' );
576
+          echo wp_kses_post( '<ul class="filter-links">' );
577
+          echo wp_kses_post( '<li><a class="' . $this->itemd( $tab, 'default', 'current', false ) . '" href="' . admin_url( 'admin.php' ) . '?page=' . $this->plugin_slug . '">' . esc_attr__( 'Home', 'lsx-wetu-importer' ) . '</a></li>' );
578
+
579
+          foreach ( $post_types as $post_type => $label ) {
580
+               echo wp_kses_post( ' | <li><a class="' . $this->itemd( $tab, $post_type, 'current', false ) . '" href="' . admin_url( 'admin.php' ) . '?page=' . $this->plugin_slug . '&tab=' . $post_type . '">' . $label . '</a></li>' );
581
+          }
582
+
583
+          echo wp_kses_post( ' | <li><a class="' . $this->itemd( $tab, 'settings', 'current', false ) . '" href="' . admin_url( 'admin.php' ) . '?page=' . $this->plugin_slug . '&tab=settings">' . esc_attr__( 'Settings', 'lsx-wetu-importer' ) . '</a></li>' );
584
+          echo wp_kses_post( '</ul> </div>' );
585
+     }
586
+
587
+     /**
588
+      * Wetu Status Bar.
589
+      */
590
+     public function wetu_status() {
591
+          $tours = get_transient( 'lsx_ti_tours' );
592
+          echo '<div class="wetu-status tour-wetu-status"><h3>' . esc_html__( 'Wetu Status', 'lsx-wetu-importer' ) . ' - ';
593
+
594
+          if ( '' === $tours || false === $tours || isset( $_GET['refresh_tours'] ) ) {
595
+               $result = $this->update_options();
596
+               if ( true === $result ) {
597
+                    echo '<span style="color:green;">' . esc_attr( 'Connected', 'lsx-wetu-importer' ) . '</span>';
598
+                    echo ' - <small><a href="#">' . esc_attr( 'Refresh', 'lsx-wetu-importer' ) . '</a></small>';
599
+               } else {
600
+                    echo '<span style="color:red;">' . wp_kses_post( $result ) . '</span>';
601
+               }
602
+          } else {
603
+               echo '<span style="color:green;">' . esc_attr( 'Connected', 'lsx-wetu-importer' ) . '</span> - <small><a href="#">' . esc_attr( 'Refresh', 'lsx-wetu-importer' ) . '</a></small>';
604
+          }
605
+          echo '</h3>';
606
+          echo '</div>';
607
+     }
608
+
609
+     /**
610
+      * Set_taxonomy with some terms
611
+      */
612
+     public function team_member_checkboxes( $selected = array() ) {
613
+          if ( post_type_exists( 'team' ) ) {
614
+               ?>
615 615
 			<ul>
616 616
 				<?php
617
-					$team_args = array(
618
-						'post_type'   => 'team',
619
-						'post_status' => 'publish',
620
-						'nopagin'     => true,
621
-						'fields'      => 'ids',
622
-					);
623
-
624
-					$team_members = new WP_Query( $team_args );
625
-
626
-					if ( $team_members->have_posts() ) {
627
-						foreach ( $team_members->posts as $member ) {
628
-							?>
617
+                         $team_args = array(
618
+                              'post_type'   => 'team',
619
+                              'post_status' => 'publish',
620
+                              'nopagin'     => true,
621
+                              'fields'      => 'ids',
622
+                         );
623
+
624
+                         $team_members = new WP_Query( $team_args );
625
+
626
+                         if ( $team_members->have_posts() ) {
627
+                              foreach ( $team_members->posts as $member ) {
628
+                                   ?>
629 629
 							<li><input class="team" <?php $this->checked( $selected, $member ); ?> type="checkbox" value="<?php echo esc_attr( $member ); ?>" /> <?php echo wp_kses_post( get_the_title( $member ) ); ?></li>
630 630
 							<?php
631
-						}
632
-					} else {
633
-						?>
631
+                              }
632
+                         } else {
633
+                              ?>
634 634
 						<li><input class="team" type="checkbox" value="0" /> <?php esc_html_e( 'None', 'lsx-wetu-importer' ); ?></li>
635 635
 						<?php
636
-					}
637
-					?>
636
+                         }
637
+                         ?>
638 638
 			</ul>
639 639
 			<?php
640
-		}
641
-	}
642
-
643
-
644
-	// GENERAL FUNCTIONS.
645
-
646
-	/**
647
-	 * Checks to see if an item is checked.
648
-	 *
649
-	 * @param $haystack array|string
650
-	 * @param $needle string
651
-	 * @param $echo bool
652
-	 */
653
-	public function checked( $haystack = false, $needle = '', $echo = true ) {
654
-		$return = $this->itemd( $haystack, $needle, 'checked', false );
655
-
656
-		if ( '' !== $return ) {
657
-			if ( true === $echo ) {
658
-				echo wp_kses_post( $return );
659
-			} else {
660
-				return $return;
661
-			}
662
-		}
663
-	}
664
-
665
-	/**
666
-	 * Checks to see if an item is checked.
667
-	 *
668
-	 * @param $haystack array|string
669
-	 * @param $needle string
670
-	 * @param $echo bool
671
-	 */
672
-	public function selected( $haystack = false, $needle = '', $echo = true ) {
673
-		$return = $this->itemd( $haystack, $needle, 'selected' );
674
-
675
-		if ( '' !== $return ) {
676
-			if ( true === $echo ) {
677
-				echo wp_kses_post( $return );
678
-			} else {
679
-				return $return;
680
-			}
681
-		}
682
-	}
683
-
684
-	/**
685
-	 * Checks to see if an item is selected. If $echo is false,  it will return the $type if conditions are true.
686
-	 *
687
-	 * @param $haystack array|string
688
-	 * @param $needle string
689
-	 * @param $type string
690
-	 * @param $wrap bool
691
-	 * @return $html string
692
-	 */
693
-	public function itemd( $haystack = false, $needle = '', $type = '', $wrap = true ) {
694
-		$html = '';
695
-
696
-		if ( '' !== $type ) {
697
-			if ( ! is_array( $haystack ) ) {
698
-				$haystack = array( $haystack );
699
-			}
700
-			if ( in_array( $needle, $haystack ) ) {
701
-				if ( true === $wrap || 'true' === $wrap ) {
702
-					$html = $type . '="' . $type . '"';
703
-				} else {
704
-					$html = $type;
705
-				}
706
-			}
707
-		}
708
-
709
-		return $html;
710
-	}
711
-
712
-	/**
713
-	 * Grabs any attachments for the current item
714
-	 */
715
-	public function find_attachments( $id = false ) {
716
-		if ( false !== $id ) {
717
-			if ( empty( $this->found_attachments ) ) {
718
-				$attachments_args = array(
719
-					'post_parent'    => $id,
720
-					'post_status'    => 'inherit',
721
-					'post_type'      => 'attachment',
722
-					'order'          => 'ASC',
723
-					'nopagin'        => 'true',
724
-					'posts_per_page' => '-1',
725
-				);
726
-
727
-				$attachments = new WP_Query( $attachments_args );
728
-
729
-				if ( $attachments->have_posts() ) {
730
-					foreach ( $attachments->posts as $attachment ) {
731
-						$this->found_attachments[ $attachment->ID ] = str_replace( array( '.jpg', '.png', '.jpeg' ), '', $attachment->post_title );
732
-					}
733
-				}
734
-			}
735
-		}
736
-	}
737
-
738
-	// CUSTOM FIELD FUNCTIONS.
739
-
740
-	/**
741
-	 * Saves the room data
742
-	 */
743
-	public function save_custom_field( $value = false, $meta_key, $id, $decrease = false, $unique = true ) {
744
-		if ( false !== $value ) {
745
-			if ( false !== $decrease ) {
746
-				$value = intval( $value );
747
-				$value--;
748
-			}
749
-
750
-			$prev = get_post_meta( $id, $meta_key, true );
751
-
752
-			if ( false !== $id && '0' !== $id && false !== $prev && true === $unique ) {
753
-				update_post_meta( $id, $meta_key, $value, $prev );
754
-			} else {
755
-				add_post_meta( $id, $meta_key, $value, $unique );
756
-			}
757
-		}
758
-	}
759
-
760
-	/**
761
-	 * Grabs the custom fields,  and resaves an array of unique items.
762
-	 */
763
-	public function cleanup_posts() {
764
-		if ( ! empty( $this->cleanup_posts ) ) {
765
-
766
-			foreach ( $this->cleanup_posts as $id => $key ) {
767
-				$prev_items = get_post_meta( $id, $key, false );
768
-				$new_items  = array_unique( $prev_items );
769
-				delete_post_meta( $id, $key );
770
-
771
-				foreach ( $new_items as $new_item ) {
772
-					add_post_meta( $id, $key, $new_item, false );
773
-				}
774
-			}
775
-		}
776
-	}
777
-
778
-	// TAXONOMY FUNCTIONS.
779
-
780
-	/**
781
-	 * Set_taxonomy with some terms
782
-	 */
783
-	public function set_taxonomy( $taxonomy, $terms, $id ) {
784
-		$result = array();
785
-
786
-		if ( ! empty( $data ) ) {
787
-			foreach ( $data as $k ) {
788
-				if ( $id ) {
789
-					$term = term_exists( trim( $k ), $tax );
790
-					if ( ! $term ) {
791
-						$term = wp_insert_term( trim( $k ), $tax );
792
-
793
-						if ( is_wp_error( $term ) ) {
794
-							echo wp_kses_post( $term->get_error_message() );
795
-						} else {
796
-							wp_set_object_terms( $id, intval( $term['term_id'] ), $taxonomy, true );
797
-						}
798
-					} else {
799
-						wp_set_object_terms( $id, intval( $term['term_id'] ), $taxonomy, true );
800
-					}
801
-				} else {
802
-					$result[] = trim( $k );
803
-				}
804
-			}
805
-		}
806
-		return $result;
807
-	}
808
-
809
-	/**
810
-	 * Sets the terms of the current post
811
-	 *
812
-	 * @param boolean $id
813
-	 * @param boolean $name
814
-	 * @param boolean $taxonomy
815
-	 * @param boolean $parent
816
-	 * @return void
817
-	 */
818
-	public function set_term( $id = false, $name = false, $taxonomy = false, $parent = false ) {
819
-		$term = term_exists( $name, $taxonomy );
820
-		if ( ! $term ) {
821
-			if ( false !== $parent ) {
822
-				$parent = array(
823
-					'parent' => $parent,
824
-				);
825
-			}
826
-			$term = wp_insert_term( trim( $name ), $taxonomy, $parent );
827
-
828
-			if ( is_wp_error( $term ) ) {
829
-				echo wp_kses_post( $term->get_error_message() );
830
-			} else {
831
-				wp_set_object_terms( $id, intval( $term['term_id'] ), $taxonomy, true );
832
-			}
833
-		} else {
834
-			wp_set_object_terms( $id, intval( $term['term_id'] ), $taxonomy, true );
835
-		}
836
-
837
-		return $term['term_id'];
838
-	}
839
-
840
-	/**
841
-	 * set_taxonomy with some terms
842
-	 */
843
-	public function taxonomy_checkboxes( $taxonomy = false, $selected = array() ) {
844
-		$return = '';
845
-
846
-		if ( false !== $taxonomy ) {
847
-			$return .= '<ul>';
848
-			$terms   = get_terms(
849
-				array(
850
-					'taxonomy'   => $taxonomy,
851
-					'hide_empty' => false,
852
-				)
853
-			);
854
-
855
-			if ( ! is_wp_error( $terms ) ) {
856
-				foreach ( $terms as $term ) {
857
-					$return .= '<li><input class="' . $taxonomy . '" ' . $this->checked( $selected, $term->term_id, false ) . ' type="checkbox" value="' . $term->term_id . '" /> ' . $term->name . '</li>';
858
-				}
859
-			} else {
860
-				$return .= '<li><input type="checkbox" value="" /> ' . __( 'None', 'lsx-wetu-importer' ) . '</li>';
861
-			}
862
-
863
-			$return .= '</ul>';
864
-		}
865
-
866
-		return $return;
867
-	}
868
-
869
-	// MAP FUNCTIONS
870
-
871
-	/**
872
-	 * Saves the longitude and lattitude, as well as sets the map marker.
873
-	 */
874
-	public function set_map_data( $data, $id, $zoom = '10' ) {
875
-		$longitude = false;
876
-		$latitude  = false;
877
-		$address   = false;
878
-
879
-		if ( isset( $data[0]['position'] ) ) {
880
-			if ( isset( $data[0]['position']['driving_latitude'] ) ) {
881
-				$latitude = $data[0]['position']['driving_latitude'];
882
-			} elseif ( isset( $data[0]['position']['latitude'] ) ) {
883
-				$latitude = $data[0]['position']['latitude'];
884
-			}
885
-
886
-			if ( isset( $data[0]['position']['driving_longitude'] ) ) {
887
-				$longitude = $data[0]['position']['driving_longitude'];
888
-			} elseif ( isset( $data[0]['position']['longitude'] ) ) {
889
-				$longitude = $data[0]['position']['longitude'];
890
-			}
891
-		}
892
-
893
-		if ( isset( $data[0]['content'] ) && isset( $data[0]['content']['contact_information'] ) ) {
894
-			if ( isset( $data[0]['content']['contact_information']['address'] ) ) {
895
-				$address = strip_tags( $data[0]['content']['contact_information']['address'] );
896
-				$address = explode( "\n", $address );
897
-
898
-				foreach ( $address as $bitkey => $bit ) {
899
-					$bit = ltrim( rtrim( $bit ) );
900
-
901
-					if ( false === $bit || '' === $bit || null === $bit || empty( $bit ) ) {
902
-						unset( $address[ $bitkey ] );
903
-					}
904
-				}
905
-
906
-				$address = implode( ', ', $address );
907
-				$address = str_replace( ', , ', ', ', $address );
908
-			}
909
-		}
910
-
911
-		if ( false !== $longitude ) {
912
-			$location_data = array(
913
-				'address'   => (string) $address,
914
-				'lat'       => (string) $latitude,
915
-				'long'      => (string) $longitude,
916
-				'zoom'      => (string) $zoom,
917
-				'elevation' => '',
918
-			);
919
-
920
-			if ( false !== $id && '0' !== $id ) {
921
-				$prev = get_post_meta( $id, 'location', true );
922
-				update_post_meta( $id, 'location', $location_data, $prev );
923
-			} else {
924
-				add_post_meta( $id, 'location', $location_data, true );
925
-			}
926
-		}
927
-	}
928
-
929
-	// IMAGE FUNCTIONS
930
-
931
-	/**
932
-	 * Creates the main gallery data
933
-	 */
934
-	public function set_featured_image( $data, $id ) {
935
-		if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) {
936
-			$this->featured_image = $this->attach_image(
937
-				$data[0]['content']['images'][0],
938
-				$id,
939
-				array(
940
-					'width'    => '800',
941
-					'height'   => '600',
942
-					'cropping' => 'h',
943
-				)
944
-			);
945
-
946
-			if ( false !== $this->featured_image ) {
947
-				delete_post_meta( $id, '_thumbnail_id' );
948
-				add_post_meta( $id, '_thumbnail_id', $this->featured_image, true );
949
-			}
950
-		}
951
-	}
952
-
953
-	/**
954
-	 * Sets a banner image
955
-	 */
956
-	public function set_banner_image( $data, $id, $content = array( 'none' ) ) {
957
-		if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) {
958
-			if ( in_array( 'unique_banner_image', $content ) && isset( $data[0]['destination_image'] ) && is_array( $data[0]['destination_image'] ) ) {
959
-				$temp_banner = $this->attach_image(
960
-					$data[0]['destination_image'],
961
-					$id,
962
-					array(
963
-						'width'    => '1920',
964
-						'height'   => '600',
965
-						'cropping' => 'c',
966
-					)
967
-				);
968
-			} else {
969
-				$temp_banner = $this->attach_image(
970
-					$data[0]['content']['images'][1],
971
-					$id,
972
-					array(
973
-						'width'    => '1920',
974
-						'height'   => '600',
975
-						'cropping' => 'c',
976
-					)
977
-				);
978
-			}
979
-
980
-			if ( false !== $temp_banner ) {
981
-				$this->banner_image = $temp_banner;
982
-
983
-				delete_post_meta( $id, 'image_group' );
984
-
985
-				$new_banner = array(
986
-					'banner_image' => array(
987
-						'cmb-field-0' => $this->banner_image,
988
-					),
989
-				);
990
-
991
-				add_post_meta( $id, 'image_group', $new_banner, true );
992
-			}
993
-		}
994
-	}
995
-
996
-	/**
997
-	 * Checks if the current image is being used as a thumbnail somewhere else.
998
-	 */
999
-	public function is_image_being_used( $image_id = '', $post_id = '' ) {
1000
-		global $wpdb;
1001
-		$being_used = false;
1002
-		if ( '' !== $image_id ) {
1003
-			$sql     = "SELECT * FROM `{$wpdb->postmeta}` WHERE `post_id` != {$post_id} AND `meta_key` LIKE '_thumbnail_id' AND `meta_value` LIKE '{$image_id}'";
1004
-			$results = $wpdb->query( $sql );
1005
-			if ( false !== $results && ! empty( $results ) ) {
1006
-				$being_used = true;
1007
-			}
1008
-		}
1009
-		return $being_used;
1010
-	}
1011
-
1012
-	/**
1013
-	 * Creates the main gallery data
1014
-	 */
1015
-	public function create_main_gallery( $data, $id ) {
1016
-		if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) {
1017
-			if ( isset( $this->options['image_replacing'] ) && 'on' === $this->options['image_replacing'] ) {
1018
-				$current_gallery = get_post_meta( $id, 'gallery', false );
1019
-
1020
-				if ( false !== $current_gallery && ! empty( $current_gallery ) ) {
1021
-					foreach ( $current_gallery as $g ) {
1022
-						delete_post_meta( $id, 'gallery', $g );
1023
-
1024
-						if ( 'attachment' === get_post_type( $g ) && false === $this->is_image_being_used( $g, $id ) ) {
1025
-							wp_delete_attachment( $g, true );
1026
-						}
1027
-					}
1028
-				}
1029
-			}
1030
-
1031
-			$counter = 0;
1032
-
1033
-			foreach ( $data[0]['content']['images'] as $image_data ) {
1034
-				if ( ( 0 === $counter && false !== $this->featured_image ) || ( 1 === $counter && false !== $this->banner_image ) ) {
1035
-					$counter++;
1036
-
1037
-					if ( false !== $this->image_limit && false !== $this->image_limit ) {
1038
-						$this->image_limit++;
1039
-					}
1040
-
1041
-					continue;
1042
-				}
1043
-
1044
-				if ( false !== $this->image_limit && $counter >= $this->image_limit ) {
1045
-					continue;
1046
-				}
1047
-
1048
-				$this->gallery_meta[] = $this->attach_image( $image_data, $id );
1049
-				$counter++;
1050
-			}
1051
-
1052
-			if ( ! empty( $this->gallery_meta ) ) {
1053
-				delete_post_meta( $id, 'gallery' );
1054
-				$this->gallery_meta = array_unique( $this->gallery_meta );
1055
-
1056
-				foreach ( $this->gallery_meta as $gallery_id ) {
1057
-					if ( false !== $gallery_id && '' !== $gallery_id && ! is_array( $gallery_id ) ) {
1058
-						add_post_meta( $id, 'gallery', $gallery_id, false );
1059
-					}
1060
-				}
1061
-			}
1062
-		}
1063
-	}
1064
-
1065
-	/**
1066
-	 * search_form
1067
-	 */
1068
-	public function get_scaling_url( $args = array() ) {
1069
-		$defaults = array(
1070
-			'width'    => '1024',
1071
-			'height'   => '768',
1072
-			// 'cropping' => 'w',
1073
-			'cropping' => 'h',
1074
-		);
1075
-
1076
-		if ( false !== $this->options ) {
1077
-			if ( isset( $this->options['width'] ) && '' !== $this->options['width'] ) {
1078
-				$defaults['width'] = $this->options['width'];
1079
-			}
1080
-
1081
-			if ( isset( $this->options['height'] ) && '' !== $this->options['height'] ) {
1082
-				$defaults['height'] = $this->options['height'];
1083
-			}
1084
-
1085
-			if ( isset( $this->options['cropping'] ) && '' !== $this->options['cropping'] ) {
1086
-				$defaults['cropping'] = $this->options['cropping'];
1087
-			}
1088
-		}
1089
-
1090
-		$args     = wp_parse_args( $args, $defaults );
1091
-		$cropping = $args['cropping'];
1092
-		$width    = $args['width'];
1093
-		$height   = $args['height'];
1094
-
1095
-		return 'https://wetu.com/ImageHandler/' . $cropping . $width . 'x' . $height . '/';
1096
-	}
1097
-
1098
-	/**
1099
-	 * Attaches 1 image
1100
-	 */
1101
-	public function attach_image( $v = false, $parent_id, $image_sizes = false, $banner = false ) {
1102
-		if ( false !== $v ) {
1103
-			$temp_fragment = explode( '/', $v['url_fragment'] );
1104
-			$url_filename  = $temp_fragment[ count( $temp_fragment ) - 1 ];
1105
-			$url_filename  = str_replace( array( '.jpg', '.png', '.jpeg' ), '', $url_filename );
1106
-			$url_filename  = trim( $url_filename );
1107
-			$title         = $url_filename;
1108
-			$url_filename  = str_replace( ' ', '_', $url_filename );
1109
-
1110
-			if ( ! isset( $this->options['image_replacing'] ) && in_array( $url_filename, $this->found_attachments ) ) {
1111
-				return array_search( $url_filename, $this->found_attachments );
1112
-			}
1113
-
1114
-			$postdata = array();
1115
-
1116
-			if ( empty( $v['label'] ) ) {
1117
-				$v['label'] = '';
1118
-			}
1119
-
1120
-			if ( ! empty( $v['description'] ) ) {
1121
-				$desc    = wp_strip_all_tags( $v['description'] );
1122
-				$posdata = array(
1123
-					'post_excerpt' => $desc,
1124
-				);
1125
-			}
1126
-
1127
-			if ( ! empty( $v['section'] ) ) {
1128
-				$desc    = wp_strip_all_tags( $v['section'] );
1129
-				$posdata = array(
1130
-					'post_excerpt' => $desc,
1131
-				);
1132
-			}
1133
-
1134
-			$attach_id = null;
1135
-			// Resizor - add option to setting if required.
1136
-			$fragment  = str_replace( ' ', '%20', $v['url_fragment'] );
1137
-			$url       = $this->get_scaling_url( $image_sizes ) . $fragment;
1138
-			$attach_id = $this->attach_external_image2( $url, $parent_id, '', $v['label'], $postdata );
1139
-			if ( ! empty( $attach_id ) ) {
1140
-				$this->found_attachments[ $attach_id ] = $url_filename;
1141
-				add_post_meta( $attach_id, 'lsx_wetu_id', $v['url_fragment'], true );
1142
-				return $attach_id;
1143
-			}
1144
-		}
1145
-		return false;
1146
-	}
1147
-
1148
-	public function attach_external_image2( $url = null, $post_id = null, $thumb = null, $filename = null, $post_data = array() ) {
1149
-		if ( ! $url || ! $post_id ) {
1150
-			return new WP_Error( 'missing', 'Need a valid URL and post ID...' ); }
1151
-		$att_id = false;
1152
-
1153
-		require_once ABSPATH . 'wp-admin/includes/file.php';
1154
-		require_once ABSPATH . 'wp-admin/includes/media.php';
1155
-		require_once ABSPATH . 'wp-admin/includes/image.php';
1156
-		// Download file to temp location, returns full server path to temp file.
1157
-
1158
-		$tmp   = tempnam( '/tmp', 'FOO' );
1159
-		$image = wp_remote_get( $url );
1160
-		if ( ! is_wp_error( $image ) && ! empty( $image ) && isset( $image['response'] ) && isset( $image['response']['code'] ) && 200 === $image['response']['code'] ) {
1161
-			file_put_contents( $tmp, $image['body'] );
1162
-			chmod( $tmp, '777' );
1163
-
1164
-			preg_match( '/[^\?]+\.(tif|TIFF|jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG|pdf|PDF|bmp|BMP)/', $url, $matches );    // fix file filename for query strings
1165
-			$url_filename = basename( $matches[0] );
1166
-			$url_filename = str_replace( '%20', '_', $url_filename );
1167
-			// extract filename from url for title
1168
-			$url_type = wp_check_filetype( $url_filename );                                           // determine file type (ext and mime/type)
1169
-
1170
-			// override filename if given, reconstruct server path.
1171
-			if ( ! empty( $filename ) && ' ' != $filename ) {
1172
-				$filename = sanitize_file_name( $filename );
1173
-				$tmppath  = pathinfo( $tmp );
1174
-
1175
-				$extension = '';
1176
-				if ( isset( $tmppath['extension'] ) ) {
1177
-					$extension = $tmppath['extension'];
1178
-				}
1179
-
1180
-				$new = $tmppath['dirname'] . '/' . $filename . '.' . $extension;
1181
-				rename( $tmp, $new );                                                                 // renames temp file on server
1182
-				$tmp = $new;                                                                        // push new filename (in path) to be used in file array later
1183
-			}
1184
-
1185
-			// assemble file data (should be built like $_FILES since wp_handle_sideload() will be using).
1186
-			$file_array['tmp_name'] = $tmp;                                                         // full server path to temp file
1187
-
1188
-			if ( ! empty( $filename ) && ' ' != $filename ) {
1189
-				$file_array['name'] = $filename . '.' . $url_type['ext'];                           // user given filename for title, add original URL extension
1190
-			} else {
1191
-				$file_array['name'] = $url_filename;                                                // just use original URL filename
1192
-			}
1193
-
1194
-			// set additional wp_posts columns.
1195
-			if ( empty( $post_data['post_title'] ) ) {
1196
-
1197
-				$url_filename = str_replace( '%20', ' ', $url_filename );
1198
-
1199
-				$post_data['post_title'] = basename( $url_filename, '.' . $url_type['ext'] );         // just use the original filename (no extension)
1200
-			}
1201
-
1202
-			// make sure gets tied to parent.
1203
-			if ( empty( $post_data['post_parent'] ) ) {
1204
-				$post_data['post_parent'] = $post_id;
1205
-			}
1206
-
1207
-			// do the validation and storage stuff.
1208
-			$att_id = media_handle_sideload( $file_array, $post_id, null, $post_data );             // $post_data can override the items saved to wp_posts table, like post_mime_type, guid, post_parent, post_title, post_content, post_status
1209
-
1210
-			// If error storing permanently, unlink.
1211
-			if ( is_wp_error( $att_id ) ) {
1212
-				unlink( $file_array['tmp_name'] );
1213
-				return false;
1214
-			}
1215
-		}
1216
-		return $att_id;
1217
-	}
1218
-
1219
-	// AJAX FUNCTIONS
1220
-	/**
1221
-	 * Run through the accommodation grabbed from the DB.
1222
-	 */
1223
-	public function process_ajax_search() {
1224
-		$this->current_importer->process_ajax_search();
1225
-		die();
1226
-	}
1227
-
1228
-	/**
1229
-	 * Connect to wetu
1230
-	 */
1231
-	public function process_ajax_import() {
1232
-		$this->current_importer->process_ajax_import();
1233
-		die();
1234
-	}
1235
-
1236
-	/**
1237
-	 * Formats the row for the completed list.
1238
-	 */
1239
-	public function format_completed_row( $response ) {
1240
-		echo wp_kses_post( '<li class="post-' . $response . '"><span class="dashicons dashicons-yes"></span> <a target="_blank" href="' . get_permalink( $response ) . '">' . get_the_title( $response ) . '</a></li>' );
1241
-	}
1242
-
1243
-	/**
1244
-	 * Formats the error.
1245
-	 */
1246
-	public function format_error( $response ) {
1247
-		echo wp_kses_post( '<li class="post-error"><span class="dashicons dashicons-no"></span>' . $response . '</li>' );
1248
-	}
1249
-
1250
-	/**
1251
-	 * Does a multine search
1252
-	 */
1253
-	public function multineedle_stripos( $haystack, $needles, $offset = 0 ) {
1254
-		$found        = false;
1255
-		$needle_count = count( $needles );
1256
-
1257
-		foreach ( $needles as $needle ) {
1258
-			if ( false !== stripos( $haystack, $needle, $offset ) ) {
1259
-				$found[] = true;
1260
-			}
1261
-		}
1262
-
1263
-		if ( false !== $found && count( $found ) === $needle_count ) {
1264
-			return true;
1265
-		} else {
1266
-			return false;
1267
-		}
1268
-	}
1269
-
1270
-	/**
1271
-	 * Grab all the current accommodation posts via the lsx_wetu_id field.
1272
-	 */
1273
-	public function find_current_accommodation( $post_type = 'accommodation' ) {
1274
-		global $wpdb;
1275
-		$return = array();
1276
-
1277
-		// @codingStandardsIgnoreStart
1278
-		$current_accommodation = $wpdb->get_results("
640
+          }
641
+     }
642
+
643
+
644
+     // GENERAL FUNCTIONS.
645
+
646
+     /**
647
+      * Checks to see if an item is checked.
648
+      *
649
+      * @param $haystack array|string
650
+      * @param $needle string
651
+      * @param $echo bool
652
+      */
653
+     public function checked( $haystack = false, $needle = '', $echo = true ) {
654
+          $return = $this->itemd( $haystack, $needle, 'checked', false );
655
+
656
+          if ( '' !== $return ) {
657
+               if ( true === $echo ) {
658
+                    echo wp_kses_post( $return );
659
+               } else {
660
+                    return $return;
661
+               }
662
+          }
663
+     }
664
+
665
+     /**
666
+      * Checks to see if an item is checked.
667
+      *
668
+      * @param $haystack array|string
669
+      * @param $needle string
670
+      * @param $echo bool
671
+      */
672
+     public function selected( $haystack = false, $needle = '', $echo = true ) {
673
+          $return = $this->itemd( $haystack, $needle, 'selected' );
674
+
675
+          if ( '' !== $return ) {
676
+               if ( true === $echo ) {
677
+                    echo wp_kses_post( $return );
678
+               } else {
679
+                    return $return;
680
+               }
681
+          }
682
+     }
683
+
684
+     /**
685
+      * Checks to see if an item is selected. If $echo is false,  it will return the $type if conditions are true.
686
+      *
687
+      * @param $haystack array|string
688
+      * @param $needle string
689
+      * @param $type string
690
+      * @param $wrap bool
691
+      * @return $html string
692
+      */
693
+     public function itemd( $haystack = false, $needle = '', $type = '', $wrap = true ) {
694
+          $html = '';
695
+
696
+          if ( '' !== $type ) {
697
+               if ( ! is_array( $haystack ) ) {
698
+                    $haystack = array( $haystack );
699
+               }
700
+               if ( in_array( $needle, $haystack ) ) {
701
+                    if ( true === $wrap || 'true' === $wrap ) {
702
+                         $html = $type . '="' . $type . '"';
703
+                    } else {
704
+                         $html = $type;
705
+                    }
706
+               }
707
+          }
708
+
709
+          return $html;
710
+     }
711
+
712
+     /**
713
+      * Grabs any attachments for the current item
714
+      */
715
+     public function find_attachments( $id = false ) {
716
+          if ( false !== $id ) {
717
+               if ( empty( $this->found_attachments ) ) {
718
+                    $attachments_args = array(
719
+                         'post_parent'    => $id,
720
+                         'post_status'    => 'inherit',
721
+                         'post_type'      => 'attachment',
722
+                         'order'          => 'ASC',
723
+                         'nopagin'        => 'true',
724
+                         'posts_per_page' => '-1',
725
+                    );
726
+
727
+                    $attachments = new WP_Query( $attachments_args );
728
+
729
+                    if ( $attachments->have_posts() ) {
730
+                         foreach ( $attachments->posts as $attachment ) {
731
+                              $this->found_attachments[ $attachment->ID ] = str_replace( array( '.jpg', '.png', '.jpeg' ), '', $attachment->post_title );
732
+                         }
733
+                    }
734
+               }
735
+          }
736
+     }
737
+
738
+     // CUSTOM FIELD FUNCTIONS.
739
+
740
+     /**
741
+      * Saves the room data
742
+      */
743
+     public function save_custom_field( $value = false, $meta_key, $id, $decrease = false, $unique = true ) {
744
+          if ( false !== $value ) {
745
+               if ( false !== $decrease ) {
746
+                    $value = intval( $value );
747
+                    $value--;
748
+               }
749
+
750
+               $prev = get_post_meta( $id, $meta_key, true );
751
+
752
+               if ( false !== $id && '0' !== $id && false !== $prev && true === $unique ) {
753
+                    update_post_meta( $id, $meta_key, $value, $prev );
754
+               } else {
755
+                    add_post_meta( $id, $meta_key, $value, $unique );
756
+               }
757
+          }
758
+     }
759
+
760
+     /**
761
+      * Grabs the custom fields,  and resaves an array of unique items.
762
+      */
763
+     public function cleanup_posts() {
764
+          if ( ! empty( $this->cleanup_posts ) ) {
765
+
766
+               foreach ( $this->cleanup_posts as $id => $key ) {
767
+                    $prev_items = get_post_meta( $id, $key, false );
768
+                    $new_items  = array_unique( $prev_items );
769
+                    delete_post_meta( $id, $key );
770
+
771
+                    foreach ( $new_items as $new_item ) {
772
+                         add_post_meta( $id, $key, $new_item, false );
773
+                    }
774
+               }
775
+          }
776
+     }
777
+
778
+     // TAXONOMY FUNCTIONS.
779
+
780
+     /**
781
+      * Set_taxonomy with some terms
782
+      */
783
+     public function set_taxonomy( $taxonomy, $terms, $id ) {
784
+          $result = array();
785
+
786
+          if ( ! empty( $data ) ) {
787
+               foreach ( $data as $k ) {
788
+                    if ( $id ) {
789
+                         $term = term_exists( trim( $k ), $tax );
790
+                         if ( ! $term ) {
791
+                              $term = wp_insert_term( trim( $k ), $tax );
792
+
793
+                              if ( is_wp_error( $term ) ) {
794
+                                   echo wp_kses_post( $term->get_error_message() );
795
+                              } else {
796
+                                   wp_set_object_terms( $id, intval( $term['term_id'] ), $taxonomy, true );
797
+                              }
798
+                         } else {
799
+                              wp_set_object_terms( $id, intval( $term['term_id'] ), $taxonomy, true );
800
+                         }
801
+                    } else {
802
+                         $result[] = trim( $k );
803
+                    }
804
+               }
805
+          }
806
+          return $result;
807
+     }
808
+
809
+     /**
810
+      * Sets the terms of the current post
811
+      *
812
+      * @param boolean $id
813
+      * @param boolean $name
814
+      * @param boolean $taxonomy
815
+      * @param boolean $parent
816
+      * @return void
817
+      */
818
+     public function set_term( $id = false, $name = false, $taxonomy = false, $parent = false ) {
819
+          $term = term_exists( $name, $taxonomy );
820
+          if ( ! $term ) {
821
+               if ( false !== $parent ) {
822
+                    $parent = array(
823
+                         'parent' => $parent,
824
+                    );
825
+               }
826
+               $term = wp_insert_term( trim( $name ), $taxonomy, $parent );
827
+
828
+               if ( is_wp_error( $term ) ) {
829
+                    echo wp_kses_post( $term->get_error_message() );
830
+               } else {
831
+                    wp_set_object_terms( $id, intval( $term['term_id'] ), $taxonomy, true );
832
+               }
833
+          } else {
834
+               wp_set_object_terms( $id, intval( $term['term_id'] ), $taxonomy, true );
835
+          }
836
+
837
+          return $term['term_id'];
838
+     }
839
+
840
+     /**
841
+      * set_taxonomy with some terms
842
+      */
843
+     public function taxonomy_checkboxes( $taxonomy = false, $selected = array() ) {
844
+          $return = '';
845
+
846
+          if ( false !== $taxonomy ) {
847
+               $return .= '<ul>';
848
+               $terms   = get_terms(
849
+                    array(
850
+                         'taxonomy'   => $taxonomy,
851
+                         'hide_empty' => false,
852
+                    )
853
+               );
854
+
855
+               if ( ! is_wp_error( $terms ) ) {
856
+                    foreach ( $terms as $term ) {
857
+                         $return .= '<li><input class="' . $taxonomy . '" ' . $this->checked( $selected, $term->term_id, false ) . ' type="checkbox" value="' . $term->term_id . '" /> ' . $term->name . '</li>';
858
+                    }
859
+               } else {
860
+                    $return .= '<li><input type="checkbox" value="" /> ' . __( 'None', 'lsx-wetu-importer' ) . '</li>';
861
+               }
862
+
863
+               $return .= '</ul>';
864
+          }
865
+
866
+          return $return;
867
+     }
868
+
869
+     // MAP FUNCTIONS
870
+
871
+     /**
872
+      * Saves the longitude and lattitude, as well as sets the map marker.
873
+      */
874
+     public function set_map_data( $data, $id, $zoom = '10' ) {
875
+          $longitude = false;
876
+          $latitude  = false;
877
+          $address   = false;
878
+
879
+          if ( isset( $data[0]['position'] ) ) {
880
+               if ( isset( $data[0]['position']['driving_latitude'] ) ) {
881
+                    $latitude = $data[0]['position']['driving_latitude'];
882
+               } elseif ( isset( $data[0]['position']['latitude'] ) ) {
883
+                    $latitude = $data[0]['position']['latitude'];
884
+               }
885
+
886
+               if ( isset( $data[0]['position']['driving_longitude'] ) ) {
887
+                    $longitude = $data[0]['position']['driving_longitude'];
888
+               } elseif ( isset( $data[0]['position']['longitude'] ) ) {
889
+                    $longitude = $data[0]['position']['longitude'];
890
+               }
891
+          }
892
+
893
+          if ( isset( $data[0]['content'] ) && isset( $data[0]['content']['contact_information'] ) ) {
894
+               if ( isset( $data[0]['content']['contact_information']['address'] ) ) {
895
+                    $address = strip_tags( $data[0]['content']['contact_information']['address'] );
896
+                    $address = explode( "\n", $address );
897
+
898
+                    foreach ( $address as $bitkey => $bit ) {
899
+                         $bit = ltrim( rtrim( $bit ) );
900
+
901
+                         if ( false === $bit || '' === $bit || null === $bit || empty( $bit ) ) {
902
+                              unset( $address[ $bitkey ] );
903
+                         }
904
+                    }
905
+
906
+                    $address = implode( ', ', $address );
907
+                    $address = str_replace( ', , ', ', ', $address );
908
+               }
909
+          }
910
+
911
+          if ( false !== $longitude ) {
912
+               $location_data = array(
913
+                    'address'   => (string) $address,
914
+                    'lat'       => (string) $latitude,
915
+                    'long'      => (string) $longitude,
916
+                    'zoom'      => (string) $zoom,
917
+                    'elevation' => '',
918
+               );
919
+
920
+               if ( false !== $id && '0' !== $id ) {
921
+                    $prev = get_post_meta( $id, 'location', true );
922
+                    update_post_meta( $id, 'location', $location_data, $prev );
923
+               } else {
924
+                    add_post_meta( $id, 'location', $location_data, true );
925
+               }
926
+          }
927
+     }
928
+
929
+     // IMAGE FUNCTIONS
930
+
931
+     /**
932
+      * Creates the main gallery data
933
+      */
934
+     public function set_featured_image( $data, $id ) {
935
+          if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) {
936
+               $this->featured_image = $this->attach_image(
937
+                    $data[0]['content']['images'][0],
938
+                    $id,
939
+                    array(
940
+                         'width'    => '800',
941
+                         'height'   => '600',
942
+                         'cropping' => 'h',
943
+                    )
944
+               );
945
+
946
+               if ( false !== $this->featured_image ) {
947
+                    delete_post_meta( $id, '_thumbnail_id' );
948
+                    add_post_meta( $id, '_thumbnail_id', $this->featured_image, true );
949
+               }
950
+          }
951
+     }
952
+
953
+     /**
954
+      * Sets a banner image
955
+      */
956
+     public function set_banner_image( $data, $id, $content = array( 'none' ) ) {
957
+          if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) {
958
+               if ( in_array( 'unique_banner_image', $content ) && isset( $data[0]['destination_image'] ) && is_array( $data[0]['destination_image'] ) ) {
959
+                    $temp_banner = $this->attach_image(
960
+                         $data[0]['destination_image'],
961
+                         $id,
962
+                         array(
963
+                              'width'    => '1920',
964
+                              'height'   => '600',
965
+                              'cropping' => 'c',
966
+                         )
967
+                    );
968
+               } else {
969
+                    $temp_banner = $this->attach_image(
970
+                         $data[0]['content']['images'][1],
971
+                         $id,
972
+                         array(
973
+                              'width'    => '1920',
974
+                              'height'   => '600',
975
+                              'cropping' => 'c',
976
+                         )
977
+                    );
978
+               }
979
+
980
+               if ( false !== $temp_banner ) {
981
+                    $this->banner_image = $temp_banner;
982
+
983
+                    delete_post_meta( $id, 'image_group' );
984
+
985
+                    $new_banner = array(
986
+                         'banner_image' => array(
987
+                              'cmb-field-0' => $this->banner_image,
988
+                         ),
989
+                    );
990
+
991
+                    add_post_meta( $id, 'image_group', $new_banner, true );
992
+               }
993
+          }
994
+     }
995
+
996
+     /**
997
+      * Checks if the current image is being used as a thumbnail somewhere else.
998
+      */
999
+     public function is_image_being_used( $image_id = '', $post_id = '' ) {
1000
+          global $wpdb;
1001
+          $being_used = false;
1002
+          if ( '' !== $image_id ) {
1003
+               $sql     = "SELECT * FROM `{$wpdb->postmeta}` WHERE `post_id` != {$post_id} AND `meta_key` LIKE '_thumbnail_id' AND `meta_value` LIKE '{$image_id}'";
1004
+               $results = $wpdb->query( $sql );
1005
+               if ( false !== $results && ! empty( $results ) ) {
1006
+                    $being_used = true;
1007
+               }
1008
+          }
1009
+          return $being_used;
1010
+     }
1011
+
1012
+     /**
1013
+      * Creates the main gallery data
1014
+      */
1015
+     public function create_main_gallery( $data, $id ) {
1016
+          if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) {
1017
+               if ( isset( $this->options['image_replacing'] ) && 'on' === $this->options['image_replacing'] ) {
1018
+                    $current_gallery = get_post_meta( $id, 'gallery', false );
1019
+
1020
+                    if ( false !== $current_gallery && ! empty( $current_gallery ) ) {
1021
+                         foreach ( $current_gallery as $g ) {
1022
+                              delete_post_meta( $id, 'gallery', $g );
1023
+
1024
+                              if ( 'attachment' === get_post_type( $g ) && false === $this->is_image_being_used( $g, $id ) ) {
1025
+                                   wp_delete_attachment( $g, true );
1026
+                              }
1027
+                         }
1028
+                    }
1029
+               }
1030
+
1031
+               $counter = 0;
1032
+
1033
+               foreach ( $data[0]['content']['images'] as $image_data ) {
1034
+                    if ( ( 0 === $counter && false !== $this->featured_image ) || ( 1 === $counter && false !== $this->banner_image ) ) {
1035
+                         $counter++;
1036
+
1037
+                         if ( false !== $this->image_limit && false !== $this->image_limit ) {
1038
+                              $this->image_limit++;
1039
+                         }
1040
+
1041
+                         continue;
1042
+                    }
1043
+
1044
+                    if ( false !== $this->image_limit && $counter >= $this->image_limit ) {
1045
+                         continue;
1046
+                    }
1047
+
1048
+                    $this->gallery_meta[] = $this->attach_image( $image_data, $id );
1049
+                    $counter++;
1050
+               }
1051
+
1052
+               if ( ! empty( $this->gallery_meta ) ) {
1053
+                    delete_post_meta( $id, 'gallery' );
1054
+                    $this->gallery_meta = array_unique( $this->gallery_meta );
1055
+
1056
+                    foreach ( $this->gallery_meta as $gallery_id ) {
1057
+                         if ( false !== $gallery_id && '' !== $gallery_id && ! is_array( $gallery_id ) ) {
1058
+                              add_post_meta( $id, 'gallery', $gallery_id, false );
1059
+                         }
1060
+                    }
1061
+               }
1062
+          }
1063
+     }
1064
+
1065
+     /**
1066
+      * search_form
1067
+      */
1068
+     public function get_scaling_url( $args = array() ) {
1069
+          $defaults = array(
1070
+               'width'    => '1024',
1071
+               'height'   => '768',
1072
+               // 'cropping' => 'w',
1073
+               'cropping' => 'h',
1074
+          );
1075
+
1076
+          if ( false !== $this->options ) {
1077
+               if ( isset( $this->options['width'] ) && '' !== $this->options['width'] ) {
1078
+                    $defaults['width'] = $this->options['width'];
1079
+               }
1080
+
1081
+               if ( isset( $this->options['height'] ) && '' !== $this->options['height'] ) {
1082
+                    $defaults['height'] = $this->options['height'];
1083
+               }
1084
+
1085
+               if ( isset( $this->options['cropping'] ) && '' !== $this->options['cropping'] ) {
1086
+                    $defaults['cropping'] = $this->options['cropping'];
1087
+               }
1088
+          }
1089
+
1090
+          $args     = wp_parse_args( $args, $defaults );
1091
+          $cropping = $args['cropping'];
1092
+          $width    = $args['width'];
1093
+          $height   = $args['height'];
1094
+
1095
+          return 'https://wetu.com/ImageHandler/' . $cropping . $width . 'x' . $height . '/';
1096
+     }
1097
+
1098
+     /**
1099
+      * Attaches 1 image
1100
+      */
1101
+     public function attach_image( $v = false, $parent_id, $image_sizes = false, $banner = false ) {
1102
+          if ( false !== $v ) {
1103
+               $temp_fragment = explode( '/', $v['url_fragment'] );
1104
+               $url_filename  = $temp_fragment[ count( $temp_fragment ) - 1 ];
1105
+               $url_filename  = str_replace( array( '.jpg', '.png', '.jpeg' ), '', $url_filename );
1106
+               $url_filename  = trim( $url_filename );
1107
+               $title         = $url_filename;
1108
+               $url_filename  = str_replace( ' ', '_', $url_filename );
1109
+
1110
+               if ( ! isset( $this->options['image_replacing'] ) && in_array( $url_filename, $this->found_attachments ) ) {
1111
+                    return array_search( $url_filename, $this->found_attachments );
1112
+               }
1113
+
1114
+               $postdata = array();
1115
+
1116
+               if ( empty( $v['label'] ) ) {
1117
+                    $v['label'] = '';
1118
+               }
1119
+
1120
+               if ( ! empty( $v['description'] ) ) {
1121
+                    $desc    = wp_strip_all_tags( $v['description'] );
1122
+                    $posdata = array(
1123
+                         'post_excerpt' => $desc,
1124
+                    );
1125
+               }
1126
+
1127
+               if ( ! empty( $v['section'] ) ) {
1128
+                    $desc    = wp_strip_all_tags( $v['section'] );
1129
+                    $posdata = array(
1130
+                         'post_excerpt' => $desc,
1131
+                    );
1132
+               }
1133
+
1134
+               $attach_id = null;
1135
+               // Resizor - add option to setting if required.
1136
+               $fragment  = str_replace( ' ', '%20', $v['url_fragment'] );
1137
+               $url       = $this->get_scaling_url( $image_sizes ) . $fragment;
1138
+               $attach_id = $this->attach_external_image2( $url, $parent_id, '', $v['label'], $postdata );
1139
+               if ( ! empty( $attach_id ) ) {
1140
+                    $this->found_attachments[ $attach_id ] = $url_filename;
1141
+                    add_post_meta( $attach_id, 'lsx_wetu_id', $v['url_fragment'], true );
1142
+                    return $attach_id;
1143
+               }
1144
+          }
1145
+          return false;
1146
+     }
1147
+
1148
+     public function attach_external_image2( $url = null, $post_id = null, $thumb = null, $filename = null, $post_data = array() ) {
1149
+          if ( ! $url || ! $post_id ) {
1150
+               return new WP_Error( 'missing', 'Need a valid URL and post ID...' ); }
1151
+          $att_id = false;
1152
+
1153
+          require_once ABSPATH . 'wp-admin/includes/file.php';
1154
+          require_once ABSPATH . 'wp-admin/includes/media.php';
1155
+          require_once ABSPATH . 'wp-admin/includes/image.php';
1156
+          // Download file to temp location, returns full server path to temp file.
1157
+
1158
+          $tmp   = tempnam( '/tmp', 'FOO' );
1159
+          $image = wp_remote_get( $url );
1160
+          if ( ! is_wp_error( $image ) && ! empty( $image ) && isset( $image['response'] ) && isset( $image['response']['code'] ) && 200 === $image['response']['code'] ) {
1161
+               file_put_contents( $tmp, $image['body'] );
1162
+               chmod( $tmp, '777' );
1163
+
1164
+               preg_match( '/[^\?]+\.(tif|TIFF|jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG|pdf|PDF|bmp|BMP)/', $url, $matches );    // fix file filename for query strings
1165
+               $url_filename = basename( $matches[0] );
1166
+               $url_filename = str_replace( '%20', '_', $url_filename );
1167
+               // extract filename from url for title
1168
+               $url_type = wp_check_filetype( $url_filename );                                           // determine file type (ext and mime/type)
1169
+
1170
+               // override filename if given, reconstruct server path.
1171
+               if ( ! empty( $filename ) && ' ' != $filename ) {
1172
+                    $filename = sanitize_file_name( $filename );
1173
+                    $tmppath  = pathinfo( $tmp );
1174
+
1175
+                    $extension = '';
1176
+                    if ( isset( $tmppath['extension'] ) ) {
1177
+                         $extension = $tmppath['extension'];
1178
+                    }
1179
+
1180
+                    $new = $tmppath['dirname'] . '/' . $filename . '.' . $extension;
1181
+                    rename( $tmp, $new );                                                                 // renames temp file on server
1182
+                    $tmp = $new;                                                                        // push new filename (in path) to be used in file array later
1183
+               }
1184
+
1185
+               // assemble file data (should be built like $_FILES since wp_handle_sideload() will be using).
1186
+               $file_array['tmp_name'] = $tmp;                                                         // full server path to temp file
1187
+
1188
+               if ( ! empty( $filename ) && ' ' != $filename ) {
1189
+                    $file_array['name'] = $filename . '.' . $url_type['ext'];                           // user given filename for title, add original URL extension
1190
+               } else {
1191
+                    $file_array['name'] = $url_filename;                                                // just use original URL filename
1192
+               }
1193
+
1194
+               // set additional wp_posts columns.
1195
+               if ( empty( $post_data['post_title'] ) ) {
1196
+
1197
+                    $url_filename = str_replace( '%20', ' ', $url_filename );
1198
+
1199
+                    $post_data['post_title'] = basename( $url_filename, '.' . $url_type['ext'] );         // just use the original filename (no extension)
1200
+               }
1201
+
1202
+               // make sure gets tied to parent.
1203
+               if ( empty( $post_data['post_parent'] ) ) {
1204
+                    $post_data['post_parent'] = $post_id;
1205
+               }
1206
+
1207
+               // do the validation and storage stuff.
1208
+               $att_id = media_handle_sideload( $file_array, $post_id, null, $post_data );             // $post_data can override the items saved to wp_posts table, like post_mime_type, guid, post_parent, post_title, post_content, post_status
1209
+
1210
+               // If error storing permanently, unlink.
1211
+               if ( is_wp_error( $att_id ) ) {
1212
+                    unlink( $file_array['tmp_name'] );
1213
+                    return false;
1214
+               }
1215
+          }
1216
+          return $att_id;
1217
+     }
1218
+
1219
+     // AJAX FUNCTIONS
1220
+     /**
1221
+      * Run through the accommodation grabbed from the DB.
1222
+      */
1223
+     public function process_ajax_search() {
1224
+          $this->current_importer->process_ajax_search();
1225
+          die();
1226
+     }
1227
+
1228
+     /**
1229
+      * Connect to wetu
1230
+      */
1231
+     public function process_ajax_import() {
1232
+          $this->current_importer->process_ajax_import();
1233
+          die();
1234
+     }
1235
+
1236
+     /**
1237
+      * Formats the row for the completed list.
1238
+      */
1239
+     public function format_completed_row( $response ) {
1240
+          echo wp_kses_post( '<li class="post-' . $response . '"><span class="dashicons dashicons-yes"></span> <a target="_blank" href="' . get_permalink( $response ) . '">' . get_the_title( $response ) . '</a></li>' );
1241
+     }
1242
+
1243
+     /**
1244
+      * Formats the error.
1245
+      */
1246
+     public function format_error( $response ) {
1247
+          echo wp_kses_post( '<li class="post-error"><span class="dashicons dashicons-no"></span>' . $response . '</li>' );
1248
+     }
1249
+
1250
+     /**
1251
+      * Does a multine search
1252
+      */
1253
+     public function multineedle_stripos( $haystack, $needles, $offset = 0 ) {
1254
+          $found        = false;
1255
+          $needle_count = count( $needles );
1256
+
1257
+          foreach ( $needles as $needle ) {
1258
+               if ( false !== stripos( $haystack, $needle, $offset ) ) {
1259
+                    $found[] = true;
1260
+               }
1261
+          }
1262
+
1263
+          if ( false !== $found && count( $found ) === $needle_count ) {
1264
+               return true;
1265
+          } else {
1266
+               return false;
1267
+          }
1268
+     }
1269
+
1270
+     /**
1271
+      * Grab all the current accommodation posts via the lsx_wetu_id field.
1272
+      */
1273
+     public function find_current_accommodation( $post_type = 'accommodation' ) {
1274
+          global $wpdb;
1275
+          $return = array();
1276
+
1277
+          // @codingStandardsIgnoreStart
1278
+          $current_accommodation = $wpdb->get_results("
1279 1279
 			SELECT key1.post_id,key1.meta_value
1280 1280
 			FROM {$wpdb->postmeta} key1
1281 1281
 
@@ -1287,128 +1287,128 @@  discard block
 block discarded – undo
1287 1287
 
1288 1288
 			LIMIT 0,5000
1289 1289
 		");
1290
-		// @codingStandardsIgnoreEnd
1291
-
1292
-		if ( null !== $current_accommodation && ! empty( $current_accommodation ) ) {
1293
-			foreach ( $current_accommodation as $accom ) {
1294
-				$return[ $accom->meta_value ] = $accom;
1295
-			}
1296
-		}
1297
-
1298
-		return $return;
1299
-	}
1300
-
1301
-	/**
1302
-	 * Set the Video date
1303
-	 */
1304
-	public function set_video_data( $data, $id ) {
1305
-		if ( ! empty( $data[0]['content']['youtube_videos'] ) && is_array( $data[0]['content']['youtube_videos'] ) ) {
1306
-			$videos = false;
1307
-
1308
-			foreach ( $data[0]['content']['youtube_videos'] as $video ) {
1309
-				$temp_video = array();
1310
-
1311
-				if ( isset( $video['label'] ) ) {
1312
-					$temp_video['title'] = $video['label'];
1313
-				}
1314
-				if ( isset( $video['description'] ) ) {
1315
-					$temp_video['description'] = strip_tags( $video['description'] );
1316
-				}
1317
-				if ( isset( $video['url'] ) ) {
1318
-					$temp_video['url'] = $video['url'];
1319
-				}
1320
-
1321
-				$temp_video['thumbnail'] = '';
1322
-				$videos[]                = $temp_video;
1323
-			}
1324
-
1325
-			if ( false !== $id && '0' !== $id ) {
1326
-				delete_post_meta( $id, 'videos' );
1327
-			}
1328
-
1329
-			foreach ( $videos as $video ) {
1330
-				add_post_meta( $id, 'videos', $video, false );
1331
-			}
1332
-		}
1333
-	}
1334
-
1335
-	public function shuffle_assoc( &$array ) {
1336
-		$new  = array();
1337
-		$keys = array_keys( $array );
1338
-
1339
-		shuffle( $keys );
1340
-
1341
-		foreach ( $keys as $key ) {
1342
-			$new[ $key ] = $array[ $key ];
1343
-		}
1344
-
1345
-		$array = $new;
1346
-
1347
-		return true;
1348
-	}
1349
-
1350
-	/**
1351
-	 * Save the list of Tours into an option
1352
-	 */
1353
-	public function update_options() {
1354
-		$own     = '';
1355
-		$options = array();
1356
-		delete_option( 'lsx_ti_tours_api_options' );
1357
-
1358
-		if ( isset( $_GET['own'] ) ) {
1359
-			$this->current_importer->url_qs .= '&own=true';
1360
-			$options[]                       = 'own';
1361
-		}
1362
-
1363
-		if ( isset( $_GET['type'] ) && 'allitineraries' !== $_GET['type'] ) {
1364
-			$this->current_importer->url_qs .= '&type=' . $_GET['type'];
1365
-			$options[]                       = $_GET['type'];
1366
-		} else {
1367
-			$options[]                       = 'sample';
1368
-			$this->current_importer->url_qs .= '&type=sample';
1369
-		}
1370
-
1371
-		$url  = str_replace( 'Pins', 'Itinerary', $this->current_importer->url . '/V8/List?' . $this->current_importer->url_qs );
1372
-		$url .= '&results=2000';
1373
-		add_option( 'lsx_ti_tours_api_options', $options );
1374
-		$data  = wp_remote_get( $url );
1375
-		$tours = json_decode( wp_remote_retrieve_body( $data ), true );
1376
-
1377
-		if ( isset( $tours['error'] ) ) {
1378
-			return $tours['error'];
1379
-		} elseif ( isset( $tours['itineraries'] ) && ! empty( $tours['itineraries'] ) ) {
1380
-			set_transient( 'lsx_ti_tours', $tours['itineraries'], 60 * 60 * 4 );
1381
-			return true;
1382
-		}
1383
-	}
1384
-
1385
-	/**
1386
-	 * Gets the post_id from the key
1387
-	 *
1388
-	 * @param boolean $wetu_id
1389
-	 * @return string
1390
-	 */
1391
-	public function get_post_id_by_key_value( $wetu_id = false ) {
1392
-		global $wpdb;
1393
-		$id = false;
1394
-		if ( false !== $wetu_id && '' !== $wetu_id ) {
1395
-			$result = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM `$wpdb->postmeta` WHERE `meta_key` = 'lsx_wetu_id' AND `meta_value` = '%s'", array( $wetu_id ) ) );
1396
-			if ( false !== $result && ! empty( $result ) ) {
1397
-				$id = $result;
1398
-			}
1399
-		}
1400
-		return $id;
1401
-	}
1402
-	/**
1403
-	 * Set the team memberon each item.
1404
-	 */
1405
-	public function set_team_member( $id, $team_members ) {
1406
-		delete_post_meta( $id, 'team_to_' . $this->tab_slug );
1407
-
1408
-		foreach ( $team_members as $team ) {
1409
-			add_post_meta( $id, 'team_to_' . $this->tab_slug, $team );
1410
-		}
1411
-	}
1290
+          // @codingStandardsIgnoreEnd
1291
+
1292
+          if ( null !== $current_accommodation && ! empty( $current_accommodation ) ) {
1293
+               foreach ( $current_accommodation as $accom ) {
1294
+                    $return[ $accom->meta_value ] = $accom;
1295
+               }
1296
+          }
1297
+
1298
+          return $return;
1299
+     }
1300
+
1301
+     /**
1302
+      * Set the Video date
1303
+      */
1304
+     public function set_video_data( $data, $id ) {
1305
+          if ( ! empty( $data[0]['content']['youtube_videos'] ) && is_array( $data[0]['content']['youtube_videos'] ) ) {
1306
+               $videos = false;
1307
+
1308
+               foreach ( $data[0]['content']['youtube_videos'] as $video ) {
1309
+                    $temp_video = array();
1310
+
1311
+                    if ( isset( $video['label'] ) ) {
1312
+                         $temp_video['title'] = $video['label'];
1313
+                    }
1314
+                    if ( isset( $video['description'] ) ) {
1315
+                         $temp_video['description'] = strip_tags( $video['description'] );
1316
+                    }
1317
+                    if ( isset( $video['url'] ) ) {
1318
+                         $temp_video['url'] = $video['url'];
1319
+                    }
1320
+
1321
+                    $temp_video['thumbnail'] = '';
1322
+                    $videos[]                = $temp_video;
1323
+               }
1324
+
1325
+               if ( false !== $id && '0' !== $id ) {
1326
+                    delete_post_meta( $id, 'videos' );
1327
+               }
1328
+
1329
+               foreach ( $videos as $video ) {
1330
+                    add_post_meta( $id, 'videos', $video, false );
1331
+               }
1332
+          }
1333
+     }
1334
+
1335
+     public function shuffle_assoc( &$array ) {
1336
+          $new  = array();
1337
+          $keys = array_keys( $array );
1338
+
1339
+          shuffle( $keys );
1340
+
1341
+          foreach ( $keys as $key ) {
1342
+               $new[ $key ] = $array[ $key ];
1343
+          }
1344
+
1345
+          $array = $new;
1346
+
1347
+          return true;
1348
+     }
1349
+
1350
+     /**
1351
+      * Save the list of Tours into an option
1352
+      */
1353
+     public function update_options() {
1354
+          $own     = '';
1355
+          $options = array();
1356
+          delete_option( 'lsx_ti_tours_api_options' );
1357
+
1358
+          if ( isset( $_GET['own'] ) ) {
1359
+               $this->current_importer->url_qs .= '&own=true';
1360
+               $options[]                       = 'own';
1361
+          }
1362
+
1363
+          if ( isset( $_GET['type'] ) && 'allitineraries' !== $_GET['type'] ) {
1364
+               $this->current_importer->url_qs .= '&type=' . $_GET['type'];
1365
+               $options[]                       = $_GET['type'];
1366
+          } else {
1367
+               $options[]                       = 'sample';
1368
+               $this->current_importer->url_qs .= '&type=sample';
1369
+          }
1370
+
1371
+          $url  = str_replace( 'Pins', 'Itinerary', $this->current_importer->url . '/V8/List?' . $this->current_importer->url_qs );
1372
+          $url .= '&results=2000';
1373
+          add_option( 'lsx_ti_tours_api_options', $options );
1374
+          $data  = wp_remote_get( $url );
1375
+          $tours = json_decode( wp_remote_retrieve_body( $data ), true );
1376
+
1377
+          if ( isset( $tours['error'] ) ) {
1378
+               return $tours['error'];
1379
+          } elseif ( isset( $tours['itineraries'] ) && ! empty( $tours['itineraries'] ) ) {
1380
+               set_transient( 'lsx_ti_tours', $tours['itineraries'], 60 * 60 * 4 );
1381
+               return true;
1382
+          }
1383
+     }
1384
+
1385
+     /**
1386
+      * Gets the post_id from the key
1387
+      *
1388
+      * @param boolean $wetu_id
1389
+      * @return string
1390
+      */
1391
+     public function get_post_id_by_key_value( $wetu_id = false ) {
1392
+          global $wpdb;
1393
+          $id = false;
1394
+          if ( false !== $wetu_id && '' !== $wetu_id ) {
1395
+               $result = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM `$wpdb->postmeta` WHERE `meta_key` = 'lsx_wetu_id' AND `meta_value` = '%s'", array( $wetu_id ) ) );
1396
+               if ( false !== $result && ! empty( $result ) ) {
1397
+                    $id = $result;
1398
+               }
1399
+          }
1400
+          return $id;
1401
+     }
1402
+     /**
1403
+      * Set the team memberon each item.
1404
+      */
1405
+     public function set_team_member( $id, $team_members ) {
1406
+          delete_post_meta( $id, 'team_to_' . $this->tab_slug );
1407
+
1408
+          foreach ( $team_members as $team ) {
1409
+               add_post_meta( $id, 'team_to_' . $this->tab_slug, $team );
1410
+          }
1411
+     }
1412 1412
 }
1413 1413
 
1414 1414
 $lsx_wetu_importer = new LSX_WETU_Importer();
Please login to merge, or discard this patch.
Spacing   +367 added lines, -367 removed lines patch added patch discarded remove patch
@@ -197,40 +197,40 @@  discard block
 block discarded – undo
197 197
 	 * @access private
198 198
 	 */
199 199
 	public function __construct() {
200
-		add_action( 'admin_init', array( $this, 'compatible_version_check' ) );
201
-		require_once LSX_WETU_IMPORTER_PATH . 'includes/helpers.php';
200
+		add_action('admin_init', array($this, 'compatible_version_check'));
201
+		require_once LSX_WETU_IMPORTER_PATH.'includes/helpers.php';
202 202
 
203 203
 		// Don't run anything else in the plugin, if we're on an incompatible PHP version.
204
-		if ( ! self::compatible_version() ) {
204
+		if (!self::compatible_version()) {
205 205
 			return;
206 206
 		}
207 207
 
208 208
 		$this->set_variables();
209 209
 
210
-		add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
211
-		add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ), 11 );
212
-		add_action( 'admin_menu', array( $this, 'register_importer_page' ), 20 );
210
+		add_action('init', array($this, 'load_plugin_textdomain'));
211
+		add_action('admin_enqueue_scripts', array($this, 'admin_scripts'), 11);
212
+		add_action('admin_menu', array($this, 'register_importer_page'), 20);
213 213
 
214
-		require_once LSX_WETU_IMPORTER_PATH . 'classes/class-lsx-wetu-importer-welcome.php';
215
-		require_once LSX_WETU_IMPORTER_PATH . 'classes/class-lsx-wetu-importer-accommodation.php';
216
-		require_once LSX_WETU_IMPORTER_PATH . 'classes/class-lsx-wetu-importer-destination.php';
217
-		require_once LSX_WETU_IMPORTER_PATH . 'classes/class-lsx-wetu-importer-tours.php';
218
-		require_once LSX_WETU_IMPORTER_PATH . 'classes/class-lsx-wetu-importer-settings.php';
219
-		require_once LSX_WETU_IMPORTER_PATH . 'classes/class-cron.php';
214
+		require_once LSX_WETU_IMPORTER_PATH.'classes/class-lsx-wetu-importer-welcome.php';
215
+		require_once LSX_WETU_IMPORTER_PATH.'classes/class-lsx-wetu-importer-accommodation.php';
216
+		require_once LSX_WETU_IMPORTER_PATH.'classes/class-lsx-wetu-importer-destination.php';
217
+		require_once LSX_WETU_IMPORTER_PATH.'classes/class-lsx-wetu-importer-tours.php';
218
+		require_once LSX_WETU_IMPORTER_PATH.'classes/class-lsx-wetu-importer-settings.php';
219
+		require_once LSX_WETU_IMPORTER_PATH.'classes/class-cron.php';
220 220
 
221
-		if ( isset( $this->options ) && isset( $this->options['enable_tour_ref_column'] ) && '' !== $this->options['enable_tour_ref_column'] ) {
222
-			require_once LSX_WETU_IMPORTER_PATH . 'classes/class-lsx-wetu-importer-post-columns.php';
221
+		if (isset($this->options) && isset($this->options['enable_tour_ref_column']) && '' !== $this->options['enable_tour_ref_column']) {
222
+			require_once LSX_WETU_IMPORTER_PATH.'classes/class-lsx-wetu-importer-post-columns.php';
223 223
 			$this->post_columns = LSX_WETU_Importer_Post_Columns::get_instance();
224 224
 		}
225 225
 
226
-		add_action( 'init', array( $this, 'load_class' ) );
226
+		add_action('init', array($this, 'load_class'));
227 227
 
228
-		if ( 'default' !== $this->tab_slug ) {
229
-			add_action( 'wp_ajax_lsx_tour_importer', array( $this, 'process_ajax_search' ) );
230
-			add_action( 'wp_ajax_nopriv_lsx_tour_importer', array( $this, 'process_ajax_search' ) );
228
+		if ('default' !== $this->tab_slug) {
229
+			add_action('wp_ajax_lsx_tour_importer', array($this, 'process_ajax_search'));
230
+			add_action('wp_ajax_nopriv_lsx_tour_importer', array($this, 'process_ajax_search'));
231 231
 
232
-			add_action( 'wp_ajax_lsx_import_items', array( $this, 'process_ajax_import' ) );
233
-			add_action( 'wp_ajax_nopriv_lsx_import_items', array( $this, 'process_ajax_import' ) );
232
+			add_action('wp_ajax_lsx_import_items', array($this, 'process_ajax_import'));
233
+			add_action('wp_ajax_nopriv_lsx_import_items', array($this, 'process_ajax_import'));
234 234
 		}
235 235
 	}
236 236
 
@@ -240,21 +240,21 @@  discard block
 block discarded – undo
240 240
 	 * @since 1.0.0
241 241
 	 */
242 242
 	public function load_plugin_textdomain() {
243
-		load_plugin_textdomain( 'lsx-wetu-importer', false, basename( LSX_WETU_IMPORTER_PATH ) . '/languages' );
243
+		load_plugin_textdomain('lsx-wetu-importer', false, basename(LSX_WETU_IMPORTER_PATH).'/languages');
244 244
 	}
245 245
 
246 246
 	/**
247 247
 	 * Sets the variables used throughout the plugin.
248 248
 	 */
249 249
 	public function set_variables() {
250
-		$this->post_types = array( 'accommodation', 'destination', 'tour' );
250
+		$this->post_types = array('accommodation', 'destination', 'tour');
251 251
 		$options          = lsx_wetu_get_options();
252 252
 
253 253
 		// Set the options.
254 254
 		$this->options = $options;
255 255
 
256
-		$temp_options = get_option( '_lsx-to_settings', false );
257
-		if ( false !== $temp_options ) {
256
+		$temp_options = get_option('_lsx-to_settings', false);
257
+		if (false !== $temp_options) {
258 258
 			$this->accommodation_settings = $temp_options['accommodation'];
259 259
 			$this->tour_settings          = $temp_options['tour'];
260 260
 			$this->destination_settings   = $temp_options['destination'];
@@ -262,51 +262,51 @@  discard block
 block discarded – undo
262 262
 
263 263
 		$this->api_key = false;
264 264
 
265
-		if ( ! defined( 'WETU_API_KEY' ) ) {
266
-			if ( isset( $options['api_key'] ) && '' !== $options['api_key'] ) {
265
+		if (!defined('WETU_API_KEY')) {
266
+			if (isset($options['api_key']) && '' !== $options['api_key']) {
267 267
 				$this->api_key = $options['api_key'];
268 268
 			}
269
-		} else {
269
+		}else {
270 270
 			$this->api_key = WETU_API_KEY;
271 271
 		}
272 272
 
273 273
 		// Set the tab slug.
274 274
 		// @codingStandardsIgnoreLine
275
-		if ( isset( $_GET['tab'] ) || ( defined( 'DOING_AJAX' ) && isset( $_POST['type'] ) ) ) {
276
-			if ( isset( $_GET['tab'] ) ) {
277
-				$this->tab_slug = sanitize_text_field( $_GET['tab'] );
278
-			} else {
275
+		if (isset($_GET['tab']) || (defined('DOING_AJAX') && isset($_POST['type']))) {
276
+			if (isset($_GET['tab'])) {
277
+				$this->tab_slug = sanitize_text_field($_GET['tab']);
278
+			}else {
279 279
 				// @codingStandardsIgnoreLine
280
-				$this->tab_slug = sanitize_text_field( $_POST['type'] );
280
+				$this->tab_slug = sanitize_text_field($_POST['type']);
281 281
 			}
282 282
 		}
283 283
 
284 284
 		// If any tours were queued.
285
-		$this->queued_imports = get_option( 'lsx_wetu_importer_que', array() );
285
+		$this->queued_imports = get_option('lsx_wetu_importer_que', array());
286 286
 
287 287
 		// Set the scaling options.
288
-		if ( isset( $this->options ) && isset( $this->options['image_scaling'] ) ) {
288
+		if (isset($this->options) && isset($this->options['image_scaling'])) {
289 289
 			$this->scale_images = true;
290 290
 
291 291
 			$width = '1024';
292
-			if ( isset( $this->options['width'] ) && '' !== $this->options['width'] ) {
292
+			if (isset($this->options['width']) && '' !== $this->options['width']) {
293 293
 				$width = $this->options['width'];
294 294
 			}
295 295
 
296 296
 			$height = '768';
297
-			if ( isset( $this->options['height'] ) && '' !== $this->options['height'] ) {
297
+			if (isset($this->options['height']) && '' !== $this->options['height']) {
298 298
 				$height = $this->options['height'];
299 299
 			}
300 300
 
301 301
 			$cropping = 'w';
302
-			if ( isset( $this->options['cropping'] ) && '' !== $this->options['cropping'] ) {
302
+			if (isset($this->options['cropping']) && '' !== $this->options['cropping']) {
303 303
 				$cropping = $this->options['cropping'];
304 304
 			}
305 305
 
306
-			$this->image_scaling_url = 'https://wetu.com/ImageHandler/' . $cropping . $width . 'x' . $height . '/';
306
+			$this->image_scaling_url = 'https://wetu.com/ImageHandler/'.$cropping.$width.'x'.$height.'/';
307 307
 		}
308 308
 
309
-		if ( isset( $this->options ) && isset( $this->options['image_limit'] ) && '' !== $this->options['image_limit'] ) {
309
+		if (isset($this->options) && isset($this->options['image_limit']) && '' !== $this->options['image_limit']) {
310 310
 			$this->image_limit = $this->options['image_limit'];
311 311
 		}
312 312
 	}
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
 	 * @since 1.0.0
329 329
 	 */
330 330
 	public static function compatible_version() {
331
-		if ( version_compare( PHP_VERSION, '5.6', '<' ) ) {
331
+		if (version_compare(PHP_VERSION, '5.6', '<')) {
332 332
 			return false;
333 333
 		}
334 334
 
@@ -342,13 +342,13 @@  discard block
 block discarded – undo
342 342
 	 * @since 1.0.0
343 343
 	 */
344 344
 	public function compatible_version_check() {
345
-		if ( ! self::compatible_version() ) {
346
-			if ( is_plugin_active( plugin_basename( LSX_WETU_IMPORTER_CORE ) ) ) {
347
-				deactivate_plugins( plugin_basename( LSX_WETU_IMPORTER_CORE ) );
348
-				add_action( 'admin_notices', array( $this, 'compatible_version_notice' ) );
345
+		if (!self::compatible_version()) {
346
+			if (is_plugin_active(plugin_basename(LSX_WETU_IMPORTER_CORE))) {
347
+				deactivate_plugins(plugin_basename(LSX_WETU_IMPORTER_CORE));
348
+				add_action('admin_notices', array($this, 'compatible_version_notice'));
349 349
 
350
-				if ( isset( $_GET['activate'] ) ) {
351
-					unset( $_GET['activate'] );
350
+				if (isset($_GET['activate'])) {
351
+					unset($_GET['activate']);
352 352
 				}
353 353
 			}
354 354
 		}
@@ -361,8 +361,8 @@  discard block
 block discarded – undo
361 361
 	 */
362 362
 	public function compatible_version_notice() {
363 363
 		$class   = 'notice notice-error';
364
-		$message = esc_html__( 'LSX Importer for Wetu Plugin requires PHP 5.6 or higher.', 'lsx-wetu-importer' );
365
-		printf( '<div class="%1$s"><p>%2$s</p></div>', esc_html( $class ), esc_html( $message ) );
364
+		$message = esc_html__('LSX Importer for Wetu Plugin requires PHP 5.6 or higher.', 'lsx-wetu-importer');
365
+		printf('<div class="%1$s"><p>%2$s</p></div>', esc_html($class), esc_html($message));
366 366
 	}
367 367
 
368 368
 	/**
@@ -372,9 +372,9 @@  discard block
 block discarded – undo
372 372
 	 * @since 1.0.0
373 373
 	 */
374 374
 	public static function compatible_version_check_on_activation() {
375
-		if ( ! self::compatible_version() ) {
376
-			deactivate_plugins( plugin_basename( LSX_WETU_IMPORTER_CORE ) );
377
-			wp_die( esc_html__( 'LSX Importer for Wetu Plugin requires PHP 5.6 or higher.', 'lsx-wetu-importer' ) );
375
+		if (!self::compatible_version()) {
376
+			deactivate_plugins(plugin_basename(LSX_WETU_IMPORTER_CORE));
377
+			wp_die(esc_html__('LSX Importer for Wetu Plugin requires PHP 5.6 or higher.', 'lsx-wetu-importer'));
378 378
 		}
379 379
 	}
380 380
 
@@ -384,7 +384,7 @@  discard block
 block discarded – undo
384 384
 	 * Load the importer class you want to use
385 385
 	 */
386 386
 	public function load_class() {
387
-		switch ( $this->tab_slug ) {
387
+		switch ($this->tab_slug) {
388 388
 			case 'accommodation':
389 389
 				$this->current_importer = new LSX_WETU_Importer_Accommodation();
390 390
 				break;
@@ -411,36 +411,36 @@  discard block
 block discarded – undo
411 411
 	 * Registers the admin page which will house the importer form.
412 412
 	 */
413 413
 	public function register_importer_page() {
414
-		add_submenu_page( 'tour-operator', esc_html__( 'Importer', 'tour-operator' ), esc_html__( 'Importer', 'tour-operator' ), 'manage_options', 'lsx-wetu-importer', array( $this, 'display_page' ) );
414
+		add_submenu_page('tour-operator', esc_html__('Importer', 'tour-operator'), esc_html__('Importer', 'tour-operator'), 'manage_options', 'lsx-wetu-importer', array($this, 'display_page'));
415 415
 	}
416 416
 
417 417
 	/**
418 418
 	 * Enqueue the JS needed to contact wetu and return your result.
419 419
 	 */
420 420
 	public function admin_scripts() {
421
-		if ( defined( 'WP_DEBUG' ) && true === WP_DEBUG ) {
421
+		if (defined('WP_DEBUG') && true === WP_DEBUG) {
422 422
 			$min = '';
423
-		} else {
423
+		}else {
424 424
 			$min = '.min';
425 425
 		}
426 426
 
427 427
 		$min = '';
428 428
 
429
-		if ( is_admin() && isset( $_GET['page'] ) && $this->plugin_slug === $_GET['page'] ) {
429
+		if (is_admin() && isset($_GET['page']) && $this->plugin_slug === $_GET['page']) {
430 430
 
431 431
 			// wp_enqueue_style( 'datatables', LSX_WETU_IMPORTER_URL . 'assets/css/datatables' . $min . '.css', LSX_WETU_IMPORTER_VER, true );
432
-			wp_enqueue_style( 'lsx-wetu-importer-style', LSX_WETU_IMPORTER_URL . 'assets/css/lsx-wetu-importer.css', LSX_WETU_IMPORTER_VER, true );
432
+			wp_enqueue_style('lsx-wetu-importer-style', LSX_WETU_IMPORTER_URL.'assets/css/lsx-wetu-importer.css', LSX_WETU_IMPORTER_VER, true);
433 433
 
434
-			if ( isset( $_GET['tab'] ) ) {
435
-				wp_enqueue_script( 'datatables', LSX_WETU_IMPORTER_URL . 'assets/js/datatables' . $min . '.js', array( 'jquery' ), LSX_WETU_IMPORTER_VER, true );
436
-				wp_enqueue_script( 'lsx-wetu-importers-script', LSX_WETU_IMPORTER_URL . 'assets/js/lsx-wetu-importer' . $min . '.js', array( 'jquery', 'datatables' ), LSX_WETU_IMPORTER_VER, true );
434
+			if (isset($_GET['tab'])) {
435
+				wp_enqueue_script('datatables', LSX_WETU_IMPORTER_URL.'assets/js/datatables'.$min.'.js', array('jquery'), LSX_WETU_IMPORTER_VER, true);
436
+				wp_enqueue_script('lsx-wetu-importers-script', LSX_WETU_IMPORTER_URL.'assets/js/lsx-wetu-importer'.$min.'.js', array('jquery', 'datatables'), LSX_WETU_IMPORTER_VER, true);
437 437
 
438 438
 				wp_localize_script(
439 439
 					'lsx-wetu-importers-script',
440 440
 					'lsx_tour_importer_params',
441 441
 					array(
442
-						'ajax_url'   => admin_url( 'admin-ajax.php' ),
443
-						'ajax_nonce' => wp_create_nonce( 'lsx_wetu_ajax_action' ),
442
+						'ajax_url'   => admin_url('admin-ajax.php'),
443
+						'ajax_nonce' => wp_create_nonce('lsx_wetu_ajax_action'),
444 444
 					)
445 445
 				);
446 446
 			}
@@ -454,8 +454,8 @@  discard block
 block discarded – undo
454 454
 		?>
455 455
 		<div class="wrap">
456 456
 			<?php
457
-			$this->navigation( $this->tab_slug );
458
-			if ( 'default' !== $this->tab_slug && 'settings' !== $this->tab_slug ) {
457
+			$this->navigation($this->tab_slug);
458
+			if ('default' !== $this->tab_slug && 'settings' !== $this->tab_slug) {
459 459
 				$this->wetu_status();
460 460
 				$this->post_status_navigation();
461 461
 			}
@@ -473,18 +473,18 @@  discard block
 block discarded – undo
473 473
 	public function post_status_navigation() {
474 474
 		?>
475 475
 		<ul class="subsubsub">
476
-			<li class="searchform"><a class="current" href="#search"><?php esc_attr_e( 'Search', 'lsx-wetu-importer' ); ?></a> | </li>
477
-			<li class="publish"><a href="#publish"><?php esc_attr_e( 'Published', 'lsx-wetu-importer' ); ?> <span class="count"> (<?php echo esc_attr( lsx_wetu_get_post_count( $this->tab_slug, 'publish ' ) ); ?>)</span></a> | </li>
478
-			<li class="pending"><a href="#pending"><?php esc_attr_e( 'Pending', 'lsx-wetu-importer' ); ?> <span class="count"> (<?php echo esc_attr( lsx_wetu_get_post_count( $this->tab_slug, 'pending ' ) ); ?>)</span></a>| </li>
479
-			<li class="draft"><a href="#draft"><?php esc_attr_e( 'Draft', 'lsx-wetu-importer' ); ?></a> <span class="count"> (<?php echo esc_attr( lsx_wetu_get_post_count( $this->tab_slug, 'draft ' ) ); ?>)</span></li>
480
-
481
-			<?php if ( 'tour' === $this->tab_slug ) { ?>
482
-				<li class="import"> | <a class="import search-toggle"  href="#import"><?php esc_attr_e( 'WETU', 'lsx-wetu-importer' ); ?> <span class="count"> (<?php echo esc_attr( lsx_wetu_get_tour_count() ); ?>)</span></a></li>
483
-			<?php } elseif ( ! empty( $this->queued_imports ) ) { ?>
484
-				<li class="import"> | <a class="import search-toggle"  href="#import"><?php esc_attr_e( 'WETU Queue', 'lsx-wetu-importer' ); ?> <span class="count"> (<?php echo esc_attr( lsx_wetu_get_queue_count( $this->tab_slug ) ); ?>)</span></a></li>
476
+			<li class="searchform"><a class="current" href="#search"><?php esc_attr_e('Search', 'lsx-wetu-importer'); ?></a> | </li>
477
+			<li class="publish"><a href="#publish"><?php esc_attr_e('Published', 'lsx-wetu-importer'); ?> <span class="count"> (<?php echo esc_attr(lsx_wetu_get_post_count($this->tab_slug, 'publish ')); ?>)</span></a> | </li>
478
+			<li class="pending"><a href="#pending"><?php esc_attr_e('Pending', 'lsx-wetu-importer'); ?> <span class="count"> (<?php echo esc_attr(lsx_wetu_get_post_count($this->tab_slug, 'pending ')); ?>)</span></a>| </li>
479
+			<li class="draft"><a href="#draft"><?php esc_attr_e('Draft', 'lsx-wetu-importer'); ?></a> <span class="count"> (<?php echo esc_attr(lsx_wetu_get_post_count($this->tab_slug, 'draft ')); ?>)</span></li>
480
+
481
+			<?php if ('tour' === $this->tab_slug) { ?>
482
+				<li class="import"> | <a class="import search-toggle"  href="#import"><?php esc_attr_e('WETU', 'lsx-wetu-importer'); ?> <span class="count"> (<?php echo esc_attr(lsx_wetu_get_tour_count()); ?>)</span></a></li>
483
+			<?php } elseif (!empty($this->queued_imports)) { ?>
484
+				<li class="import"> | <a class="import search-toggle"  href="#import"><?php esc_attr_e('WETU Queue', 'lsx-wetu-importer'); ?> <span class="count"> (<?php echo esc_attr(lsx_wetu_get_queue_count($this->tab_slug)); ?>)</span></a></li>
485 485
 			<?php } ?>
486 486
 		</ul>
487
-		<a class="documentation" target="_blank"href="https://tour-operator.lsdev.biz/documentation/extension/wetu-importer/"><?php esc_attr_e( 'Documentation', 'lsx-wetu-importer' ); ?></a>
487
+		<a class="documentation" target="_blank"href="https://tour-operator.lsdev.biz/documentation/extension/wetu-importer/"><?php esc_attr_e('Documentation', 'lsx-wetu-importer'); ?></a>
488 488
 		<?php
489 489
 	}
490 490
 
@@ -493,29 +493,29 @@  discard block
 block discarded – undo
493 493
 	 */
494 494
 	public function search_form() {
495 495
 		?>
496
-		<form class="ajax-form" id="<?php echo esc_attr( $this->plugin_slug ); ?>-search-form" method="get" action="tools.php" data-type="<?php echo esc_attr( $this->tab_slug ); ?>">
497
-			<input type="hidden" name="page" value="<?php echo esc_attr( $this->tab_slug ); ?>" />
496
+		<form class="ajax-form" id="<?php echo esc_attr($this->plugin_slug); ?>-search-form" method="get" action="tools.php" data-type="<?php echo esc_attr($this->tab_slug); ?>">
497
+			<input type="hidden" name="page" value="<?php echo esc_attr($this->tab_slug); ?>" />
498 498
 
499
-			<?php do_action( 'lsx_wetu_importer_search_form', $this ); ?>
499
+			<?php do_action('lsx_wetu_importer_search_form', $this); ?>
500 500
 
501 501
 			<div class="normal-search">
502
-				<input pattern=".{3,}" placeholder="3 characters minimum" class="keyword" name="keyword" value=""> <input class="button button-primary submit" type="submit" value="<?php esc_html_e( 'Search', 'lsx-wetu-importer' ); ?>" />
502
+				<input pattern=".{3,}" placeholder="3 characters minimum" class="keyword" name="keyword" value=""> <input class="button button-primary submit" type="submit" value="<?php esc_html_e('Search', 'lsx-wetu-importer'); ?>" />
503 503
 			</div>
504 504
 
505 505
 			<div class="advanced-search hidden" style="display:none;">
506 506
 				<textarea rows="10" cols="40" name="bulk-keywords"></textarea>
507
-				<input class="button button-primary submit" type="submit" value="<?php esc_attr_e( 'Search', 'lsx-wetu-importer' ); ?>" />
507
+				<input class="button button-primary submit" type="submit" value="<?php esc_attr_e('Search', 'lsx-wetu-importer'); ?>" />
508 508
 			</div>
509 509
 
510 510
 			<div class="ajax-loader" style="display:none;width:100%;text-align:center;">
511
-				<img style="width:64px;" src="<?php echo esc_url( LSX_WETU_IMPORTER_URL . 'assets/images/ajaxloader.gif' ); ?>" />
511
+				<img style="width:64px;" src="<?php echo esc_url(LSX_WETU_IMPORTER_URL.'assets/images/ajaxloader.gif'); ?>" />
512 512
 			</div>
513 513
 
514 514
 			<div class="ajax-loader-small" style="display:none;width:100%;text-align:center;">
515
-				<img style="width:32px;" src="<?php echo esc_url( LSX_WETU_IMPORTER_URL . 'assets/images/ajaxloader.gif' ); ?>" />
515
+				<img style="width:32px;" src="<?php echo esc_url(LSX_WETU_IMPORTER_URL.'assets/images/ajaxloader.gif'); ?>" />
516 516
 			</div>
517 517
 
518
-			<a class="button advanced-search-toggle" href="#"><?php esc_html_e( 'Bulk Search', 'lsx-wetu-importer' ); ?></a>
518
+			<a class="button advanced-search-toggle" href="#"><?php esc_html_e('Bulk Search', 'lsx-wetu-importer'); ?></a>
519 519
 		</form>
520 520
 		<?php
521 521
 	}
@@ -528,13 +528,13 @@  discard block
 block discarded – undo
528 528
 		<thead>
529 529
 		<tr>
530 530
 			<th style="" class="manage-column column-cb check-column no-sort" id="cb" scope="col">
531
-				<label for="cb-select-all-1" class="screen-reader-text"><?php esc_attr_e( 'Select All', 'lsx-wetu-importer' ); ?></label>
531
+				<label for="cb-select-all-1" class="screen-reader-text"><?php esc_attr_e('Select All', 'lsx-wetu-importer'); ?></label>
532 532
 				<input type="checkbox" id="cb-select-all-1">
533 533
 			</th>
534
-			<th style="" class="manage-column column-order " id="order"><?php esc_attr_e( 'Order', 'lsx-wetu-importer' ); ?></th>
535
-			<th style="" class="manage-column column-title " id="title" style="width:50%;" scope="col"><?php esc_attr_e( 'Title', 'lsx-wetu-importer' ); ?></th>
536
-			<th style="" class="manage-column column-date" id="date" scope="col"><?php esc_attr_e( 'Date', 'lsx-wetu-importer' ); ?></th>
537
-			<th style="" class="manage-column column-ssid" id="ssid" scope="col"><?php esc_attr_e( 'WETU ID', 'lsx-wetu-importer' ); ?></th>
534
+			<th style="" class="manage-column column-order " id="order"><?php esc_attr_e('Order', 'lsx-wetu-importer'); ?></th>
535
+			<th style="" class="manage-column column-title " id="title" style="width:50%;" scope="col"><?php esc_attr_e('Title', 'lsx-wetu-importer'); ?></th>
536
+			<th style="" class="manage-column column-date" id="date" scope="col"><?php esc_attr_e('Date', 'lsx-wetu-importer'); ?></th>
537
+			<th style="" class="manage-column column-ssid" id="ssid" scope="col"><?php esc_attr_e('WETU ID', 'lsx-wetu-importer'); ?></th>
538 538
 		</tr>
539 539
 		</thead>
540 540
 		<?php
@@ -548,13 +548,13 @@  discard block
 block discarded – undo
548 548
 		<tfoot>
549 549
 		<tr>
550 550
 			<th style="" class="manage-column column-cb check-column" id="cb" scope="col">
551
-				<label for="cb-select-all-1" class="screen-reader-text"><?php esc_attr_e( 'Select All', 'lsx-wetu-importer' ); ?></label>
551
+				<label for="cb-select-all-1" class="screen-reader-text"><?php esc_attr_e('Select All', 'lsx-wetu-importer'); ?></label>
552 552
 				<input type="checkbox" id="cb-select-all-1">
553 553
 			</th>
554
-			<th style="" class="manage-column column-order "><?php esc_attr_e( 'Order', 'lsx-wetu-importer' ); ?></th>
555
-			<th style="" class="manage-column column-title" scope="col"><?php esc_attr_e( 'Title', 'lsx-wetu-importer' ); ?></th>
556
-			<th style="" class="manage-column column-date" scope="col"><?php esc_attr_e( 'Date', 'lsx-wetu-importer' ); ?></th>
557
-			<th style="" class="manage-column column-ssid" scope="col"><?php esc_attr_e( 'WETU ID', 'lsx-wetu-importer' ); ?></th>
554
+			<th style="" class="manage-column column-order "><?php esc_attr_e('Order', 'lsx-wetu-importer'); ?></th>
555
+			<th style="" class="manage-column column-title" scope="col"><?php esc_attr_e('Title', 'lsx-wetu-importer'); ?></th>
556
+			<th style="" class="manage-column column-date" scope="col"><?php esc_attr_e('Date', 'lsx-wetu-importer'); ?></th>
557
+			<th style="" class="manage-column column-ssid" scope="col"><?php esc_attr_e('WETU ID', 'lsx-wetu-importer'); ?></th>
558 558
 		</tr>
559 559
 		</tfoot>
560 560
 		<?php
@@ -565,42 +565,42 @@  discard block
 block discarded – undo
565 565
 	 *
566 566
 	 * @param $tab string
567 567
 	 */
568
-	public function navigation( $tab = '' ) {
568
+	public function navigation($tab = '') {
569 569
 		$post_types = array(
570
-			'tour'          => esc_attr( 'Tours', 'lsx-wetu-importer' ),
571
-			'accommodation' => esc_attr( 'Accommodation', 'lsx-wetu-importer' ),
572
-			'destination'   => esc_attr( 'Destinations', 'lsx-wetu-importer' ),
570
+			'tour'          => esc_attr('Tours', 'lsx-wetu-importer'),
571
+			'accommodation' => esc_attr('Accommodation', 'lsx-wetu-importer'),
572
+			'destination'   => esc_attr('Destinations', 'lsx-wetu-importer'),
573 573
 		);
574 574
 
575
-		echo wp_kses_post( '<div class="wp-filter">' );
576
-		echo wp_kses_post( '<ul class="filter-links">' );
577
-		echo wp_kses_post( '<li><a class="' . $this->itemd( $tab, 'default', 'current', false ) . '" href="' . admin_url( 'admin.php' ) . '?page=' . $this->plugin_slug . '">' . esc_attr__( 'Home', 'lsx-wetu-importer' ) . '</a></li>' );
575
+		echo wp_kses_post('<div class="wp-filter">');
576
+		echo wp_kses_post('<ul class="filter-links">');
577
+		echo wp_kses_post('<li><a class="'.$this->itemd($tab, 'default', 'current', false).'" href="'.admin_url('admin.php').'?page='.$this->plugin_slug.'">'.esc_attr__('Home', 'lsx-wetu-importer').'</a></li>');
578 578
 
579
-		foreach ( $post_types as $post_type => $label ) {
580
-			echo wp_kses_post( ' | <li><a class="' . $this->itemd( $tab, $post_type, 'current', false ) . '" href="' . admin_url( 'admin.php' ) . '?page=' . $this->plugin_slug . '&tab=' . $post_type . '">' . $label . '</a></li>' );
579
+		foreach ($post_types as $post_type => $label) {
580
+			echo wp_kses_post(' | <li><a class="'.$this->itemd($tab, $post_type, 'current', false).'" href="'.admin_url('admin.php').'?page='.$this->plugin_slug.'&tab='.$post_type.'">'.$label.'</a></li>');
581 581
 		}
582 582
 
583
-		echo wp_kses_post( ' | <li><a class="' . $this->itemd( $tab, 'settings', 'current', false ) . '" href="' . admin_url( 'admin.php' ) . '?page=' . $this->plugin_slug . '&tab=settings">' . esc_attr__( 'Settings', 'lsx-wetu-importer' ) . '</a></li>' );
584
-		echo wp_kses_post( '</ul> </div>' );
583
+		echo wp_kses_post(' | <li><a class="'.$this->itemd($tab, 'settings', 'current', false).'" href="'.admin_url('admin.php').'?page='.$this->plugin_slug.'&tab=settings">'.esc_attr__('Settings', 'lsx-wetu-importer').'</a></li>');
584
+		echo wp_kses_post('</ul> </div>');
585 585
 	}
586 586
 
587 587
 	/**
588 588
 	 * Wetu Status Bar.
589 589
 	 */
590 590
 	public function wetu_status() {
591
-		$tours = get_transient( 'lsx_ti_tours' );
592
-		echo '<div class="wetu-status tour-wetu-status"><h3>' . esc_html__( 'Wetu Status', 'lsx-wetu-importer' ) . ' - ';
591
+		$tours = get_transient('lsx_ti_tours');
592
+		echo '<div class="wetu-status tour-wetu-status"><h3>'.esc_html__('Wetu Status', 'lsx-wetu-importer').' - ';
593 593
 
594
-		if ( '' === $tours || false === $tours || isset( $_GET['refresh_tours'] ) ) {
594
+		if ('' === $tours || false === $tours || isset($_GET['refresh_tours'])) {
595 595
 			$result = $this->update_options();
596
-			if ( true === $result ) {
597
-				echo '<span style="color:green;">' . esc_attr( 'Connected', 'lsx-wetu-importer' ) . '</span>';
598
-				echo ' - <small><a href="#">' . esc_attr( 'Refresh', 'lsx-wetu-importer' ) . '</a></small>';
599
-			} else {
600
-				echo '<span style="color:red;">' . wp_kses_post( $result ) . '</span>';
596
+			if (true === $result) {
597
+				echo '<span style="color:green;">'.esc_attr('Connected', 'lsx-wetu-importer').'</span>';
598
+				echo ' - <small><a href="#">'.esc_attr('Refresh', 'lsx-wetu-importer').'</a></small>';
599
+			}else {
600
+				echo '<span style="color:red;">'.wp_kses_post($result).'</span>';
601 601
 			}
602
-		} else {
603
-			echo '<span style="color:green;">' . esc_attr( 'Connected', 'lsx-wetu-importer' ) . '</span> - <small><a href="#">' . esc_attr( 'Refresh', 'lsx-wetu-importer' ) . '</a></small>';
602
+		}else {
603
+			echo '<span style="color:green;">'.esc_attr('Connected', 'lsx-wetu-importer').'</span> - <small><a href="#">'.esc_attr('Refresh', 'lsx-wetu-importer').'</a></small>';
604 604
 		}
605 605
 		echo '</h3>';
606 606
 		echo '</div>';
@@ -609,8 +609,8 @@  discard block
 block discarded – undo
609 609
 	/**
610 610
 	 * Set_taxonomy with some terms
611 611
 	 */
612
-	public function team_member_checkboxes( $selected = array() ) {
613
-		if ( post_type_exists( 'team' ) ) {
612
+	public function team_member_checkboxes($selected = array()) {
613
+		if (post_type_exists('team')) {
614 614
 			?>
615 615
 			<ul>
616 616
 				<?php
@@ -621,17 +621,17 @@  discard block
 block discarded – undo
621 621
 						'fields'      => 'ids',
622 622
 					);
623 623
 
624
-					$team_members = new WP_Query( $team_args );
624
+					$team_members = new WP_Query($team_args);
625 625
 
626
-					if ( $team_members->have_posts() ) {
627
-						foreach ( $team_members->posts as $member ) {
626
+					if ($team_members->have_posts()) {
627
+						foreach ($team_members->posts as $member) {
628 628
 							?>
629
-							<li><input class="team" <?php $this->checked( $selected, $member ); ?> type="checkbox" value="<?php echo esc_attr( $member ); ?>" /> <?php echo wp_kses_post( get_the_title( $member ) ); ?></li>
629
+							<li><input class="team" <?php $this->checked($selected, $member); ?> type="checkbox" value="<?php echo esc_attr($member); ?>" /> <?php echo wp_kses_post(get_the_title($member)); ?></li>
630 630
 							<?php
631 631
 						}
632
-					} else {
632
+					}else {
633 633
 						?>
634
-						<li><input class="team" type="checkbox" value="0" /> <?php esc_html_e( 'None', 'lsx-wetu-importer' ); ?></li>
634
+						<li><input class="team" type="checkbox" value="0" /> <?php esc_html_e('None', 'lsx-wetu-importer'); ?></li>
635 635
 						<?php
636 636
 					}
637 637
 					?>
@@ -650,13 +650,13 @@  discard block
 block discarded – undo
650 650
 	 * @param $needle string
651 651
 	 * @param $echo bool
652 652
 	 */
653
-	public function checked( $haystack = false, $needle = '', $echo = true ) {
654
-		$return = $this->itemd( $haystack, $needle, 'checked', false );
653
+	public function checked($haystack = false, $needle = '', $echo = true) {
654
+		$return = $this->itemd($haystack, $needle, 'checked', false);
655 655
 
656
-		if ( '' !== $return ) {
657
-			if ( true === $echo ) {
658
-				echo wp_kses_post( $return );
659
-			} else {
656
+		if ('' !== $return) {
657
+			if (true === $echo) {
658
+				echo wp_kses_post($return);
659
+			}else {
660 660
 				return $return;
661 661
 			}
662 662
 		}
@@ -669,13 +669,13 @@  discard block
 block discarded – undo
669 669
 	 * @param $needle string
670 670
 	 * @param $echo bool
671 671
 	 */
672
-	public function selected( $haystack = false, $needle = '', $echo = true ) {
673
-		$return = $this->itemd( $haystack, $needle, 'selected' );
672
+	public function selected($haystack = false, $needle = '', $echo = true) {
673
+		$return = $this->itemd($haystack, $needle, 'selected');
674 674
 
675
-		if ( '' !== $return ) {
676
-			if ( true === $echo ) {
677
-				echo wp_kses_post( $return );
678
-			} else {
675
+		if ('' !== $return) {
676
+			if (true === $echo) {
677
+				echo wp_kses_post($return);
678
+			}else {
679 679
 				return $return;
680 680
 			}
681 681
 		}
@@ -690,17 +690,17 @@  discard block
 block discarded – undo
690 690
 	 * @param $wrap bool
691 691
 	 * @return $html string
692 692
 	 */
693
-	public function itemd( $haystack = false, $needle = '', $type = '', $wrap = true ) {
693
+	public function itemd($haystack = false, $needle = '', $type = '', $wrap = true) {
694 694
 		$html = '';
695 695
 
696
-		if ( '' !== $type ) {
697
-			if ( ! is_array( $haystack ) ) {
698
-				$haystack = array( $haystack );
696
+		if ('' !== $type) {
697
+			if (!is_array($haystack)) {
698
+				$haystack = array($haystack);
699 699
 			}
700
-			if ( in_array( $needle, $haystack ) ) {
701
-				if ( true === $wrap || 'true' === $wrap ) {
702
-					$html = $type . '="' . $type . '"';
703
-				} else {
700
+			if (in_array($needle, $haystack)) {
701
+				if (true === $wrap || 'true' === $wrap) {
702
+					$html = $type.'="'.$type.'"';
703
+				}else {
704 704
 					$html = $type;
705 705
 				}
706 706
 			}
@@ -712,9 +712,9 @@  discard block
 block discarded – undo
712 712
 	/**
713 713
 	 * Grabs any attachments for the current item
714 714
 	 */
715
-	public function find_attachments( $id = false ) {
716
-		if ( false !== $id ) {
717
-			if ( empty( $this->found_attachments ) ) {
715
+	public function find_attachments($id = false) {
716
+		if (false !== $id) {
717
+			if (empty($this->found_attachments)) {
718 718
 				$attachments_args = array(
719 719
 					'post_parent'    => $id,
720 720
 					'post_status'    => 'inherit',
@@ -724,11 +724,11 @@  discard block
 block discarded – undo
724 724
 					'posts_per_page' => '-1',
725 725
 				);
726 726
 
727
-				$attachments = new WP_Query( $attachments_args );
727
+				$attachments = new WP_Query($attachments_args);
728 728
 
729
-				if ( $attachments->have_posts() ) {
730
-					foreach ( $attachments->posts as $attachment ) {
731
-						$this->found_attachments[ $attachment->ID ] = str_replace( array( '.jpg', '.png', '.jpeg' ), '', $attachment->post_title );
729
+				if ($attachments->have_posts()) {
730
+					foreach ($attachments->posts as $attachment) {
731
+						$this->found_attachments[$attachment->ID] = str_replace(array('.jpg', '.png', '.jpeg'), '', $attachment->post_title);
732 732
 					}
733 733
 				}
734 734
 			}
@@ -740,19 +740,19 @@  discard block
 block discarded – undo
740 740
 	/**
741 741
 	 * Saves the room data
742 742
 	 */
743
-	public function save_custom_field( $value = false, $meta_key, $id, $decrease = false, $unique = true ) {
744
-		if ( false !== $value ) {
745
-			if ( false !== $decrease ) {
746
-				$value = intval( $value );
743
+	public function save_custom_field($value = false, $meta_key, $id, $decrease = false, $unique = true) {
744
+		if (false !== $value) {
745
+			if (false !== $decrease) {
746
+				$value = intval($value);
747 747
 				$value--;
748 748
 			}
749 749
 
750
-			$prev = get_post_meta( $id, $meta_key, true );
750
+			$prev = get_post_meta($id, $meta_key, true);
751 751
 
752
-			if ( false !== $id && '0' !== $id && false !== $prev && true === $unique ) {
753
-				update_post_meta( $id, $meta_key, $value, $prev );
754
-			} else {
755
-				add_post_meta( $id, $meta_key, $value, $unique );
752
+			if (false !== $id && '0' !== $id && false !== $prev && true === $unique) {
753
+				update_post_meta($id, $meta_key, $value, $prev);
754
+			}else {
755
+				add_post_meta($id, $meta_key, $value, $unique);
756 756
 			}
757 757
 		}
758 758
 	}
@@ -761,15 +761,15 @@  discard block
 block discarded – undo
761 761
 	 * Grabs the custom fields,  and resaves an array of unique items.
762 762
 	 */
763 763
 	public function cleanup_posts() {
764
-		if ( ! empty( $this->cleanup_posts ) ) {
764
+		if (!empty($this->cleanup_posts)) {
765 765
 
766
-			foreach ( $this->cleanup_posts as $id => $key ) {
767
-				$prev_items = get_post_meta( $id, $key, false );
768
-				$new_items  = array_unique( $prev_items );
769
-				delete_post_meta( $id, $key );
766
+			foreach ($this->cleanup_posts as $id => $key) {
767
+				$prev_items = get_post_meta($id, $key, false);
768
+				$new_items  = array_unique($prev_items);
769
+				delete_post_meta($id, $key);
770 770
 
771
-				foreach ( $new_items as $new_item ) {
772
-					add_post_meta( $id, $key, $new_item, false );
771
+				foreach ($new_items as $new_item) {
772
+					add_post_meta($id, $key, $new_item, false);
773 773
 				}
774 774
 			}
775 775
 		}
@@ -780,26 +780,26 @@  discard block
 block discarded – undo
780 780
 	/**
781 781
 	 * Set_taxonomy with some terms
782 782
 	 */
783
-	public function set_taxonomy( $taxonomy, $terms, $id ) {
783
+	public function set_taxonomy($taxonomy, $terms, $id) {
784 784
 		$result = array();
785 785
 
786
-		if ( ! empty( $data ) ) {
787
-			foreach ( $data as $k ) {
788
-				if ( $id ) {
789
-					$term = term_exists( trim( $k ), $tax );
790
-					if ( ! $term ) {
791
-						$term = wp_insert_term( trim( $k ), $tax );
792
-
793
-						if ( is_wp_error( $term ) ) {
794
-							echo wp_kses_post( $term->get_error_message() );
795
-						} else {
796
-							wp_set_object_terms( $id, intval( $term['term_id'] ), $taxonomy, true );
786
+		if (!empty($data)) {
787
+			foreach ($data as $k) {
788
+				if ($id) {
789
+					$term = term_exists(trim($k), $tax);
790
+					if (!$term) {
791
+						$term = wp_insert_term(trim($k), $tax);
792
+
793
+						if (is_wp_error($term)) {
794
+							echo wp_kses_post($term->get_error_message());
795
+						}else {
796
+							wp_set_object_terms($id, intval($term['term_id']), $taxonomy, true);
797 797
 						}
798
-					} else {
799
-						wp_set_object_terms( $id, intval( $term['term_id'] ), $taxonomy, true );
798
+					}else {
799
+						wp_set_object_terms($id, intval($term['term_id']), $taxonomy, true);
800 800
 					}
801
-				} else {
802
-					$result[] = trim( $k );
801
+				}else {
802
+					$result[] = trim($k);
803 803
 				}
804 804
 			}
805 805
 		}
@@ -815,23 +815,23 @@  discard block
 block discarded – undo
815 815
 	 * @param boolean $parent
816 816
 	 * @return void
817 817
 	 */
818
-	public function set_term( $id = false, $name = false, $taxonomy = false, $parent = false ) {
819
-		$term = term_exists( $name, $taxonomy );
820
-		if ( ! $term ) {
821
-			if ( false !== $parent ) {
818
+	public function set_term($id = false, $name = false, $taxonomy = false, $parent = false) {
819
+		$term = term_exists($name, $taxonomy);
820
+		if (!$term) {
821
+			if (false !== $parent) {
822 822
 				$parent = array(
823 823
 					'parent' => $parent,
824 824
 				);
825 825
 			}
826
-			$term = wp_insert_term( trim( $name ), $taxonomy, $parent );
826
+			$term = wp_insert_term(trim($name), $taxonomy, $parent);
827 827
 
828
-			if ( is_wp_error( $term ) ) {
829
-				echo wp_kses_post( $term->get_error_message() );
830
-			} else {
831
-				wp_set_object_terms( $id, intval( $term['term_id'] ), $taxonomy, true );
828
+			if (is_wp_error($term)) {
829
+				echo wp_kses_post($term->get_error_message());
830
+			}else {
831
+				wp_set_object_terms($id, intval($term['term_id']), $taxonomy, true);
832 832
 			}
833
-		} else {
834
-			wp_set_object_terms( $id, intval( $term['term_id'] ), $taxonomy, true );
833
+		}else {
834
+			wp_set_object_terms($id, intval($term['term_id']), $taxonomy, true);
835 835
 		}
836 836
 
837 837
 		return $term['term_id'];
@@ -840,10 +840,10 @@  discard block
 block discarded – undo
840 840
 	/**
841 841
 	 * set_taxonomy with some terms
842 842
 	 */
843
-	public function taxonomy_checkboxes( $taxonomy = false, $selected = array() ) {
843
+	public function taxonomy_checkboxes($taxonomy = false, $selected = array()) {
844 844
 		$return = '';
845 845
 
846
-		if ( false !== $taxonomy ) {
846
+		if (false !== $taxonomy) {
847 847
 			$return .= '<ul>';
848 848
 			$terms   = get_terms(
849 849
 				array(
@@ -852,12 +852,12 @@  discard block
 block discarded – undo
852 852
 				)
853 853
 			);
854 854
 
855
-			if ( ! is_wp_error( $terms ) ) {
856
-				foreach ( $terms as $term ) {
857
-					$return .= '<li><input class="' . $taxonomy . '" ' . $this->checked( $selected, $term->term_id, false ) . ' type="checkbox" value="' . $term->term_id . '" /> ' . $term->name . '</li>';
855
+			if (!is_wp_error($terms)) {
856
+				foreach ($terms as $term) {
857
+					$return .= '<li><input class="'.$taxonomy.'" '.$this->checked($selected, $term->term_id, false).' type="checkbox" value="'.$term->term_id.'" /> '.$term->name.'</li>';
858 858
 				}
859
-			} else {
860
-				$return .= '<li><input type="checkbox" value="" /> ' . __( 'None', 'lsx-wetu-importer' ) . '</li>';
859
+			}else {
860
+				$return .= '<li><input type="checkbox" value="" /> '.__('None', 'lsx-wetu-importer').'</li>';
861 861
 			}
862 862
 
863 863
 			$return .= '</ul>';
@@ -871,44 +871,44 @@  discard block
 block discarded – undo
871 871
 	/**
872 872
 	 * Saves the longitude and lattitude, as well as sets the map marker.
873 873
 	 */
874
-	public function set_map_data( $data, $id, $zoom = '10' ) {
874
+	public function set_map_data($data, $id, $zoom = '10') {
875 875
 		$longitude = false;
876 876
 		$latitude  = false;
877 877
 		$address   = false;
878 878
 
879
-		if ( isset( $data[0]['position'] ) ) {
880
-			if ( isset( $data[0]['position']['driving_latitude'] ) ) {
879
+		if (isset($data[0]['position'])) {
880
+			if (isset($data[0]['position']['driving_latitude'])) {
881 881
 				$latitude = $data[0]['position']['driving_latitude'];
882
-			} elseif ( isset( $data[0]['position']['latitude'] ) ) {
882
+			} elseif (isset($data[0]['position']['latitude'])) {
883 883
 				$latitude = $data[0]['position']['latitude'];
884 884
 			}
885 885
 
886
-			if ( isset( $data[0]['position']['driving_longitude'] ) ) {
886
+			if (isset($data[0]['position']['driving_longitude'])) {
887 887
 				$longitude = $data[0]['position']['driving_longitude'];
888
-			} elseif ( isset( $data[0]['position']['longitude'] ) ) {
888
+			} elseif (isset($data[0]['position']['longitude'])) {
889 889
 				$longitude = $data[0]['position']['longitude'];
890 890
 			}
891 891
 		}
892 892
 
893
-		if ( isset( $data[0]['content'] ) && isset( $data[0]['content']['contact_information'] ) ) {
894
-			if ( isset( $data[0]['content']['contact_information']['address'] ) ) {
895
-				$address = strip_tags( $data[0]['content']['contact_information']['address'] );
896
-				$address = explode( "\n", $address );
893
+		if (isset($data[0]['content']) && isset($data[0]['content']['contact_information'])) {
894
+			if (isset($data[0]['content']['contact_information']['address'])) {
895
+				$address = strip_tags($data[0]['content']['contact_information']['address']);
896
+				$address = explode("\n", $address);
897 897
 
898
-				foreach ( $address as $bitkey => $bit ) {
899
-					$bit = ltrim( rtrim( $bit ) );
898
+				foreach ($address as $bitkey => $bit) {
899
+					$bit = ltrim(rtrim($bit));
900 900
 
901
-					if ( false === $bit || '' === $bit || null === $bit || empty( $bit ) ) {
902
-						unset( $address[ $bitkey ] );
901
+					if (false === $bit || '' === $bit || null === $bit || empty($bit)) {
902
+						unset($address[$bitkey]);
903 903
 					}
904 904
 				}
905 905
 
906
-				$address = implode( ', ', $address );
907
-				$address = str_replace( ', , ', ', ', $address );
906
+				$address = implode(', ', $address);
907
+				$address = str_replace(', , ', ', ', $address);
908 908
 			}
909 909
 		}
910 910
 
911
-		if ( false !== $longitude ) {
911
+		if (false !== $longitude) {
912 912
 			$location_data = array(
913 913
 				'address'   => (string) $address,
914 914
 				'lat'       => (string) $latitude,
@@ -917,11 +917,11 @@  discard block
 block discarded – undo
917 917
 				'elevation' => '',
918 918
 			);
919 919
 
920
-			if ( false !== $id && '0' !== $id ) {
921
-				$prev = get_post_meta( $id, 'location', true );
922
-				update_post_meta( $id, 'location', $location_data, $prev );
923
-			} else {
924
-				add_post_meta( $id, 'location', $location_data, true );
920
+			if (false !== $id && '0' !== $id) {
921
+				$prev = get_post_meta($id, 'location', true);
922
+				update_post_meta($id, 'location', $location_data, $prev);
923
+			}else {
924
+				add_post_meta($id, 'location', $location_data, true);
925 925
 			}
926 926
 		}
927 927
 	}
@@ -931,8 +931,8 @@  discard block
 block discarded – undo
931 931
 	/**
932 932
 	 * Creates the main gallery data
933 933
 	 */
934
-	public function set_featured_image( $data, $id ) {
935
-		if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) {
934
+	public function set_featured_image($data, $id) {
935
+		if (is_array($data[0]['content']['images']) && !empty($data[0]['content']['images'])) {
936 936
 			$this->featured_image = $this->attach_image(
937 937
 				$data[0]['content']['images'][0],
938 938
 				$id,
@@ -943,9 +943,9 @@  discard block
 block discarded – undo
943 943
 				)
944 944
 			);
945 945
 
946
-			if ( false !== $this->featured_image ) {
947
-				delete_post_meta( $id, '_thumbnail_id' );
948
-				add_post_meta( $id, '_thumbnail_id', $this->featured_image, true );
946
+			if (false !== $this->featured_image) {
947
+				delete_post_meta($id, '_thumbnail_id');
948
+				add_post_meta($id, '_thumbnail_id', $this->featured_image, true);
949 949
 			}
950 950
 		}
951 951
 	}
@@ -953,9 +953,9 @@  discard block
 block discarded – undo
953 953
 	/**
954 954
 	 * Sets a banner image
955 955
 	 */
956
-	public function set_banner_image( $data, $id, $content = array( 'none' ) ) {
957
-		if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) {
958
-			if ( in_array( 'unique_banner_image', $content ) && isset( $data[0]['destination_image'] ) && is_array( $data[0]['destination_image'] ) ) {
956
+	public function set_banner_image($data, $id, $content = array('none')) {
957
+		if (is_array($data[0]['content']['images']) && !empty($data[0]['content']['images'])) {
958
+			if (in_array('unique_banner_image', $content) && isset($data[0]['destination_image']) && is_array($data[0]['destination_image'])) {
959 959
 				$temp_banner = $this->attach_image(
960 960
 					$data[0]['destination_image'],
961 961
 					$id,
@@ -965,7 +965,7 @@  discard block
 block discarded – undo
965 965
 						'cropping' => 'c',
966 966
 					)
967 967
 				);
968
-			} else {
968
+			}else {
969 969
 				$temp_banner = $this->attach_image(
970 970
 					$data[0]['content']['images'][1],
971 971
 					$id,
@@ -977,10 +977,10 @@  discard block
 block discarded – undo
977 977
 				);
978 978
 			}
979 979
 
980
-			if ( false !== $temp_banner ) {
980
+			if (false !== $temp_banner) {
981 981
 				$this->banner_image = $temp_banner;
982 982
 
983
-				delete_post_meta( $id, 'image_group' );
983
+				delete_post_meta($id, 'image_group');
984 984
 
985 985
 				$new_banner = array(
986 986
 					'banner_image' => array(
@@ -988,7 +988,7 @@  discard block
 block discarded – undo
988 988
 					),
989 989
 				);
990 990
 
991
-				add_post_meta( $id, 'image_group', $new_banner, true );
991
+				add_post_meta($id, 'image_group', $new_banner, true);
992 992
 			}
993 993
 		}
994 994
 	}
@@ -996,13 +996,13 @@  discard block
 block discarded – undo
996 996
 	/**
997 997
 	 * Checks if the current image is being used as a thumbnail somewhere else.
998 998
 	 */
999
-	public function is_image_being_used( $image_id = '', $post_id = '' ) {
999
+	public function is_image_being_used($image_id = '', $post_id = '') {
1000 1000
 		global $wpdb;
1001 1001
 		$being_used = false;
1002
-		if ( '' !== $image_id ) {
1002
+		if ('' !== $image_id) {
1003 1003
 			$sql     = "SELECT * FROM `{$wpdb->postmeta}` WHERE `post_id` != {$post_id} AND `meta_key` LIKE '_thumbnail_id' AND `meta_value` LIKE '{$image_id}'";
1004
-			$results = $wpdb->query( $sql );
1005
-			if ( false !== $results && ! empty( $results ) ) {
1004
+			$results = $wpdb->query($sql);
1005
+			if (false !== $results && !empty($results)) {
1006 1006
 				$being_used = true;
1007 1007
 			}
1008 1008
 		}
@@ -1012,17 +1012,17 @@  discard block
 block discarded – undo
1012 1012
 	/**
1013 1013
 	 * Creates the main gallery data
1014 1014
 	 */
1015
-	public function create_main_gallery( $data, $id ) {
1016
-		if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) {
1017
-			if ( isset( $this->options['image_replacing'] ) && 'on' === $this->options['image_replacing'] ) {
1018
-				$current_gallery = get_post_meta( $id, 'gallery', false );
1015
+	public function create_main_gallery($data, $id) {
1016
+		if (is_array($data[0]['content']['images']) && !empty($data[0]['content']['images'])) {
1017
+			if (isset($this->options['image_replacing']) && 'on' === $this->options['image_replacing']) {
1018
+				$current_gallery = get_post_meta($id, 'gallery', false);
1019 1019
 
1020
-				if ( false !== $current_gallery && ! empty( $current_gallery ) ) {
1021
-					foreach ( $current_gallery as $g ) {
1022
-						delete_post_meta( $id, 'gallery', $g );
1020
+				if (false !== $current_gallery && !empty($current_gallery)) {
1021
+					foreach ($current_gallery as $g) {
1022
+						delete_post_meta($id, 'gallery', $g);
1023 1023
 
1024
-						if ( 'attachment' === get_post_type( $g ) && false === $this->is_image_being_used( $g, $id ) ) {
1025
-							wp_delete_attachment( $g, true );
1024
+						if ('attachment' === get_post_type($g) && false === $this->is_image_being_used($g, $id)) {
1025
+							wp_delete_attachment($g, true);
1026 1026
 						}
1027 1027
 					}
1028 1028
 				}
@@ -1030,32 +1030,32 @@  discard block
 block discarded – undo
1030 1030
 
1031 1031
 			$counter = 0;
1032 1032
 
1033
-			foreach ( $data[0]['content']['images'] as $image_data ) {
1034
-				if ( ( 0 === $counter && false !== $this->featured_image ) || ( 1 === $counter && false !== $this->banner_image ) ) {
1033
+			foreach ($data[0]['content']['images'] as $image_data) {
1034
+				if ((0 === $counter && false !== $this->featured_image) || (1 === $counter && false !== $this->banner_image)) {
1035 1035
 					$counter++;
1036 1036
 
1037
-					if ( false !== $this->image_limit && false !== $this->image_limit ) {
1037
+					if (false !== $this->image_limit && false !== $this->image_limit) {
1038 1038
 						$this->image_limit++;
1039 1039
 					}
1040 1040
 
1041 1041
 					continue;
1042 1042
 				}
1043 1043
 
1044
-				if ( false !== $this->image_limit && $counter >= $this->image_limit ) {
1044
+				if (false !== $this->image_limit && $counter >= $this->image_limit) {
1045 1045
 					continue;
1046 1046
 				}
1047 1047
 
1048
-				$this->gallery_meta[] = $this->attach_image( $image_data, $id );
1048
+				$this->gallery_meta[] = $this->attach_image($image_data, $id);
1049 1049
 				$counter++;
1050 1050
 			}
1051 1051
 
1052
-			if ( ! empty( $this->gallery_meta ) ) {
1053
-				delete_post_meta( $id, 'gallery' );
1054
-				$this->gallery_meta = array_unique( $this->gallery_meta );
1052
+			if (!empty($this->gallery_meta)) {
1053
+				delete_post_meta($id, 'gallery');
1054
+				$this->gallery_meta = array_unique($this->gallery_meta);
1055 1055
 
1056
-				foreach ( $this->gallery_meta as $gallery_id ) {
1057
-					if ( false !== $gallery_id && '' !== $gallery_id && ! is_array( $gallery_id ) ) {
1058
-						add_post_meta( $id, 'gallery', $gallery_id, false );
1056
+				foreach ($this->gallery_meta as $gallery_id) {
1057
+					if (false !== $gallery_id && '' !== $gallery_id && !is_array($gallery_id)) {
1058
+						add_post_meta($id, 'gallery', $gallery_id, false);
1059 1059
 					}
1060 1060
 				}
1061 1061
 			}
@@ -1065,7 +1065,7 @@  discard block
 block discarded – undo
1065 1065
 	/**
1066 1066
 	 * search_form
1067 1067
 	 */
1068
-	public function get_scaling_url( $args = array() ) {
1068
+	public function get_scaling_url($args = array()) {
1069 1069
 		$defaults = array(
1070 1070
 			'width'    => '1024',
1071 1071
 			'height'   => '768',
@@ -1073,59 +1073,59 @@  discard block
 block discarded – undo
1073 1073
 			'cropping' => 'h',
1074 1074
 		);
1075 1075
 
1076
-		if ( false !== $this->options ) {
1077
-			if ( isset( $this->options['width'] ) && '' !== $this->options['width'] ) {
1076
+		if (false !== $this->options) {
1077
+			if (isset($this->options['width']) && '' !== $this->options['width']) {
1078 1078
 				$defaults['width'] = $this->options['width'];
1079 1079
 			}
1080 1080
 
1081
-			if ( isset( $this->options['height'] ) && '' !== $this->options['height'] ) {
1081
+			if (isset($this->options['height']) && '' !== $this->options['height']) {
1082 1082
 				$defaults['height'] = $this->options['height'];
1083 1083
 			}
1084 1084
 
1085
-			if ( isset( $this->options['cropping'] ) && '' !== $this->options['cropping'] ) {
1085
+			if (isset($this->options['cropping']) && '' !== $this->options['cropping']) {
1086 1086
 				$defaults['cropping'] = $this->options['cropping'];
1087 1087
 			}
1088 1088
 		}
1089 1089
 
1090
-		$args     = wp_parse_args( $args, $defaults );
1090
+		$args     = wp_parse_args($args, $defaults);
1091 1091
 		$cropping = $args['cropping'];
1092 1092
 		$width    = $args['width'];
1093 1093
 		$height   = $args['height'];
1094 1094
 
1095
-		return 'https://wetu.com/ImageHandler/' . $cropping . $width . 'x' . $height . '/';
1095
+		return 'https://wetu.com/ImageHandler/'.$cropping.$width.'x'.$height.'/';
1096 1096
 	}
1097 1097
 
1098 1098
 	/**
1099 1099
 	 * Attaches 1 image
1100 1100
 	 */
1101
-	public function attach_image( $v = false, $parent_id, $image_sizes = false, $banner = false ) {
1102
-		if ( false !== $v ) {
1103
-			$temp_fragment = explode( '/', $v['url_fragment'] );
1104
-			$url_filename  = $temp_fragment[ count( $temp_fragment ) - 1 ];
1105
-			$url_filename  = str_replace( array( '.jpg', '.png', '.jpeg' ), '', $url_filename );
1106
-			$url_filename  = trim( $url_filename );
1101
+	public function attach_image($v = false, $parent_id, $image_sizes = false, $banner = false) {
1102
+		if (false !== $v) {
1103
+			$temp_fragment = explode('/', $v['url_fragment']);
1104
+			$url_filename  = $temp_fragment[count($temp_fragment) - 1];
1105
+			$url_filename  = str_replace(array('.jpg', '.png', '.jpeg'), '', $url_filename);
1106
+			$url_filename  = trim($url_filename);
1107 1107
 			$title         = $url_filename;
1108
-			$url_filename  = str_replace( ' ', '_', $url_filename );
1108
+			$url_filename  = str_replace(' ', '_', $url_filename);
1109 1109
 
1110
-			if ( ! isset( $this->options['image_replacing'] ) && in_array( $url_filename, $this->found_attachments ) ) {
1111
-				return array_search( $url_filename, $this->found_attachments );
1110
+			if (!isset($this->options['image_replacing']) && in_array($url_filename, $this->found_attachments)) {
1111
+				return array_search($url_filename, $this->found_attachments);
1112 1112
 			}
1113 1113
 
1114 1114
 			$postdata = array();
1115 1115
 
1116
-			if ( empty( $v['label'] ) ) {
1116
+			if (empty($v['label'])) {
1117 1117
 				$v['label'] = '';
1118 1118
 			}
1119 1119
 
1120
-			if ( ! empty( $v['description'] ) ) {
1121
-				$desc    = wp_strip_all_tags( $v['description'] );
1120
+			if (!empty($v['description'])) {
1121
+				$desc    = wp_strip_all_tags($v['description']);
1122 1122
 				$posdata = array(
1123 1123
 					'post_excerpt' => $desc,
1124 1124
 				);
1125 1125
 			}
1126 1126
 
1127
-			if ( ! empty( $v['section'] ) ) {
1128
-				$desc    = wp_strip_all_tags( $v['section'] );
1127
+			if (!empty($v['section'])) {
1128
+				$desc    = wp_strip_all_tags($v['section']);
1129 1129
 				$posdata = array(
1130 1130
 					'post_excerpt' => $desc,
1131 1131
 				);
@@ -1133,83 +1133,83 @@  discard block
 block discarded – undo
1133 1133
 
1134 1134
 			$attach_id = null;
1135 1135
 			// Resizor - add option to setting if required.
1136
-			$fragment  = str_replace( ' ', '%20', $v['url_fragment'] );
1137
-			$url       = $this->get_scaling_url( $image_sizes ) . $fragment;
1138
-			$attach_id = $this->attach_external_image2( $url, $parent_id, '', $v['label'], $postdata );
1139
-			if ( ! empty( $attach_id ) ) {
1140
-				$this->found_attachments[ $attach_id ] = $url_filename;
1141
-				add_post_meta( $attach_id, 'lsx_wetu_id', $v['url_fragment'], true );
1136
+			$fragment  = str_replace(' ', '%20', $v['url_fragment']);
1137
+			$url       = $this->get_scaling_url($image_sizes).$fragment;
1138
+			$attach_id = $this->attach_external_image2($url, $parent_id, '', $v['label'], $postdata);
1139
+			if (!empty($attach_id)) {
1140
+				$this->found_attachments[$attach_id] = $url_filename;
1141
+				add_post_meta($attach_id, 'lsx_wetu_id', $v['url_fragment'], true);
1142 1142
 				return $attach_id;
1143 1143
 			}
1144 1144
 		}
1145 1145
 		return false;
1146 1146
 	}
1147 1147
 
1148
-	public function attach_external_image2( $url = null, $post_id = null, $thumb = null, $filename = null, $post_data = array() ) {
1149
-		if ( ! $url || ! $post_id ) {
1150
-			return new WP_Error( 'missing', 'Need a valid URL and post ID...' ); }
1148
+	public function attach_external_image2($url = null, $post_id = null, $thumb = null, $filename = null, $post_data = array()) {
1149
+		if (!$url || !$post_id) {
1150
+			return new WP_Error('missing', 'Need a valid URL and post ID...'); }
1151 1151
 		$att_id = false;
1152 1152
 
1153
-		require_once ABSPATH . 'wp-admin/includes/file.php';
1154
-		require_once ABSPATH . 'wp-admin/includes/media.php';
1155
-		require_once ABSPATH . 'wp-admin/includes/image.php';
1153
+		require_once ABSPATH.'wp-admin/includes/file.php';
1154
+		require_once ABSPATH.'wp-admin/includes/media.php';
1155
+		require_once ABSPATH.'wp-admin/includes/image.php';
1156 1156
 		// Download file to temp location, returns full server path to temp file.
1157 1157
 
1158
-		$tmp   = tempnam( '/tmp', 'FOO' );
1159
-		$image = wp_remote_get( $url );
1160
-		if ( ! is_wp_error( $image ) && ! empty( $image ) && isset( $image['response'] ) && isset( $image['response']['code'] ) && 200 === $image['response']['code'] ) {
1161
-			file_put_contents( $tmp, $image['body'] );
1162
-			chmod( $tmp, '777' );
1158
+		$tmp   = tempnam('/tmp', 'FOO');
1159
+		$image = wp_remote_get($url);
1160
+		if (!is_wp_error($image) && !empty($image) && isset($image['response']) && isset($image['response']['code']) && 200 === $image['response']['code']) {
1161
+			file_put_contents($tmp, $image['body']);
1162
+			chmod($tmp, '777');
1163 1163
 
1164
-			preg_match( '/[^\?]+\.(tif|TIFF|jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG|pdf|PDF|bmp|BMP)/', $url, $matches );    // fix file filename for query strings
1165
-			$url_filename = basename( $matches[0] );
1166
-			$url_filename = str_replace( '%20', '_', $url_filename );
1164
+			preg_match('/[^\?]+\.(tif|TIFF|jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG|pdf|PDF|bmp|BMP)/', $url, $matches); // fix file filename for query strings
1165
+			$url_filename = basename($matches[0]);
1166
+			$url_filename = str_replace('%20', '_', $url_filename);
1167 1167
 			// extract filename from url for title
1168
-			$url_type = wp_check_filetype( $url_filename );                                           // determine file type (ext and mime/type)
1168
+			$url_type = wp_check_filetype($url_filename); // determine file type (ext and mime/type)
1169 1169
 
1170 1170
 			// override filename if given, reconstruct server path.
1171
-			if ( ! empty( $filename ) && ' ' != $filename ) {
1172
-				$filename = sanitize_file_name( $filename );
1173
-				$tmppath  = pathinfo( $tmp );
1171
+			if (!empty($filename) && ' ' != $filename) {
1172
+				$filename = sanitize_file_name($filename);
1173
+				$tmppath  = pathinfo($tmp);
1174 1174
 
1175 1175
 				$extension = '';
1176
-				if ( isset( $tmppath['extension'] ) ) {
1176
+				if (isset($tmppath['extension'])) {
1177 1177
 					$extension = $tmppath['extension'];
1178 1178
 				}
1179 1179
 
1180
-				$new = $tmppath['dirname'] . '/' . $filename . '.' . $extension;
1181
-				rename( $tmp, $new );                                                                 // renames temp file on server
1182
-				$tmp = $new;                                                                        // push new filename (in path) to be used in file array later
1180
+				$new = $tmppath['dirname'].'/'.$filename.'.'.$extension;
1181
+				rename($tmp, $new); // renames temp file on server
1182
+				$tmp = $new; // push new filename (in path) to be used in file array later
1183 1183
 			}
1184 1184
 
1185 1185
 			// assemble file data (should be built like $_FILES since wp_handle_sideload() will be using).
1186
-			$file_array['tmp_name'] = $tmp;                                                         // full server path to temp file
1186
+			$file_array['tmp_name'] = $tmp; // full server path to temp file
1187 1187
 
1188
-			if ( ! empty( $filename ) && ' ' != $filename ) {
1189
-				$file_array['name'] = $filename . '.' . $url_type['ext'];                           // user given filename for title, add original URL extension
1190
-			} else {
1191
-				$file_array['name'] = $url_filename;                                                // just use original URL filename
1188
+			if (!empty($filename) && ' ' != $filename) {
1189
+				$file_array['name'] = $filename.'.'.$url_type['ext']; // user given filename for title, add original URL extension
1190
+			}else {
1191
+				$file_array['name'] = $url_filename; // just use original URL filename
1192 1192
 			}
1193 1193
 
1194 1194
 			// set additional wp_posts columns.
1195
-			if ( empty( $post_data['post_title'] ) ) {
1195
+			if (empty($post_data['post_title'])) {
1196 1196
 
1197
-				$url_filename = str_replace( '%20', ' ', $url_filename );
1197
+				$url_filename = str_replace('%20', ' ', $url_filename);
1198 1198
 
1199
-				$post_data['post_title'] = basename( $url_filename, '.' . $url_type['ext'] );         // just use the original filename (no extension)
1199
+				$post_data['post_title'] = basename($url_filename, '.'.$url_type['ext']); // just use the original filename (no extension)
1200 1200
 			}
1201 1201
 
1202 1202
 			// make sure gets tied to parent.
1203
-			if ( empty( $post_data['post_parent'] ) ) {
1203
+			if (empty($post_data['post_parent'])) {
1204 1204
 				$post_data['post_parent'] = $post_id;
1205 1205
 			}
1206 1206
 
1207 1207
 			// do the validation and storage stuff.
1208
-			$att_id = media_handle_sideload( $file_array, $post_id, null, $post_data );             // $post_data can override the items saved to wp_posts table, like post_mime_type, guid, post_parent, post_title, post_content, post_status
1208
+			$att_id = media_handle_sideload($file_array, $post_id, null, $post_data); // $post_data can override the items saved to wp_posts table, like post_mime_type, guid, post_parent, post_title, post_content, post_status
1209 1209
 
1210 1210
 			// If error storing permanently, unlink.
1211
-			if ( is_wp_error( $att_id ) ) {
1212
-				unlink( $file_array['tmp_name'] );
1211
+			if (is_wp_error($att_id)) {
1212
+				unlink($file_array['tmp_name']);
1213 1213
 				return false;
1214 1214
 			}
1215 1215
 		}
@@ -1236,33 +1236,33 @@  discard block
 block discarded – undo
1236 1236
 	/**
1237 1237
 	 * Formats the row for the completed list.
1238 1238
 	 */
1239
-	public function format_completed_row( $response ) {
1240
-		echo wp_kses_post( '<li class="post-' . $response . '"><span class="dashicons dashicons-yes"></span> <a target="_blank" href="' . get_permalink( $response ) . '">' . get_the_title( $response ) . '</a></li>' );
1239
+	public function format_completed_row($response) {
1240
+		echo wp_kses_post('<li class="post-'.$response.'"><span class="dashicons dashicons-yes"></span> <a target="_blank" href="'.get_permalink($response).'">'.get_the_title($response).'</a></li>');
1241 1241
 	}
1242 1242
 
1243 1243
 	/**
1244 1244
 	 * Formats the error.
1245 1245
 	 */
1246
-	public function format_error( $response ) {
1247
-		echo wp_kses_post( '<li class="post-error"><span class="dashicons dashicons-no"></span>' . $response . '</li>' );
1246
+	public function format_error($response) {
1247
+		echo wp_kses_post('<li class="post-error"><span class="dashicons dashicons-no"></span>'.$response.'</li>');
1248 1248
 	}
1249 1249
 
1250 1250
 	/**
1251 1251
 	 * Does a multine search
1252 1252
 	 */
1253
-	public function multineedle_stripos( $haystack, $needles, $offset = 0 ) {
1253
+	public function multineedle_stripos($haystack, $needles, $offset = 0) {
1254 1254
 		$found        = false;
1255
-		$needle_count = count( $needles );
1255
+		$needle_count = count($needles);
1256 1256
 
1257
-		foreach ( $needles as $needle ) {
1258
-			if ( false !== stripos( $haystack, $needle, $offset ) ) {
1257
+		foreach ($needles as $needle) {
1258
+			if (false !== stripos($haystack, $needle, $offset)) {
1259 1259
 				$found[] = true;
1260 1260
 			}
1261 1261
 		}
1262 1262
 
1263
-		if ( false !== $found && count( $found ) === $needle_count ) {
1263
+		if (false !== $found && count($found) === $needle_count) {
1264 1264
 			return true;
1265
-		} else {
1265
+		}else {
1266 1266
 			return false;
1267 1267
 		}
1268 1268
 	}
@@ -1270,7 +1270,7 @@  discard block
 block discarded – undo
1270 1270
 	/**
1271 1271
 	 * Grab all the current accommodation posts via the lsx_wetu_id field.
1272 1272
 	 */
1273
-	public function find_current_accommodation( $post_type = 'accommodation' ) {
1273
+	public function find_current_accommodation($post_type = 'accommodation') {
1274 1274
 		global $wpdb;
1275 1275
 		$return = array();
1276 1276
 
@@ -1289,9 +1289,9 @@  discard block
 block discarded – undo
1289 1289
 		");
1290 1290
 		// @codingStandardsIgnoreEnd
1291 1291
 
1292
-		if ( null !== $current_accommodation && ! empty( $current_accommodation ) ) {
1293
-			foreach ( $current_accommodation as $accom ) {
1294
-				$return[ $accom->meta_value ] = $accom;
1292
+		if (null !== $current_accommodation && !empty($current_accommodation)) {
1293
+			foreach ($current_accommodation as $accom) {
1294
+				$return[$accom->meta_value] = $accom;
1295 1295
 			}
1296 1296
 		}
1297 1297
 
@@ -1301,20 +1301,20 @@  discard block
 block discarded – undo
1301 1301
 	/**
1302 1302
 	 * Set the Video date
1303 1303
 	 */
1304
-	public function set_video_data( $data, $id ) {
1305
-		if ( ! empty( $data[0]['content']['youtube_videos'] ) && is_array( $data[0]['content']['youtube_videos'] ) ) {
1304
+	public function set_video_data($data, $id) {
1305
+		if (!empty($data[0]['content']['youtube_videos']) && is_array($data[0]['content']['youtube_videos'])) {
1306 1306
 			$videos = false;
1307 1307
 
1308
-			foreach ( $data[0]['content']['youtube_videos'] as $video ) {
1308
+			foreach ($data[0]['content']['youtube_videos'] as $video) {
1309 1309
 				$temp_video = array();
1310 1310
 
1311
-				if ( isset( $video['label'] ) ) {
1311
+				if (isset($video['label'])) {
1312 1312
 					$temp_video['title'] = $video['label'];
1313 1313
 				}
1314
-				if ( isset( $video['description'] ) ) {
1315
-					$temp_video['description'] = strip_tags( $video['description'] );
1314
+				if (isset($video['description'])) {
1315
+					$temp_video['description'] = strip_tags($video['description']);
1316 1316
 				}
1317
-				if ( isset( $video['url'] ) ) {
1317
+				if (isset($video['url'])) {
1318 1318
 					$temp_video['url'] = $video['url'];
1319 1319
 				}
1320 1320
 
@@ -1322,24 +1322,24 @@  discard block
 block discarded – undo
1322 1322
 				$videos[]                = $temp_video;
1323 1323
 			}
1324 1324
 
1325
-			if ( false !== $id && '0' !== $id ) {
1326
-				delete_post_meta( $id, 'videos' );
1325
+			if (false !== $id && '0' !== $id) {
1326
+				delete_post_meta($id, 'videos');
1327 1327
 			}
1328 1328
 
1329
-			foreach ( $videos as $video ) {
1330
-				add_post_meta( $id, 'videos', $video, false );
1329
+			foreach ($videos as $video) {
1330
+				add_post_meta($id, 'videos', $video, false);
1331 1331
 			}
1332 1332
 		}
1333 1333
 	}
1334 1334
 
1335
-	public function shuffle_assoc( &$array ) {
1335
+	public function shuffle_assoc(&$array) {
1336 1336
 		$new  = array();
1337
-		$keys = array_keys( $array );
1337
+		$keys = array_keys($array);
1338 1338
 
1339
-		shuffle( $keys );
1339
+		shuffle($keys);
1340 1340
 
1341
-		foreach ( $keys as $key ) {
1342
-			$new[ $key ] = $array[ $key ];
1341
+		foreach ($keys as $key) {
1342
+			$new[$key] = $array[$key];
1343 1343
 		}
1344 1344
 
1345 1345
 		$array = $new;
@@ -1353,31 +1353,31 @@  discard block
 block discarded – undo
1353 1353
 	public function update_options() {
1354 1354
 		$own     = '';
1355 1355
 		$options = array();
1356
-		delete_option( 'lsx_ti_tours_api_options' );
1356
+		delete_option('lsx_ti_tours_api_options');
1357 1357
 
1358
-		if ( isset( $_GET['own'] ) ) {
1358
+		if (isset($_GET['own'])) {
1359 1359
 			$this->current_importer->url_qs .= '&own=true';
1360 1360
 			$options[]                       = 'own';
1361 1361
 		}
1362 1362
 
1363
-		if ( isset( $_GET['type'] ) && 'allitineraries' !== $_GET['type'] ) {
1364
-			$this->current_importer->url_qs .= '&type=' . $_GET['type'];
1363
+		if (isset($_GET['type']) && 'allitineraries' !== $_GET['type']) {
1364
+			$this->current_importer->url_qs .= '&type='.$_GET['type'];
1365 1365
 			$options[]                       = $_GET['type'];
1366
-		} else {
1366
+		}else {
1367 1367
 			$options[]                       = 'sample';
1368 1368
 			$this->current_importer->url_qs .= '&type=sample';
1369 1369
 		}
1370 1370
 
1371
-		$url  = str_replace( 'Pins', 'Itinerary', $this->current_importer->url . '/V8/List?' . $this->current_importer->url_qs );
1371
+		$url  = str_replace('Pins', 'Itinerary', $this->current_importer->url.'/V8/List?'.$this->current_importer->url_qs);
1372 1372
 		$url .= '&results=2000';
1373
-		add_option( 'lsx_ti_tours_api_options', $options );
1374
-		$data  = wp_remote_get( $url );
1375
-		$tours = json_decode( wp_remote_retrieve_body( $data ), true );
1373
+		add_option('lsx_ti_tours_api_options', $options);
1374
+		$data  = wp_remote_get($url);
1375
+		$tours = json_decode(wp_remote_retrieve_body($data), true);
1376 1376
 
1377
-		if ( isset( $tours['error'] ) ) {
1377
+		if (isset($tours['error'])) {
1378 1378
 			return $tours['error'];
1379
-		} elseif ( isset( $tours['itineraries'] ) && ! empty( $tours['itineraries'] ) ) {
1380
-			set_transient( 'lsx_ti_tours', $tours['itineraries'], 60 * 60 * 4 );
1379
+		} elseif (isset($tours['itineraries']) && !empty($tours['itineraries'])) {
1380
+			set_transient('lsx_ti_tours', $tours['itineraries'], 60 * 60 * 4);
1381 1381
 			return true;
1382 1382
 		}
1383 1383
 	}
@@ -1388,12 +1388,12 @@  discard block
 block discarded – undo
1388 1388
 	 * @param boolean $wetu_id
1389 1389
 	 * @return string
1390 1390
 	 */
1391
-	public function get_post_id_by_key_value( $wetu_id = false ) {
1391
+	public function get_post_id_by_key_value($wetu_id = false) {
1392 1392
 		global $wpdb;
1393 1393
 		$id = false;
1394
-		if ( false !== $wetu_id && '' !== $wetu_id ) {
1395
-			$result = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM `$wpdb->postmeta` WHERE `meta_key` = 'lsx_wetu_id' AND `meta_value` = '%s'", array( $wetu_id ) ) );
1396
-			if ( false !== $result && ! empty( $result ) ) {
1394
+		if (false !== $wetu_id && '' !== $wetu_id) {
1395
+			$result = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM `$wpdb->postmeta` WHERE `meta_key` = 'lsx_wetu_id' AND `meta_value` = '%s'", array($wetu_id)));
1396
+			if (false !== $result && !empty($result)) {
1397 1397
 				$id = $result;
1398 1398
 			}
1399 1399
 		}
@@ -1402,11 +1402,11 @@  discard block
 block discarded – undo
1402 1402
 	/**
1403 1403
 	 * Set the team memberon each item.
1404 1404
 	 */
1405
-	public function set_team_member( $id, $team_members ) {
1406
-		delete_post_meta( $id, 'team_to_' . $this->tab_slug );
1405
+	public function set_team_member($id, $team_members) {
1406
+		delete_post_meta($id, 'team_to_'.$this->tab_slug);
1407 1407
 
1408
-		foreach ( $team_members as $team ) {
1409
-			add_post_meta( $id, 'team_to_' . $this->tab_slug, $team );
1408
+		foreach ($team_members as $team) {
1409
+			add_post_meta($id, 'team_to_'.$this->tab_slug, $team);
1410 1410
 		}
1411 1411
 	}
1412 1412
 }
Please login to merge, or discard this patch.
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'] ) ) {
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'] ) ) {
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'] ) ) {
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'])) {
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.
classes/class-cron.php 2 patches
Indentation   +283 added lines, -283 removed lines patch added patch discarded remove patch
@@ -16,288 +16,288 @@
 block discarded – undo
16 16
  */
17 17
 class Cron {
18 18
 
19
-	/**
20
-	 * Holds class instance
21
-	 *
22
-	 * @since 1.0.0
23
-	 *
24
-	 * @var      object|Module_Template
25
-	 */
26
-	protected static $instance = null;
27
-
28
-	/**
29
-	 * Initialize the plugin by setting localization, filters, and administration functions.
30
-	 *
31
-	 * @since 1.0.0
32
-	 *
33
-	 * @access private
34
-	 */
35
-	public function __construct() {
36
-		add_filter( 'cron_schedules', array( $this, 'register_schedule' ), 10, 1 );
37
-		add_action( 'lsx_wetu_importer_settings_before', array( $this, 'watch_for_trigger' ), 200 );
38
-		add_action( 'lsx_wetu_accommodation_images_cron', array( $this, 'process' ), 10, 1 );
39
-		add_action( 'lsx_wetu_accommodation_images_sync', array( $this, 'cron_callback' ), 10, 1 );
40
-		add_filter( 'cmb_meta_boxes', array( $this, 'metaboxes' ) );
41
-	}
42
-
43
-	/**
44
-	 * Return an instance of this class.
45
-	 *
46
-	 * @since 1.0.0
47
-	 *
48
-	 * @return    object Cron()    A single instance of this class.
49
-	 */
50
-	public static function get_instance() {
51
-		// If the single instance hasn't been set, set it now.
52
-		if ( null === self::$instance ) {
53
-			self::$instance = new self();
54
-		}
55
-		return self::$instance;
56
-	}
57
-
58
-	/**
59
-	 * Define the metabox and field configurations.
60
-	 *
61
-	 * @param  array $meta_boxes
62
-	 * @return array
63
-	 */
64
-	public function metaboxes( array $meta_boxes ) {
65
-		// Allowed post types.
66
-		$allowed_post_types = array( 'accommodation' );
67
-
68
-		$fields = array();
69
-
70
-		$fields[] = array(
71
-			'id'   => 'wetu_skip_banner',
72
-			'name' => esc_html__( 'Skip Banner Image', 'lsx-banners' ),
73
-			'type' => 'checkbox',
74
-		);
75
-
76
-		$fields[] = array(
77
-			'id'   => 'wetu_skip_featured',
78
-			'name' => esc_html__( 'Skip Featured Image', 'lsx-banners' ),
79
-			'type' => 'checkbox',
80
-		);
81
-
82
-		$meta_boxes[] = array(
83
-			'title'    => esc_html__( 'WETU Settings', 'lsx-banners' ),
84
-			'pages'    => $allowed_post_types,
85
-			'fields'   => $fields,
86
-			'context'  => 'side',
87
-			'priority' => 'low',
88
-		);
89
-
90
-		return $meta_boxes;
91
-	}
92
-
93
-	/**
94
-	 * Registers a 5 min schedule for us to use.
95
-	 *
96
-	 * @param  array $schedules
97
-	 * @return array
98
-	 */
99
-	public function register_schedule( $schedules ) {
100
-		$schedules['wetu-5-minutes'] = array(
101
-			'interval' => 5 * MINUTE_IN_SECONDS,
102
-			'display'  => __( 'Every 5 minutes', 'lsx-wetu-importer' ),
103
-		);
104
-		return $schedules;
105
-	}
106
-
107
-	/**
108
-	 * Watches for changes in the button triggers.
109
-	 *
110
-	 * @return void
111
-	 */
112
-	public function watch_for_trigger() {
113
-
114
-		if ( isset( $_GET['page'] ) && 'lsx-wetu-importer' === $_GET['page'] && isset( $_GET['tab'] ) && 'settings' === $_GET['tab'] ) {
115
-			$options = lsx_wetu_get_options();
116
-
117
-			// Check what state the option is in.
118
-			$accommodation_cron = 'deactivate';
119
-			if ( isset( $options['accommodation_images_cron'] ) && '' !== $options['accommodation_images_cron'] ) {
120
-				$accommodation_cron = 'activate';
121
-			}
122
-
123
-			// Check what state the cron is in.
124
-			$scheduled = false;
125
-			if ( wp_next_scheduled( 'lsx_wetu_accommodation_images_cron' ) ) {
126
-				$scheduled = true;
127
-			}
128
-
129
-			// If activate and its not running.
130
-			if ( false === $scheduled && 'activate' === $accommodation_cron ) {
131
-				$schedule = 'weekly';
132
-				$this->schedule( 'lsx_wetu_accommodation_images_cron', $schedule );
133
-			} elseif ( true === $scheduled && 'deactivate' === $accommodation_cron ) {
134
-				$this->deactivate();
135
-			}
136
-		}
137
-	}
138
-
139
-	/**
140
-	 * Remove our cron from the shedule.
141
-	 *
142
-	 * @return void
143
-	 */
144
-	public function deactivate( $task = 'lsx_wetu_accommodation_images_cron' ) {
145
-		wp_clear_scheduled_hook( $task, array( $task ) );
146
-	}
147
-
148
-	/**
149
-	 * This function will schedule the cron event.
150
-	 *
151
-	 * @param string $task
152
-	 * @param string $schedule
153
-	 * @param string $time
154
-	 * @return void
155
-	 */
156
-	public function schedule( $task = 'lsx_wetu_accommodation_images_cron', $schedule = 'weekly', $time = 'Sunday 10pm' ) {
157
-		$args = array( $task );
158
-		if ( '' === $time ) {
159
-			$time = time();
160
-		}
161
-
162
-		if ( isset( $_GET['accommodation_images_cron_featured'] ) && '' !== $_GET['accommodation_images_cron_featured'] ) {
163
-			$args[] = 'featured_image';
164
-		}
165
-		wp_schedule_event( $time, $schedule, $task, $args );
166
-	}
167
-
168
-	/**
169
-	 * This is the function that will be triggered by the cron event.
170
-	 *
171
-	 * @return void
172
-	 */
173
-	public function process( $task = '' ) {
174
-		switch ( $task ) {
175
-			case 'lsx_wetu_accommodation_images_cron':
176
-					$this->register_accommodation_images_sync();
177
-				break;
178
-
179
-			default:
180
-				break;
181
-		}
182
-	}
183
-
184
-	/**
185
-	 * This is the function that will be triggered by the cron event.
186
-	 *
187
-	 * @return void
188
-	 */
189
-	public function register_accommodation_images_sync() {
190
-		$time = strtotime( '+5 min' );
191
-		if ( ! wp_next_scheduled( 'lsx_wetu_accommodation_images_sync' ) ) {
192
-			$this->load_items_to_sync( 'accommodation_images' );
193
-			$this->schedule( 'lsx_wetu_accommodation_images_sync', 'wetu-5-minutes', $time );
194
-		}
195
-	}
196
-
197
-	/**
198
-	 * This is the function that will be triggered by the cron event.
199
-	 *
200
-	 * @return void
201
-	 */
202
-	public function cron_callback( $task = '', $featured_image = '' ) {
203
-		$has_accommodation = get_option( $task );
204
-		if ( false !== $has_accommodation && ! empty( $has_accommodation ) ) {
205
-			$next_time = array_slice( $has_accommodation, 3 );
206
-			$this_time = array_slice( $has_accommodation, 0, 2 );
207
-
208
-			$api_key = $this->get_api_key();
209
-			$url     = 'https://wetu.com/API/Pins/' . $api_key . '/Get?all=include&ids=';
210
-
211
-			// Run through the current items.
212
-			foreach ( $this_time as $accommodation ) {
213
-				$wetu_id   = get_post_meta( $accommodation, 'lsx_wetu_id', true );
214
-				$last_date = get_post_meta( $accommodation, 'lsx_wetu_modified_date', true );
215
-
216
-				// Grabbing the image sync.
217
-				$featured_image = get_post_meta( $accommodation, 'wetu_skip_featured', true );
218
-				$banner_image   = get_post_meta( $accommodation, 'wetu_skip_banner', true );
219
-
220
-				$accommodation_info = wp_remote_get( $url . $wetu_id );
221
-				if ( ! empty( $accommodation_info ) && isset( $accommodation_info['response'] ) && isset( $accommodation_info['response']['code'] ) && 200 === $accommodation_info['response']['code'] ) {
222
-					$adata = json_decode( $accommodation_info['body'], true );
223
-
224
-					if ( isset( $adata[0] ) && isset( $adata[0]['last_modified'] ) && '' !== $adata[0]['last_modified'] ) {
225
-						$modified_time = strtotime( $adata[0]['last_modified'] );
226
-						if ( $modified_time > $last_date ) {
227
-							$accommodation_importer = new \LSX_WETU_Importer_Accommodation();
228
-
229
-							if ( false === $banner_image || '' === $banner_image ) {
230
-								$accommodation_importer->set_banner_image( $adata, $accommodation );
231
-							}
232
-
233
-							if ( false === $featured_image || '' === $featured_image ) {
234
-								$accommodation_importer->set_featured_image( $adata, $accommodation );
235
-							}
236
-
237
-							$accommodation_importer->create_main_gallery( $adata, $accommodation );
238
-							update_post_meta( $accommodation, 'lsx_wetu_modified_date', $modified_time, $last_date );
239
-						}
240
-					}
241
-				}
242
-			}
243
-
244
-			// Save the values for next time.
245
-			if ( ! empty( $next_time ) ) {
246
-				update_option( $task, $next_time );
247
-			} else {
248
-				delete_option( $task );
249
-				$this->deactivate( $task );
250
-			}
251
-		} else {
252
-			$this->deactivate( $task );
253
-			update_option( 'lsx_wetu_nexttime', $task );
254
-		}
255
-	}
256
-
257
-	/**
258
-	 * This will grab the accommodation ids and load them up into an option field.
259
-	 *
260
-	 * @param  string $task
261
-	 * @return void
262
-	 */
263
-	public function load_items_to_sync( $task = 'accommodation_images' ) {
264
-		$args = array(
265
-			'post_status'    => 'publish',
266
-			'posts_per_page' => -1,
267
-			'nopagin'        => true,
268
-			'fields'         => 'ids',
269
-		);
270
-		switch ( $task ) {
271
-			case 'accommodation_images':
272
-					$args['post_type'] = 'accommodation';
273
-				break;
274
-
275
-			default:
276
-				break;
277
-		}
278
-		$items = new \WP_Query( $args );
279
-		if ( $items->have_posts() ) {
280
-			update_option( 'lsx_wetu_' . $task . '_sync', $items->posts );
281
-		}
282
-	}
283
-
284
-	/**
285
-	 * Gets the API key stored in the options table.
286
-	 *
287
-	 * @return string
288
-	 */
289
-	public function get_api_key() {
290
-		$api_key = false;
291
-		$options = lsx_wetu_get_options();
292
-
293
-		if ( ! defined( 'WETU_API_KEY' ) ) {
294
-			if ( isset( $options['api_key'] ) && '' !== $options['api_key'] ) {
295
-				$api_key = $options['api_key'];
296
-			}
297
-		} else {
298
-			$api_key = WETU_API_KEY;
299
-		}
300
-		return $api_key;
301
-	}
19
+     /**
20
+      * Holds class instance
21
+      *
22
+      * @since 1.0.0
23
+      *
24
+      * @var      object|Module_Template
25
+      */
26
+     protected static $instance = null;
27
+
28
+     /**
29
+      * Initialize the plugin by setting localization, filters, and administration functions.
30
+      *
31
+      * @since 1.0.0
32
+      *
33
+      * @access private
34
+      */
35
+     public function __construct() {
36
+          add_filter( 'cron_schedules', array( $this, 'register_schedule' ), 10, 1 );
37
+          add_action( 'lsx_wetu_importer_settings_before', array( $this, 'watch_for_trigger' ), 200 );
38
+          add_action( 'lsx_wetu_accommodation_images_cron', array( $this, 'process' ), 10, 1 );
39
+          add_action( 'lsx_wetu_accommodation_images_sync', array( $this, 'cron_callback' ), 10, 1 );
40
+          add_filter( 'cmb_meta_boxes', array( $this, 'metaboxes' ) );
41
+     }
42
+
43
+     /**
44
+      * Return an instance of this class.
45
+      *
46
+      * @since 1.0.0
47
+      *
48
+      * @return    object Cron()    A single instance of this class.
49
+      */
50
+     public static function get_instance() {
51
+          // If the single instance hasn't been set, set it now.
52
+          if ( null === self::$instance ) {
53
+               self::$instance = new self();
54
+          }
55
+          return self::$instance;
56
+     }
57
+
58
+     /**
59
+      * Define the metabox and field configurations.
60
+      *
61
+      * @param  array $meta_boxes
62
+      * @return array
63
+      */
64
+     public function metaboxes( array $meta_boxes ) {
65
+          // Allowed post types.
66
+          $allowed_post_types = array( 'accommodation' );
67
+
68
+          $fields = array();
69
+
70
+          $fields[] = array(
71
+               'id'   => 'wetu_skip_banner',
72
+               'name' => esc_html__( 'Skip Banner Image', 'lsx-banners' ),
73
+               'type' => 'checkbox',
74
+          );
75
+
76
+          $fields[] = array(
77
+               'id'   => 'wetu_skip_featured',
78
+               'name' => esc_html__( 'Skip Featured Image', 'lsx-banners' ),
79
+               'type' => 'checkbox',
80
+          );
81
+
82
+          $meta_boxes[] = array(
83
+               'title'    => esc_html__( 'WETU Settings', 'lsx-banners' ),
84
+               'pages'    => $allowed_post_types,
85
+               'fields'   => $fields,
86
+               'context'  => 'side',
87
+               'priority' => 'low',
88
+          );
89
+
90
+          return $meta_boxes;
91
+     }
92
+
93
+     /**
94
+      * Registers a 5 min schedule for us to use.
95
+      *
96
+      * @param  array $schedules
97
+      * @return array
98
+      */
99
+     public function register_schedule( $schedules ) {
100
+          $schedules['wetu-5-minutes'] = array(
101
+               'interval' => 5 * MINUTE_IN_SECONDS,
102
+               'display'  => __( 'Every 5 minutes', 'lsx-wetu-importer' ),
103
+          );
104
+          return $schedules;
105
+     }
106
+
107
+     /**
108
+      * Watches for changes in the button triggers.
109
+      *
110
+      * @return void
111
+      */
112
+     public function watch_for_trigger() {
113
+
114
+          if ( isset( $_GET['page'] ) && 'lsx-wetu-importer' === $_GET['page'] && isset( $_GET['tab'] ) && 'settings' === $_GET['tab'] ) {
115
+               $options = lsx_wetu_get_options();
116
+
117
+               // Check what state the option is in.
118
+               $accommodation_cron = 'deactivate';
119
+               if ( isset( $options['accommodation_images_cron'] ) && '' !== $options['accommodation_images_cron'] ) {
120
+                    $accommodation_cron = 'activate';
121
+               }
122
+
123
+               // Check what state the cron is in.
124
+               $scheduled = false;
125
+               if ( wp_next_scheduled( 'lsx_wetu_accommodation_images_cron' ) ) {
126
+                    $scheduled = true;
127
+               }
128
+
129
+               // If activate and its not running.
130
+               if ( false === $scheduled && 'activate' === $accommodation_cron ) {
131
+                    $schedule = 'weekly';
132
+                    $this->schedule( 'lsx_wetu_accommodation_images_cron', $schedule );
133
+               } elseif ( true === $scheduled && 'deactivate' === $accommodation_cron ) {
134
+                    $this->deactivate();
135
+               }
136
+          }
137
+     }
138
+
139
+     /**
140
+      * Remove our cron from the shedule.
141
+      *
142
+      * @return void
143
+      */
144
+     public function deactivate( $task = 'lsx_wetu_accommodation_images_cron' ) {
145
+          wp_clear_scheduled_hook( $task, array( $task ) );
146
+     }
147
+
148
+     /**
149
+      * This function will schedule the cron event.
150
+      *
151
+      * @param string $task
152
+      * @param string $schedule
153
+      * @param string $time
154
+      * @return void
155
+      */
156
+     public function schedule( $task = 'lsx_wetu_accommodation_images_cron', $schedule = 'weekly', $time = 'Sunday 10pm' ) {
157
+          $args = array( $task );
158
+          if ( '' === $time ) {
159
+               $time = time();
160
+          }
161
+
162
+          if ( isset( $_GET['accommodation_images_cron_featured'] ) && '' !== $_GET['accommodation_images_cron_featured'] ) {
163
+               $args[] = 'featured_image';
164
+          }
165
+          wp_schedule_event( $time, $schedule, $task, $args );
166
+     }
167
+
168
+     /**
169
+      * This is the function that will be triggered by the cron event.
170
+      *
171
+      * @return void
172
+      */
173
+     public function process( $task = '' ) {
174
+          switch ( $task ) {
175
+               case 'lsx_wetu_accommodation_images_cron':
176
+                         $this->register_accommodation_images_sync();
177
+                    break;
178
+
179
+               default:
180
+                    break;
181
+          }
182
+     }
183
+
184
+     /**
185
+      * This is the function that will be triggered by the cron event.
186
+      *
187
+      * @return void
188
+      */
189
+     public function register_accommodation_images_sync() {
190
+          $time = strtotime( '+5 min' );
191
+          if ( ! wp_next_scheduled( 'lsx_wetu_accommodation_images_sync' ) ) {
192
+               $this->load_items_to_sync( 'accommodation_images' );
193
+               $this->schedule( 'lsx_wetu_accommodation_images_sync', 'wetu-5-minutes', $time );
194
+          }
195
+     }
196
+
197
+     /**
198
+      * This is the function that will be triggered by the cron event.
199
+      *
200
+      * @return void
201
+      */
202
+     public function cron_callback( $task = '', $featured_image = '' ) {
203
+          $has_accommodation = get_option( $task );
204
+          if ( false !== $has_accommodation && ! empty( $has_accommodation ) ) {
205
+               $next_time = array_slice( $has_accommodation, 3 );
206
+               $this_time = array_slice( $has_accommodation, 0, 2 );
207
+
208
+               $api_key = $this->get_api_key();
209
+               $url     = 'https://wetu.com/API/Pins/' . $api_key . '/Get?all=include&ids=';
210
+
211
+               // Run through the current items.
212
+               foreach ( $this_time as $accommodation ) {
213
+                    $wetu_id   = get_post_meta( $accommodation, 'lsx_wetu_id', true );
214
+                    $last_date = get_post_meta( $accommodation, 'lsx_wetu_modified_date', true );
215
+
216
+                    // Grabbing the image sync.
217
+                    $featured_image = get_post_meta( $accommodation, 'wetu_skip_featured', true );
218
+                    $banner_image   = get_post_meta( $accommodation, 'wetu_skip_banner', true );
219
+
220
+                    $accommodation_info = wp_remote_get( $url . $wetu_id );
221
+                    if ( ! empty( $accommodation_info ) && isset( $accommodation_info['response'] ) && isset( $accommodation_info['response']['code'] ) && 200 === $accommodation_info['response']['code'] ) {
222
+                         $adata = json_decode( $accommodation_info['body'], true );
223
+
224
+                         if ( isset( $adata[0] ) && isset( $adata[0]['last_modified'] ) && '' !== $adata[0]['last_modified'] ) {
225
+                              $modified_time = strtotime( $adata[0]['last_modified'] );
226
+                              if ( $modified_time > $last_date ) {
227
+                                   $accommodation_importer = new \LSX_WETU_Importer_Accommodation();
228
+
229
+                                   if ( false === $banner_image || '' === $banner_image ) {
230
+                                        $accommodation_importer->set_banner_image( $adata, $accommodation );
231
+                                   }
232
+
233
+                                   if ( false === $featured_image || '' === $featured_image ) {
234
+                                        $accommodation_importer->set_featured_image( $adata, $accommodation );
235
+                                   }
236
+
237
+                                   $accommodation_importer->create_main_gallery( $adata, $accommodation );
238
+                                   update_post_meta( $accommodation, 'lsx_wetu_modified_date', $modified_time, $last_date );
239
+                              }
240
+                         }
241
+                    }
242
+               }
243
+
244
+               // Save the values for next time.
245
+               if ( ! empty( $next_time ) ) {
246
+                    update_option( $task, $next_time );
247
+               } else {
248
+                    delete_option( $task );
249
+                    $this->deactivate( $task );
250
+               }
251
+          } else {
252
+               $this->deactivate( $task );
253
+               update_option( 'lsx_wetu_nexttime', $task );
254
+          }
255
+     }
256
+
257
+     /**
258
+      * This will grab the accommodation ids and load them up into an option field.
259
+      *
260
+      * @param  string $task
261
+      * @return void
262
+      */
263
+     public function load_items_to_sync( $task = 'accommodation_images' ) {
264
+          $args = array(
265
+               'post_status'    => 'publish',
266
+               'posts_per_page' => -1,
267
+               'nopagin'        => true,
268
+               'fields'         => 'ids',
269
+          );
270
+          switch ( $task ) {
271
+               case 'accommodation_images':
272
+                         $args['post_type'] = 'accommodation';
273
+                    break;
274
+
275
+               default:
276
+                    break;
277
+          }
278
+          $items = new \WP_Query( $args );
279
+          if ( $items->have_posts() ) {
280
+               update_option( 'lsx_wetu_' . $task . '_sync', $items->posts );
281
+          }
282
+     }
283
+
284
+     /**
285
+      * Gets the API key stored in the options table.
286
+      *
287
+      * @return string
288
+      */
289
+     public function get_api_key() {
290
+          $api_key = false;
291
+          $options = lsx_wetu_get_options();
292
+
293
+          if ( ! defined( 'WETU_API_KEY' ) ) {
294
+               if ( isset( $options['api_key'] ) && '' !== $options['api_key'] ) {
295
+                    $api_key = $options['api_key'];
296
+               }
297
+          } else {
298
+               $api_key = WETU_API_KEY;
299
+          }
300
+          return $api_key;
301
+     }
302 302
 }
303 303
 Cron::get_instance();
Please login to merge, or discard this patch.
Spacing   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -33,11 +33,11 @@  discard block
 block discarded – undo
33 33
 	 * @access private
34 34
 	 */
35 35
 	public function __construct() {
36
-		add_filter( 'cron_schedules', array( $this, 'register_schedule' ), 10, 1 );
37
-		add_action( 'lsx_wetu_importer_settings_before', array( $this, 'watch_for_trigger' ), 200 );
38
-		add_action( 'lsx_wetu_accommodation_images_cron', array( $this, 'process' ), 10, 1 );
39
-		add_action( 'lsx_wetu_accommodation_images_sync', array( $this, 'cron_callback' ), 10, 1 );
40
-		add_filter( 'cmb_meta_boxes', array( $this, 'metaboxes' ) );
36
+		add_filter('cron_schedules', array($this, 'register_schedule'), 10, 1);
37
+		add_action('lsx_wetu_importer_settings_before', array($this, 'watch_for_trigger'), 200);
38
+		add_action('lsx_wetu_accommodation_images_cron', array($this, 'process'), 10, 1);
39
+		add_action('lsx_wetu_accommodation_images_sync', array($this, 'cron_callback'), 10, 1);
40
+		add_filter('cmb_meta_boxes', array($this, 'metaboxes'));
41 41
 	}
42 42
 
43 43
 	/**
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
 	 */
50 50
 	public static function get_instance() {
51 51
 		// If the single instance hasn't been set, set it now.
52
-		if ( null === self::$instance ) {
52
+		if (null === self::$instance) {
53 53
 			self::$instance = new self();
54 54
 		}
55 55
 		return self::$instance;
@@ -61,26 +61,26 @@  discard block
 block discarded – undo
61 61
 	 * @param  array $meta_boxes
62 62
 	 * @return array
63 63
 	 */
64
-	public function metaboxes( array $meta_boxes ) {
64
+	public function metaboxes(array $meta_boxes) {
65 65
 		// Allowed post types.
66
-		$allowed_post_types = array( 'accommodation' );
66
+		$allowed_post_types = array('accommodation');
67 67
 
68 68
 		$fields = array();
69 69
 
70 70
 		$fields[] = array(
71 71
 			'id'   => 'wetu_skip_banner',
72
-			'name' => esc_html__( 'Skip Banner Image', 'lsx-banners' ),
72
+			'name' => esc_html__('Skip Banner Image', 'lsx-banners'),
73 73
 			'type' => 'checkbox',
74 74
 		);
75 75
 
76 76
 		$fields[] = array(
77 77
 			'id'   => 'wetu_skip_featured',
78
-			'name' => esc_html__( 'Skip Featured Image', 'lsx-banners' ),
78
+			'name' => esc_html__('Skip Featured Image', 'lsx-banners'),
79 79
 			'type' => 'checkbox',
80 80
 		);
81 81
 
82 82
 		$meta_boxes[] = array(
83
-			'title'    => esc_html__( 'WETU Settings', 'lsx-banners' ),
83
+			'title'    => esc_html__('WETU Settings', 'lsx-banners'),
84 84
 			'pages'    => $allowed_post_types,
85 85
 			'fields'   => $fields,
86 86
 			'context'  => 'side',
@@ -96,10 +96,10 @@  discard block
 block discarded – undo
96 96
 	 * @param  array $schedules
97 97
 	 * @return array
98 98
 	 */
99
-	public function register_schedule( $schedules ) {
99
+	public function register_schedule($schedules) {
100 100
 		$schedules['wetu-5-minutes'] = array(
101 101
 			'interval' => 5 * MINUTE_IN_SECONDS,
102
-			'display'  => __( 'Every 5 minutes', 'lsx-wetu-importer' ),
102
+			'display'  => __('Every 5 minutes', 'lsx-wetu-importer'),
103 103
 		);
104 104
 		return $schedules;
105 105
 	}
@@ -111,26 +111,26 @@  discard block
 block discarded – undo
111 111
 	 */
112 112
 	public function watch_for_trigger() {
113 113
 
114
-		if ( isset( $_GET['page'] ) && 'lsx-wetu-importer' === $_GET['page'] && isset( $_GET['tab'] ) && 'settings' === $_GET['tab'] ) {
114
+		if (isset($_GET['page']) && 'lsx-wetu-importer' === $_GET['page'] && isset($_GET['tab']) && 'settings' === $_GET['tab']) {
115 115
 			$options = lsx_wetu_get_options();
116 116
 
117 117
 			// Check what state the option is in.
118 118
 			$accommodation_cron = 'deactivate';
119
-			if ( isset( $options['accommodation_images_cron'] ) && '' !== $options['accommodation_images_cron'] ) {
119
+			if (isset($options['accommodation_images_cron']) && '' !== $options['accommodation_images_cron']) {
120 120
 				$accommodation_cron = 'activate';
121 121
 			}
122 122
 
123 123
 			// Check what state the cron is in.
124 124
 			$scheduled = false;
125
-			if ( wp_next_scheduled( 'lsx_wetu_accommodation_images_cron' ) ) {
125
+			if (wp_next_scheduled('lsx_wetu_accommodation_images_cron')) {
126 126
 				$scheduled = true;
127 127
 			}
128 128
 
129 129
 			// If activate and its not running.
130
-			if ( false === $scheduled && 'activate' === $accommodation_cron ) {
130
+			if (false === $scheduled && 'activate' === $accommodation_cron) {
131 131
 				$schedule = 'weekly';
132
-				$this->schedule( 'lsx_wetu_accommodation_images_cron', $schedule );
133
-			} elseif ( true === $scheduled && 'deactivate' === $accommodation_cron ) {
132
+				$this->schedule('lsx_wetu_accommodation_images_cron', $schedule);
133
+			} elseif (true === $scheduled && 'deactivate' === $accommodation_cron) {
134 134
 				$this->deactivate();
135 135
 			}
136 136
 		}
@@ -141,8 +141,8 @@  discard block
 block discarded – undo
141 141
 	 *
142 142
 	 * @return void
143 143
 	 */
144
-	public function deactivate( $task = 'lsx_wetu_accommodation_images_cron' ) {
145
-		wp_clear_scheduled_hook( $task, array( $task ) );
144
+	public function deactivate($task = 'lsx_wetu_accommodation_images_cron') {
145
+		wp_clear_scheduled_hook($task, array($task));
146 146
 	}
147 147
 
148 148
 	/**
@@ -153,16 +153,16 @@  discard block
 block discarded – undo
153 153
 	 * @param string $time
154 154
 	 * @return void
155 155
 	 */
156
-	public function schedule( $task = 'lsx_wetu_accommodation_images_cron', $schedule = 'weekly', $time = 'Sunday 10pm' ) {
157
-		$args = array( $task );
158
-		if ( '' === $time ) {
156
+	public function schedule($task = 'lsx_wetu_accommodation_images_cron', $schedule = 'weekly', $time = 'Sunday 10pm') {
157
+		$args = array($task);
158
+		if ('' === $time) {
159 159
 			$time = time();
160 160
 		}
161 161
 
162
-		if ( isset( $_GET['accommodation_images_cron_featured'] ) && '' !== $_GET['accommodation_images_cron_featured'] ) {
162
+		if (isset($_GET['accommodation_images_cron_featured']) && '' !== $_GET['accommodation_images_cron_featured']) {
163 163
 			$args[] = 'featured_image';
164 164
 		}
165
-		wp_schedule_event( $time, $schedule, $task, $args );
165
+		wp_schedule_event($time, $schedule, $task, $args);
166 166
 	}
167 167
 
168 168
 	/**
@@ -170,8 +170,8 @@  discard block
 block discarded – undo
170 170
 	 *
171 171
 	 * @return void
172 172
 	 */
173
-	public function process( $task = '' ) {
174
-		switch ( $task ) {
173
+	public function process($task = '') {
174
+		switch ($task) {
175 175
 			case 'lsx_wetu_accommodation_images_cron':
176 176
 					$this->register_accommodation_images_sync();
177 177
 				break;
@@ -187,10 +187,10 @@  discard block
 block discarded – undo
187 187
 	 * @return void
188 188
 	 */
189 189
 	public function register_accommodation_images_sync() {
190
-		$time = strtotime( '+5 min' );
191
-		if ( ! wp_next_scheduled( 'lsx_wetu_accommodation_images_sync' ) ) {
192
-			$this->load_items_to_sync( 'accommodation_images' );
193
-			$this->schedule( 'lsx_wetu_accommodation_images_sync', 'wetu-5-minutes', $time );
190
+		$time = strtotime('+5 min');
191
+		if (!wp_next_scheduled('lsx_wetu_accommodation_images_sync')) {
192
+			$this->load_items_to_sync('accommodation_images');
193
+			$this->schedule('lsx_wetu_accommodation_images_sync', 'wetu-5-minutes', $time);
194 194
 		}
195 195
 	}
196 196
 
@@ -199,58 +199,58 @@  discard block
 block discarded – undo
199 199
 	 *
200 200
 	 * @return void
201 201
 	 */
202
-	public function cron_callback( $task = '', $featured_image = '' ) {
203
-		$has_accommodation = get_option( $task );
204
-		if ( false !== $has_accommodation && ! empty( $has_accommodation ) ) {
205
-			$next_time = array_slice( $has_accommodation, 3 );
206
-			$this_time = array_slice( $has_accommodation, 0, 2 );
202
+	public function cron_callback($task = '', $featured_image = '') {
203
+		$has_accommodation = get_option($task);
204
+		if (false !== $has_accommodation && !empty($has_accommodation)) {
205
+			$next_time = array_slice($has_accommodation, 3);
206
+			$this_time = array_slice($has_accommodation, 0, 2);
207 207
 
208 208
 			$api_key = $this->get_api_key();
209
-			$url     = 'https://wetu.com/API/Pins/' . $api_key . '/Get?all=include&ids=';
209
+			$url     = 'https://wetu.com/API/Pins/'.$api_key.'/Get?all=include&ids=';
210 210
 
211 211
 			// Run through the current items.
212
-			foreach ( $this_time as $accommodation ) {
213
-				$wetu_id   = get_post_meta( $accommodation, 'lsx_wetu_id', true );
214
-				$last_date = get_post_meta( $accommodation, 'lsx_wetu_modified_date', true );
212
+			foreach ($this_time as $accommodation) {
213
+				$wetu_id   = get_post_meta($accommodation, 'lsx_wetu_id', true);
214
+				$last_date = get_post_meta($accommodation, 'lsx_wetu_modified_date', true);
215 215
 
216 216
 				// Grabbing the image sync.
217
-				$featured_image = get_post_meta( $accommodation, 'wetu_skip_featured', true );
218
-				$banner_image   = get_post_meta( $accommodation, 'wetu_skip_banner', true );
217
+				$featured_image = get_post_meta($accommodation, 'wetu_skip_featured', true);
218
+				$banner_image   = get_post_meta($accommodation, 'wetu_skip_banner', true);
219 219
 
220
-				$accommodation_info = wp_remote_get( $url . $wetu_id );
221
-				if ( ! empty( $accommodation_info ) && isset( $accommodation_info['response'] ) && isset( $accommodation_info['response']['code'] ) && 200 === $accommodation_info['response']['code'] ) {
222
-					$adata = json_decode( $accommodation_info['body'], true );
220
+				$accommodation_info = wp_remote_get($url.$wetu_id);
221
+				if (!empty($accommodation_info) && isset($accommodation_info['response']) && isset($accommodation_info['response']['code']) && 200 === $accommodation_info['response']['code']) {
222
+					$adata = json_decode($accommodation_info['body'], true);
223 223
 
224
-					if ( isset( $adata[0] ) && isset( $adata[0]['last_modified'] ) && '' !== $adata[0]['last_modified'] ) {
225
-						$modified_time = strtotime( $adata[0]['last_modified'] );
226
-						if ( $modified_time > $last_date ) {
224
+					if (isset($adata[0]) && isset($adata[0]['last_modified']) && '' !== $adata[0]['last_modified']) {
225
+						$modified_time = strtotime($adata[0]['last_modified']);
226
+						if ($modified_time > $last_date) {
227 227
 							$accommodation_importer = new \LSX_WETU_Importer_Accommodation();
228 228
 
229
-							if ( false === $banner_image || '' === $banner_image ) {
230
-								$accommodation_importer->set_banner_image( $adata, $accommodation );
229
+							if (false === $banner_image || '' === $banner_image) {
230
+								$accommodation_importer->set_banner_image($adata, $accommodation);
231 231
 							}
232 232
 
233
-							if ( false === $featured_image || '' === $featured_image ) {
234
-								$accommodation_importer->set_featured_image( $adata, $accommodation );
233
+							if (false === $featured_image || '' === $featured_image) {
234
+								$accommodation_importer->set_featured_image($adata, $accommodation);
235 235
 							}
236 236
 
237
-							$accommodation_importer->create_main_gallery( $adata, $accommodation );
238
-							update_post_meta( $accommodation, 'lsx_wetu_modified_date', $modified_time, $last_date );
237
+							$accommodation_importer->create_main_gallery($adata, $accommodation);
238
+							update_post_meta($accommodation, 'lsx_wetu_modified_date', $modified_time, $last_date);
239 239
 						}
240 240
 					}
241 241
 				}
242 242
 			}
243 243
 
244 244
 			// Save the values for next time.
245
-			if ( ! empty( $next_time ) ) {
246
-				update_option( $task, $next_time );
247
-			} else {
248
-				delete_option( $task );
249
-				$this->deactivate( $task );
245
+			if (!empty($next_time)) {
246
+				update_option($task, $next_time);
247
+			}else {
248
+				delete_option($task);
249
+				$this->deactivate($task);
250 250
 			}
251
-		} else {
252
-			$this->deactivate( $task );
253
-			update_option( 'lsx_wetu_nexttime', $task );
251
+		}else {
252
+			$this->deactivate($task);
253
+			update_option('lsx_wetu_nexttime', $task);
254 254
 		}
255 255
 	}
256 256
 
@@ -260,14 +260,14 @@  discard block
 block discarded – undo
260 260
 	 * @param  string $task
261 261
 	 * @return void
262 262
 	 */
263
-	public function load_items_to_sync( $task = 'accommodation_images' ) {
263
+	public function load_items_to_sync($task = 'accommodation_images') {
264 264
 		$args = array(
265 265
 			'post_status'    => 'publish',
266 266
 			'posts_per_page' => -1,
267 267
 			'nopagin'        => true,
268 268
 			'fields'         => 'ids',
269 269
 		);
270
-		switch ( $task ) {
270
+		switch ($task) {
271 271
 			case 'accommodation_images':
272 272
 					$args['post_type'] = 'accommodation';
273 273
 				break;
@@ -275,9 +275,9 @@  discard block
 block discarded – undo
275 275
 			default:
276 276
 				break;
277 277
 		}
278
-		$items = new \WP_Query( $args );
279
-		if ( $items->have_posts() ) {
280
-			update_option( 'lsx_wetu_' . $task . '_sync', $items->posts );
278
+		$items = new \WP_Query($args);
279
+		if ($items->have_posts()) {
280
+			update_option('lsx_wetu_'.$task.'_sync', $items->posts);
281 281
 		}
282 282
 	}
283 283
 
@@ -290,11 +290,11 @@  discard block
 block discarded – undo
290 290
 		$api_key = false;
291 291
 		$options = lsx_wetu_get_options();
292 292
 
293
-		if ( ! defined( 'WETU_API_KEY' ) ) {
294
-			if ( isset( $options['api_key'] ) && '' !== $options['api_key'] ) {
293
+		if (!defined('WETU_API_KEY')) {
294
+			if (isset($options['api_key']) && '' !== $options['api_key']) {
295 295
 				$api_key = $options['api_key'];
296 296
 			}
297
-		} else {
297
+		}else {
298 298
 			$api_key = WETU_API_KEY;
299 299
 		}
300 300
 		return $api_key;
Please login to merge, or discard this patch.
classes/class-lsx-wetu-importer-banner-integration.php 2 patches
Indentation   +207 added lines, -207 removed lines patch added patch discarded remove patch
@@ -9,32 +9,32 @@  discard block
 block discarded – undo
9 9
 
10 10
 class LSX_WETU_Importer_Banner_Integration 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 = 'banners';
20
-
21
-	/**
22
-	 * Initialize the plugin by setting localization, filters, and administration functions.
23
-	 *
24
-	 * @since 1.0.0
25
-	 *
26
-	 * @access private
27
-	 */
28
-	public function __construct() {
29
-		add_action( 'wp_ajax_lsx_import_sync_banners', array( $this, 'sync_new_banner' ) );
30
-		add_action( 'wp_ajax_nopriv_lsx_import_sync_banners', array( $this, 'sync_new_banner' ) );
31
-	}
32
-
33
-	/**
34
-	 * Display the importer administration screen
35
-	 */
36
-	public function display_page() {
37
-		?>
12
+     /**
13
+      * The url to list items from WETU
14
+      *
15
+      * @since 0.0.1
16
+      *
17
+      * @var      string
18
+      */
19
+     public $tab_slug = 'banners';
20
+
21
+     /**
22
+      * Initialize the plugin by setting localization, filters, and administration functions.
23
+      *
24
+      * @since 1.0.0
25
+      *
26
+      * @access private
27
+      */
28
+     public function __construct() {
29
+          add_action( 'wp_ajax_lsx_import_sync_banners', array( $this, 'sync_new_banner' ) );
30
+          add_action( 'wp_ajax_nopriv_lsx_import_sync_banners', array( $this, 'sync_new_banner' ) );
31
+     }
32
+
33
+     /**
34
+      * Display the importer administration screen
35
+      */
36
+     public function display_page() {
37
+          ?>
38 38
 		<div class="wrap">
39 39
 			<h2><?php esc_html_e( 'Download new banners straight from WETU', 'lsx-wetu-importer' ); ?></h2>
40 40
 
@@ -58,67 +58,67 @@  discard block
 block discarded – undo
58 58
 					</thead>
59 59
 
60 60
 					<?php
61
-						$accommodation_args = array(
62
-							'post_type'      => 'accommodation',
63
-							'post_status'    => array( 'publish', 'pending', 'draft', 'future', 'private' ),
64
-							'nopagin'        => 'true',
65
-							'posts_per_page' => '1000',
66
-							'meta_query'     => array(
67
-								'relation' => 'AND',
68
-								array(
69
-									'key'     => 'lsx_wetu_id',
70
-									'compare' => 'EXISTS',
71
-								),
72
-								array(
73
-									'key'     => 'image_group',
74
-									'compare' => 'EXISTS',
75
-								),
76
-								array(
77
-									'key'     => 'image_group',
78
-									'value'   => 'a:1:{s:12:"banner_image";a:0:{}}',
79
-									'compare' => '!=',
80
-								),
81
-							),
82
-						);
83
-						$accommodation      = new WP_Query( $accommodation_args );
84
-						?>
61
+                              $accommodation_args = array(
62
+                                   'post_type'      => 'accommodation',
63
+                                   'post_status'    => array( 'publish', 'pending', 'draft', 'future', 'private' ),
64
+                                   'nopagin'        => 'true',
65
+                                   'posts_per_page' => '1000',
66
+                                   'meta_query'     => array(
67
+                                        'relation' => 'AND',
68
+                                        array(
69
+                                             'key'     => 'lsx_wetu_id',
70
+                                             'compare' => 'EXISTS',
71
+                                        ),
72
+                                        array(
73
+                                             'key'     => 'image_group',
74
+                                             'compare' => 'EXISTS',
75
+                                        ),
76
+                                        array(
77
+                                             'key'     => 'image_group',
78
+                                             'value'   => 'a:1:{s:12:"banner_image";a:0:{}}',
79
+                                             'compare' => '!=',
80
+                                        ),
81
+                                   ),
82
+                              );
83
+                              $accommodation      = new WP_Query( $accommodation_args );
84
+                              ?>
85 85
 
86 86
 					<tbody id="the-list">
87 87
 						<?php
88
-						if ( $accommodation->have_posts() ) {
89
-							while ( $accommodation->have_posts() ) {
90
-								$accommodation->the_post();
91
-								?>
88
+                              if ( $accommodation->have_posts() ) {
89
+                                   while ( $accommodation->have_posts() ) {
90
+                                        $accommodation->the_post();
91
+                                        ?>
92 92
 									<tr class="post-<?php the_ID(); ?> type-tour status-none" id="post-<?php the_ID(); ?>">
93 93
 									<?php
94
-									$banner_size_appropriate = false;
95
-									$min_width               = '1920';
96
-									$min_height              = '500';
94
+                                             $banner_size_appropriate = false;
95
+                                             $min_width               = '1920';
96
+                                             $min_height              = '500';
97 97
 
98
-									$img_group = get_post_meta( get_the_ID(), 'image_group', true );
98
+                                             $img_group = get_post_meta( get_the_ID(), 'image_group', true );
99 99
 
100
-									$thumbnails_html = false;
100
+                                             $thumbnails_html = false;
101 101
 
102
-									if ( false !== $img_group ) {
103
-										foreach ( $img_group['banner_image'] as $banner_image ) {
104
-											$large       = wp_get_attachment_image_src( $banner_image, 'full' );
105
-											$real_width  = $large[1];
106
-											$real_height = $large[2];
102
+                                             if ( false !== $img_group ) {
103
+                                                  foreach ( $img_group['banner_image'] as $banner_image ) {
104
+                                                       $large       = wp_get_attachment_image_src( $banner_image, 'full' );
105
+                                                       $real_width  = $large[1];
106
+                                                       $real_height = $large[2];
107 107
 
108
-											$status = 'optimized';
109
-											if ( $real_width < intval( $real_width ) ) {
110
-												$status = 'width not enough.';
111
-											}
108
+                                                       $status = 'optimized';
109
+                                                       if ( $real_width < intval( $real_width ) ) {
110
+                                                            $status = 'width not enough.';
111
+                                                       }
112 112
 
113
-											$thumbnail         = wp_get_attachment_image_src( $banner_image, 'thumbnail' );
114
-											$thumbnails_html[] = '
113
+                                                       $thumbnail         = wp_get_attachment_image_src( $banner_image, 'thumbnail' );
114
+                                                       $thumbnails_html[] = '
115 115
 													<div style="display:block;float:left;">
116 116
 														<img src="' . $thumbnail[0] . '" />
117 117
 														<p style="text-align:center;">' . $real_width . 'px by ' . $real_height . 'px</p>
118 118
 													</div>';
119
-										}
120
-									}
121
-									?>
119
+                                                  }
120
+                                             }
121
+                                             ?>
122 122
 									<th class="check-column" scope="row">
123 123
 										<label for="cb-select-<?php the_ID(); ?>" class="screen-reader-text"></label>
124 124
 										<input type="checkbox" data-identifier="<?php the_ID(); ?>" value="<?php the_ID(); ?>" name="post[]" id="cb-select-<?php the_ID(); ?>">
@@ -126,26 +126,26 @@  discard block
 block discarded – undo
126 126
 
127 127
 										<td class="post-title page-title column-title">
128 128
 									<?php
129
-									echo '<a href="' . esc_url( admin_url( '/post.php?post=' . get_the_ID() . '&action=edit' ) ) . '" target="_blank">';
130
-									the_title();
131
-									echo '</a>';
132
-									?>
129
+                                             echo '<a href="' . esc_url( admin_url( '/post.php?post=' . get_the_ID() . '&action=edit' ) ) . '" target="_blank">';
130
+                                             the_title();
131
+                                             echo '</a>';
132
+                                             ?>
133 133
 										</td>
134 134
 
135 135
 										<td colspan="2" class="thumbnails column-thumbnails">
136 136
 									<?php
137
-									if ( false !== $thumbnails_html ) {
138
-										echo wp_kses_post( implode( '', $thumbnails_html ) );
139
-									} else {
140
-										echo '<p>There was an error retrieving your images.</p>';
141
-									}
142
-									?>
137
+                                             if ( false !== $thumbnails_html ) {
138
+                                                  echo wp_kses_post( implode( '', $thumbnails_html ) );
139
+                                             } else {
140
+                                                  echo '<p>There was an error retrieving your images.</p>';
141
+                                             }
142
+                                             ?>
143 143
 										</td>
144 144
 									</tr>
145 145
 								<?php
146
-							}
147
-						}
148
-						?>
146
+                                   }
147
+                              }
148
+                              ?>
149 149
 					</tbody>
150 150
 
151 151
 					<tfoot>
@@ -166,125 +166,125 @@  discard block
 block discarded – undo
166 166
 			</form>
167 167
 		</div>
168 168
 		<?php
169
-	}
170
-
171
-	/**
172
-	 * Creates the main gallery data
173
-	 */
174
-	public function sync_new_banner() {
175
-		check_ajax_referer( 'lsx_wetu_ajax_action', 'security' );
176
-		if ( isset( $_POST['action'] ) && 'lsx_import_sync_banners' === $_POST['action'] && isset( $_POST['post_id'] ) ) {
177
-
178
-			$post_id       = sanitize_text_field( $_POST['post_id'] );
179
-			$banners       = get_post_meta( $post_id, 'image_group', true );
180
-			$this->wetu_id = get_post_meta( $post_id, 'lsx_wetu_id', true );
181
-
182
-			$new_banner_array = false;
183
-			$array_index      = 0;
184
-
185
-			foreach ( $banners['banner_image'] as $banner_image ) {
186
-				$image_id = $this->attach_external_image2( $this->format_wetu_url( $banner_image ), array(), $post_id );
187
-				if ( null !== $image_id && '' !== $image_id ) {
188
-					$new_banner_array['banner_image'][ 'cmb-field-' . $array_index ] = $image_id;
189
-					$array_index++;
190
-				}
191
-			}
192
-
193
-			if ( false !== $new_banner_array ) {
194
-				delete_post_meta( $post_id, 'image_group' );
195
-				add_post_meta( $post_id, 'image_group', $new_banner_array, true );
196
-				echo true;
197
-			} else {
198
-				echo false;
199
-			}
200
-		} else {
201
-			echo false;
202
-		}
203
-
204
-		die();
205
-	}
206
-
207
-	/**
208
-	 * formats the url
209
-	 */
210
-	public function format_wetu_url( $post_id ) {
211
-		return 'https://wetu.com/ImageHandler/c1920x800/' . $this->wetu_id . '/' . $this->format_filename( $post_id );
212
-	}
213
-
214
-	/**
215
-	 * formats the filename
216
-	 */
217
-	public function format_filename( $post_id ) {
218
-		$base = str_replace( '_', ' ', get_the_title( $post_id ) );
219
-		$base = rawurlencode( $base );
220
-		$type = get_post_mime_type( $post_id );
221
-
222
-		switch ( $type ) {
223
-			case 'image/jpeg':
224
-				return $base . '.jpg';
225
-			break;
226
-			case 'image/png':
227
-				return $base . '.png';
228
-			break;
229
-			case 'image/gif':
230
-				return $base . '.gif';
231
-			break;
232
-			default:
233
-				return false;
234
-		}
235
-	}
236
-
237
-	public function attach_external_image2( $url = null, $post_data = array(), $post_id = '' ) {
238
-		if ( ! $url ) {
239
-			return new WP_Error( 'missing', 'Need a valid URL' ); }
240
-		$att_id = false;
241
-
242
-		require_once ABSPATH . 'wp-admin/includes/file.php';
243
-		require_once ABSPATH . 'wp-admin/includes/media.php';
244
-		require_once ABSPATH . 'wp-admin/includes/image.php';
245
-
246
-		$tmp   = tempnam( '/tmp', 'FOO' );
247
-		$image = wp_remote_get( $url );
248
-
249
-		if ( ! empty( $image ) && isset( $image['response'] ) && isset( $image['response']['code'] ) && 200 === $image['response']['code'] ) {
250
-			file_put_contents( $tmp, $image['body'] );
251
-			chmod( $tmp, '777' );
252
-
253
-			preg_match( '/[^\?]+\.(tif|TIFF|jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG|pdf|PDF|bmp|BMP)/', $url, $matches );
254
-			$url_filename = basename( $matches[0] );
255
-			$url_filename = str_replace( '%20', '_', $url_filename );
256
-			// extract filename from url for title.
257
-			$url_type = wp_check_filetype( $url_filename );
258
-
259
-			// assemble file data (should be built like $_FILES since wp_handle_sideload() will be using).
260
-			$file_array['tmp_name'] = $tmp;
261
-
262
-			if ( ! empty( $filename ) && ' ' != $filename ) {
263
-				$file_array['name'] = $filename . '.' . $url_type['ext'];
264
-			} else {
265
-				$file_array['name'] = $url_filename;
266
-			}
267
-
268
-			// set additional wp_posts columns.
269
-			if ( empty( $post_data['post_title'] ) ) {
270
-				$url_filename            = str_replace( '%20', ' ', $url_filename );
271
-				$post_data['post_title'] = basename( $url_filename, '.' . $url_type['ext'] );
272
-			}
273
-
274
-			// make sure gets tied to parent.
275
-			if ( empty( $post_data['post_parent'] ) ) {
276
-				$post_data['post_parent'] = $post_id;
277
-			}
278
-
279
-			// do the validation and storage stuff.
280
-			$att_id = media_handle_sideload( $file_array, $post_id, null, $post_data );
281
-
282
-			// If error storing permanently, unlink.
283
-			if ( is_wp_error( $att_id ) ) {
284
-				unlink( $file_array['tmp_name'] );
285
-				return false;
286
-			}
287
-		}
288
-		return $att_id;
289
-	}
169
+     }
170
+
171
+     /**
172
+      * Creates the main gallery data
173
+      */
174
+     public function sync_new_banner() {
175
+          check_ajax_referer( 'lsx_wetu_ajax_action', 'security' );
176
+          if ( isset( $_POST['action'] ) && 'lsx_import_sync_banners' === $_POST['action'] && isset( $_POST['post_id'] ) ) {
177
+
178
+               $post_id       = sanitize_text_field( $_POST['post_id'] );
179
+               $banners       = get_post_meta( $post_id, 'image_group', true );
180
+               $this->wetu_id = get_post_meta( $post_id, 'lsx_wetu_id', true );
181
+
182
+               $new_banner_array = false;
183
+               $array_index      = 0;
184
+
185
+               foreach ( $banners['banner_image'] as $banner_image ) {
186
+                    $image_id = $this->attach_external_image2( $this->format_wetu_url( $banner_image ), array(), $post_id );
187
+                    if ( null !== $image_id && '' !== $image_id ) {
188
+                         $new_banner_array['banner_image'][ 'cmb-field-' . $array_index ] = $image_id;
189
+                         $array_index++;
190
+                    }
191
+               }
192
+
193
+               if ( false !== $new_banner_array ) {
194
+                    delete_post_meta( $post_id, 'image_group' );
195
+                    add_post_meta( $post_id, 'image_group', $new_banner_array, true );
196
+                    echo true;
197
+               } else {
198
+                    echo false;
199
+               }
200
+          } else {
201
+               echo false;
202
+          }
203
+
204
+          die();
205
+     }
206
+
207
+     /**
208
+      * formats the url
209
+      */
210
+     public function format_wetu_url( $post_id ) {
211
+          return 'https://wetu.com/ImageHandler/c1920x800/' . $this->wetu_id . '/' . $this->format_filename( $post_id );
212
+     }
213
+
214
+     /**
215
+      * formats the filename
216
+      */
217
+     public function format_filename( $post_id ) {
218
+          $base = str_replace( '_', ' ', get_the_title( $post_id ) );
219
+          $base = rawurlencode( $base );
220
+          $type = get_post_mime_type( $post_id );
221
+
222
+          switch ( $type ) {
223
+               case 'image/jpeg':
224
+                    return $base . '.jpg';
225
+               break;
226
+               case 'image/png':
227
+                    return $base . '.png';
228
+               break;
229
+               case 'image/gif':
230
+                    return $base . '.gif';
231
+               break;
232
+               default:
233
+                    return false;
234
+          }
235
+     }
236
+
237
+     public function attach_external_image2( $url = null, $post_data = array(), $post_id = '' ) {
238
+          if ( ! $url ) {
239
+               return new WP_Error( 'missing', 'Need a valid URL' ); }
240
+          $att_id = false;
241
+
242
+          require_once ABSPATH . 'wp-admin/includes/file.php';
243
+          require_once ABSPATH . 'wp-admin/includes/media.php';
244
+          require_once ABSPATH . 'wp-admin/includes/image.php';
245
+
246
+          $tmp   = tempnam( '/tmp', 'FOO' );
247
+          $image = wp_remote_get( $url );
248
+
249
+          if ( ! empty( $image ) && isset( $image['response'] ) && isset( $image['response']['code'] ) && 200 === $image['response']['code'] ) {
250
+               file_put_contents( $tmp, $image['body'] );
251
+               chmod( $tmp, '777' );
252
+
253
+               preg_match( '/[^\?]+\.(tif|TIFF|jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG|pdf|PDF|bmp|BMP)/', $url, $matches );
254
+               $url_filename = basename( $matches[0] );
255
+               $url_filename = str_replace( '%20', '_', $url_filename );
256
+               // extract filename from url for title.
257
+               $url_type = wp_check_filetype( $url_filename );
258
+
259
+               // assemble file data (should be built like $_FILES since wp_handle_sideload() will be using).
260
+               $file_array['tmp_name'] = $tmp;
261
+
262
+               if ( ! empty( $filename ) && ' ' != $filename ) {
263
+                    $file_array['name'] = $filename . '.' . $url_type['ext'];
264
+               } else {
265
+                    $file_array['name'] = $url_filename;
266
+               }
267
+
268
+               // set additional wp_posts columns.
269
+               if ( empty( $post_data['post_title'] ) ) {
270
+                    $url_filename            = str_replace( '%20', ' ', $url_filename );
271
+                    $post_data['post_title'] = basename( $url_filename, '.' . $url_type['ext'] );
272
+               }
273
+
274
+               // make sure gets tied to parent.
275
+               if ( empty( $post_data['post_parent'] ) ) {
276
+                    $post_data['post_parent'] = $post_id;
277
+               }
278
+
279
+               // do the validation and storage stuff.
280
+               $att_id = media_handle_sideload( $file_array, $post_id, null, $post_data );
281
+
282
+               // If error storing permanently, unlink.
283
+               if ( is_wp_error( $att_id ) ) {
284
+                    unlink( $file_array['tmp_name'] );
285
+                    return false;
286
+               }
287
+          }
288
+          return $att_id;
289
+     }
290 290
 }
Please login to merge, or discard this patch.
Spacing   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -26,8 +26,8 @@  discard block
 block discarded – undo
26 26
 	 * @access private
27 27
 	 */
28 28
 	public function __construct() {
29
-		add_action( 'wp_ajax_lsx_import_sync_banners', array( $this, 'sync_new_banner' ) );
30
-		add_action( 'wp_ajax_nopriv_lsx_import_sync_banners', array( $this, 'sync_new_banner' ) );
29
+		add_action('wp_ajax_lsx_import_sync_banners', array($this, 'sync_new_banner'));
30
+		add_action('wp_ajax_nopriv_lsx_import_sync_banners', array($this, 'sync_new_banner'));
31 31
 	}
32 32
 
33 33
 	/**
@@ -36,13 +36,13 @@  discard block
 block discarded – undo
36 36
 	public function display_page() {
37 37
 		?>
38 38
 		<div class="wrap">
39
-			<h2><?php esc_html_e( 'Download new banners straight from WETU', 'lsx-wetu-importer' ); ?></h2>
39
+			<h2><?php esc_html_e('Download new banners straight from WETU', 'lsx-wetu-importer'); ?></h2>
40 40
 
41 41
 			<form method="get" action="" id="banners-filter">
42
-				<input type="hidden" name="post_type" class="post_type" value="<?php echo esc_attr( $this->tab_slug ); ?>" />
42
+				<input type="hidden" name="post_type" class="post_type" value="<?php echo esc_attr($this->tab_slug); ?>" />
43 43
 
44 44
 			   <div class="ajax-loader-small" style="display:none;width:100%;text-align:center;">
45
-					<img style="width:32px;" src="<?php echo esc_url( LSX_WETU_IMPORTER_URL . 'assets/images/ajaxloader.gif' ); ?>" />
45
+					<img style="width:32px;" src="<?php echo esc_url(LSX_WETU_IMPORTER_URL.'assets/images/ajaxloader.gif'); ?>" />
46 46
 				</div>
47 47
 
48 48
 				<table class="wp-list-table widefat fixed posts">
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 					<?php
61 61
 						$accommodation_args = array(
62 62
 							'post_type'      => 'accommodation',
63
-							'post_status'    => array( 'publish', 'pending', 'draft', 'future', 'private' ),
63
+							'post_status'    => array('publish', 'pending', 'draft', 'future', 'private'),
64 64
 							'nopagin'        => 'true',
65 65
 							'posts_per_page' => '1000',
66 66
 							'meta_query'     => array(
@@ -80,13 +80,13 @@  discard block
 block discarded – undo
80 80
 								),
81 81
 							),
82 82
 						);
83
-						$accommodation      = new WP_Query( $accommodation_args );
83
+						$accommodation = new WP_Query($accommodation_args);
84 84
 						?>
85 85
 
86 86
 					<tbody id="the-list">
87 87
 						<?php
88
-						if ( $accommodation->have_posts() ) {
89
-							while ( $accommodation->have_posts() ) {
88
+						if ($accommodation->have_posts()) {
89
+							while ($accommodation->have_posts()) {
90 90
 								$accommodation->the_post();
91 91
 								?>
92 92
 									<tr class="post-<?php the_ID(); ?> type-tour status-none" id="post-<?php the_ID(); ?>">
@@ -95,26 +95,26 @@  discard block
 block discarded – undo
95 95
 									$min_width               = '1920';
96 96
 									$min_height              = '500';
97 97
 
98
-									$img_group = get_post_meta( get_the_ID(), 'image_group', true );
98
+									$img_group = get_post_meta(get_the_ID(), 'image_group', true);
99 99
 
100 100
 									$thumbnails_html = false;
101 101
 
102
-									if ( false !== $img_group ) {
103
-										foreach ( $img_group['banner_image'] as $banner_image ) {
104
-											$large       = wp_get_attachment_image_src( $banner_image, 'full' );
102
+									if (false !== $img_group) {
103
+										foreach ($img_group['banner_image'] as $banner_image) {
104
+											$large       = wp_get_attachment_image_src($banner_image, 'full');
105 105
 											$real_width  = $large[1];
106 106
 											$real_height = $large[2];
107 107
 
108 108
 											$status = 'optimized';
109
-											if ( $real_width < intval( $real_width ) ) {
109
+											if ($real_width < intval($real_width)) {
110 110
 												$status = 'width not enough.';
111 111
 											}
112 112
 
113
-											$thumbnail         = wp_get_attachment_image_src( $banner_image, 'thumbnail' );
113
+											$thumbnail         = wp_get_attachment_image_src($banner_image, 'thumbnail');
114 114
 											$thumbnails_html[] = '
115 115
 													<div style="display:block;float:left;">
116
-														<img src="' . $thumbnail[0] . '" />
117
-														<p style="text-align:center;">' . $real_width . 'px by ' . $real_height . 'px</p>
116
+														<img src="' . $thumbnail[0].'" />
117
+														<p style="text-align:center;">' . $real_width.'px by '.$real_height.'px</p>
118 118
 													</div>';
119 119
 										}
120 120
 									}
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 
127 127
 										<td class="post-title page-title column-title">
128 128
 									<?php
129
-									echo '<a href="' . esc_url( admin_url( '/post.php?post=' . get_the_ID() . '&action=edit' ) ) . '" target="_blank">';
129
+									echo '<a href="'.esc_url(admin_url('/post.php?post='.get_the_ID().'&action=edit')).'" target="_blank">';
130 130
 									the_title();
131 131
 									echo '</a>';
132 132
 									?>
@@ -134,9 +134,9 @@  discard block
 block discarded – undo
134 134
 
135 135
 										<td colspan="2" class="thumbnails column-thumbnails">
136 136
 									<?php
137
-									if ( false !== $thumbnails_html ) {
138
-										echo wp_kses_post( implode( '', $thumbnails_html ) );
139
-									} else {
137
+									if (false !== $thumbnails_html) {
138
+										echo wp_kses_post(implode('', $thumbnails_html));
139
+									}else {
140 140
 										echo '<p>There was an error retrieving your images.</p>';
141 141
 									}
142 142
 									?>
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
 
162 162
 				</table>
163 163
 
164
-				<p><input class="button button-primary download" type="button" value="<?php esc_html_e( 'Download new Banners', 'lsx-wetu-importer' ); ?>" />
164
+				<p><input class="button button-primary download" type="button" value="<?php esc_html_e('Download new Banners', 'lsx-wetu-importer'); ?>" />
165 165
 				</p>
166 166
 			</form>
167 167
 		</div>
@@ -172,32 +172,32 @@  discard block
 block discarded – undo
172 172
 	 * Creates the main gallery data
173 173
 	 */
174 174
 	public function sync_new_banner() {
175
-		check_ajax_referer( 'lsx_wetu_ajax_action', 'security' );
176
-		if ( isset( $_POST['action'] ) && 'lsx_import_sync_banners' === $_POST['action'] && isset( $_POST['post_id'] ) ) {
175
+		check_ajax_referer('lsx_wetu_ajax_action', 'security');
176
+		if (isset($_POST['action']) && 'lsx_import_sync_banners' === $_POST['action'] && isset($_POST['post_id'])) {
177 177
 
178
-			$post_id       = sanitize_text_field( $_POST['post_id'] );
179
-			$banners       = get_post_meta( $post_id, 'image_group', true );
180
-			$this->wetu_id = get_post_meta( $post_id, 'lsx_wetu_id', true );
178
+			$post_id       = sanitize_text_field($_POST['post_id']);
179
+			$banners       = get_post_meta($post_id, 'image_group', true);
180
+			$this->wetu_id = get_post_meta($post_id, 'lsx_wetu_id', true);
181 181
 
182 182
 			$new_banner_array = false;
183 183
 			$array_index      = 0;
184 184
 
185
-			foreach ( $banners['banner_image'] as $banner_image ) {
186
-				$image_id = $this->attach_external_image2( $this->format_wetu_url( $banner_image ), array(), $post_id );
187
-				if ( null !== $image_id && '' !== $image_id ) {
188
-					$new_banner_array['banner_image'][ 'cmb-field-' . $array_index ] = $image_id;
185
+			foreach ($banners['banner_image'] as $banner_image) {
186
+				$image_id = $this->attach_external_image2($this->format_wetu_url($banner_image), array(), $post_id);
187
+				if (null !== $image_id && '' !== $image_id) {
188
+					$new_banner_array['banner_image']['cmb-field-'.$array_index] = $image_id;
189 189
 					$array_index++;
190 190
 				}
191 191
 			}
192 192
 
193
-			if ( false !== $new_banner_array ) {
194
-				delete_post_meta( $post_id, 'image_group' );
195
-				add_post_meta( $post_id, 'image_group', $new_banner_array, true );
193
+			if (false !== $new_banner_array) {
194
+				delete_post_meta($post_id, 'image_group');
195
+				add_post_meta($post_id, 'image_group', $new_banner_array, true);
196 196
 				echo true;
197
-			} else {
197
+			}else {
198 198
 				echo false;
199 199
 			}
200
-		} else {
200
+		}else {
201 201
 			echo false;
202 202
 		}
203 203
 
@@ -207,81 +207,81 @@  discard block
 block discarded – undo
207 207
 	/**
208 208
 	 * formats the url
209 209
 	 */
210
-	public function format_wetu_url( $post_id ) {
211
-		return 'https://wetu.com/ImageHandler/c1920x800/' . $this->wetu_id . '/' . $this->format_filename( $post_id );
210
+	public function format_wetu_url($post_id) {
211
+		return 'https://wetu.com/ImageHandler/c1920x800/'.$this->wetu_id.'/'.$this->format_filename($post_id);
212 212
 	}
213 213
 
214 214
 	/**
215 215
 	 * formats the filename
216 216
 	 */
217
-	public function format_filename( $post_id ) {
218
-		$base = str_replace( '_', ' ', get_the_title( $post_id ) );
219
-		$base = rawurlencode( $base );
220
-		$type = get_post_mime_type( $post_id );
217
+	public function format_filename($post_id) {
218
+		$base = str_replace('_', ' ', get_the_title($post_id));
219
+		$base = rawurlencode($base);
220
+		$type = get_post_mime_type($post_id);
221 221
 
222
-		switch ( $type ) {
222
+		switch ($type) {
223 223
 			case 'image/jpeg':
224
-				return $base . '.jpg';
224
+				return $base.'.jpg';
225 225
 			break;
226 226
 			case 'image/png':
227
-				return $base . '.png';
227
+				return $base.'.png';
228 228
 			break;
229 229
 			case 'image/gif':
230
-				return $base . '.gif';
230
+				return $base.'.gif';
231 231
 			break;
232 232
 			default:
233 233
 				return false;
234 234
 		}
235 235
 	}
236 236
 
237
-	public function attach_external_image2( $url = null, $post_data = array(), $post_id = '' ) {
238
-		if ( ! $url ) {
239
-			return new WP_Error( 'missing', 'Need a valid URL' ); }
237
+	public function attach_external_image2($url = null, $post_data = array(), $post_id = '') {
238
+		if (!$url) {
239
+			return new WP_Error('missing', 'Need a valid URL'); }
240 240
 		$att_id = false;
241 241
 
242
-		require_once ABSPATH . 'wp-admin/includes/file.php';
243
-		require_once ABSPATH . 'wp-admin/includes/media.php';
244
-		require_once ABSPATH . 'wp-admin/includes/image.php';
242
+		require_once ABSPATH.'wp-admin/includes/file.php';
243
+		require_once ABSPATH.'wp-admin/includes/media.php';
244
+		require_once ABSPATH.'wp-admin/includes/image.php';
245 245
 
246
-		$tmp   = tempnam( '/tmp', 'FOO' );
247
-		$image = wp_remote_get( $url );
246
+		$tmp   = tempnam('/tmp', 'FOO');
247
+		$image = wp_remote_get($url);
248 248
 
249
-		if ( ! empty( $image ) && isset( $image['response'] ) && isset( $image['response']['code'] ) && 200 === $image['response']['code'] ) {
250
-			file_put_contents( $tmp, $image['body'] );
251
-			chmod( $tmp, '777' );
249
+		if (!empty($image) && isset($image['response']) && isset($image['response']['code']) && 200 === $image['response']['code']) {
250
+			file_put_contents($tmp, $image['body']);
251
+			chmod($tmp, '777');
252 252
 
253
-			preg_match( '/[^\?]+\.(tif|TIFF|jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG|pdf|PDF|bmp|BMP)/', $url, $matches );
254
-			$url_filename = basename( $matches[0] );
255
-			$url_filename = str_replace( '%20', '_', $url_filename );
253
+			preg_match('/[^\?]+\.(tif|TIFF|jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG|pdf|PDF|bmp|BMP)/', $url, $matches);
254
+			$url_filename = basename($matches[0]);
255
+			$url_filename = str_replace('%20', '_', $url_filename);
256 256
 			// extract filename from url for title.
257
-			$url_type = wp_check_filetype( $url_filename );
257
+			$url_type = wp_check_filetype($url_filename);
258 258
 
259 259
 			// assemble file data (should be built like $_FILES since wp_handle_sideload() will be using).
260 260
 			$file_array['tmp_name'] = $tmp;
261 261
 
262
-			if ( ! empty( $filename ) && ' ' != $filename ) {
263
-				$file_array['name'] = $filename . '.' . $url_type['ext'];
264
-			} else {
262
+			if (!empty($filename) && ' ' != $filename) {
263
+				$file_array['name'] = $filename.'.'.$url_type['ext'];
264
+			}else {
265 265
 				$file_array['name'] = $url_filename;
266 266
 			}
267 267
 
268 268
 			// set additional wp_posts columns.
269
-			if ( empty( $post_data['post_title'] ) ) {
270
-				$url_filename            = str_replace( '%20', ' ', $url_filename );
271
-				$post_data['post_title'] = basename( $url_filename, '.' . $url_type['ext'] );
269
+			if (empty($post_data['post_title'])) {
270
+				$url_filename            = str_replace('%20', ' ', $url_filename);
271
+				$post_data['post_title'] = basename($url_filename, '.'.$url_type['ext']);
272 272
 			}
273 273
 
274 274
 			// make sure gets tied to parent.
275
-			if ( empty( $post_data['post_parent'] ) ) {
275
+			if (empty($post_data['post_parent'])) {
276 276
 				$post_data['post_parent'] = $post_id;
277 277
 			}
278 278
 
279 279
 			// do the validation and storage stuff.
280
-			$att_id = media_handle_sideload( $file_array, $post_id, null, $post_data );
280
+			$att_id = media_handle_sideload($file_array, $post_id, null, $post_data);
281 281
 
282 282
 			// If error storing permanently, unlink.
283
-			if ( is_wp_error( $att_id ) ) {
284
-				unlink( $file_array['tmp_name'] );
283
+			if (is_wp_error($att_id)) {
284
+				unlink($file_array['tmp_name']);
285 285
 				return false;
286 286
 			}
287 287
 		}
Please login to merge, or discard this patch.