Passed
Push — master ( cb691f...b5dbe8 )
by Warwick
02:25
created

WETU_Importer_Destination::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * @package   WETU_Importer_Destination
4
 * @author    LightSpeed
5
 * @license   GPL-2.0+
6
 * @link
7
 * @copyright 2016 LightSpeed
8
 **/
9
10
class WETU_Importer_Destination extends WETU_Importer {
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 View Code Duplication
	public function set_variables() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
72
		parent::set_variables();
73
		// ** This request only works with API KEY **
74
		//if ( false !== $this->api_username && false !== $this->api_password ) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
49% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
75
		//	$this->url    = 'https://wetu.com/API/Pins/';
0 ignored issues
show
Unused Code Comprehensibility introduced by
45% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
76
		//	$this->url_qs = 'username=' . $this->api_username . '&password=' . $this->api_password;
0 ignored issues
show
Unused Code Comprehensibility introduced by
36% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
77
		//} elseif ( false !== $this->api_key ) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
78
		$this->url = 'https://wetu.com/API/Pins/' . $this->api_key;
79
		$this->url_qs = '';
80
		//}
81
82
		$temp_options = get_option( '_lsx-to_settings', false );
83
84
		if ( false !== $temp_options && isset( $temp_options[ $this->plugin_slug ] ) && ! empty( $temp_options[ $this->plugin_slug ] ) ) {
85
			$this->options = $temp_options[ $this->plugin_slug ];
86
		}
87
88
		$destination_options = get_option( 'wetu_importer_destination_settings', false );
89
90
		if ( false !== $destination_options ) {
91
			$this->destination_options = $destination_options;
92
		}
93
	}
94
95
	/**
96
	 * Display the importer administration screen
97
	 */
