Passed
Push — dependabot/npm_and_yarn/gulp-s... ( 6becbf )
by
unknown
07:26 queued 03:09
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-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.
classes/class-lsx-wetu-importer-destination.php 2 patches
Indentation   +506 added lines, -506 removed lines patch added patch discarded remove patch
@@ -9,87 +9,87 @@  discard block
 block discarded – undo
9 9
 
10 10
 class LSX_WETU_Importer_Destination 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 = 'destination';
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 $destination_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
-		$this->url    = 'https://wetu.com/API/Pins/' . $this->api_key;
74
-		$this->url_qs = 'all=include';
75
-		$temp_options = get_option( '_lsx-to_settings', false );
76
-
77
-		if ( false !== $temp_options && isset( $temp_options[ $this->plugin_slug ] ) && ! empty( $temp_options[ $this->plugin_slug ] ) ) {
78
-			$this->options = $temp_options[ $this->plugin_slug ];
79
-		}
80
-
81
-		$destination_options = get_option( 'lsx_wetu_importer_destination_settings', false );
82
-
83
-		if ( false !== $destination_options ) {
84
-			$this->destination_options = $destination_options;
85
-		}
86
-	}
87
-
88
-	/**
89
-	 * Display the importer administration screen
90
-	 */
91
-	public function display_page() {
92
-		?>
12
+     /**
13
+      * The url to list items from WETU
14
+      *
15
+      * @since 0.0.1
16
+      *
17
+      * @var      string
18
+      */
19
+     public $tab_slug = 'destination';
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 $destination_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
+          $this->url    = 'https://wetu.com/API/Pins/' . $this->api_key;
74
+          $this->url_qs = 'all=include';
75
+          $temp_options = get_option( '_lsx-to_settings', false );
76
+
77
+          if ( false !== $temp_options && isset( $temp_options[ $this->plugin_slug ] ) && ! empty( $temp_options[ $this->plugin_slug ] ) ) {
78
+               $this->options = $temp_options[ $this->plugin_slug ];
79
+          }
80
+
81
+          $destination_options = get_option( 'lsx_wetu_importer_destination_settings', false );
82
+
83
+          if ( false !== $destination_options ) {
84
+               $this->destination_options = $destination_options;
85
+          }
86
+     }
87
+
88
+     /**
89
+      * Display the importer administration screen
90
+      */
91
+     public function display_page() {
92
+          ?>
93 93
 		<div class="wrap">
94 94
 			<div class="tablenav top">
95 95
 				<div class="actions">
@@ -190,13 +190,13 @@  discard block
 block discarded – undo
190 190
 											value="banner_image"/> <?php esc_html_e( 'Set Banner Image', 'lsx-wetu-importer' ); ?>
191 191
 								</li>
192 192
 								<?php
193
-								/*
193
+                                        /*
194 194
 								<li>
195 195
 									<input class="content"
196 196
 											type="checkbox" name="content[]"
197 197
 											value="unique_banner_image"/> <?php esc_html_e( 'Use the WETU banner field', 'lsx-wetu-importer' ); ?>
198 198
 								</li>*/
199
-								?>
199
+                                        ?>
200 200
 
201 201
 								<li>
202 202
 									<input class="content" checked="checked"
@@ -282,17 +282,17 @@  discard block
 block discarded – undo
282 282
 			</div>
283 283
 		</div>
284 284
 		<?php
285
-	}
285
+     }
286 286
 