98
	public function display_page() {
99
		?>
100
		<div class="wrap">
101
			<?php $this->navigation( 'destination' ); ?>
102
103
			<?php $this->search_form(); ?>
104
105
			<form method="get" action="" id="posts-filter">
106
				<input type="hidden" name="post_type" class="post_type" value="<?php echo esc_attr( $this->tab_slug ); ?>"/>
107
108
				<p><input class="button button-primary add" type="button"
109
						  value="<?php esc_html_e( 'Add to List', 'wetu-importer' ); ?>"/>
110
					<input class="button button-primary clear" type="button"
111
						   value="<?php esc_html_e( 'Clear', 'wetu-importer' ); ?>"/>
112
				</p>
113
114
				<table class="wp-list-table widefat fixed posts">
115
					<?php $this->table_header(); ?>
0 ignored issues
show
Unused Code introduced by
The call to the method WETU_Importer_Destination::table_header() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
116
117
					<tbody id="the-list">
118
					<tr class="post-0 type-tour status-none" id="post-0">
119
						<th class="check-column" scope="row">
120
							<label for="cb-select-0"
121
								   class="screen-reader-text"><?php esc_html_e( 'Enter a title to search for and press enter', 'wetu-importer' ); ?></label>
122
						</th>
123
						<td class="post-title page-title column-title">
124
							<strong>
125
								<?php esc_html_e( 'Enter a title to search for', 'wetu-importer' ); ?>
126
							</strong>
127
						</td>
128
						<td class="date column-date">
129
						</td>
130
						<td class="ssid column-ssid">
131
						</td>
132
					</tr>
133
					</tbody>
134
135
					<?php $this->table_footer(); ?>
0 ignored issues
show
Unused Code introduced by
The call to the method WETU_Importer_Destination::table_footer() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
136
137
				</table>
138
139
				<p><input class="button button-primary add" type="button"
140
						  value="<?php esc_html_e( 'Add to List', 'wetu-importer' ); ?>"/>
141
					<input class="button button-primary clear" type="button"
142
						   value="<?php esc_html_e( 'Clear', 'wetu-importer' ); ?>"/>
143
				</p>
144
			</form>
145
146
			<div style="display:none;" class="import-list-wrapper">
147
				<br/>
148
				<form method="get" action="" id="import-list">
149
150
					<div class="row">
151
						<div class="settings-all" style="width:30%;display:block;float:left;">
152
							<h3><?php esc_html_e( 'What content to Sync from WETU' ); ?></h3>
153
							<ul>
154
								<li>
155
									<input class="content select-all" <?php $this->checked( $this->destination_options, 'all' ); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
156
										   type="checkbox" name="content[]"
157
										   value="all"/> <?php esc_html_e( 'Select All', 'wetu-importer' ); ?></li>
158
								<?php if ( isset( $this->options ) && 'on' !== $this->options['disable_destination_descriptions'] ) { ?>
159
								<li>
160
									<input class="content" <?php $this->checked( $this->destination_options, 'description' ); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
161
										   type="checkbox" name="content[]"
162
										   value="description"/> <?php esc_html_e( 'Description', 'wetu-importer' ); ?></li>
163
								<?php } ?>
164
165
								<li>
166
									<input class="content" <?php $this->checked( $this->destination_options, 'gallery' ); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
167
										   type="checkbox" name="content[]"
168
										   value="gallery"/> <?php esc_html_e( 'Main Gallery', 'wetu-importer' ); ?></li>
169
								<?php if ( class_exists( 'LSX_TO_Maps' ) ) { ?>
170
									<li>
171
										<input class="content" <?php $this->checked( $this->destination_options, 'location' ); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
172
											   type="checkbox" name="content[]"
173
											   value="location"/> <?php esc_html_e( 'Location', 'wetu-importer' ); ?></li>
174
								<?php } ?>
175
176
								<?php if ( class_exists( 'LSX_TO_Videos' ) ) { ?>
177
									<li>
178
										<input class="content" <?php $this->checked( $this->destination_options, 'videos' ); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
179
											   type="checkbox" name="content[]"
180
											   value="videos"/> <?php esc_html_e( 'Videos', 'wetu-importer' ); ?></li>
181
								<?php } ?>
182
183
							</ul>
184
							<h4><?php esc_html_e( 'Additional Content' ); ?></h4>
185
							<ul>
186
								<li>
187
									<input class="content" <?php $this->checked( $this->destination_options, 'continent' ); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
188
										   type="checkbox" name="content[]"
189
										   value="continent"/> <?php esc_html_e( 'Set Continent', 'wetu-importer' ); ?></li>
190
191
								<li>
192
									<input class="content" <?php $this->checked( $this->destination_options, 'featured_image' ); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
193
										   type="checkbox" name="content[]"
194
										   value="featured_image"/> <?php esc_html_e( 'Set Featured Image', 'wetu-importer' ); ?>
195
								</li>
196
								<?php if ( class_exists( 'LSX_Banners' ) ) { ?>
197
									<li>
198
										<input class="content" <?php $this->checked( $this->destination_options, 'banner_image' ); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
199
											   type="checkbox" name="content[]"
200
											   value="banner_image"/> <?php esc_html_e( 'Set Banner Image', 'wetu-importer' ); ?>
201
									</li>
202
								<?php } ?>
203
204
								<li>
205
									<input class="content" <?php $this->checked( $this->destination_options, 'strip_tags' ); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
206
										   type="checkbox" name="content[]"
207
										   value="strip_tags"/> <?php esc_html_e( 'Strip HTML from the description', 'wetu-importer' ); ?></li>
208
							</ul>
209
						</div>
210
						<div class="settings-all" style="width:30%;display:block;float:left;">
211
							<h3><?php esc_html_e( 'Travel Information' ); ?></h3>
212
							<ul>
213
								<li>
214
									<input class="content" <?php $this->checked( $this->destination_options, 'electricity' ); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
215
										   type="checkbox" name="content[]"
216
										   value="electricity"/> <?php esc_html_e( 'Electricity', 'wetu-importer' ); ?></li>
217
								<li>
218
									<input class="content" <?php $this->checked( $this->destination_options, 'banking' ); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
219
										   type="checkbox" name="content[]"
220
										   value="banking"/> <?php esc_html_e( 'Banking', 'wetu-importer' ); ?></li>
221
								<li>
222
									<input class="content" <?php $this->checked( $this->destination_options, 'cuisine' ); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
223
										   type="checkbox" name="content[]"
224
										   value="cuisine"/> <?php esc_html_e( 'Cuisine', 'wetu-importer' ); ?></li>
225
								<li>
226
									<input class="content" <?php $this->checked( $this->destination_options, 'climate' ); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
227
										   type="checkbox" name="content[]"
228
										   value="climate"/> <?php esc_html_e( 'Climate', 'wetu-importer' ); ?></li>
229
								<li>
230
									<input class="content" <?php $this->checked( $this->destination_options, 'transport' ); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
231
										   type="checkbox" name="content[]"
232
										   value="transport"/> <?php esc_html_e( 'Transport', 'wetu-importer' ); ?></li>
233
								<li><input class="content" <?php $this->checked( $this->destination_options, 'dress' ); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
234
										   type="checkbox" name="content[]"
235
										   value="dress"/> <?php esc_html_e( 'Dress', 'wetu-importer' ); ?></li>
236
								<li><input class="content" <?php $this->checked( $this->destination_options, 'health' ); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
237
										   type="checkbox" name="content[]"
238
										   value="health"/> <?php esc_html_e( 'Health', 'wetu-importer' ); ?></li>
239
								<li><input class="content" <?php $this->checked( $this->destination_options, 'safety' ); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
240
										   type="checkbox" name="content[]"
241
										   value="safety"/> <?php esc_html_e( 'Safety', 'wetu-importer' ); ?></li>
242
								<li><input class="content" <?php $this->checked( $this->destination_options, 'visa' ); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
243
										   type="checkbox" name="content[]"
244
										   value="visa"/> <?php esc_html_e( 'Visa', 'wetu-importer' ); ?></li>
245
								<li><input class="content" <?php $this->checked( $this->destination_options, 'additional_info' ); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_options is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
246
										   type="checkbox" name="content[]"
247
										   value="additional_info"/> <?php esc_html_e( 'General', 'wetu-importer' ); ?></li>
248
							</ul>
249
						</div>
250
251
						<?php if ( class_exists( 'LSX_TO_Team' ) ) { ?>
252
							<div style="width:30%;display:block;float:left;">
253
								<h3><?php esc_html_e( 'Assign a Team Member' ); ?></h3>
254
								<?php $this->team_member_checkboxes( $this->destination_options ); ?>
0 ignored issues
show
Documentation introduced by
$this->destination_options is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
255
							</div>
256
						<?php } ?>
257
258
						<br clear="both"/>
259
					</div>
260
261
262
					<h3><?php esc_html_e( 'Your List' ); ?></h3>
263
					<p><input class="button button-primary" type="submit"
264
							  value="<?php esc_html_e( 'Sync', 'wetu-importer' ); ?>"/></p>
265
					<table class="wp-list-table widefat fixed posts">
266
						<?php $this->table_header(); ?>
0 ignored issues
show
Unused Code introduced by
The call to the method WETU_Importer_Destination::table_header() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
267
268
						<tbody>
269
270
						</tbody>
271
272
						<?php $this->table_footer(); ?>
0 ignored issues
show
Unused Code introduced by
The call to the method WETU_Importer_Destination::table_footer() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
273
274
					</table>
275
276
					<p><input class="button button-primary" type="submit"
277
							  value="<?php esc_html_e( 'Sync', 'wetu-importer' ); ?>"/></p>
278
				</form>
279
			</div>
280
281
			<div style="display:none;" class="completed-list-wrapper">
282
				<h3><?php esc_html_e( 'Completed' ); ?></h3>
283
				<ul>
284
				</ul>
285
			</div>
286
		</div>
287
		<?php
288
	}
289
290
	/**
291
	 * Grab all the current destination posts via the lsx_wetu_id field.
292
	 */
293 View Code Duplication
	public function find_current_destination( $post_type = 'destination' ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
294
		global $wpdb;
295
		$return = array();
296
297
		// @codingStandardsIgnoreStart
298
		$current_destination = $wpdb->get_results("
299
			SELECT key1.post_id,key1.meta_value,key2.post_title as name,key2.post_date as last_modified
300
			FROM {$wpdb->postmeta} key1
301
302
			INNER JOIN  {$wpdb->posts} key2
303
			ON key1.post_id = key2.ID
304
305
			WHERE key1.meta_key = 'lsx_wetu_id'
306
			AND key2.post_type = '{$post_type}'
307
308
			LIMIT 0,1000
309
		");
310
		// @codingStandardsIgnoreEnd
311
312
		if ( null !== $current_destination && ! empty( $current_destination ) ) {
313
			foreach ( $current_destination as $accom ) {
314
				$return[ $accom->meta_value ] = $accom;
315
			}
316
		}
317
318
		return $return;
319
	}
320
321
	/**
322
	 * Run through the accommodation grabbed from the DB.
323
	 */
324
	public function process_ajax_search() {
325
		$return = false;
326
327
		// @codingStandardsIgnoreLine
328
		if ( isset( $_POST['action'] ) && $_POST['action'] === 'lsx_tour_importer' && isset( $_POST['type'] ) && $_POST['type'] === 'accommodation' ) {
329
			$accommodation = get_transient( 'lsx_ti_accommodation' );
330
331
			if ( false === $accommodation ) {
332
				$this->update_options();
333
			}
334
335
			if ( false !== $accommodation ) {
336
				$searched_items = false;
337
338
				// @codingStandardsIgnoreLine
339 View Code Duplication
				if ( isset( $_POST['keyword'] ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
340
					// @codingStandardsIgnoreLine
341
					$keyphrases = $_POST['keyword'];
342
				} else {
343
					$keyphrases = array( 0 );
344
				}
345
346
				if ( ! is_array( $keyphrases ) ) {
347
					$keyphrases = array( $keyphrases );
348
				}
349
				foreach ( $keyphrases as &$keyword ) {
350
					$keyword = ltrim( rtrim( $keyword ) );
351
				}
352
353
				$post_status = false;
354
355
				if ( in_array( 'publish',$keyphrases ) ) {
356
					$post_status = 'publish';
357
				}
358
				if ( in_array( 'pending',$keyphrases ) ) {
359
					$post_status = 'pending';
360
				}
361
				if ( in_array( 'draft',$keyphrases ) ) {
362
					$post_status = 'draft';
363
				}
364
				if ( in_array( 'import',$keyphrases ) ) {
365
					$post_status = 'import';
366
				}
367
368
				if ( ! empty( $accommodation ) ) {
369
					$current_accommodation = $this->find_current_accommodation();
370
371
					foreach ( $accommodation as $row_key => $row ) {
372
373
						if ( 'Destination' !== trim( $row[0]['type'] ) ) {
374
							continue;
375
						}
376
377
						//If this is a current tour, add its ID to the row.
378
						$row['post_id'] = 0;
379
380 View Code Duplication
						if ( false !== $current_accommodation && array_key_exists( $row['id'], $current_accommodation ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
381
							$row['post_id'] = $current_accommodation[ $row['id'] ]->post_id;
382
						}
383
384
						//If we are searching for
385 View Code Duplication
						if ( false !== $post_status ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
386
							if ( 'import' === $post_status ) {
387
388
								if ( is_array( $this->queued_imports ) && in_array( $row['post_id'],$this->queued_imports ) ) {
389
									$searched_items[ sanitize_title( $row['name'] ) . '-' . $row['id'] ] = $this->format_row( $row );
0 ignored issues
show
Documentation introduced by
$row is of type array<string,?,{"post_id":"?"}>, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
390
								} else {
391
									continue;
392
								}
393
							} else {
394
								if ( 0 === $row['post_id'] ) {
395
									continue;
396
								} else {
397
									$current_status = get_post_status( $row['post_id'] );
398
399
									if ( $current_status !== $post_status ) {
400
										continue;
401
									}
402
								}
403
404
								$searched_items[ sanitize_title( $row['name'] ) . '-' . $row['id'] ] = $this->format_row( $row );
0 ignored issues
show
Documentation introduced by
$row is of type array<string,?,{"post_id":"?"}>, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
405
							}
406
						} else {
407
							//Search through each keyword.
408
							foreach ( $keyphrases as $keyphrase ) {
409
								//Make sure the keyphrase is turned into an array
410
								$keywords = explode( ' ',$keyphrase );
411
412
								if ( ! is_array( $keywords ) ) {
413
									$keywords = array( $keywords );
414
								}
415
416
								if ( $this->multineedle_stripos( ltrim( rtrim( $row['name'] ) ), $keywords ) !== false ) {
417
									$searched_items[ sanitize_title( $row['name'] ) . '-' . $row['id'] ] = $this->format_row( $row );
0 ignored issues
show
Documentation introduced by
$row is of type array<string,?,{"post_id":"?"}>, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
418
								}
419
							}
420
						}
421
					}
422
				}
423
424
				if ( false !== $searched_items ) {
425
					ksort( $searched_items );
426
					$return = implode( $searched_items );
427
				}
428
			}
429
430
			print_r( $return );
431
		}
432
433
		die();
434
	}
435
436
	/**
437
	 * Formats the row for output on the screen.
438
	 */
439
	public function format_row( $row = false ) {
440
		if ( false !== $row ) {
441
442
			$status = 'import';
443
			if ( 0 !== $row->post_id ) {
444
				$status = '<a href="' . admin_url( '/post.php?post=' . $row->post_id . '&action=edit' ) . '" target="_blank">' . get_post_status( $row->post_id ) . '</a>';
445
			}
446
447
			$row_html = '
448
			<tr class="post-' . $row->post_id . ' type-tour" id="post-' . $row->post_id . '">
449
				<th class="check-column" scope="row">
450
					<label for="cb-select-' . $row->meta_value . '" class="screen-reader-text">' . $row->name . '</label>
451
					<input type="checkbox" data-identifier="' . $row->meta_value . '" value="' . $row->post_id . '" name="post[]" id="cb-select-' . $row->meta_value . '">
452
				</th>
453
				<td class="post-title page-title column-title">
454
					<strong>' . $row->name . '</strong> - ' . $status . '
455
				</td>
456
				<td class="date column-date">
457
					<abbr title="' . date( 'Y/m/d', strtotime( $row->last_modified ) ) . '">' . date( 'Y/m/d', strtotime( $row->last_modified ) ) . '</abbr><br>Last Modified
458
				</td>
459
				<td class="ssid column-ssid">
460
					' . $row->meta_value . '
461
				</td>
462
			</tr>';
463
			return $row_html;
464
		}
465
	}
466
467
	/**
468
	 * Connect to wetu
469
	 */
470
	public function process_ajax_import() {
471
		$return = false;
0 ignored issues
show
Unused Code introduced by
$return is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
472
473
		// @codingStandardsIgnoreLine
474
		if ( isset( $_POST['action'] ) && $_POST['action'] === 'lsx_import_items' && isset( $_POST['type'] ) && $_POST['type'] === 'destination' && isset( $_POST['wetu_id'] ) ) {
475
			// @codingStandardsIgnoreLine
476
			$wetu_id = $_POST['wetu_id'];
477
478
			// @codingStandardsIgnoreLine
479
			if ( isset( $_POST['post_id'] ) ) {
480
				// @codingStandardsIgnoreLine
481
				$post_id = $_POST['post_id'];
482
				$this->current_post = get_post( $post_id );
483
			} else {
484
				$post_id = 0;
485
			}
486
487
			// @codingStandardsIgnoreLine
488
			if ( isset( $_POST['team_members'] ) ) {
489
				// @codingStandardsIgnoreLine
490
				$team_members = $_POST['team_members'];
491
			} else {
492
				$team_members = false;
493
			}
494
495
			$safari_brands = false;
496
497
			delete_option( 'wetu_importer_destination_settings' );
498
499
			// @codingStandardsIgnoreLine
500 View Code Duplication
			if ( isset( $_POST['content'] ) && is_array( $_POST['content'] ) && ! empty( $_POST['content'] ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
501
				// @codingStandardsIgnoreLine
502
				$content = $_POST['content'];
503
				add_option( 'wetu_importer_destination_settings', $content );
504
			} else {
505
				$content = false;
506
			}
507
508
			$jdata = file_get_contents( $this->url . '/Get?' . $this->url_qs . '&ids=' . $wetu_id );
509
510 View Code Duplication
			if ( $jdata ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
511
				$adata = json_decode( $jdata, true );
512
513
				if ( ! empty( $adata ) && ! isset( $adata['error'] ) ) {
514
					$return = $this->import_row( $adata, $wetu_id, $post_id, $team_members, $content, $safari_brands );
515
					$this->remove_from_queue( $return );
516
					$this->format_completed_row( $return );
517
				} else {
518
					if ( isset( $adata['error'] ) ) {
519
						$this->format_error( $adata['error'] );
520
					} else {
521
						$this->format_error( esc_html__( 'There was a problem importing your destination, please try refreshing the page.','wetu-importer' ) );
522
					}
523
				}
524
			}
525
		}
526
	}
527
528
	/**
529
	 * Saves the queue to the option.
530
	 */
531 View Code Duplication
	public function remove_from_queue( $id ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
532
		if ( ! empty( $this->queued_imports ) ) {
533
			// @codingStandardsIgnoreLine
534
			if ( ( $key = array_search( $id, $this->queued_imports ) ) !== false ) {
535
				unset( $this->queued_imports[ $key ] );
536
537
				delete_option( 'wetu_importer_que' );
538
				update_option( 'wetu_importer_que',$this->queued_imports );
539
			}
540
		}
541
	}
542
543
	/**
544
	 * Connect to wetu
545
	 */
546
	public function import_row( $data, $wetu_id, $id = 0, $team_members = false, $importable_content = false, $safari_brands = false ) {
0 ignored issues
show
Unused Code introduced by
The parameter $safari_brands is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
547
		if ( 'Destination' === trim( $data[0]['type'] ) ) {
548
			$post_name = '';
549
			$data_post_content = '';
0 ignored issues
show
Unused Code introduced by
$data_post_content is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
550
			$data_post_excerpt = '';
0 ignored issues
show
Unused Code introduced by
$data_post_excerpt is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
551
552
			$post = array(
553
				'post_type' => 'destination',
554
			);
555
556
			//Set the post_content
557
			if ( false !== $importable_content && in_array( 'description', $importable_content ) ) {
558
				if ( isset( $data[0]['content']['general_description'] ) ) {
559
560
					if ( false !== $importable_content && in_array( 'strip_tags', $importable_content ) ) {
561
						$post['post_content'] = wp_strip_all_tags( $data[0]['content']['general_description'] );
562
					} else {
563
						$post['post_content'] = $data[0]['content']['general_description'];
564
					}
565
				}
566
			}
567
568 View Code Duplication
			if ( false !== $id && '0' !== $id ) {
0 ignored issues
show
Unused Code Bug introduced by
The strict comparison !== seems to always evaluate to true as the types of '0' (string) and $id (integer) can never be identical. Maybe you want to use a loose comparison != instead?
Loading history...
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
569
				$post['ID'] = $id;
570
571
				if ( isset( $data[0]['name'] ) ) {
572
					$post['post_title'] = $data[0]['name'];
573
					$post['post_status'] = 'publish';
574
					$post['post_name'] = wp_unique_post_slug( sanitize_title( $data[0]['name'] ), $id, 'draft', 'destination', 0 );
575
				}
576
577
				$id = wp_update_post( $post );
578
				$prev_date = get_post_meta( $id, 'lsx_wetu_modified_date', true );
579
				update_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data[0]['last_modified'] ), $prev_date );
580
			} else {
581
				//Set the name
582
				if ( isset( $data[0]['name'] ) ) {
583
					$post_name = wp_unique_post_slug( sanitize_title( $data[0]['name'] ), $id, 'draft', 'destination', 0 );
584
				}
585
586
				$post['post_name'] = $post_name;
587
				$post['post_title'] = $data[0]['name'];
588
				$post['post_status'] = 'publish';
589
				$id = wp_insert_post( $post );
590
591
				//Save the WETU ID and the Last date it was modified.
592
				if ( false !== $id ) {
593
					add_post_meta( $id, 'lsx_wetu_id', $wetu_id );
594
					add_post_meta( $id, 'lsx_wetu_modified_date', strtotime( $data[0]['last_modified'] ) );
595
				}
596
			}
597
598
			$this->find_attachments( $id );
599
600
			//Set the team member if it is there
601 View Code Duplication
			if ( post_type_exists( 'team' ) && false !== $team_members && '' !== $team_members ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
602
				$this->set_team_member( $id, $team_members );
603
			}
604
605
			if ( class_exists( 'LSX_TO_Maps' ) ) {
606
				$this->set_map_data( $data, $id, 9 );
607
			}
608
609
			//Set the Room Data
610
			if ( false !== $importable_content && in_array( 'videos', $importable_content ) ) {
611
				$this->set_video_data( $data, $id );
612
			}
613
614
			//Set the Electricity
615
			if ( false !== $importable_content && in_array( 'electricity', $importable_content ) ) {
616
				$this->set_travel_info( $data, $id, 'electricity' );
617
			}
618
			//Set the cuisine
619
			if ( false !== $importable_content && in_array( 'cuisine', $importable_content ) ) {
620
				$this->set_travel_info( $data, $id, 'cuisine' );
621
			}
622
			//Set the banking
623
			if ( false !== $importable_content && in_array( 'banking', $importable_content ) ) {
624
				$this->set_travel_info( $data, $id, 'banking' );
625
			}
626
			//Set the transport
627
			if ( false !== $importable_content && in_array( 'transport', $importable_content ) ) {
628
				$this->set_travel_info( $data, $id, 'transport' );
629
			}
630
			//Set the dress
631
			if ( false !== $importable_content && in_array( 'dress', $importable_content ) ) {
632
				$this->set_travel_info( $data, $id, 'dress' );
633
			}
634
			//Set the climate
635
			if ( false !== $importable_content && in_array( 'climate', $importable_content ) ) {
636
				$this->set_travel_info( $data, $id, 'climate' );
637
			}
638
			//Set the Health
639
			if ( false !== $importable_content && in_array( 'health', $importable_content ) ) {
640
				$this->set_travel_info( $data, $id, 'health' );
641
			}
642
			//Set the Safety
643
			if ( false !== $importable_content && in_array( 'safety', $importable_content ) ) {
644
				$this->set_travel_info( $data, $id, 'safety' );
645
			}
646
			//Set the Visa
647
			if ( false !== $importable_content && in_array( 'visa', $importable_content ) ) {
648
				$this->set_travel_info( $data, $id, 'visa' );
649
			}
650
			//Set the General
651
			if ( false !== $importable_content && in_array( 'additional_info', $importable_content ) ) {
652
				$this->set_travel_info( $data, $id, 'additional_info' );
653
			}
654
655
			//Setup some default for use in the import
656
			if ( false !== $importable_content && (in_array( 'gallery', $importable_content ) || in_array( 'banner_image', $importable_content ) || in_array( 'featured_image', $importable_content )) ) {
657
				$this->find_attachments( $id );
658
659
				//Set the featured image
660
				if ( false !== $importable_content && in_array( 'featured_image', $importable_content ) ) {
661
					$this->set_featured_image( $data, $id );
662
				}
663
				if ( false !== $importable_content && in_array( 'banner_image', $importable_content ) ) {
664
					$this->set_banner_image( $data, $id );
665
				}
666
				//Import the main gallery
667
				if ( false !== $importable_content && in_array( 'gallery', $importable_content ) ) {
668
					$this->create_main_gallery( $data, $id );
669
				}
670
			}
671
672
			//Set the continent
673
			if ( false !== $importable_content && in_array( 'continent', $importable_content ) ) {
674
				$this->set_continent( $data, $id );
675
			}
676
		}
677
678
		return $id;
679
	}
680
681
	/**
682
	 * Set the team memberon each item.
683
	 */
684 View Code Duplication
	public function set_team_member( $id, $team_members ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
685
		delete_post_meta( $id, 'team_to_' . $this->tab_slug );
686
687
		foreach ( $team_members as $team ) {
688
			add_post_meta( $id, 'team_to_' . $this->tab_slug, $team );
689
		}
690
	}
691
692
	/**
693
	 * Saves the room data
694
	 */
695
	public function set_travel_info( $data, $id, $meta_key ) {
696
		if ( ! empty( $data[0]['travel_information'] ) && isset( $data[0]['travel_information'][ $meta_key ] ) ) {
697
			$content = $data[0]['travel_information'][ $meta_key ];
698
			$this->save_custom_field( $content, $meta_key, $id );
699
		}
700
	}
701
702
	/**
703
	 * Set the Travel Style
704
	 */
705
	public function set_continent( $data, $id ) {
706
707
		if ( isset( $data[0]['position']['country'] ) && $data[0]['map_object_id'] === $data[0]['position']['country_content_entity_id'] ) {
708
			//get the continent code.
709
			$continent_code = to_continent_label( to_continent_code( to_country_data( $data[0]['position']['country'], false ) ) );
710
711
			if ( '' !== $continent_code ) {
712
				// @codingStandardsIgnoreLine
713
				if ( ! $term = term_exists( trim( $continent_code ), 'continent' ) ) {
714
					$term = wp_insert_term( trim( $continent_code ), 'continent' );
715
716
					if ( is_wp_error( $term ) ) {
717
						// @codingStandardsIgnoreLine
718
						echo $term->get_error_message();
719
					}
720
				} else {
721
					wp_set_object_terms( $id, sanitize_title( $continent_code ), 'continent', true );
722
				}
723
			}
724
725
		}
726
	}
727
728
	/**
729
	 * search_form
730
	 */
731 View Code Duplication
	public function update_options_form() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
732
		echo '<div style="display:none;" class="wetu-status"><h3>' . esc_html__( 'Wetu Status', 'wetu-importer' ) . '</h3>';
733
734
		$accommodation = get_transient( 'lsx_ti_accommodation' );
735
736
		if ( '' === $accommodation || false === $accommodation || isset( $_GET['refresh_accommodation'] ) ) {
737
			$this->update_options();
738
		}
739
740
		echo '</div>';
741
	}
742
743
	/**
744
	 * Save the list of Accommodation into an option
745
	 */
746 View Code Duplication
	public function update_options() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
747
		$data = file_get_contents( $this->url . '/List?' . $this->url_qs );
748
749
		$accommodation = json_decode( $data, true );
750
751
		if ( isset( $accommodation['error'] ) ) {
752
			return $accommodation['error'];
753
		} elseif ( isset( $accommodation ) && ! empty( $accommodation ) ) {
754
			set_transient( 'lsx_ti_accommodation',$accommodation,60 * 60 * 2 );
755
			return true;
756
		}
757
	}
758
759
}
760