287
-	/**
288
-	 * Grab all the current destination posts via the lsx_wetu_id field.
289
-	 */
290
-	public function find_current_destination( $post_type = 'destination' ) {
291
-		global $wpdb;
292
-		$return = array();
287
+     /**
288
+      * Grab all the current destination posts via the lsx_wetu_id field.
289
+      */
290
+     public function find_current_destination( $post_type = 'destination' ) {
291
+          global $wpdb;
292
+          $return = array();
293 293
 
294
-		// @codingStandardsIgnoreStart
295
-		$current_destination = $wpdb->get_results("
294
+          // @codingStandardsIgnoreStart
295
+          $current_destination = $wpdb->get_results("
296 296
 			SELECT key1.post_id,key1.meta_value,key2.post_title as name,key2.post_date as last_modified
297 297
 			FROM {$wpdb->postmeta} key1
298 298
 
@@ -304,151 +304,151 @@  discard block
 block discarded – undo
304 304
 
305 305
 			LIMIT 0,1000
306 306
 		");
307
-		// @codingStandardsIgnoreEnd
308
-
309
-		if ( null !== $current_destination && ! empty( $current_destination ) ) {
310
-			foreach ( $current_destination as $accom ) {
311
-				$return[ $accom->meta_value ] = $accom;
312
-			}
313
-		}
314
-
315
-		return $return;
316
-	}
317
-
318
-	/**
319
-	 * Run through the accommodation grabbed from the DB.
320
-	 */
321
-	public function process_ajax_search() {
322
-		$return = false;
323
-		check_ajax_referer( 'lsx_wetu_ajax_action', 'security' );
324
-		if ( isset( $_POST['action'] ) && 'lsx_tour_importer' === $_POST['action'] && isset( $_POST['type'] ) && 'destination' === $_POST['type'] ) {
325
-
326
-			$searched_items = false;
327
-			if ( isset( $_POST['keyword'] ) ) {
328
-				$keyphrases = array_map( 'sanitize_text_field', wp_unslash( $_POST['keyword'] ) );
329
-			} else {
330
-				$keyphrases = array( 0 );
331
-			}
332
-
333
-			if ( ! is_array( $keyphrases ) ) {
334
-				$keyphrases = array( $keyphrases );
335
-			}
336
-			foreach ( $keyphrases as &$keyword ) {
337
-				$keyword = ltrim( rtrim( $keyword ) );
338
-			}
339
-
340
-			$post_status = false;
341
-
342
-			if ( in_array( 'publish', $keyphrases ) ) {
343
-				$post_status = 'publish';
344
-			}
345
-			if ( in_array( 'pending', $keyphrases ) ) {
346
-				$post_status = 'pending';
347
-			}
348
-			if ( in_array( 'draft', $keyphrases ) ) {
349
-				$post_status = 'draft';
350
-			}
351
-			if ( in_array( 'import', $keyphrases ) ) {
352
-				$post_status = 'import';
353
-			}
354
-
355
-			// If there is a post status use it.
356
-			if ( false !== $post_status ) {
357
-
358
-				$accommodation         = array();
359
-				$current_accommodation = $this->find_current_accommodation( 'destination' );
360
-				if ( ! empty( $current_accommodation ) ) {
361
-					foreach ( $current_accommodation as $cs_key => $ccs_id ) {
362
-						$accommodation[] = $this->prepare_row_attributes( $cs_key, $ccs_id->post_id );
363
-					}
364
-				}
365
-
366
-				// Run through each accommodation and use it.
367
-				if ( ! empty( $accommodation ) ) {
368
-					foreach ( $accommodation as $row_key => $row ) {
369
-						$row['post_title'] = $row['name'];
370
-						if ( 'import' === $post_status ) {
371
-							if ( is_array( $this->queued_imports ) && in_array( $row['post_id'], $this->queued_imports ) ) {
372
-								$current_status = get_post_status( $row['post_id'] );
373
-								if ( 'draft' === $current_status ) {
374
-									$searched_items[ sanitize_title( $row['name'] ) . '-' . $row['id'] ] = $this->format_row( $row, $row_key );
375
-								}
376
-							} else {
377
-								continue;
378
-							}
379
-						} else {
380
-							if ( 0 === $row['post_id'] ) {
381
-								continue;
382
-							} else {
383
-								$current_status = get_post_status( $row['post_id'] );
384
-
385
-								if ( $current_status !== $post_status ) {
386
-									continue;
387
-								}
388
-							}
389
-							$searched_items[ sanitize_title( $row['name'] ) . '-' . $row['id'] ] = $this->format_row( $row, $row_key );
390
-						}
391
-					}
392
-				}
393
-			} else {
394
-
395
-				$key_string_search = implode( '+', $keyphrases );
396
-				$search_data       = wp_remote_get( $this->url . '/Search/' . $key_string_search . '/?all=include' );
397
-
398
-				if ( ! is_wp_error( $search_data ) || ! empty( $search_data ) && isset( $search_data['response'] ) && isset( $search_data['response']['code'] ) && 200 === $search_data['response']['code'] ) {
399
-					$search_data = json_decode( $search_data['body'], true );
400
-					foreach ( $search_data as $sdata_key => $sdata ) {
401
-
402
-						if ( isset( $sdata['type'] ) && 'Destination' !== trim( $sdata['type'] ) && 'Area' !== trim( $sdata['type'] ) ) {
403
-							continue;
404
-						}
405
-
406
-						$temp_id = $this->get_post_id_by_key_value( $sdata['id'] );
407
-						if ( false === $temp_id ) {
408
-							$sdata['post_id']    = 0;
409
-							$sdata['post_title'] = $sdata['name'];
410
-						} else {
411
-							$sdata['post_id']    = $temp_id;
412
-							$sdata['post_title'] = get_the_title( $temp_id );
413
-						}
414
-						$searched_items[ sanitize_title( $sdata['name'] ) . '-' . $sdata['id'] ] = $this->format_row( $sdata, $sdata_key );
415
-					}
416
-				}
417
-			}
418
-
419
-			if ( false !== $searched_items ) {
420
-				$return = implode( $searched_items );
421
-			}
422
-			print_r( $return );
423
-		} else {
424
-			echo esc_attr( 'None found' );
425
-		}
426
-		die();
427
-	}
428
-
429
-	public function prepare_row_attributes( $cs_key, $ccs_id ) {
430
-		$row_item = array(
431
-			'id'            => $cs_key,
432
-			'type'          => 'Destination',
433
-			'name'          => get_the_title( $ccs_id ),
434
-			'last_modified' => date( 'Y-m-d', strtotime( 'now' ) ),
435
-			'post_id'       => $ccs_id,
436
-		);
437
-		return $row_item;
438
-	}
439
-
440
-	/**
441
-	 * Formats the row for output on the screen.
442
-	 */
443
-	public function format_row( $row = false, $row_key = '' ) {
444
-		if ( false !== $row ) {
445
-
446
-			$status = 'import';
447
-			if ( 0 !== $row['post_id'] ) {
448
-				$status = '<a href="' . admin_url( '/post.php?post=' . $row['post_id'] . '&action=edit' ) . '" target="_blank">' . get_post_status( $row['post_id'] ) . '</a>';
449
-			}
450
-
451
-			$row_html = '
307
+          // @codingStandardsIgnoreEnd
308
+
309
+          if ( null !== $current_destination && ! empty( $current_destination ) ) {
310
+               foreach ( $current_destination as $accom ) {
311
+                    $return[ $accom->meta_value ] = $accom;
312
+               }
313
+          }
314
+
315
+          return $return;
316
+     }
317
+
318
+     /**
319
+      * Run through the accommodation grabbed from the DB.
320
+      */
321
+     public function process_ajax_search() {
322
+          $return = false;
323
+          check_ajax_referer( 'lsx_wetu_ajax_action', 'security' );
324
+          if ( isset( $_POST['action'] ) && 'lsx_tour_importer' === $_POST['action'] && isset( $_POST['type'] ) && 'destination' === $_POST['type'] ) {
325
+
326
+               $searched_items = false;
327
+               if ( isset( $_POST['keyword'] ) ) {
328
+                    $keyphrases = array_map( 'sanitize_text_field', wp_unslash( $_POST['keyword'] ) );
329
+               } else {
330
+                    $keyphrases = array( 0 );
331
+               }
332
+
333
+               if ( ! is_array( $keyphrases ) ) {
334
+                    $keyphrases = array( $keyphrases );
335
+               }
336
+               foreach ( $keyphrases as &$keyword ) {
337
+                    $keyword = ltrim( rtrim( $keyword ) );
338
+               }
339
+
340
+               $post_status = false;
341
+
342
+               if ( in_array( 'publish', $keyphrases ) ) {
343
+                    $post_status = 'publish';
344
+               }
345
+               if ( in_array( 'pending', $keyphrases ) ) {
346
+                    $post_status = 'pending';
347
+               }
348
+               if ( in_array( 'draft', $keyphrases ) ) {
349
+                    $post_status = 'draft';
350
+               }
351
+               if ( in_array( 'import', $keyphrases ) ) {
352
+                    $post_status = 'import';
353
+               }
354
+
355
+               // If there is a post status use it.
356
+               if ( false !== $post_status ) {
357
+
358
+                    $accommodation         = array();
359
+                    $current_accommodation = $this->find_current_accommodation( 'destination' );
360
+                    if ( ! empty( $current_accommodation ) ) {
361
+                         foreach ( $current_accommodation as $cs_key => $ccs_id ) {
362
+                              $accommodation[] = $this->prepare_row_attributes( $cs_key, $ccs_id->post_id );
363
+                         }
364
+                    }
365
+
366
+                    // Run through each accommodation and use it.
367
+                    if ( ! empty( $accommodation ) ) {
368
+                         foreach ( $accommodation as $row_key => $row ) {
369
+                              $row['post_title'] = $row['name'];
370
+                              if ( 'import' === $post_status ) {
371
+                                   if ( is_array( $this->queued_imports ) && in_array( $row['post_id'], $this->queued_imports ) ) {
372
+                                        $current_status = get_post_status( $row['post_id'] );
373
+                                        if ( 'draft' === $current_status ) {
374
+                                             $searched_items[ sanitize_title( $row['name'] ) . '-' . $row['id'] ] = $this->format_row( $row, $row_key );
375
+                                        }
376
+                                   } else {
377
+                                        continue;
378
+                                   }
379
+                              } else {
380
+                                   if ( 0 === $row['post_id'] ) {
381
+                                        continue;
382
+                                   } else {
383
+                                        $current_status = get_post_status( $row['post_id'] );
384
+
385
+                                        if ( $current_status !== $post_status ) {
386
+                                             continue;
387
+                                        }
388
+                                   }
389
+                                   $searched_items[ sanitize_title( $row['name'] ) . '-' . $row['id'] ] = $this->format_row( $row, $row_key );
390
+                              }
391
+                         }
392
+                    }
393
+               } else {
394
+
395
+                    $key_string_search = implode( '+', $keyphrases );
396
+                    $search_data       = wp_remote_get( $this->url . '/Search/' . $key_string_search . '/?all=include' );
397
+
398
+                    if ( ! is_wp_error( $search_data ) || ! empty( $search_data ) && isset( $search_data['response'] ) && isset( $search_data['response']['code'] ) && 200 === $search_data['response']['code'] ) {
399
+                         $search_data = json_decode( $search_data['body'], true );
400
+                         foreach ( $search_data as $sdata_key => $sdata ) {
401
+
402
+                              if ( isset( $sdata['type'] ) && 'Destination' !== trim( $sdata['type'] ) && 'Area' !== trim( $sdata['type'] ) ) {
403
+                                   continue;
404
+                              }
405
+
406
+                              $temp_id = $this->get_post_id_by_key_value( $sdata['id'] );
407
+                              if ( false === $temp_id ) {
408
+                                   $sdata['post_id']    = 0;
409
+                                   $sdata['post_title'] = $sdata['name'];
410
+                              } else {
411
+                                   $sdata['post_id']    = $temp_id;
412
+                                   $sdata['post_title'] = get_the_title( $temp_id );
413
+                              }
414
+                              $searched_items[ sanitize_title( $sdata['name'] ) . '-' . $sdata['id'] ] = $this->format_row( $sdata, $sdata_key );
415
+                         }
416
+                    }
417
+               }
418
+
419
+               if ( false !== $searched_items ) {
420
+                    $return = implode( $searched_items );
421
+               }
422
+               print_r( $return );
423
+          } else {
424
+               echo esc_attr( 'None found' );
425
+          }
426
+          die();
427
+     }
428
+
429
+     public function prepare_row_attributes( $cs_key, $ccs_id ) {
430
+          $row_item = array(
431
+               'id'            => $cs_key,
432
+               'type'          => 'Destination',
433
+               'name'          => get_the_title( $ccs_id ),
434
+               'last_modified' => date( 'Y-m-d', strtotime( 'now' ) ),
435
+               'post_id'       => $ccs_id,
436
+          );
437
+          return $row_item;
438
+     }
439
+
440
+     /**
441
+      * Formats the row for output on the screen.
442
+      */
443
+     public function format_row( $row = false, $row_key = '' ) {
444
+          if ( false !== $row ) {
445
+
446
+               $status = 'import';
447
+               if ( 0 !== $row['post_id'] ) {
448
+                    $status = '<a href="' . admin_url( '/post.php?post=' . $row['post_id'] . '&action=edit' ) . '" target="_blank">' . get_post_status( $row['post_id'] ) . '</a>';
449
+               }
450
+
451
+               $row_html = '
452 452
 			<tr class="post-' . $row['post_id'] . ' type-tour" id="post-' . $row['post_id'] . '">
453 453
 				<th class="check-column" scope="row">
454 454
 					<label for="cb-select-' . $row['id'] . '" class="screen-reader-text">' . $row['name'] . '</label>
@@ -467,273 +467,273 @@  discard block
 block discarded – undo
467 467
 					' . $row['id'] . '
468 468
 				</td>
469 469
 			</tr>';
470
-			return $row_html;
471
-		}
472
-	}
473
-
474
-	/**
475
-	 * Connect to wetu
476
-	 */
477
-	public function process_ajax_import() {
478
-		$return = false;
479
-
480
-		check_ajax_referer( 'lsx_wetu_ajax_action', 'security' );
481
-		if ( isset( $_POST['action'] ) && 'lsx_import_items' === $_POST['action'] && isset( $_POST['type'] ) && 'destination' === $_POST['type'] && isset( $_POST['wetu_id'] ) ) {
482
-
483
-			$wetu_id = sanitize_text_field( $_POST['wetu_id'] );
484
-
485
-			if ( isset( $_POST['post_id'] ) ) {
486
-				$post_id            = sanitize_text_field( $_POST['post_id'] );
487
-				$this->current_post = get_post( $post_id );
488
-			} else {
489
-				$post_id = 0;
490
-			}
491
-
492
-			if ( isset( $_POST['team_members'] ) ) {
493
-				$team_members = array_map( 'sanitize_text_field', wp_unslash( $_POST['team_members'] ) );
494
-			} else {
495
-				$team_members = false;
496
-			}
497
-
498
-			$safari_brands = false;
499
-
500
-			delete_option( 'lsx_wetu_importer_destination_settings' );
501
-
502
-			if ( isset( $_POST['content'] ) && is_array( $_POST['content'] ) && ! empty( $_POST['content'] ) ) {
503
-				$content = array_map( 'sanitize_text_field', wp_unslash( $_POST['content'] ) );
504
-				add_option( 'lsx_wetu_importer_destination_settings', $content );
505
-			} else {
506
-				$content = false;
507
-			}
508
-
509
-			$jdata = wp_remote_get( $this->url . '/Get?' . $this->url_qs . '&ids=' . $wetu_id );
510
-
511
-			if ( ! empty( $jdata ) && isset( $jdata['response'] ) && isset( $jdata['response']['code'] ) && 200 === $jdata['response']['code'] ) {
512
-				$adata  = json_decode( $jdata['body'], true );
513
-				$return = $this->import_row( $adata, $wetu_id, $post_id, $team_members, $content, $safari_brands );
514
-				$this->remove_from_queue( $return );
515
-				$this->format_completed_row( $return );
516
-			} else {
517
-				$this->format_error( esc_html__( 'There was a problem importing your destination, please try refreshing the page.', 'lsx-wetu-importer' ) );
518
-			}
519
-		}
520
-		die();
521
-	}
522
-
523
-	/**
524
-	 * Saves the queue to the option.
525
-	 */
526
-	public function remove_from_queue( $id ) {
527
-		if ( ! empty( $this->queued_imports ) ) {
528
-			$key = array_search( $id, $this->queued_imports );
529
-			if ( false !== $key ) {
530
-				unset( $this->queued_imports[ $key ] );
531
-
532
-				delete_option( 'lsx_wetu_importer_que' );
533
-				update_option( 'lsx_wetu_importer_que', $this->queued_imports );
534
-			}
535
-		}
536
-	}
537
-
538
-	/**
539
-	 * Connect to wetu
540
-	 */
541
-	public function import_row( $data, $wetu_id, $id = 0, $team_members = false, $importable_content = array(), $safari_brands = false ) {
542
-		if ( 'Destination' === trim( $data[0]['type'] ) || 'Area' === trim( $data[0]['type'] ) ) {
543
-			$post_name         = '';
544
-			$data_post_content = '';
545
-			$data_post_excerpt = '';
546
-
547
-			$post = array(
548
-				'post_type' => 'destination',
549
-			);
550
-
551
-			if ( ! empty( $importable_content ) && in_array( 'country', $importable_content ) ) {
552
-				$parent = $this->check_for_parent( $data );
553
-				if ( false !== $parent ) {
554
-					$post['post_parent'] = $parent;
555
-				}
556
-			}
557
-
558
-			// Set the post_content.
559
-			if ( ! empty( $importable_content ) && in_array( 'description', $importable_content ) ) {
560
-				if ( isset( $data[0]['content']['general_description'] ) ) {
561
-
562
-					if ( in_array( 'strip_tags', $importable_content ) ) {
563
-						$post['post_content'] = wp_strip_all_tags( $data[0]['content']['general_description'] );
564
-					} else {
565
-						$post['post_content'] = $data[0]['content']['general_description'];
566
-					}
567
-				}
568
-			}
569
-
570
-			if ( false !== $id && '0' !== $id ) {
571
-				$post['ID'] = $id;
572
-				if ( isset( $this->options ) && 'on' !== $this->options['disable_destination_title'] && isset( $data[0]['name'] ) ) {
573
-					$post['post_title'] = $data[0]['name'];
574
-					$post['post_name']  = wp_unique_post_slug( sanitize_title( $data[0]['name'] ), $id, 'draft', 'destination', 0 );
575
-				}
576
-				$post['post_status'] = 'publish';
577
-
578
-				$id        = wp_update_post( $post );
579
-				$prev_date = get_post_meta( $id, 'lsx_wetu_modified_date', true );
580
-				update_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data[0]['last_modified'] ), $prev_date );
581
-			} else {
582
-				// Set the name.
583
-				if ( isset( $data[0]['name'] ) ) {
584
-					$post_name = wp_unique_post_slug( sanitize_title( $data[0]['name'] ), $id, 'draft', 'destination', 0 );
585
-				}
586
-
587
-				$post['post_name']   = $post_name;
588
-				$post['post_title']  = $data[0]['name'];
589
-				$post['post_status'] = 'publish';
590
-				$id                  = wp_insert_post( $post );
591
-
592
-				// Save the WETU ID and the Last date it was modified.
593
-				if ( false !== $id ) {
594
-					add_post_meta( $id, 'lsx_wetu_id', $wetu_id );
595
-					add_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data[0]['last_modified'] ) );
596
-				}
597
-			}
598
-
599
-			$this->find_attachments( $id );
600
-
601
-			// Set the team member if it is there.
602
-			if ( post_type_exists( 'team' ) && false !== $team_members && '' !== $team_members ) {
603
-				$this->set_team_member( $id, $team_members );
604
-			}
605
-
606
-			$this->set_map_data( $data, $id, 9 );
607
-
608
-			// Set the Room Data.
609
-			if ( false !== $importable_content && in_array( 'videos', $importable_content ) ) {
610
-				$this->set_video_data( $data, $id );
611
-			}
612
-
613
-			// Set the Electricity.
614
-			if ( false !== $importable_content && in_array( 'electricity', $importable_content ) ) {
615
-				$this->set_travel_info( $data, $id, 'electricity', $importable_content );
616
-			}
617
-			// Set the cuisine.
618
-			if ( false !== $importable_content && in_array( 'cuisine', $importable_content ) ) {
619
-				$this->set_travel_info( $data, $id, 'cuisine', $importable_content );
620
-			}
621
-			// Set the banking.
622
-			if ( false !== $importable_content && in_array( 'banking', $importable_content ) ) {
623
-				$this->set_travel_info( $data, $id, 'banking', $importable_content );
624
-			}
625
-			// Set the transport.
626
-			if ( false !== $importable_content && in_array( 'transport', $importable_content ) ) {
627
-				$this->set_travel_info( $data, $id, 'transport', $importable_content );
628
-			}
629
-			// Set the dress.
630
-			if ( false !== $importable_content && in_array( 'dress', $importable_content ) ) {
631
-				$this->set_travel_info( $data, $id, 'dress', $importable_content );
632
-			}
633
-			// Set the climate.
634
-			if ( false !== $importable_content && in_array( 'climate', $importable_content ) ) {
635
-				$this->set_travel_info( $data, $id, 'climate', $importable_content );
636
-			}
637
-			// Set the Health.
638
-			if ( false !== $importable_content && in_array( 'health', $importable_content ) ) {
639
-				$this->set_travel_info( $data, $id, 'health', $importable_content );
640
-			}
641
-			// Set the Safety.
642
-			if ( false !== $importable_content && in_array( 'safety', $importable_content ) ) {
643
-				$this->set_travel_info( $data, $id, 'safety', $importable_content );
644
-			}
645
-			// Set the Visa.
646
-			if ( false !== $importable_content && in_array( 'visa', $importable_content ) ) {
647
-				$this->set_travel_info( $data, $id, 'visa', $importable_content );
648
-			}
649
-			// Set the General.
650
-			if ( false !== $importable_content && in_array( 'additional_info', $importable_content ) ) {
651
-				$this->set_travel_info( $data, $id, 'additional_info', $importable_content );
652
-			}
653
-
654
-			// Setup some default for use in the import.
655
-			if ( false !== $importable_content && ( in_array( 'gallery', $importable_content ) || in_array( 'banner_image', $importable_content ) || in_array( 'featured_image', $importable_content ) ) ) {
656
-				$this->find_attachments( $id );
657
-
658
-				// Set the featured image.
659
-				if ( false !== $importable_content && in_array( 'featured_image', $importable_content ) ) {
660
-					$this->set_featured_image( $data, $id );
661
-				}
662
-				if ( false !== $importable_content && in_array( 'banner_image', $importable_content ) ) {
663
-					$this->set_banner_image( $data, $id, $importable_content );
664
-				}
665
-				// Import the main gallery.
666
-				if ( false !== $importable_content && in_array( 'gallery', $importable_content ) ) {
667
-					$this->create_main_gallery( $data, $id );
668
-				}
669
-			}
670
-
671
-			// Set the continent.
672
-			if ( false !== $importable_content && in_array( 'continent', $importable_content ) ) {
673
-				$this->set_continent( $data, $id );
674
-			}
675
-		}
676
-
677
-		return $id;
678
-	}
679
-
680
-	/**
681
-	 * Saves the room data
682
-	 */
683
-	public function set_travel_info( $data, $id, $meta_key, $importable = array( 'none' ) ) {
684
-		if ( ! empty( $data[0]['travel_information'] ) && isset( $data[0]['travel_information'][ $meta_key ] ) ) {
685
-			$content = $data[0]['travel_information'][ $meta_key ];
686
-
687
-			if ( in_array( 'strip_tags', $importable ) ) {
688
-				$content = strip_tags( $content );
689
-			}
690
-
691
-			$this->save_custom_field( $content, $meta_key, $id );
692
-		}
693
-	}
694
-
695
-	/**
696
-	 * Set the Travel Style
697
-	 */
698
-	public function set_continent( $data, $id ) {
699
-
700
-		if ( isset( $data[0]['position']['country'] ) && $data[0]['map_object_id'] === $data[0]['position']['country_content_entity_id'] ) {
701
-			// Get the continent code.
702
-			$country_code    = to_country_data( $data[0]['position']['country'], false );
703
-			$continent_code  = to_continent_code( $country_code );
704
-			$continent_label = to_continent_label( $continent_code );
705
-
706
-			if ( ! empty( tour_operator()->options['display']['enable_search_region_filter'] ) ) {
707
-				$continent_label = to_continent_region_label( $country_code );
708
-			}
709
-
710
-			if ( '' !== $continent_label ) {
711
-				$term = term_exists( trim( $continent_label ), 'continent' );
712
-				if ( ! $term ) {
713
-					$term = wp_insert_term( trim( $continent_label ), 'continent' );
714
-
715
-					if ( is_wp_error( $term ) ) {
716
-						echo wp_kses_post( $term->get_error_message() );
717
-					}
718
-				} else {
719
-					wp_set_object_terms( $id, sanitize_title( $continent_label ), 'continent', true );
720
-				}
721
-			}
722
-		}
723
-	}
724
-
725
-	/**
726
-	 * Save the list of Accommodation into an option
727
-	 */
728
-	public function check_for_parent( $data = array() ) {
729
-		global $wpdb;
730
-
731
-		if ( $data[0]['position']['country_content_entity_id'] !== $data[0]['position']['destination_content_entity_id'] ) {
732
-			$result = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = 'lsx_wetu_id' AND meta_value = '%s'", array( $data[0]['position']['country_content_entity_id'] ) ) );
733
-			if ( ! empty( $result ) && '' !== $result && false !== $result ) {
734
-				return $result;
735
-			}
736
-		}
737
-		return false;
738
-	}
470
+               return $row_html;
471
+          }
472
+     }
473
+
474
+     /**
475
+      * Connect to wetu
476
+      */
477
+     public function process_ajax_import() {
478
+          $return = false;
479
+
480
+          check_ajax_referer( 'lsx_wetu_ajax_action', 'security' );
481
+          if ( isset( $_POST['action'] ) && 'lsx_import_items' === $_POST['action'] && isset( $_POST['type'] ) && 'destination' === $_POST['type'] && isset( $_POST['wetu_id'] ) ) {
482
+
483
+               $wetu_id = sanitize_text_field( $_POST['wetu_id'] );
484
+
485
+               if ( isset( $_POST['post_id'] ) ) {
486
+                    $post_id            = sanitize_text_field( $_POST['post_id'] );
487
+                    $this->current_post = get_post( $post_id );
488
+               } else {
489
+                    $post_id = 0;
490
+               }
491
+
492
+               if ( isset( $_POST['team_members'] ) ) {
493
+                    $team_members = array_map( 'sanitize_text_field', wp_unslash( $_POST['team_members'] ) );
494
+               } else {
495
+                    $team_members = false;
496
+               }
497
+
498
+               $safari_brands = false;
499
+
500
+               delete_option( 'lsx_wetu_importer_destination_settings' );
501
+
502
+               if ( isset( $_POST['content'] ) && is_array( $_POST['content'] ) && ! empty( $_POST['content'] ) ) {
503
+                    $content = array_map( 'sanitize_text_field', wp_unslash( $_POST['content'] ) );
504
+                    add_option( 'lsx_wetu_importer_destination_settings', $content );
505
+               } else {
506
+                    $content = false;
507
+               }
508
+
509
+               $jdata = wp_remote_get( $this->url . '/Get?' . $this->url_qs . '&ids=' . $wetu_id );
510
+
511
+               if ( ! empty( $jdata ) && isset( $jdata['response'] ) && isset( $jdata['response']['code'] ) && 200 === $jdata['response']['code'] ) {
512
+                    $adata  = json_decode( $jdata['body'], true );
513
+                    $return = $this->import_row( $adata, $wetu_id, $post_id, $team_members, $content, $safari_brands );
514
+                    $this->remove_from_queue( $return );
515
+                    $this->format_completed_row( $return );
516
+               } else {
517
+                    $this->format_error( esc_html__( 'There was a problem importing your destination, please try refreshing the page.', 'lsx-wetu-importer' ) );
518
+               }
519
+          }
520
+          die();
521
+     }
522
+
523
+     /**
524
+      * Saves the queue to the option.
525
+      */
526
+     public function remove_from_queue( $id ) {
527
+          if ( ! empty( $this->queued_imports ) ) {
528
+               $key = array_search( $id, $this->queued_imports );
529
+               if ( false !== $key ) {
530
+                    unset( $this->queued_imports[ $key ] );
531
+
532
+                    delete_option( 'lsx_wetu_importer_que' );
533
+                    update_option( 'lsx_wetu_importer_que', $this->queued_imports );
534
+               }
535
+          }
536
+     }
537
+
538
+     /**
539
+      * Connect to wetu
540
+      */
541
+     public function import_row( $data, $wetu_id, $id = 0, $team_members = false, $importable_content = array(), $safari_brands = false ) {
542
+          if ( 'Destination' === trim( $data[0]['type'] ) || 'Area' === trim( $data[0]['type'] ) ) {
543
+               $post_name         = '';
544
+               $data_post_content = '';
545
+               $data_post_excerpt = '';
546
+
547
+               $post = array(
548
+                    'post_type' => 'destination',
549
+               );
550
+
551
+               if ( ! empty( $importable_content ) && in_array( 'country', $importable_content ) ) {
552
+                    $parent = $this->check_for_parent( $data );
553
+                    if ( false !== $parent ) {
554
+                         $post['post_parent'] = $parent;
555
+                    }
556
+               }
557
+
558
+               // Set the post_content.
559
+               if ( ! empty( $importable_content ) && in_array( 'description', $importable_content ) ) {
560
+                    if ( isset( $data[0]['content']['general_description'] ) ) {
561
+
562
+                         if ( in_array( 'strip_tags', $importable_content ) ) {
563
+                              $post['post_content'] = wp_strip_all_tags( $data[0]['content']['general_description'] );
564
+                         } else {
565
+                              $post['post_content'] = $data[0]['content']['general_description'];
566
+                         }
567
+                    }
568
+               }
569
+
570
+               if ( false !== $id && '0' !== $id ) {
571
+                    $post['ID'] = $id;
572
+                    if ( isset( $this->options ) && 'on' !== $this->options['disable_destination_title'] && isset( $data[0]['name'] ) ) {
573
+                         $post['post_title'] = $data[0]['name'];
574
+                         $post['post_name']  = wp_unique_post_slug( sanitize_title( $data[0]['name'] ), $id, 'draft', 'destination', 0 );
575
+                    }
576
+                    $post['post_status'] = 'publish';
577
+
578
+                    $id        = wp_update_post( $post );
579
+                    $prev_date = get_post_meta( $id, 'lsx_wetu_modified_date', true );
580
+                    update_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data[0]['last_modified'] ), $prev_date );
581
+               } else {
582
+                    // Set the name.
583
+                    if ( isset( $data[0]['name'] ) ) {
584
+                         $post_name = wp_unique_post_slug( sanitize_title( $data[0]['name'] ), $id, 'draft', 'destination', 0 );
585
+                    }
586
+
587
+                    $post['post_name']   = $post_name;
588
+                    $post['post_title']  = $data[0]['name'];
589
+                    $post['post_status'] = 'publish';
590
+                    $id                  = wp_insert_post( $post );
591
+
592
+                    // Save the WETU ID and the Last date it was modified.
593
+                    if ( false !== $id ) {
594
+                         add_post_meta( $id, 'lsx_wetu_id', $wetu_id );
595
+                         add_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data[0]['last_modified'] ) );
596
+                    }
597
+               }
598
+
599
+               $this->find_attachments( $id );
600
+
601
+               // Set the team member if it is there.
602
+               if ( post_type_exists( 'team' ) && false !== $team_members && '' !== $team_members ) {
603
+                    $this->set_team_member( $id, $team_members );
604
+               }
605
+
606
+               $this->set_map_data( $data, $id, 9 );
607
+
608
+               // Set the Room Data.
609
+               if ( false !== $importable_content && in_array( 'videos', $importable_content ) ) {
610
+                    $this->set_video_data( $data, $id );
611
+               }
612
+
613
+               // Set the Electricity.
614
+               if ( false !== $importable_content && in_array( 'electricity', $importable_content ) ) {
615
+                    $this->set_travel_info( $data, $id, 'electricity', $importable_content );
616
+               }
617
+               // Set the cuisine.
618
+               if ( false !== $importable_content && in_array( 'cuisine', $importable_content ) ) {
619
+                    $this->set_travel_info( $data, $id, 'cuisine', $importable_content );
620
+               }
621
+               // Set the banking.
622
+               if ( false !== $importable_content && in_array( 'banking', $importable_content ) ) {
623
+                    $this->set_travel_info( $data, $id, 'banking', $importable_content );
624
+               }
625
+               // Set the transport.
626
+               if ( false !== $importable_content && in_array( 'transport', $importable_content ) ) {
627
+                    $this->set_travel_info( $data, $id, 'transport', $importable_content );
628
+               }
629
+               // Set the dress.
630
+               if ( false !== $importable_content && in_array( 'dress', $importable_content ) ) {
631
+                    $this->set_travel_info( $data, $id, 'dress', $importable_content );
632
+               }
633
+               // Set the climate.
634
+               if ( false !== $importable_content && in_array( 'climate', $importable_content ) ) {
635
+                    $this->set_travel_info( $data, $id, 'climate', $importable_content );
636
+               }
637
+               // Set the Health.
638
+               if ( false !== $importable_content && in_array( 'health', $importable_content ) ) {
639
+                    $this->set_travel_info( $data, $id, 'health', $importable_content );
640
+               }
641
+               // Set the Safety.
642
+               if ( false !== $importable_content && in_array( 'safety', $importable_content ) ) {
643
+                    $this->set_travel_info( $data, $id, 'safety', $importable_content );
644
+               }
645
+               // Set the Visa.
646
+               if ( false !== $importable_content && in_array( 'visa', $importable_content ) ) {
647
+                    $this->set_travel_info( $data, $id, 'visa', $importable_content );
648
+               }
649
+               // Set the General.
650
+               if ( false !== $importable_content && in_array( 'additional_info', $importable_content ) ) {
651
+                    $this->set_travel_info( $data, $id, 'additional_info', $importable_content );
652
+               }
653
+
654
+               // Setup some default for use in the import.
655
+               if ( false !== $importable_content && ( in_array( 'gallery', $importable_content ) || in_array( 'banner_image', $importable_content ) || in_array( 'featured_image', $importable_content ) ) ) {
656
+                    $this->find_attachments( $id );
657
+
658
+                    // Set the featured image.
659
+                    if ( false !== $importable_content && in_array( 'featured_image', $importable_content ) ) {
660
+                         $this->set_featured_image( $data, $id );
661
+                    }
662
+                    if ( false !== $importable_content && in_array( 'banner_image', $importable_content ) ) {
663
+                         $this->set_banner_image( $data, $id, $importable_content );
664
+                    }
665
+                    // Import the main gallery.
666
+                    if ( false !== $importable_content && in_array( 'gallery', $importable_content ) ) {
667
+                         $this->create_main_gallery( $data, $id );
668
+                    }
669
+               }
670
+
671
+               // Set the continent.
672
+               if ( false !== $importable_content && in_array( 'continent', $importable_content ) ) {
673
+                    $this->set_continent( $data, $id );
674
+               }
675
+          }
676
+
677
+          return $id;
678
+     }
679
+
680
+     /**
681
+      * Saves the room data
682
+      */
683
+     public function set_travel_info( $data, $id, $meta_key, $importable = array( 'none' ) ) {
684
+          if ( ! empty( $data[0]['travel_information'] ) && isset( $data[0]['travel_information'][ $meta_key ] ) ) {
685
+               $content = $data[0]['travel_information'][ $meta_key ];
686
+
687
+               if ( in_array( 'strip_tags', $importable ) ) {
688
+                    $content = strip_tags( $content );
689
+               }
690
+
691
+               $this->save_custom_field( $content, $meta_key, $id );
692
+          }
693
+     }
694
+
695
+     /**
696
+      * Set the Travel Style
697
+      */
698
+     public function set_continent( $data, $id ) {
699
+
700
+          if ( isset( $data[0]['position']['country'] ) && $data[0]['map_object_id'] === $data[0]['position']['country_content_entity_id'] ) {
701
+               // Get the continent code.
702
+               $country_code    = to_country_data( $data[0]['position']['country'], false );
703
+               $continent_code  = to_continent_code( $country_code );
704
+               $continent_label = to_continent_label( $continent_code );
705
+
706
+               if ( ! empty( tour_operator()->options['display']['enable_search_region_filter'] ) ) {
707
+                    $continent_label = to_continent_region_label( $country_code );
708
+               }
709
+
710
+               if ( '' !== $continent_label ) {
711
+                    $term = term_exists( trim( $continent_label ), 'continent' );
712
+                    if ( ! $term ) {
713
+                         $term = wp_insert_term( trim( $continent_label ), 'continent' );
714
+
715
+                         if ( is_wp_error( $term ) ) {
716
+                              echo wp_kses_post( $term->get_error_message() );
717
+                         }
718
+                    } else {
719
+                         wp_set_object_terms( $id, sanitize_title( $continent_label ), 'continent', true );
720
+                    }
721
+               }
722
+          }
723
+     }
724
+
725
+     /**
726
+      * Save the list of Accommodation into an option
727
+      */
728
+     public function check_for_parent( $data = array() ) {
729
+          global $wpdb;
730
+
731
+          if ( $data[0]['position']['country_content_entity_id'] !== $data[0]['position']['destination_content_entity_id'] ) {
732
+               $result = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = 'lsx_wetu_id' AND meta_value = '%s'", array( $data[0]['position']['country_content_entity_id'] ) ) );
733
+               if ( ! empty( $result ) && '' !== $result && false !== $result ) {
734
+                    return $result;
735
+               }
736
+          }
737
+          return false;
738
+     }
739 739
 }
Please login to merge, or discard this patch.
Spacing   +224 added lines, -224 removed lines patch added patch discarded remove patch
@@ -70,17 +70,17 @@  discard block
 block discarded – undo
70 70
 	 */
71 71
 	public function set_variables() {
72 72
 		parent::set_variables();
73
-		$this->url    = 'https://wetu.com/API/Pins/' . $this->api_key;
73
+		$this->url    = 'https://wetu.com/API/Pins/'.$this->api_key;
74 74
 		$this->url_qs = 'all=include';
75
-		$temp_options = get_option( '_lsx-to_settings', false );
75
+		$temp_options = get_option('_lsx-to_settings', false);
76 76
 
77
-		if ( false !== $temp_options && isset( $temp_options[ $this->plugin_slug ] ) && ! empty( $temp_options[ $this->plugin_slug ] ) ) {
78
-			$this->options = $temp_options[ $this->plugin_slug ];
77
+		if (false !== $temp_options && isset($temp_options[$this->plugin_slug]) && !empty($temp_options[$this->plugin_slug])) {
78
+			$this->options = $temp_options[$this->plugin_slug];
79 79
 		}
80 80
 
81
-		$destination_options = get_option( 'lsx_wetu_importer_destination_settings', false );
81
+		$destination_options = get_option('lsx_wetu_importer_destination_settings', false);
82 82
 
83
-		if ( false !== $destination_options ) {
83
+		if (false !== $destination_options) {
84 84
 			$this->destination_options = $destination_options;
85 85
 		}
86 86
 	}
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 			</div>
99 99
 
100 100
 			<form method="get" action="" id="posts-filter">
101
-				<input type="hidden" name="post_type" class="post_type" value="<?php echo esc_attr( $this->tab_slug ); ?>"/>
101
+				<input type="hidden" name="post_type" class="post_type" value="<?php echo esc_attr($this->tab_slug); ?>"/>
102 102
 
103 103
 				<table class="wp-list-table widefat fixed posts">
104 104
 					<?php $this->table_header(); ?>
@@ -107,11 +107,11 @@  discard block
 block discarded – undo
107 107
 					<tr class="post-0 type-tour status-none" id="post-0">
108 108
 						<th class="check-column" scope="row">
109 109
 							<label for="cb-select-0"
110
-								   class="screen-reader-text"><?php esc_html_e( 'Enter a title to search for and press enter', 'lsx-wetu-importer' ); ?></label>
110
+								   class="screen-reader-text"><?php esc_html_e('Enter a title to search for and press enter', 'lsx-wetu-importer'); ?></label>
111 111
 						</th>
112 112
 						<td class="post-title page-title column-title">
113 113
 							<strong>
114
-								<?php esc_html_e( 'Enter a title to search for', 'lsx-wetu-importer' ); ?>
114
+								<?php esc_html_e('Enter a title to search for', 'lsx-wetu-importer'); ?>
115 115
 							</strong>
116 116
 						</td>
117 117
 						<td class="date column-date">
@@ -126,9 +126,9 @@  discard block
 block discarded – undo
126 126
 				</table>
127 127
 
128 128
 				<p><input class="button button-primary add" type="button"
129
-						  value="<?php esc_html_e( 'Add to List', 'lsx-wetu-importer' ); ?>"/>
129
+						  value="<?php esc_html_e('Add to List', 'lsx-wetu-importer'); ?>"/>
130 130
 					<input class="button button-primary clear" type="button"
131
-						   value="<?php esc_html_e( 'Clear', 'lsx-wetu-importer' ); ?>"/>
131
+						   value="<?php esc_html_e('Clear', 'lsx-wetu-importer'); ?>"/>
132 132
 				</p>
133 133
 			</form>
134 134
 
@@ -138,56 +138,56 @@  discard block
 block discarded – undo
138 138
 
139 139
 					<div class="row">
140 140
 						<div class="settings-all" style="width:30%;display:block;float:left;">
141
-							<h3><?php esc_html_e( 'What content to Sync from WETU' ); ?></h3>
141
+							<h3><?php esc_html_e('What content to Sync from WETU'); ?></h3>
142 142
 							<ul>
143
-								<?php if ( isset( $this->options ) && isset( $this->options['disable_destination_descriptions'] ) && 'on' !== $this->options['disable_destination_descriptions'] ) { ?>
143
+								<?php if (isset($this->options) && isset($this->options['disable_destination_descriptions']) && 'on' !== $this->options['disable_destination_descriptions']) { ?>
144 144
 								<li>
145 145
 									<input class="content" checked="checked"
146 146
 										   type="checkbox" name="content[]"
147
-										   value="description"/> <?php esc_html_e( 'Description', 'lsx-wetu-importer' ); ?></li>
147
+										   value="description"/> <?php esc_html_e('Description', 'lsx-wetu-importer'); ?></li>
148 148
 								<?php } ?>
149 149
 
150 150
 								<li>
151 151
 									<input class="content" checked="checked"
152 152
 										   type="checkbox" name="content[]"
153
-										   value="gallery"/> <?php esc_html_e( 'Main Gallery', 'lsx-wetu-importer' ); ?></li>
153
+										   value="gallery"/> <?php esc_html_e('Main Gallery', 'lsx-wetu-importer'); ?></li>
154 154
 
155 155
 									<li>
156 156
 										<input class="content" checked="checked"
157 157
 											   type="checkbox" name="content[]"
158
-											   value="location"/> <?php esc_html_e( 'Location', 'lsx-wetu-importer' ); ?>
158
+											   value="location"/> <?php esc_html_e('Location', 'lsx-wetu-importer'); ?>
159 159
 									</li>
160 160
 
161 161
 
162
-								<?php if ( class_exists( 'LSX_TO_Videos' ) ) { ?>
162
+								<?php if (class_exists('LSX_TO_Videos')) { ?>
163 163
 									<li>
164 164
 										<input class="content" checked="checked"
165 165
 											   type="checkbox" name="content[]"
166
-											   value="videos"/> <?php esc_html_e( 'Videos', 'lsx-wetu-importer' ); ?></li>
166
+											   value="videos"/> <?php esc_html_e('Videos', 'lsx-wetu-importer'); ?></li>
167 167
 								<?php } ?>
168 168
 
169 169
 							</ul>
170
-							<h4><?php esc_html_e( 'Additional Content' ); ?></h4>
170
+							<h4><?php esc_html_e('Additional Content'); ?></h4>
171 171
 							<ul>
172 172
 								<li>
173 173
 									<input class="content" checked="checked"
174 174
 										   type="checkbox" name="content[]"
175
-										   value="country"/> <?php esc_html_e( 'Set Country', 'lsx-wetu-importer' ); ?></li>
175
+										   value="country"/> <?php esc_html_e('Set Country', 'lsx-wetu-importer'); ?></li>
176 176
 								<li>
177 177
 									<input class="content" checked="checked"
178 178
 										   type="checkbox" name="content[]"
179
-										   value="continent"/> <?php esc_html_e( 'Set Continent', 'lsx-wetu-importer' ); ?></li>
179
+										   value="continent"/> <?php esc_html_e('Set Continent', 'lsx-wetu-importer'); ?></li>
180 180
 
181 181
 								<li>
182 182
 									<input class="content" checked="checked"
183 183
 										   type="checkbox" name="content[]"
184
-										   value="featured_image"/> <?php esc_html_e( 'Set Featured Image', 'lsx-wetu-importer' ); ?>
184
+										   value="featured_image"/> <?php esc_html_e('Set Featured Image', 'lsx-wetu-importer'); ?>
185 185
 								</li>
186 186
 
187 187
 								<li>
188 188
 									<input class="content" checked="checked"
189 189
 											type="checkbox" name="content[]"
190
-											value="banner_image"/> <?php esc_html_e( 'Set Banner Image', 'lsx-wetu-importer' ); ?>
190
+											value="banner_image"/> <?php esc_html_e('Set Banner Image', 'lsx-wetu-importer'); ?>
191 191
 								</li>
192 192
 								<?php
193 193
 								/*
@@ -201,54 +201,54 @@  discard block
 block discarded – undo
201 201
 								<li>
202 202
 									<input class="content" checked="checked"
203 203
 										   type="checkbox" name="content[]"
204
-										   value="strip_tags"/> <?php esc_html_e( 'Strip HTML from the description', 'lsx-wetu-importer' ); ?></li>
204
+										   value="strip_tags"/> <?php esc_html_e('Strip HTML from the description', 'lsx-wetu-importer'); ?></li>
205 205
 							</ul>
206 206
 						</div>
207 207
 						<div class="settings-all" style="width:30%;display:block;float:left;">
208
-							<h3><?php esc_html_e( 'Travel Information' ); ?></h3>
208
+							<h3><?php esc_html_e('Travel Information'); ?></h3>
209 209
 							<ul>
210 210
 								<li>
211 211
 									<input class="content" checked="checked"
212 212
 										   type="checkbox" name="content[]"
213
-										   value="electricity"/> <?php esc_html_e( 'Electricity', 'lsx-wetu-importer' ); ?></li>
213
+										   value="electricity"/> <?php esc_html_e('Electricity', 'lsx-wetu-importer'); ?></li>
214 214
 								<li>
215 215
 									<input class="content" checked="checked"
216 216
 										   type="checkbox" name="content[]"
217
-										   value="banking"/> <?php esc_html_e( 'Banking', 'lsx-wetu-importer' ); ?></li>
217
+										   value="banking"/> <?php esc_html_e('Banking', 'lsx-wetu-importer'); ?></li>
218 218
 								<li>
219 219
 									<input class="content" checked="checked"
220 220
 										   type="checkbox" name="content[]"
221
-										   value="cuisine"/> <?php esc_html_e( 'Cuisine', 'lsx-wetu-importer' ); ?></li>
221
+										   value="cuisine"/> <?php esc_html_e('Cuisine', 'lsx-wetu-importer'); ?></li>
222 222
 								<li>
223 223
 									<input class="content" checked="checked"
224 224
 										   type="checkbox" name="content[]"
225
-										   value="climate"/> <?php esc_html_e( 'Climate', 'lsx-wetu-importer' ); ?></li>
225
+										   value="climate"/> <?php esc_html_e('Climate', 'lsx-wetu-importer'); ?></li>
226 226
 								<li>
227 227
 									<input class="content" checked="checked"
228 228
 										   type="checkbox" name="content[]"
229
-										   value="transport"/> <?php esc_html_e( 'Transport', 'lsx-wetu-importer' ); ?></li>
229
+										   value="transport"/> <?php esc_html_e('Transport', 'lsx-wetu-importer'); ?></li>
230 230
 								<li><input class="content" checked="checked"
231 231
 										   type="checkbox" name="content[]"
232
-										   value="dress"/> <?php esc_html_e( 'Dress', 'lsx-wetu-importer' ); ?></li>
232
+										   value="dress"/> <?php esc_html_e('Dress', 'lsx-wetu-importer'); ?></li>
233 233
 								<li><input class="content" checked="checked"
234 234
 										   type="checkbox" name="content[]"
235
-										   value="health"/> <?php esc_html_e( 'Health', 'lsx-wetu-importer' ); ?></li>
235
+										   value="health"/> <?php esc_html_e('Health', 'lsx-wetu-importer'); ?></li>
236 236
 								<li><input class="content" checked="checked"
237 237
 										   type="checkbox" name="content[]"
238
-										   value="safety"/> <?php esc_html_e( 'Safety', 'lsx-wetu-importer' ); ?></li>
238
+										   value="safety"/> <?php esc_html_e('Safety', 'lsx-wetu-importer'); ?></li>
239 239
 								<li><input class="content" checked="checked"
240 240
 										   type="checkbox" name="content[]"
241
-										   value="visa"/> <?php esc_html_e( 'Visa', 'lsx-wetu-importer' ); ?></li>
241
+										   value="visa"/> <?php esc_html_e('Visa', 'lsx-wetu-importer'); ?></li>
242 242
 								<li><input class="content" checked="checked"
243 243
 										   type="checkbox" name="content[]"
244
-										   value="additional_info"/> <?php esc_html_e( 'General', 'lsx-wetu-importer' ); ?></li>
244
+										   value="additional_info"/> <?php esc_html_e('General', 'lsx-wetu-importer'); ?></li>
245 245
 							</ul>
246 246
 						</div>
247 247
 
248
-						<?php if ( class_exists( 'LSX_TO_Team' ) ) { ?>
248
+						<?php if (class_exists('LSX_TO_Team')) { ?>
249 249
 							<div style="width:30%;display:block;float:left;">
250
-								<h3><?php esc_html_e( 'Assign a Team Member' ); ?></h3>
251
-								<?php $this->team_member_checkboxes( $this->destination_options ); ?>
250
+								<h3><?php esc_html_e('Assign a Team Member'); ?></h3>
251
+								<?php $this->team_member_checkboxes($this->destination_options); ?>
252 252
 							</div>
253 253
 						<?php } ?>
254 254
 
@@ -256,9 +256,9 @@  discard block
 block discarded – undo
256 256
 					</div>
257 257
 
258 258
 
259
-					<h3><?php esc_html_e( 'Your List' ); ?></h3>
259
+					<h3><?php esc_html_e('Your List'); ?></h3>
260 260
 					<p><input class="button button-primary" type="submit"
261
-							  value="<?php esc_html_e( 'Sync', 'lsx-wetu-importer' ); ?>"/></p>
261
+							  value="<?php esc_html_e('Sync', 'lsx-wetu-importer'); ?>"/></p>
262 262
 					<table class="wp-list-table widefat fixed posts">
263 263
 						<?php $this->table_header(); ?>
264 264
 
@@ -271,12 +271,12 @@  discard block
 block discarded – undo
271 271
 					</table>
272 272
 
273 273
 					<p><input class="button button-primary" type="submit"
274
-							  value="<?php esc_html_e( 'Sync', 'lsx-wetu-importer' ); ?>"/></p>
274
+							  value="<?php esc_html_e('Sync', 'lsx-wetu-importer'); ?>"/></p>
275 275
 				</form>
276 276
 			</div>
277 277
 
278 278
 			<div style="display:none;" class="completed-list-wrapper">
279
-				<h3><?php esc_html_e( 'Completed' ); ?></h3>
279
+				<h3><?php esc_html_e('Completed'); ?></h3>
280 280
 				<ul>
281 281
 				</ul>
282 282
 			</div>
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
 	/**
288 288
 	 * Grab all the current destination posts via the lsx_wetu_id field.
289 289
 	 */
290
-	public function find_current_destination( $post_type = 'destination' ) {
290
+	public function find_current_destination($post_type = 'destination') {
291 291
 		global $wpdb;
292 292
 		$return = array();
293 293
 
@@ -306,9 +306,9 @@  discard block
 block discarded – undo
306 306
 		");
307 307
 		// @codingStandardsIgnoreEnd
308 308
 
309
-		if ( null !== $current_destination && ! empty( $current_destination ) ) {
310
-			foreach ( $current_destination as $accom ) {
311
-				$return[ $accom->meta_value ] = $accom;
309
+		if (null !== $current_destination && !empty($current_destination)) {
310
+			foreach ($current_destination as $accom) {
311
+				$return[$accom->meta_value] = $accom;
312 312
 			}
313 313
 		}
314 314
 
@@ -320,118 +320,118 @@  discard block
 block discarded – undo
320 320
 	 */
321 321
 	public function process_ajax_search() {
322 322
 		$return = false;
323
-		check_ajax_referer( 'lsx_wetu_ajax_action', 'security' );
324
-		if ( isset( $_POST['action'] ) && 'lsx_tour_importer' === $_POST['action'] && isset( $_POST['type'] ) && 'destination' === $_POST['type'] ) {
323
+		check_ajax_referer('lsx_wetu_ajax_action', 'security');
324
+		if (isset($_POST['action']) && 'lsx_tour_importer' === $_POST['action'] && isset($_POST['type']) && 'destination' === $_POST['type']) {
325 325
 
326 326
 			$searched_items = false;
327
-			if ( isset( $_POST['keyword'] ) ) {
328
-				$keyphrases = array_map( 'sanitize_text_field', wp_unslash( $_POST['keyword'] ) );
329
-			} else {
330
-				$keyphrases = array( 0 );
327
+			if (isset($_POST['keyword'])) {
328
+				$keyphrases = array_map('sanitize_text_field', wp_unslash($_POST['keyword']));
329
+			}else {
330
+				$keyphrases = array(0);
331 331
 			}
332 332
 
333
-			if ( ! is_array( $keyphrases ) ) {
334
-				$keyphrases = array( $keyphrases );
333
+			if (!is_array($keyphrases)) {
334
+				$keyphrases = array($keyphrases);
335 335
 			}
336
-			foreach ( $keyphrases as &$keyword ) {
337
-				$keyword = ltrim( rtrim( $keyword ) );
336
+			foreach ($keyphrases as &$keyword) {
337
+				$keyword = ltrim(rtrim($keyword));
338 338
 			}
339 339
 
340 340
 			$post_status = false;
341 341
 
342
-			if ( in_array( 'publish', $keyphrases ) ) {
342
+			if (in_array('publish', $keyphrases)) {
343 343
 				$post_status = 'publish';
344 344
 			}
345
-			if ( in_array( 'pending', $keyphrases ) ) {
345
+			if (in_array('pending', $keyphrases)) {
346 346
 				$post_status = 'pending';
347 347
 			}
348
-			if ( in_array( 'draft', $keyphrases ) ) {
348
+			if (in_array('draft', $keyphrases)) {
349 349
 				$post_status = 'draft';
350 350
 			}
351
-			if ( in_array( 'import', $keyphrases ) ) {
351
+			if (in_array('import', $keyphrases)) {
352 352
 				$post_status = 'import';
353 353
 			}
354 354
 
355 355
 			// If there is a post status use it.
356
-			if ( false !== $post_status ) {
356
+			if (false !== $post_status) {
357 357
 
358 358
 				$accommodation         = array();
359
-				$current_accommodation = $this->find_current_accommodation( 'destination' );
360
-				if ( ! empty( $current_accommodation ) ) {
361
-					foreach ( $current_accommodation as $cs_key => $ccs_id ) {
362
-						$accommodation[] = $this->prepare_row_attributes( $cs_key, $ccs_id->post_id );
359
+				$current_accommodation = $this->find_current_accommodation('destination');
360
+				if (!empty($current_accommodation)) {
361
+					foreach ($current_accommodation as $cs_key => $ccs_id) {
362
+						$accommodation[] = $this->prepare_row_attributes($cs_key, $ccs_id->post_id);
363 363
 					}
364 364
 				}
365 365
 
366 366
 				// Run through each accommodation and use it.
367
-				if ( ! empty( $accommodation ) ) {
368
-					foreach ( $accommodation as $row_key => $row ) {
367
+				if (!empty($accommodation)) {
368
+					foreach ($accommodation as $row_key => $row) {
369 369
 						$row['post_title'] = $row['name'];
370
-						if ( 'import' === $post_status ) {
371
-							if ( is_array( $this->queued_imports ) && in_array( $row['post_id'], $this->queued_imports ) ) {
372
-								$current_status = get_post_status( $row['post_id'] );
373
-								if ( 'draft' === $current_status ) {
374
-									$searched_items[ sanitize_title( $row['name'] ) . '-' . $row['id'] ] = $this->format_row( $row, $row_key );
370
+						if ('import' === $post_status) {
371
+							if (is_array($this->queued_imports) && in_array($row['post_id'], $this->queued_imports)) {
372
+								$current_status = get_post_status($row['post_id']);
373
+								if ('draft' === $current_status) {
374
+									$searched_items[sanitize_title($row['name']).'-'.$row['id']] = $this->format_row($row, $row_key);
375 375
 								}
376
-							} else {
376
+							}else {
377 377
 								continue;
378 378
 							}
379
-						} else {
380
-							if ( 0 === $row['post_id'] ) {
379
+						}else {
380
+							if (0 === $row['post_id']) {
381 381
 								continue;
382
-							} else {
383
-								$current_status = get_post_status( $row['post_id'] );
382
+							}else {
383
+								$current_status = get_post_status($row['post_id']);
384 384
 
385
-								if ( $current_status !== $post_status ) {
385
+								if ($current_status !== $post_status) {
386 386
 									continue;
387 387
 								}
388 388
 							}
389
-							$searched_items[ sanitize_title( $row['name'] ) . '-' . $row['id'] ] = $this->format_row( $row, $row_key );
389
+							$searched_items[sanitize_title($row['name']).'-'.$row['id']] = $this->format_row($row, $row_key);
390 390
 						}
391 391
 					}
392 392
 				}
393
-			} else {
393
+			}else {
394 394
 
395
-				$key_string_search = implode( '+', $keyphrases );
396
-				$search_data       = wp_remote_get( $this->url . '/Search/' . $key_string_search . '/?all=include' );
395
+				$key_string_search = implode('+', $keyphrases);
396
+				$search_data       = wp_remote_get($this->url.'/Search/'.$key_string_search.'/?all=include');
397 397
 
398
-				if ( ! is_wp_error( $search_data ) || ! empty( $search_data ) && isset( $search_data['response'] ) && isset( $search_data['response']['code'] ) && 200 === $search_data['response']['code'] ) {
399
-					$search_data = json_decode( $search_data['body'], true );
400
-					foreach ( $search_data as $sdata_key => $sdata ) {
398
+				if (!is_wp_error($search_data) || !empty($search_data) && isset($search_data['response']) && isset($search_data['response']['code']) && 200 === $search_data['response']['code']) {
399
+					$search_data = json_decode($search_data['body'], true);
400
+					foreach ($search_data as $sdata_key => $sdata) {
401 401
 
402
-						if ( isset( $sdata['type'] ) && 'Destination' !== trim( $sdata['type'] ) && 'Area' !== trim( $sdata['type'] ) ) {
402
+						if (isset($sdata['type']) && 'Destination' !== trim($sdata['type']) && 'Area' !== trim($sdata['type'])) {
403 403
 							continue;
404 404
 						}
405 405
 
406
-						$temp_id = $this->get_post_id_by_key_value( $sdata['id'] );
407
-						if ( false === $temp_id ) {
406
+						$temp_id = $this->get_post_id_by_key_value($sdata['id']);
407
+						if (false === $temp_id) {
408 408
 							$sdata['post_id']    = 0;
409 409
 							$sdata['post_title'] = $sdata['name'];
410
-						} else {
410
+						}else {
411 411
 							$sdata['post_id']    = $temp_id;
412
-							$sdata['post_title'] = get_the_title( $temp_id );
412
+							$sdata['post_title'] = get_the_title($temp_id);
413 413
 						}
414
-						$searched_items[ sanitize_title( $sdata['name'] ) . '-' . $sdata['id'] ] = $this->format_row( $sdata, $sdata_key );
414
+						$searched_items[sanitize_title($sdata['name']).'-'.$sdata['id']] = $this->format_row($sdata, $sdata_key);
415 415
 					}
416 416
 				}
417 417
 			}
418 418
 
419
-			if ( false !== $searched_items ) {
420
-				$return = implode( $searched_items );
419
+			if (false !== $searched_items) {
420
+				$return = implode($searched_items);
421 421
 			}
422
-			print_r( $return );
423
-		} else {
424
-			echo esc_attr( 'None found' );
422
+			print_r($return);
423
+		}else {
424
+			echo esc_attr('None found');
425 425
 		}
426 426
 		die();
427 427
 	}
428 428
 
429
-	public function prepare_row_attributes( $cs_key, $ccs_id ) {
429
+	public function prepare_row_attributes($cs_key, $ccs_id) {
430 430
 		$row_item = array(
431 431
 			'id'            => $cs_key,
432 432
 			'type'          => 'Destination',
433
-			'name'          => get_the_title( $ccs_id ),
434
-			'last_modified' => date( 'Y-m-d', strtotime( 'now' ) ),
433
+			'name'          => get_the_title($ccs_id),
434
+			'last_modified' => date('Y-m-d', strtotime('now')),
435 435
 			'post_id'       => $ccs_id,
436 436
 		);
437 437
 		return $row_item;
@@ -440,31 +440,31 @@  discard block
 block discarded – undo
440 440
 	/**
441 441
 	 * Formats the row for output on the screen.
442 442
 	 */
443
-	public function format_row( $row = false, $row_key = '' ) {
444
-		if ( false !== $row ) {
443
+	public function format_row($row = false, $row_key = '') {
444
+		if (false !== $row) {
445 445
 
446 446
 			$status = 'import';
447
-			if ( 0 !== $row['post_id'] ) {
448
-				$status = '<a href="' . admin_url( '/post.php?post=' . $row['post_id'] . '&action=edit' ) . '" target="_blank">' . get_post_status( $row['post_id'] ) . '</a>';
447
+			if (0 !== $row['post_id']) {
448
+				$status = '<a href="'.admin_url('/post.php?post='.$row['post_id'].'&action=edit').'" target="_blank">'.get_post_status($row['post_id']).'</a>';
449 449
 			}
450 450
 
451 451
 			$row_html = '
452
-			<tr class="post-' . $row['post_id'] . ' type-tour" id="post-' . $row['post_id'] . '">
452
+			<tr class="post-' . $row['post_id'].' type-tour" id="post-'.$row['post_id'].'">
453 453
 				<th class="check-column" scope="row">
454
-					<label for="cb-select-' . $row['id'] . '" class="screen-reader-text">' . $row['name'] . '</label>
455
-					<input type="checkbox" data-identifier="' . $row['id'] . '" value="' . $row['post_id'] . '" name="post[]" id="cb-select-' . $row['id'] . '">
454
+					<label for="cb-select-' . $row['id'].'" class="screen-reader-text">'.$row['name'].'</label>
455
+					<input type="checkbox" data-identifier="' . $row['id'].'" value="'.$row['post_id'].'" name="post[]" id="cb-select-'.$row['id'].'">
456 456
 				</th>
457 457
 				<td class="column-order">
458
-					' . ( $row_key + 1 ) . '
458
+					' . ($row_key + 1).'
459 459
 				</td>
460 460
 				<td class="post-title page-title column-title">
461
-					<strong>' . $row['post_title'] . '</strong> - ' . $status . '
461
+					<strong>' . $row['post_title'].'</strong> - '.$status.'
462 462
 				</td>
463 463
 				<td class="date column-date">
464
-					<abbr title="' . date( 'Y/m/d', strtotime( $row['last_modified'] ) ) . '">' . date( 'Y/m/d', strtotime( $row['last_modified'] ) ) . '</abbr><br>Last Modified
464
+					<abbr title="' . date('Y/m/d', strtotime($row['last_modified'])).'">'.date('Y/m/d', strtotime($row['last_modified'])).'</abbr><br>Last Modified
465 465
 				</td>
466 466
 				<td class="ssid column-ssid">
467
-					' . $row['id'] . '
467
+					' . $row['id'].'
468 468
 				</td>
469 469
 			</tr>';
470 470
 			return $row_html;
@@ -477,44 +477,44 @@  discard block
 block discarded – undo
477 477
 	public function process_ajax_import() {
478 478
 		$return = false;
479 479
 
480
-		check_ajax_referer( 'lsx_wetu_ajax_action', 'security' );
481
-		if ( isset( $_POST['action'] ) && 'lsx_import_items' === $_POST['action'] && isset( $_POST['type'] ) && 'destination' === $_POST['type'] && isset( $_POST['wetu_id'] ) ) {
480
+		check_ajax_referer('lsx_wetu_ajax_action', 'security');
481
+		if (isset($_POST['action']) && 'lsx_import_items' === $_POST['action'] && isset($_POST['type']) && 'destination' === $_POST['type'] && isset($_POST['wetu_id'])) {
482 482
 
483
-			$wetu_id = sanitize_text_field( $_POST['wetu_id'] );
483
+			$wetu_id = sanitize_text_field($_POST['wetu_id']);
484 484
 
485
-			if ( isset( $_POST['post_id'] ) ) {
486
-				$post_id            = sanitize_text_field( $_POST['post_id'] );
487
-				$this->current_post = get_post( $post_id );
488
-			} else {
485
+			if (isset($_POST['post_id'])) {
486
+				$post_id            = sanitize_text_field($_POST['post_id']);
487
+				$this->current_post = get_post($post_id);
488
+			}else {
489 489
 				$post_id = 0;
490 490
 			}
491 491
 
492
-			if ( isset( $_POST['team_members'] ) ) {
493
-				$team_members = array_map( 'sanitize_text_field', wp_unslash( $_POST['team_members'] ) );
494
-			} else {
492
+			if (isset($_POST['team_members'])) {
493
+				$team_members = array_map('sanitize_text_field', wp_unslash($_POST['team_members']));
494
+			}else {
495 495
 				$team_members = false;
496 496
 			}
497 497
 
498 498
 			$safari_brands = false;
499 499
 
500
-			delete_option( 'lsx_wetu_importer_destination_settings' );
500
+			delete_option('lsx_wetu_importer_destination_settings');
501 501
 
502
-			if ( isset( $_POST['content'] ) && is_array( $_POST['content'] ) && ! empty( $_POST['content'] ) ) {
503
-				$content = array_map( 'sanitize_text_field', wp_unslash( $_POST['content'] ) );
504
-				add_option( 'lsx_wetu_importer_destination_settings', $content );
505
-			} else {
502
+			if (isset($_POST['content']) && is_array($_POST['content']) && !empty($_POST['content'])) {
503
+				$content = array_map('sanitize_text_field', wp_unslash($_POST['content']));
504
+				add_option('lsx_wetu_importer_destination_settings', $content);
505
+			}else {
506 506
 				$content = false;
507 507
 			}
508 508
 
509
-			$jdata = wp_remote_get( $this->url . '/Get?' . $this->url_qs . '&ids=' . $wetu_id );
509
+			$jdata = wp_remote_get($this->url.'/Get?'.$this->url_qs.'&ids='.$wetu_id);
510 510
 
511
-			if ( ! empty( $jdata ) && isset( $jdata['response'] ) && isset( $jdata['response']['code'] ) && 200 === $jdata['response']['code'] ) {
512
-				$adata  = json_decode( $jdata['body'], true );
513
-				$return = $this->import_row( $adata, $wetu_id, $post_id, $team_members, $content, $safari_brands );
514
-				$this->remove_from_queue( $return );
515
-				$this->format_completed_row( $return );
516
-			} else {
517
-				$this->format_error( esc_html__( 'There was a problem importing your destination, please try refreshing the page.', 'lsx-wetu-importer' ) );
511
+			if (!empty($jdata) && isset($jdata['response']) && isset($jdata['response']['code']) && 200 === $jdata['response']['code']) {
512
+				$adata  = json_decode($jdata['body'], true);
513
+				$return = $this->import_row($adata, $wetu_id, $post_id, $team_members, $content, $safari_brands);
514
+				$this->remove_from_queue($return);
515
+				$this->format_completed_row($return);
516
+			}else {
517
+				$this->format_error(esc_html__('There was a problem importing your destination, please try refreshing the page.', 'lsx-wetu-importer'));
518 518
 			}
519 519
 		}
520 520
 		die();
@@ -523,14 +523,14 @@  discard block
 block discarded – undo
523 523
 	/**
524 524
 	 * Saves the queue to the option.
525 525
 	 */
526
-	public function remove_from_queue( $id ) {
527
-		if ( ! empty( $this->queued_imports ) ) {
528
-			$key = array_search( $id, $this->queued_imports );
529
-			if ( false !== $key ) {
530
-				unset( $this->queued_imports[ $key ] );
526
+	public function remove_from_queue($id) {
527
+		if (!empty($this->queued_imports)) {
528
+			$key = array_search($id, $this->queued_imports);
529
+			if (false !== $key) {
530
+				unset($this->queued_imports[$key]);
531 531
 
532
-				delete_option( 'lsx_wetu_importer_que' );
533
-				update_option( 'lsx_wetu_importer_que', $this->queued_imports );
532
+				delete_option('lsx_wetu_importer_que');
533
+				update_option('lsx_wetu_importer_que', $this->queued_imports);
534 534
 			}
535 535
 		}
536 536
 	}
@@ -538,8 +538,8 @@  discard block
 block discarded – undo
538 538
 	/**
539 539
 	 * Connect to wetu
540 540
 	 */
541
-	public function import_row( $data, $wetu_id, $id = 0, $team_members = false, $importable_content = array(), $safari_brands = false ) {
542
-		if ( 'Destination' === trim( $data[0]['type'] ) || 'Area' === trim( $data[0]['type'] ) ) {
541
+	public function import_row($data, $wetu_id, $id = 0, $team_members = false, $importable_content = array(), $safari_brands = false) {
542
+		if ('Destination' === trim($data[0]['type']) || 'Area' === trim($data[0]['type'])) {
543 543
 			$post_name         = '';
544 544
 			$data_post_content = '';
545 545
 			$data_post_excerpt = '';
@@ -548,129 +548,129 @@  discard block
 block discarded – undo
548 548
 				'post_type' => 'destination',
549 549
 			);
550 550
 
551
-			if ( ! empty( $importable_content ) && in_array( 'country', $importable_content ) ) {
552
-				$parent = $this->check_for_parent( $data );
553
-				if ( false !== $parent ) {
551
+			if (!empty($importable_content) && in_array('country', $importable_content)) {
552
+				$parent = $this->check_for_parent($data);
553
+				if (false !== $parent) {
554 554
 					$post['post_parent'] = $parent;
555 555
 				}
556 556
 			}
557 557
 
558 558
 			// Set the post_content.
559
-			if ( ! empty( $importable_content ) && in_array( 'description', $importable_content ) ) {
560
-				if ( isset( $data[0]['content']['general_description'] ) ) {
559
+			if (!empty($importable_content) && in_array('description', $importable_content)) {
560
+				if (isset($data[0]['content']['general_description'])) {
561 561
 
562
-					if ( in_array( 'strip_tags', $importable_content ) ) {
563
-						$post['post_content'] = wp_strip_all_tags( $data[0]['content']['general_description'] );
564
-					} else {
562
+					if (in_array('strip_tags', $importable_content)) {
563
+						$post['post_content'] = wp_strip_all_tags($data[0]['content']['general_description']);
564
+					}else {
565 565
 						$post['post_content'] = $data[0]['content']['general_description'];
566 566
 					}
567 567
 				}
568 568
 			}
569 569
 
570
-			if ( false !== $id && '0' !== $id ) {
570
+			if (false !== $id && '0' !== $id) {
571 571
 				$post['ID'] = $id;
572
-				if ( isset( $this->options ) && 'on' !== $this->options['disable_destination_title'] && isset( $data[0]['name'] ) ) {
572
+				if (isset($this->options) && 'on' !== $this->options['disable_destination_title'] && isset($data[0]['name'])) {
573 573
 					$post['post_title'] = $data[0]['name'];
574
-					$post['post_name']  = wp_unique_post_slug( sanitize_title( $data[0]['name'] ), $id, 'draft', 'destination', 0 );
574
+					$post['post_name']  = wp_unique_post_slug(sanitize_title($data[0]['name']), $id, 'draft', 'destination', 0);
575 575
 				}
576 576
 				$post['post_status'] = 'publish';
577 577
 
578
-				$id        = wp_update_post( $post );
579
-				$prev_date = get_post_meta( $id, 'lsx_wetu_modified_date', true );
580
-				update_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data[0]['last_modified'] ), $prev_date );
581
-			} else {
578
+				$id        = wp_update_post($post);
579
+				$prev_date = get_post_meta($id, 'lsx_wetu_modified_date', true);
580
+				update_post_meta($id, 'lsx_wetu_modified_date', strtotime($data[0]['last_modified']), $prev_date);
581
+			}else {
582 582
 				// Set the name.
583
-				if ( isset( $data[0]['name'] ) ) {
584
-					$post_name = wp_unique_post_slug( sanitize_title( $data[0]['name'] ), $id, 'draft', 'destination', 0 );
583
+				if (isset($data[0]['name'])) {
584
+					$post_name = wp_unique_post_slug(sanitize_title($data[0]['name']), $id, 'draft', 'destination', 0);
585 585
 				}
586 586
 
587 587
 				$post['post_name']   = $post_name;
588 588
 				$post['post_title']  = $data[0]['name'];
589 589
 				$post['post_status'] = 'publish';
590
-				$id                  = wp_insert_post( $post );
590
+				$id                  = wp_insert_post($post);
591 591
 
592 592
 				// Save the WETU ID and the Last date it was modified.
593
-				if ( false !== $id ) {
594
-					add_post_meta( $id, 'lsx_wetu_id', $wetu_id );
595
-					add_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data[0]['last_modified'] ) );
593
+				if (false !== $id) {
594
+					add_post_meta($id, 'lsx_wetu_id', $wetu_id);
595
+					add_post_meta($id, 'lsx_wetu_modified_date', strtotime($data[0]['last_modified']));
596 596
 				}
597 597
 			}
598 598
 
599
-			$this->find_attachments( $id );
599
+			$this->find_attachments($id);
600 600
 
601 601
 			// Set the team member if it is there.
602
-			if ( post_type_exists( 'team' ) && false !== $team_members && '' !== $team_members ) {
603
-				$this->set_team_member( $id, $team_members );
602
+			if (post_type_exists('team') && false !== $team_members && '' !== $team_members) {
603
+				$this->set_team_member($id, $team_members);
604 604
 			}
605 605
 
606
-			$this->set_map_data( $data, $id, 9 );
606
+			$this->set_map_data($data, $id, 9);
607 607
 
608 608
 			// Set the Room Data.
609
-			if ( false !== $importable_content && in_array( 'videos', $importable_content ) ) {
610
-				$this->set_video_data( $data, $id );
609
+			if (false !== $importable_content && in_array('videos', $importable_content)) {
610
+				$this->set_video_data($data, $id);
611 611
 			}
612 612
 
613 613
 			// Set the Electricity.
614
-			if ( false !== $importable_content && in_array( 'electricity', $importable_content ) ) {
615
-				$this->set_travel_info( $data, $id, 'electricity', $importable_content );
614
+			if (false !== $importable_content && in_array('electricity', $importable_content)) {
615
+				$this->set_travel_info($data, $id, 'electricity', $importable_content);
616 616
 			}
617 617
 			// Set the cuisine.
618
-			if ( false !== $importable_content && in_array( 'cuisine', $importable_content ) ) {
619
-				$this->set_travel_info( $data, $id, 'cuisine', $importable_content );
618
+			if (false !== $importable_content && in_array('cuisine', $importable_content)) {
619
+				$this->set_travel_info($data, $id, 'cuisine', $importable_content);
620 620
 			}
621 621
 			// Set the banking.
622
-			if ( false !== $importable_content && in_array( 'banking', $importable_content ) ) {
623
-				$this->set_travel_info( $data, $id, 'banking', $importable_content );
622
+			if (false !== $importable_content && in_array('banking', $importable_content)) {
623
+				$this->set_travel_info($data, $id, 'banking', $importable_content);
624 624
 			}
625 625
 			// Set the transport.
626
-			if ( false !== $importable_content && in_array( 'transport', $importable_content ) ) {
627
-				$this->set_travel_info( $data, $id, 'transport', $importable_content );
626
+			if (false !== $importable_content && in_array('transport', $importable_content)) {
627
+				$this->set_travel_info($data, $id, 'transport', $importable_content);
628 628
 			}
629 629
 			// Set the dress.
630
-			if ( false !== $importable_content && in_array( 'dress', $importable_content ) ) {
631
-				$this->set_travel_info( $data, $id, 'dress', $importable_content );
630
+			if (false !== $importable_content && in_array('dress', $importable_content)) {
631
+				$this->set_travel_info($data, $id, 'dress', $importable_content);
632 632
 			}
633 633
 			// Set the climate.
634
-			if ( false !== $importable_content && in_array( 'climate', $importable_content ) ) {
635
-				$this->set_travel_info( $data, $id, 'climate', $importable_content );
634
+			if (false !== $importable_content && in_array('climate', $importable_content)) {
635
+				$this->set_travel_info($data, $id, 'climate', $importable_content);
636 636
 			}
637 637
 			// Set the Health.
638
-			if ( false !== $importable_content && in_array( 'health', $importable_content ) ) {
639
-				$this->set_travel_info( $data, $id, 'health', $importable_content );
638
+			if (false !== $importable_content && in_array('health', $importable_content)) {
639
+				$this->set_travel_info($data, $id, 'health', $importable_content);
640 640
 			}
641 641
 			// Set the Safety.
642
-			if ( false !== $importable_content && in_array( 'safety', $importable_content ) ) {
643
-				$this->set_travel_info( $data, $id, 'safety', $importable_content );
642
+			if (false !== $importable_content && in_array('safety', $importable_content)) {
643
+				$this->set_travel_info($data, $id, 'safety', $importable_content);
644 644
 			}
645 645
 			// Set the Visa.
646
-			if ( false !== $importable_content && in_array( 'visa', $importable_content ) ) {
647
-				$this->set_travel_info( $data, $id, 'visa', $importable_content );
646
+			if (false !== $importable_content && in_array('visa', $importable_content)) {
647
+				$this->set_travel_info($data, $id, 'visa', $importable_content);
648 648
 			}
649 649
 			// Set the General.
650
-			if ( false !== $importable_content && in_array( 'additional_info', $importable_content ) ) {
651
-				$this->set_travel_info( $data, $id, 'additional_info', $importable_content );
650
+			if (false !== $importable_content && in_array('additional_info', $importable_content)) {
651
+				$this->set_travel_info($data, $id, 'additional_info', $importable_content);
652 652
 			}
653 653
 
654 654
 			// Setup some default for use in the import.
655
-			if ( false !== $importable_content && ( in_array( 'gallery', $importable_content ) || in_array( 'banner_image', $importable_content ) || in_array( 'featured_image', $importable_content ) ) ) {
656
-				$this->find_attachments( $id );
655
+			if (false !== $importable_content && (in_array('gallery', $importable_content) || in_array('banner_image', $importable_content) || in_array('featured_image', $importable_content))) {
656
+				$this->find_attachments($id);
657 657
 
658 658
 				// Set the featured image.
659
-				if ( false !== $importable_content && in_array( 'featured_image', $importable_content ) ) {
660
-					$this->set_featured_image( $data, $id );
659
+				if (false !== $importable_content && in_array('featured_image', $importable_content)) {
660
+					$this->set_featured_image($data, $id);
661 661
 				}
662
-				if ( false !== $importable_content && in_array( 'banner_image', $importable_content ) ) {
663
-					$this->set_banner_image( $data, $id, $importable_content );
662
+				if (false !== $importable_content && in_array('banner_image', $importable_content)) {
663
+					$this->set_banner_image($data, $id, $importable_content);
664 664
 				}
665 665
 				// Import the main gallery.
666
-				if ( false !== $importable_content && in_array( 'gallery', $importable_content ) ) {
667
-					$this->create_main_gallery( $data, $id );
666
+				if (false !== $importable_content && in_array('gallery', $importable_content)) {
667
+					$this->create_main_gallery($data, $id);
668 668
 				}
669 669
 			}
670 670
 
671 671
 			// Set the continent.
672
-			if ( false !== $importable_content && in_array( 'continent', $importable_content ) ) {
673
-				$this->set_continent( $data, $id );
672
+			if (false !== $importable_content && in_array('continent', $importable_content)) {
673
+				$this->set_continent($data, $id);
674 674
 			}
675 675
 		}
676 676
 
@@ -680,43 +680,43 @@  discard block
 block discarded – undo
680 680
 	/**
681 681
 	 * Saves the room data
682 682
 	 */
683
-	public function set_travel_info( $data, $id, $meta_key, $importable = array( 'none' ) ) {
684
-		if ( ! empty( $data[0]['travel_information'] ) && isset( $data[0]['travel_information'][ $meta_key ] ) ) {
685
-			$content = $data[0]['travel_information'][ $meta_key ];
683
+	public function set_travel_info($data, $id, $meta_key, $importable = array('none')) {
684
+		if (!empty($data[0]['travel_information']) && isset($data[0]['travel_information'][$meta_key])) {
685
+			$content = $data[0]['travel_information'][$meta_key];
686 686
 
687
-			if ( in_array( 'strip_tags', $importable ) ) {
688
-				$content = strip_tags( $content );
687
+			if (in_array('strip_tags', $importable)) {
688
+				$content = strip_tags($content);
689 689
 			}
690 690
 
691
-			$this->save_custom_field( $content, $meta_key, $id );
691
+			$this->save_custom_field($content, $meta_key, $id);
692 692
 		}
693 693
 	}
694 694
 
695 695
 	/**
696 696
 	 * Set the Travel Style
697 697
 	 */
698
-	public function set_continent( $data, $id ) {
698
+	public function set_continent($data, $id) {
699 699
 
700
-		if ( isset( $data[0]['position']['country'] ) && $data[0]['map_object_id'] === $data[0]['position']['country_content_entity_id'] ) {
700
+		if (isset($data[0]['position']['country']) && $data[0]['map_object_id'] === $data[0]['position']['country_content_entity_id']) {
701 701
 			// Get the continent code.
702
-			$country_code    = to_country_data( $data[0]['position']['country'], false );
703
-			$continent_code  = to_continent_code( $country_code );
704
-			$continent_label = to_continent_label( $continent_code );
702
+			$country_code    = to_country_data($data[0]['position']['country'], false);
703
+			$continent_code  = to_continent_code($country_code);
704
+			$continent_label = to_continent_label($continent_code);
705 705
 
706
-			if ( ! empty( tour_operator()->options['display']['enable_search_region_filter'] ) ) {
707
-				$continent_label = to_continent_region_label( $country_code );
706
+			if (!empty(tour_operator()->options['display']['enable_search_region_filter'])) {
707
+				$continent_label = to_continent_region_label($country_code);
708 708
 			}
709 709
 
710
-			if ( '' !== $continent_label ) {
711
-				$term = term_exists( trim( $continent_label ), 'continent' );
712
-				if ( ! $term ) {
713
-					$term = wp_insert_term( trim( $continent_label ), 'continent' );
710
+			if ('' !== $continent_label) {
711
+				$term = term_exists(trim($continent_label), 'continent');
712
+				if (!$term) {
713
+					$term = wp_insert_term(trim($continent_label), 'continent');
714 714
 
715
-					if ( is_wp_error( $term ) ) {
716
-						echo wp_kses_post( $term->get_error_message() );
715
+					if (is_wp_error($term)) {
716
+						echo wp_kses_post($term->get_error_message());
717 717
 					}
718
-				} else {
719
-					wp_set_object_terms( $id, sanitize_title( $continent_label ), 'continent', true );
718
+				}else {
719
+					wp_set_object_terms($id, sanitize_title($continent_label), 'continent', true);
720 720
 				}
721 721
 			}
722 722
 		}
@@ -725,12 +725,12 @@  discard block
 block discarded – undo
725 725
 	/**
726 726
 	 * Save the list of Accommodation into an option
727 727
 	 */
728
-	public function check_for_parent( $data = array() ) {
728
+	public function check_for_parent($data = array()) {
729 729
 		global $wpdb;
730 730
 
731
-		if ( $data[0]['position']['country_content_entity_id'] !== $data[0]['position']['destination_content_entity_id'] ) {
732
-			$result = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = 'lsx_wetu_id' AND meta_value = '%s'", array( $data[0]['position']['country_content_entity_id'] ) ) );
733
-			if ( ! empty( $result ) && '' !== $result && false !== $result ) {
731
+		if ($data[0]['position']['country_content_entity_id'] !== $data[0]['position']['destination_content_entity_id']) {
732
+			$result = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = 'lsx_wetu_id' AND meta_value = '%s'", array($data[0]['position']['country_content_entity_id'])));
733
+			if (!empty($result) && '' !== $result && false !== $result) {
734 734
 				return $result;
735 735
 			}
736 736
 		}
Please login to merge, or discard this patch.