Passed
Push — master ( ddebd8...b1f71c )
by Warwick
11:57
created
classes/class-frontend.php 2 patches
Indentation   +379 added lines, -379 removed lines patch added patch discarded remove patch
@@ -16,385 +16,385 @@
 block discarded – undo
16 16
  */
17 17
 class Frontend {
18 18
 
19
-	/**
20
-	 * Holds instance of the class
21
-	 *
22
-	 * @var object \lsx\currencies\classes\Admin()
23
-	 */
24
-	private static $instance;
25
-
26
-	/**
27
-	 * This will hold the rates with a base currency of USD.
28
-	 *
29
-	 * @var boolean
30
-	 */
31
-	public $rates = false;
32
-
33
-	/**
34
-	 * This will hold the rates error message.
35
-	 *
36
-	 * @var boolean
37
-	 */
38
-	public $rates_message = false;
39
-
40
-	/**
41
-	 * This is the current currency selected, default to the base currency.
42
-	 *
43
-	 * @var boolean
44
-	 */
45
-	public $current_currency = false;
46
-
47
-	/**
48
-	 * Constructor
49
-	 */
50
-	public function __construct() {
51
-		if ( ! is_admin() ) {
52
-			add_action( 'plugins_loaded', array( $this, 'set_defaults' ), 11, 1 );
53
-			add_filter( 'lsx_to_custom_field_query', array( $this, 'price_filter' ), 20, 5 );
54
-			add_action( 'wp_enqueue_scripts', array( $this, 'assets' ), 5 );
55
-			add_filter( 'wp_nav_menu_items', array( $this, 'wp_nav_menu_items_filter' ), 10, 2 );
56
-			add_filter( 'wp_kses_allowed_html', array( $this, 'wp_kses_allowed_html' ), 10, 2 );
57
-			add_filter( 'get_post_metadata', array( $this, 'filter_post_meta' ), 100, 4 );
58
-		}
59
-	}
60
-
61
-	/**
62
-	 * Return an instance of this class.
63
-	 *
64
-	 * @return  object
65
-	 */
66
-	public static function init() {
67
-		// If the single instance hasn't been set, set it now.
68
-		if ( ! isset( self::$instance ) ) {
69
-			self::$instance = new self();
70
-		}
71
-		return self::$instance;
72
-	}
73
-
74
-	/**
75
-	 * Constructor
76
-	 */
77
-	public function set_defaults() {
78
-		$this->rates_message = esc_html__( 'Error: API key isn\'t set.', 'lsx-currencies' );
79
-		$this->rates = get_transient( 'lsx_currencies_rates' );
80
-		if ( false === $this->rates ) {
81
-			$rates         = wp_remote_retrieve_body( wp_safe_remote_get( lsx_currencies()->api_url ) );
82
-			$decoded_rates = json_decode( $rates );
83
-
84
-			if ( is_wp_error( $rates ) ) {
85
-				$this->rates_message = $rates->get_error_message();
86
-			} elseif ( ! empty( $decoded_rates->error ) ) {
87
-				$this->rates_message = $decoded_rates->description;
88
-			} elseif ( empty( $rates ) ) {
89
-				$this->rates_message = esc_html__( 'Error: API response is empty.', 'lsx-currencies' );
90
-			} else {
91
-				$this->rates_message = esc_html__( 'Success (new request).', 'lsx-currencies' );
92
-				set_transient( 'lsx_currencies_rates', $decoded_rates->rates, 60 * 60 * 12 );
93
-				do_action( 'lsx_currencies_rates_refreshed' );
94
-				$this->rates = $decoded_rates->rates;
95
-			}
96
-		} else {
97
-			$this->rates_message = esc_html__( 'Success (from cache).', 'lsx-currencies' );
98
-		}
99
-		$this->current_currency = isset( $_COOKIE['lsx_currencies_choice'] ) ? sanitize_key( $_COOKIE['lsx_currencies_choice'] ) : lsx_currencies()->base_currency;
100
-		$this->current_currency = strtoupper( $this->current_currency );
101
-	}
102
-
103
-	/**
104
-	 * Enques the assets
105
-	 */
106
-	public function assets() {
107
-		wp_enqueue_script( 'lsx-moneyjs', LSX_CURRENCIES_URL . 'assets/js/vendor/money.min.js', array( 'jquery' ), LSX_CURRENCIES_VER, true );
108
-		wp_enqueue_script( 'lsx-accountingjs', LSX_CURRENCIES_URL . 'assets/js/vendor/accounting.min.js', array( 'jquery' ), LSX_CURRENCIES_VER, true );
109
-		wp_enqueue_script( 'lsx-jquery-cookie', LSX_CURRENCIES_URL . 'assets/js/vendor/cookie.min.js', array( 'jquery' ), LSX_CURRENCIES_VER, true );
110
-
111
-		$prefix = '.min';
112
-		$src = '';
113
-		$script_debug = false;
114
-		if ( defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ) {
115
-			$prefix = '';
116
-			$src = 'src/';
117
-			$script_debug = true;
118
-		}
119
-		wp_enqueue_script( 'lsx-currencies', LSX_CURRENCIES_URL . 'assets/js/' . $src . 'lsx-currencies' . $prefix . '.js', array( 'jquery', 'lsx-moneyjs', 'lsx-accountingjs', 'lsx-jquery-cookie' ), LSX_CURRENCIES_VER, true );
120
-
121
-		$base_currency = lsx_currencies()->base_currency;
122
-		$current_currency = $this->current_currency;
123
-		if ( true === lsx_currencies()->convert_to_single ) {
124
-			$current_currency = $base_currency;
125
-		}
126
-
127
-		$params = apply_filters( 'lsx_currencies_js_params', array(
128
-			'current_currency'  => $current_currency,
129
-			'currency_symbols'  => $this->get_available_symbols(),
130
-			'rates'             => $this->rates,
131
-			'rates_message'     => $this->rates_message,
132
-			'base'              => $base_currency,
133
-			'flags'             => lsx_currencies()->display_flags,
134
-			'convert_to_single' => lsx_currencies()->convert_to_single,
135
-			'script_debug'      => $script_debug,
136
-			'remove_decimals'   => lsx_currencies()->remove_decimals,
137
-		));
138
-
139
-		wp_localize_script( 'lsx-currencies', 'lsx_currencies_params', $params );
140
-
141
-		wp_enqueue_style( 'lsx-currencies', LSX_CURRENCIES_URL . 'assets/css/lsx-currencies.css', array(), LSX_CURRENCIES_VER );
142
-		wp_style_add_data( 'lsx-currencies', 'rtl', 'replace' );
143
-	}
144
-
145
-	/**
146
-	 * Returns all of the available symbols.
147
-	 *
148
-	 * @return array
149
-	 */
150
-	public function get_available_symbols() {
151
-		$symbols = array();
152
-		if ( false !== lsx_currencies()->additional_currencies && ! empty( lsx_currencies()->additional_currencies ) ) {
153
-			foreach ( lsx_currencies()->additional_currencies as $key => $currency ) {
154
-				$symbols[ $key ] = lsx_currencies()->currency_symbols[ $key ];
155
-			}
156
-		}
157
-		return $symbols;
158
-	}
159
-
160
-	/**
161
-	 * Adds in the required currency conversion tags
162
-	 */
163
-	public function price_filter( $return_html, $meta_key, $value, $before, $after ) {
164
-		if ( 'price' === $meta_key ) {
165
-			$additional_html = '';
166
-			$additional_prices = get_post_meta( get_the_ID(), 'additional_prices', false );
167
-			$prefix = '<span class="amount lsx-currencies" ';
168
-
169
-			if ( true === lsx_currencies()->multi_prices && ! empty( $additional_prices ) ) {
170
-				foreach ( $additional_prices as $a_price ) {
171
-					$additional_html .= ' data-price-' . $a_price['currency'] . '="' . $a_price['amount'] . '"';
172
-				}
173
-			}
174
-
175
-			$value = preg_replace( '/[^0-9.]+/', '', $value );
176
-			$decimals = substr_count( $value, '.' );
177
-
178
-			if ( false !== $decimals && $decimals > 1 ) {
179
-				$decimals--;
180
-				$decimals = (int) $decimals;
181
-				$value = preg_replace( '/' . preg_quote( '.', '/' ) . '/', '', $value, $decimals );
182
-			}
183
-
184
-			$money_format = 2;
185
-			if ( false !== lsx_currencies()->remove_decimals ) {
186
-				$money_format = 0;
187
-			}
188
-
189
-			$prefix .= '>';
190
-			$suffix = '</span>';
191
-
192
-			setlocale( LC_MONETARY, 'en_US' );
193
-
194
-			// Work out the other tags.
195
-			$currency = '<span class="currency-icon ' . mb_strtolower( lsx_currencies()->base_currency ) . '">' . lsx_currencies()->base_currency . '</span>';
196
-
197
-			$value = ltrim( rtrim( $value ) );
19
+     /**
20
+      * Holds instance of the class
21
+      *
22
+      * @var object \lsx\currencies\classes\Admin()
23
+      */
24
+     private static $instance;
25
+
26
+     /**
27
+      * This will hold the rates with a base currency of USD.
28
+      *
29
+      * @var boolean
30
+      */
31
+     public $rates = false;
32
+
33
+     /**
34
+      * This will hold the rates error message.
35
+      *
36
+      * @var boolean
37
+      */
38
+     public $rates_message = false;
39
+
40
+     /**
41
+      * This is the current currency selected, default to the base currency.
42
+      *
43
+      * @var boolean
44
+      */
45
+     public $current_currency = false;
46
+
47
+     /**
48
+      * Constructor
49
+      */
50
+     public function __construct() {
51
+          if ( ! is_admin() ) {
52
+               add_action( 'plugins_loaded', array( $this, 'set_defaults' ), 11, 1 );
53
+               add_filter( 'lsx_to_custom_field_query', array( $this, 'price_filter' ), 20, 5 );
54
+               add_action( 'wp_enqueue_scripts', array( $this, 'assets' ), 5 );
55
+               add_filter( 'wp_nav_menu_items', array( $this, 'wp_nav_menu_items_filter' ), 10, 2 );
56
+               add_filter( 'wp_kses_allowed_html', array( $this, 'wp_kses_allowed_html' ), 10, 2 );
57
+               add_filter( 'get_post_metadata', array( $this, 'filter_post_meta' ), 100, 4 );
58
+          }
59
+     }
60
+
61
+     /**
62
+      * Return an instance of this class.
63
+      *
64
+      * @return  object
65
+      */
66
+     public static function init() {
67
+          // If the single instance hasn't been set, set it now.
68
+          if ( ! isset( self::$instance ) ) {
69
+               self::$instance = new self();
70
+          }
71
+          return self::$instance;
72
+     }
73
+
74
+     /**
75
+      * Constructor
76
+      */
77
+     public function set_defaults() {
78
+          $this->rates_message = esc_html__( 'Error: API key isn\'t set.', 'lsx-currencies' );
79
+          $this->rates = get_transient( 'lsx_currencies_rates' );
80
+          if ( false === $this->rates ) {
81
+               $rates         = wp_remote_retrieve_body( wp_safe_remote_get( lsx_currencies()->api_url ) );
82
+               $decoded_rates = json_decode( $rates );
83
+
84
+               if ( is_wp_error( $rates ) ) {
85
+                    $this->rates_message = $rates->get_error_message();
86
+               } elseif ( ! empty( $decoded_rates->error ) ) {
87
+                    $this->rates_message = $decoded_rates->description;
88
+               } elseif ( empty( $rates ) ) {
89
+                    $this->rates_message = esc_html__( 'Error: API response is empty.', 'lsx-currencies' );
90
+               } else {
91
+                    $this->rates_message = esc_html__( 'Success (new request).', 'lsx-currencies' );
92
+                    set_transient( 'lsx_currencies_rates', $decoded_rates->rates, 60 * 60 * 12 );
93
+                    do_action( 'lsx_currencies_rates_refreshed' );
94
+                    $this->rates = $decoded_rates->rates;
95
+               }
96
+          } else {
97
+               $this->rates_message = esc_html__( 'Success (from cache).', 'lsx-currencies' );
98
+          }
99
+          $this->current_currency = isset( $_COOKIE['lsx_currencies_choice'] ) ? sanitize_key( $_COOKIE['lsx_currencies_choice'] ) : lsx_currencies()->base_currency;
100
+          $this->current_currency = strtoupper( $this->current_currency );
101
+     }
102
+
103
+     /**
104
+      * Enques the assets
105
+      */
106
+     public function assets() {
107
+          wp_enqueue_script( 'lsx-moneyjs', LSX_CURRENCIES_URL . 'assets/js/vendor/money.min.js', array( 'jquery' ), LSX_CURRENCIES_VER, true );
108
+          wp_enqueue_script( 'lsx-accountingjs', LSX_CURRENCIES_URL . 'assets/js/vendor/accounting.min.js', array( 'jquery' ), LSX_CURRENCIES_VER, true );
109
+          wp_enqueue_script( 'lsx-jquery-cookie', LSX_CURRENCIES_URL . 'assets/js/vendor/cookie.min.js', array( 'jquery' ), LSX_CURRENCIES_VER, true );
110
+
111
+          $prefix = '.min';
112
+          $src = '';
113
+          $script_debug = false;
114
+          if ( defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ) {
115
+               $prefix = '';
116
+               $src = 'src/';
117
+               $script_debug = true;
118
+          }
119
+          wp_enqueue_script( 'lsx-currencies', LSX_CURRENCIES_URL . 'assets/js/' . $src . 'lsx-currencies' . $prefix . '.js', array( 'jquery', 'lsx-moneyjs', 'lsx-accountingjs', 'lsx-jquery-cookie' ), LSX_CURRENCIES_VER, true );
120
+
121
+          $base_currency = lsx_currencies()->base_currency;
122
+          $current_currency = $this->current_currency;
123
+          if ( true === lsx_currencies()->convert_to_single ) {
124
+               $current_currency = $base_currency;
125
+          }
126
+
127
+          $params = apply_filters( 'lsx_currencies_js_params', array(
128
+               'current_currency'  => $current_currency,
129
+               'currency_symbols'  => $this->get_available_symbols(),
130
+               'rates'             => $this->rates,
131
+               'rates_message'     => $this->rates_message,
132
+               'base'              => $base_currency,
133
+               'flags'             => lsx_currencies()->display_flags,
134
+               'convert_to_single' => lsx_currencies()->convert_to_single,
135
+               'script_debug'      => $script_debug,
136
+               'remove_decimals'   => lsx_currencies()->remove_decimals,
137
+          ));
138
+
139
+          wp_localize_script( 'lsx-currencies', 'lsx_currencies_params', $params );
140
+
141
+          wp_enqueue_style( 'lsx-currencies', LSX_CURRENCIES_URL . 'assets/css/lsx-currencies.css', array(), LSX_CURRENCIES_VER );
142
+          wp_style_add_data( 'lsx-currencies', 'rtl', 'replace' );
143
+     }
144
+
145
+     /**
146
+      * Returns all of the available symbols.
147
+      *
148
+      * @return array
149
+      */
150
+     public function get_available_symbols() {
151
+          $symbols = array();
152
+          if ( false !== lsx_currencies()->additional_currencies && ! empty( lsx_currencies()->additional_currencies ) ) {
153
+               foreach ( lsx_currencies()->additional_currencies as $key => $currency ) {
154
+                    $symbols[ $key ] = lsx_currencies()->currency_symbols[ $key ];
155
+               }
156
+          }
157
+          return $symbols;
158
+     }
159
+
160
+     /**
161
+      * Adds in the required currency conversion tags
162
+      */
163
+     public function price_filter( $return_html, $meta_key, $value, $before, $after ) {
164
+          if ( 'price' === $meta_key ) {
165
+               $additional_html = '';
166
+               $additional_prices = get_post_meta( get_the_ID(), 'additional_prices', false );
167
+               $prefix = '<span class="amount lsx-currencies" ';
168
+
169
+               if ( true === lsx_currencies()->multi_prices && ! empty( $additional_prices ) ) {
170
+                    foreach ( $additional_prices as $a_price ) {
171
+                         $additional_html .= ' data-price-' . $a_price['currency'] . '="' . $a_price['amount'] . '"';
172
+                    }
173
+               }
174
+
175
+               $value = preg_replace( '/[^0-9.]+/', '', $value );
176
+               $decimals = substr_count( $value, '.' );
177
+
178
+               if ( false !== $decimals && $decimals > 1 ) {
179
+                    $decimals--;
180
+                    $decimals = (int) $decimals;
181
+                    $value = preg_replace( '/' . preg_quote( '.', '/' ) . '/', '', $value, $decimals );
182
+               }
183
+
184
+               $money_format = 2;
185
+               if ( false !== lsx_currencies()->remove_decimals ) {
186
+                    $money_format = 0;
187
+               }
188
+
189
+               $prefix .= '>';
190
+               $suffix = '</span>';
191
+
192
+               setlocale( LC_MONETARY, 'en_US' );
193
+
194
+               // Work out the other tags.
195
+               $currency = '<span class="currency-icon ' . mb_strtolower( lsx_currencies()->base_currency ) . '">' . lsx_currencies()->base_currency . '</span>';
196
+
197
+               $value = ltrim( rtrim( $value ) );
198 198
 			
199
-			$for_value = number_format( (float) $value, $money_format );
200
-			$for_value = str_replace( array( '$', 'USD' ), '', $for_value );
199
+               $for_value = number_format( (float) $value, $money_format );
200
+               $for_value = str_replace( array( '$', 'USD' ), '', $for_value );
201 201
 			
202
-			$amount = '<span class="value" data-price-' . lsx_currencies()->base_currency . '="' . trim( str_replace( array( '$', 'USD' ), '', $value ) ) . '" ' . $additional_html . '>' . str_replace( array( '$', 'USD' ), '', $for_value ) . '</span>';
203
-
204
-			// Check for a price type and add that in.
205
-			$price_type = get_post_meta( get_the_ID(), 'price_type', true );
206
-
207
-			switch ( $price_type ) {
208
-				case 'per_person_per_night':
209
-				case 'per_person_sharing':
210
-				case 'per_person_sharing_per_night':
211
-					$amount = $currency . $amount . ' ' . ucwords( str_replace( '_', ' ', $price_type ) );
212
-				    break;
213
-
214
-				case 'total_percentage':
215
-					$amount .= '% ' . esc_html__( 'Off', 'lsx-currencies' );
216
-					$before = str_replace( 'from', '', $before );
217
-				    break;
218
-
219
-				case 'none':
220
-				default:
221
-					$amount = $currency . $amount;
222
-				    break;
223
-			}
224
-
225
-			$return_html = $before . $prefix . $amount . $suffix . $after;
226
-		}
227
-
228
-		return $return_html;
229
-	}
230
-
231
-	/**
232
-	 * Filter on the 'wp_nav_menu_items' hook, that potentially adds a currency switcher to the item of some menus.
233
-	 *
234
-	 * @param $items string
235
-	 * @param $args object
236
-	 *
237
-	 * @return string
238
-	 */
239
-	public function wp_nav_menu_items_filter( $items, $args ) {
240
-		if ( '' !== lsx_currencies()->menus && lsx_currencies()->menus === $args->theme_location ) {
241
-			if ( 'top-menu' === $args->theme_location ) {
242
-				$items = $this->get_menu_html( $args ) . $items;
243
-			} else {
244
-				$items = $items . $this->get_menu_html( $args );
245
-			}
246
-		}
247
-		return $items;
248
-	}
249
-
250
-	/**
251
-	 * Returns the HTML string of the language switcher for a given menu.
252
-	 *
253
-	 * @param $args object
254
-	 *
255
-	 * @return string
256
-	 */
257
-	private function get_menu_html( $args ) {
258
-		if ( empty( lsx_currencies()->additional_currencies ) ) {
259
-			return '';
260
-		}
261
-
262
-		$items = '';
263
-		$items .= '<li class="menu-item menu-item-currency menu-item-currency-current menu-item-has-children dropdown">';
264
-		$items .= isset( $args->before ) ? $args->before : '';
265
-		$items .= '<a class="current symbol-' . lsx_currencies()->switcher_symbol_position . '" href="#' . strtolower( $this->current_currency ) . '">';
266
-		$items .= isset( $args->link_before ) ? $args->link_before : '';
267
-
268
-		if ( ! empty( lsx_currencies()->display_flags ) && 'left' === lsx_currencies()->flag_position ) {
269
-			$items .= lsx_currencies()->get_currency_flag( $this->current_currency );
270
-		}
271
-
272
-		if ( 'left' === lsx_currencies()->switcher_symbol_position ) {
273
-			$items .= '<span class="currency-icon ' . strtolower( $this->current_currency ) . '"></span>';
274
-		}
275
-
276
-		$items .= $this->current_currency;
277
-
278
-		if ( 'right' === lsx_currencies()->switcher_symbol_position ) {
279
-			$items .= '<span class="currency-icon ' . strtolower( $this->current_currency ) . '"></span>';
280
-		}
281
-
282
-		if ( ! empty( lsx_currencies()->display_flags ) && 'right' === lsx_currencies()->flag_position ) {
283
-			$items .= lsx_currencies()->get_currency_flag( $this->current_currency );
284
-		}
285
-
286
-		$items .= isset( $args->link_after ) ? $args->link_after : '';
287
-		$items .= '<span class="caret"></span></a>';
288
-		$items .= isset( $args->after ) ? $args->after : '';
289
-		$items .= $this->render_sub_items();
290
-		$items .= '</li>';
291
-		return $items;
292
-	}
293
-	/**
294
-	 * Returns the HTML string of the language switcher for a given menu.
295
-	 *
296
-	 * @param object $args
297
-	 *
298
-	 * @return string
299
-	 */
300
-	private function render_sub_items() {
301
-		$sub_items = '';
302
-		foreach ( lsx_currencies()->additional_currencies as $key => $currency ) {
303
-			$hidden = '';
304
-			$class = '';
305
-
306
-			if ( $this->current_currency === $key ) {
307
-				$hidden = 'style="display:none";';
308
-				$class = 'hidden';
309
-			}
310
-
311
-			$sub_items .= '<li ' . $hidden . ' class="' . $class . ' menu-item menu-item-currency ' . lsx_currencies()->switcher_symbol_position . '">';
312
-			$sub_items .= '<a class=" symbol-' . lsx_currencies()->switcher_symbol_position . '" href="#' . strtolower( $key ) . '">';
313
-
314
-			if ( ! empty( lsx_currencies()->display_flags ) && 'left' === lsx_currencies()->flag_position ) {
315
-				$sub_items .= lsx_currencies()->get_currency_flag( $key );
316
-			}
317
-
318
-			if ( 'left' === lsx_currencies()->switcher_symbol_position ) {
319
-				$sub_items .= '<span class="currency-icon ' . strtolower( $key ) . '"></span>';
320
-			}
321
-
322
-			$sub_items .= ucwords( $key );
323
-
324
-			if ( 'right' === lsx_currencies()->switcher_symbol_position ) {
325
-				$sub_items .= '<span class="currency-icon ' . strtolower( $key ) . '"></span>';
326
-			}
327
-
328
-			if ( ! empty( lsx_currencies()->display_flags ) && 'right' === lsx_currencies()->flag_position ) {
329
-				$sub_items .= lsx_currencies()->get_currency_flag( $key );
330
-			}
331
-
332
-			$sub_items .= '</a></li>';
333
-		}
334
-
335
-		$sub_items = '<ul class="sub-menu submenu-currency dropdown-menu">' . $sub_items . '</ul>';
336
-		return $sub_items;
337
-	}
338
-
339
-	/**
340
-	 * Allow data params for Slick slider addon.
341
-	 */
342
-	public function wp_kses_allowed_html( $allowedtags, $context ) {
343
-		if ( ! isset( $allowedtags['span'] ) ) {
344
-			$allowedtags['span'] = array();
345
-		}
346
-
347
-		$allowedtags['span']['data-price-AUD'] = true;
348
-		$allowedtags['span']['data-price-BRL'] = true;
349
-		$allowedtags['span']['data-price-GBP'] = true;
350
-		$allowedtags['span']['data-price-BWP'] = true;
351
-		$allowedtags['span']['data-price-CAD'] = true;
352
-		$allowedtags['span']['data-price-CNY'] = true;
353
-		$allowedtags['span']['data-price-EUR'] = true;
354
-		$allowedtags['span']['data-price-HKD'] = true;
355
-		$allowedtags['span']['data-price-INR'] = true;
356
-		$allowedtags['span']['data-price-IDR'] = true;
357
-		$allowedtags['span']['data-price-ILS'] = true;
358
-		$allowedtags['span']['data-price-JPY'] = true;
359
-		$allowedtags['span']['data-price-KES'] = true;
360
-		$allowedtags['span']['data-price-LAK'] = true;
361
-		$allowedtags['span']['data-price-MWK'] = true;
362
-		$allowedtags['span']['data-price-MYR'] = true;
363
-		$allowedtags['span']['data-price-MZN'] = true;
364
-		$allowedtags['span']['data-price-NAD'] = true;
365
-		$allowedtags['span']['data-price-NZD'] = true;
366
-		$allowedtags['span']['data-price-NOK'] = true;
367
-		$allowedtags['span']['data-price-RUB'] = true;
368
-		$allowedtags['span']['data-price-SGD'] = true;
369
-		$allowedtags['span']['data-price-ZAR'] = true;
370
-		$allowedtags['span']['data-price-SEK'] = true;
371
-		$allowedtags['span']['data-price-CHF'] = true;
372
-		$allowedtags['span']['data-price-TZS'] = true;
373
-		$allowedtags['span']['data-price-USD'] = true;
374
-		$allowedtags['span']['data-price-AED'] = true;
375
-		$allowedtags['span']['data-price-ZMW'] = true;
376
-		$allowedtags['span']['data-price-ZWL'] = true;
377
-
378
-		return $allowedtags;
379
-	}
380
-
381
-	/**
382
-	 * Allow empty prices if the convert to single currency is active.
383
-	 *
384
-	 * @param null $metadata
385
-	 * @param string $object_id
386
-	 * @param string $meta_key
387
-	 * @param boolean $single
388
-	 * @return void
389
-	 */
390
-	public function filter_post_meta( $metadata = null, $object_id, $meta_key, $single ) {
391
-		if ( true === lsx_currencies()->convert_to_single && 'price' === $meta_key ) {
392
-			$meta_cache = wp_cache_get( $object_id, 'post_meta' );
393
-
394
-			if ( ! isset( $meta_cache[ $meta_key ] ) || '' === $meta_cache[ $meta_key ] ) {
395
-				$metadata = '0';
396
-			}
397
-		}
398
-		return $metadata;
399
-	}
202
+               $amount = '<span class="value" data-price-' . lsx_currencies()->base_currency . '="' . trim( str_replace( array( '$', 'USD' ), '', $value ) ) . '" ' . $additional_html . '>' . str_replace( array( '$', 'USD' ), '', $for_value ) . '</span>';
203
+
204
+               // Check for a price type and add that in.
205
+               $price_type = get_post_meta( get_the_ID(), 'price_type', true );
206
+
207
+               switch ( $price_type ) {
208
+                    case 'per_person_per_night':
209
+                    case 'per_person_sharing':
210
+                    case 'per_person_sharing_per_night':
211
+                         $amount = $currency . $amount . ' ' . ucwords( str_replace( '_', ' ', $price_type ) );
212
+                         break;
213
+
214
+                    case 'total_percentage':
215
+                         $amount .= '% ' . esc_html__( 'Off', 'lsx-currencies' );
216
+                         $before = str_replace( 'from', '', $before );
217
+                         break;
218
+
219
+                    case 'none':
220
+                    default:
221
+                         $amount = $currency . $amount;
222
+                         break;
223
+               }
224
+
225
+               $return_html = $before . $prefix . $amount . $suffix . $after;
226
+          }
227
+
228
+          return $return_html;
229
+     }
230
+
231
+     /**
232
+      * Filter on the 'wp_nav_menu_items' hook, that potentially adds a currency switcher to the item of some menus.
233
+      *
234
+      * @param $items string
235
+      * @param $args object
236
+      *
237
+      * @return string
238
+      */
239
+     public function wp_nav_menu_items_filter( $items, $args ) {
240
+          if ( '' !== lsx_currencies()->menus && lsx_currencies()->menus === $args->theme_location ) {
241
+               if ( 'top-menu' === $args->theme_location ) {
242
+                    $items = $this->get_menu_html( $args ) . $items;
243
+               } else {
244
+                    $items = $items . $this->get_menu_html( $args );
245
+               }
246
+          }
247
+          return $items;
248
+     }
249
+
250
+     /**
251
+      * Returns the HTML string of the language switcher for a given menu.
252
+      *
253
+      * @param $args object
254
+      *
255
+      * @return string
256
+      */
257
+     private function get_menu_html( $args ) {
258
+          if ( empty( lsx_currencies()->additional_currencies ) ) {
259
+               return '';
260
+          }
261
+
262
+          $items = '';
263
+          $items .= '<li class="menu-item menu-item-currency menu-item-currency-current menu-item-has-children dropdown">';
264
+          $items .= isset( $args->before ) ? $args->before : '';
265
+          $items .= '<a class="current symbol-' . lsx_currencies()->switcher_symbol_position . '" href="#' . strtolower( $this->current_currency ) . '">';
266
+          $items .= isset( $args->link_before ) ? $args->link_before : '';
267
+
268
+          if ( ! empty( lsx_currencies()->display_flags ) && 'left' === lsx_currencies()->flag_position ) {
269
+               $items .= lsx_currencies()->get_currency_flag( $this->current_currency );
270
+          }
271
+
272
+          if ( 'left' === lsx_currencies()->switcher_symbol_position ) {
273
+               $items .= '<span class="currency-icon ' . strtolower( $this->current_currency ) . '"></span>';
274
+          }
275
+
276
+          $items .= $this->current_currency;
277
+
278
+          if ( 'right' === lsx_currencies()->switcher_symbol_position ) {
279
+               $items .= '<span class="currency-icon ' . strtolower( $this->current_currency ) . '"></span>';
280
+          }
281
+
282
+          if ( ! empty( lsx_currencies()->display_flags ) && 'right' === lsx_currencies()->flag_position ) {
283
+               $items .= lsx_currencies()->get_currency_flag( $this->current_currency );
284
+          }
285
+
286
+          $items .= isset( $args->link_after ) ? $args->link_after : '';
287
+          $items .= '<span class="caret"></span></a>';
288
+          $items .= isset( $args->after ) ? $args->after : '';
289
+          $items .= $this->render_sub_items();
290
+          $items .= '</li>';
291
+          return $items;
292
+     }
293
+     /**
294
+      * Returns the HTML string of the language switcher for a given menu.
295
+      *
296
+      * @param object $args
297
+      *
298
+      * @return string
299
+      */
300
+     private function render_sub_items() {
301
+          $sub_items = '';
302
+          foreach ( lsx_currencies()->additional_currencies as $key => $currency ) {
303
+               $hidden = '';
304
+               $class = '';
305
+
306
+               if ( $this->current_currency === $key ) {
307
+                    $hidden = 'style="display:none";';
308
+                    $class = 'hidden';
309
+               }
310
+
311
+               $sub_items .= '<li ' . $hidden . ' class="' . $class . ' menu-item menu-item-currency ' . lsx_currencies()->switcher_symbol_position . '">';
312
+               $sub_items .= '<a class=" symbol-' . lsx_currencies()->switcher_symbol_position . '" href="#' . strtolower( $key ) . '">';
313
+
314
+               if ( ! empty( lsx_currencies()->display_flags ) && 'left' === lsx_currencies()->flag_position ) {
315
+                    $sub_items .= lsx_currencies()->get_currency_flag( $key );
316
+               }
317
+
318
+               if ( 'left' === lsx_currencies()->switcher_symbol_position ) {
319
+                    $sub_items .= '<span class="currency-icon ' . strtolower( $key ) . '"></span>';
320
+               }
321
+
322
+               $sub_items .= ucwords( $key );
323
+
324
+               if ( 'right' === lsx_currencies()->switcher_symbol_position ) {
325
+                    $sub_items .= '<span class="currency-icon ' . strtolower( $key ) . '"></span>';
326
+               }
327
+
328
+               if ( ! empty( lsx_currencies()->display_flags ) && 'right' === lsx_currencies()->flag_position ) {
329
+                    $sub_items .= lsx_currencies()->get_currency_flag( $key );
330
+               }
331
+
332
+               $sub_items .= '</a></li>';
333
+          }
334
+
335
+          $sub_items = '<ul class="sub-menu submenu-currency dropdown-menu">' . $sub_items . '</ul>';
336
+          return $sub_items;
337
+     }
338
+
339
+     /**
340
+      * Allow data params for Slick slider addon.
341
+      */
342
+     public function wp_kses_allowed_html( $allowedtags, $context ) {
343
+          if ( ! isset( $allowedtags['span'] ) ) {
344
+               $allowedtags['span'] = array();
345
+          }
346
+
347
+          $allowedtags['span']['data-price-AUD'] = true;
348
+          $allowedtags['span']['data-price-BRL'] = true;
349
+          $allowedtags['span']['data-price-GBP'] = true;
350
+          $allowedtags['span']['data-price-BWP'] = true;
351
+          $allowedtags['span']['data-price-CAD'] = true;
352
+          $allowedtags['span']['data-price-CNY'] = true;
353
+          $allowedtags['span']['data-price-EUR'] = true;
354
+          $allowedtags['span']['data-price-HKD'] = true;
355
+          $allowedtags['span']['data-price-INR'] = true;
356
+          $allowedtags['span']['data-price-IDR'] = true;
357
+          $allowedtags['span']['data-price-ILS'] = true;
358
+          $allowedtags['span']['data-price-JPY'] = true;
359
+          $allowedtags['span']['data-price-KES'] = true;
360
+          $allowedtags['span']['data-price-LAK'] = true;
361
+          $allowedtags['span']['data-price-MWK'] = true;
362
+          $allowedtags['span']['data-price-MYR'] = true;
363
+          $allowedtags['span']['data-price-MZN'] = true;
364
+          $allowedtags['span']['data-price-NAD'] = true;
365
+          $allowedtags['span']['data-price-NZD'] = true;
366
+          $allowedtags['span']['data-price-NOK'] = true;
367
+          $allowedtags['span']['data-price-RUB'] = true;
368
+          $allowedtags['span']['data-price-SGD'] = true;
369
+          $allowedtags['span']['data-price-ZAR'] = true;
370
+          $allowedtags['span']['data-price-SEK'] = true;
371
+          $allowedtags['span']['data-price-CHF'] = true;
372
+          $allowedtags['span']['data-price-TZS'] = true;
373
+          $allowedtags['span']['data-price-USD'] = true;
374
+          $allowedtags['span']['data-price-AED'] = true;
375
+          $allowedtags['span']['data-price-ZMW'] = true;
376
+          $allowedtags['span']['data-price-ZWL'] = true;
377
+
378
+          return $allowedtags;
379
+     }
380
+
381
+     /**
382
+      * Allow empty prices if the convert to single currency is active.
383
+      *
384
+      * @param null $metadata
385
+      * @param string $object_id
386
+      * @param string $meta_key
387
+      * @param boolean $single
388
+      * @return void
389
+      */
390
+     public function filter_post_meta( $metadata = null, $object_id, $meta_key, $single ) {
391
+          if ( true === lsx_currencies()->convert_to_single && 'price' === $meta_key ) {
392
+               $meta_cache = wp_cache_get( $object_id, 'post_meta' );
393
+
394
+               if ( ! isset( $meta_cache[ $meta_key ] ) || '' === $meta_cache[ $meta_key ] ) {
395
+                    $metadata = '0';
396
+               }
397
+          }
398
+          return $metadata;
399
+     }
400 400
 }
Please login to merge, or discard this patch.
Spacing   +100 added lines, -100 removed lines patch added patch discarded remove patch
@@ -48,13 +48,13 @@  discard block
 block discarded – undo
48 48
 	 * Constructor
49 49
 	 */
50 50
 	public function __construct() {
51
-		if ( ! is_admin() ) {
52
-			add_action( 'plugins_loaded', array( $this, 'set_defaults' ), 11, 1 );
53
-			add_filter( 'lsx_to_custom_field_query', array( $this, 'price_filter' ), 20, 5 );
54
-			add_action( 'wp_enqueue_scripts', array( $this, 'assets' ), 5 );
55
-			add_filter( 'wp_nav_menu_items', array( $this, 'wp_nav_menu_items_filter' ), 10, 2 );
56
-			add_filter( 'wp_kses_allowed_html', array( $this, 'wp_kses_allowed_html' ), 10, 2 );
57
-			add_filter( 'get_post_metadata', array( $this, 'filter_post_meta' ), 100, 4 );
51
+		if (!is_admin()) {
52
+			add_action('plugins_loaded', array($this, 'set_defaults'), 11, 1);
53
+			add_filter('lsx_to_custom_field_query', array($this, 'price_filter'), 20, 5);
54
+			add_action('wp_enqueue_scripts', array($this, 'assets'), 5);
55
+			add_filter('wp_nav_menu_items', array($this, 'wp_nav_menu_items_filter'), 10, 2);
56
+			add_filter('wp_kses_allowed_html', array($this, 'wp_kses_allowed_html'), 10, 2);
57
+			add_filter('get_post_metadata', array($this, 'filter_post_meta'), 100, 4);
58 58
 		}
59 59
 	}
60 60
 
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 	 */
66 66
 	public static function init() {
67 67
 		// If the single instance hasn't been set, set it now.
68
-		if ( ! isset( self::$instance ) ) {
68
+		if (!isset(self::$instance)) {
69 69
 			self::$instance = new self();
70 70
 		}
71 71
 		return self::$instance;
@@ -75,56 +75,56 @@  discard block
 block discarded – undo
75 75
 	 * Constructor
76 76
 	 */
77 77
 	public function set_defaults() {
78
-		$this->rates_message = esc_html__( 'Error: API key isn\'t set.', 'lsx-currencies' );
79
-		$this->rates = get_transient( 'lsx_currencies_rates' );
80
-		if ( false === $this->rates ) {
81
-			$rates         = wp_remote_retrieve_body( wp_safe_remote_get( lsx_currencies()->api_url ) );
82
-			$decoded_rates = json_decode( $rates );
78
+		$this->rates_message = esc_html__('Error: API key isn\'t set.', 'lsx-currencies');
79
+		$this->rates = get_transient('lsx_currencies_rates');
80
+		if (false === $this->rates) {
81
+			$rates         = wp_remote_retrieve_body(wp_safe_remote_get(lsx_currencies()->api_url));
82
+			$decoded_rates = json_decode($rates);
83 83
 
84
-			if ( is_wp_error( $rates ) ) {
84
+			if (is_wp_error($rates)) {
85 85
 				$this->rates_message = $rates->get_error_message();
86
-			} elseif ( ! empty( $decoded_rates->error ) ) {
86
+			} elseif (!empty($decoded_rates->error)) {
87 87
 				$this->rates_message = $decoded_rates->description;
88
-			} elseif ( empty( $rates ) ) {
89
-				$this->rates_message = esc_html__( 'Error: API response is empty.', 'lsx-currencies' );
88
+			} elseif (empty($rates)) {
89
+				$this->rates_message = esc_html__('Error: API response is empty.', 'lsx-currencies');
90 90
 			} else {
91
-				$this->rates_message = esc_html__( 'Success (new request).', 'lsx-currencies' );
92
-				set_transient( 'lsx_currencies_rates', $decoded_rates->rates, 60 * 60 * 12 );
93
-				do_action( 'lsx_currencies_rates_refreshed' );
91
+				$this->rates_message = esc_html__('Success (new request).', 'lsx-currencies');
92
+				set_transient('lsx_currencies_rates', $decoded_rates->rates, 60 * 60 * 12);
93
+				do_action('lsx_currencies_rates_refreshed');
94 94
 				$this->rates = $decoded_rates->rates;
95 95
 			}
96 96
 		} else {
97
-			$this->rates_message = esc_html__( 'Success (from cache).', 'lsx-currencies' );
97
+			$this->rates_message = esc_html__('Success (from cache).', 'lsx-currencies');
98 98
 		}
99
-		$this->current_currency = isset( $_COOKIE['lsx_currencies_choice'] ) ? sanitize_key( $_COOKIE['lsx_currencies_choice'] ) : lsx_currencies()->base_currency;
100
-		$this->current_currency = strtoupper( $this->current_currency );
99
+		$this->current_currency = isset($_COOKIE['lsx_currencies_choice']) ? sanitize_key($_COOKIE['lsx_currencies_choice']) : lsx_currencies()->base_currency;
100
+		$this->current_currency = strtoupper($this->current_currency);
101 101
 	}
102 102
 
103 103
 	/**
104 104
 	 * Enques the assets
105 105
 	 */
106 106
 	public function assets() {
107
-		wp_enqueue_script( 'lsx-moneyjs', LSX_CURRENCIES_URL . 'assets/js/vendor/money.min.js', array( 'jquery' ), LSX_CURRENCIES_VER, true );
108
-		wp_enqueue_script( 'lsx-accountingjs', LSX_CURRENCIES_URL . 'assets/js/vendor/accounting.min.js', array( 'jquery' ), LSX_CURRENCIES_VER, true );
109
-		wp_enqueue_script( 'lsx-jquery-cookie', LSX_CURRENCIES_URL . 'assets/js/vendor/cookie.min.js', array( 'jquery' ), LSX_CURRENCIES_VER, true );
107
+		wp_enqueue_script('lsx-moneyjs', LSX_CURRENCIES_URL.'assets/js/vendor/money.min.js', array('jquery'), LSX_CURRENCIES_VER, true);
108
+		wp_enqueue_script('lsx-accountingjs', LSX_CURRENCIES_URL.'assets/js/vendor/accounting.min.js', array('jquery'), LSX_CURRENCIES_VER, true);
109
+		wp_enqueue_script('lsx-jquery-cookie', LSX_CURRENCIES_URL.'assets/js/vendor/cookie.min.js', array('jquery'), LSX_CURRENCIES_VER, true);
110 110
 
111 111
 		$prefix = '.min';
112 112
 		$src = '';
113 113
 		$script_debug = false;
114
-		if ( defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ) {
114
+		if (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) {
115 115
 			$prefix = '';
116 116
 			$src = 'src/';
117 117
 			$script_debug = true;
118 118
 		}
119
-		wp_enqueue_script( 'lsx-currencies', LSX_CURRENCIES_URL . 'assets/js/' . $src . 'lsx-currencies' . $prefix . '.js', array( 'jquery', 'lsx-moneyjs', 'lsx-accountingjs', 'lsx-jquery-cookie' ), LSX_CURRENCIES_VER, true );
119
+		wp_enqueue_script('lsx-currencies', LSX_CURRENCIES_URL.'assets/js/'.$src.'lsx-currencies'.$prefix.'.js', array('jquery', 'lsx-moneyjs', 'lsx-accountingjs', 'lsx-jquery-cookie'), LSX_CURRENCIES_VER, true);
120 120
 
121 121
 		$base_currency = lsx_currencies()->base_currency;
122 122
 		$current_currency = $this->current_currency;
123
-		if ( true === lsx_currencies()->convert_to_single ) {
123
+		if (true === lsx_currencies()->convert_to_single) {
124 124
 			$current_currency = $base_currency;
125 125
 		}
126 126
 
127
-		$params = apply_filters( 'lsx_currencies_js_params', array(
127
+		$params = apply_filters('lsx_currencies_js_params', array(
128 128
 			'current_currency'  => $current_currency,
129 129
 			'currency_symbols'  => $this->get_available_symbols(),
130 130
 			'rates'             => $this->rates,
@@ -136,10 +136,10 @@  discard block
 block discarded – undo
136 136
 			'remove_decimals'   => lsx_currencies()->remove_decimals,
137 137
 		));
138 138
 
139
-		wp_localize_script( 'lsx-currencies', 'lsx_currencies_params', $params );
139
+		wp_localize_script('lsx-currencies', 'lsx_currencies_params', $params);
140 140
 
141
-		wp_enqueue_style( 'lsx-currencies', LSX_CURRENCIES_URL . 'assets/css/lsx-currencies.css', array(), LSX_CURRENCIES_VER );
142
-		wp_style_add_data( 'lsx-currencies', 'rtl', 'replace' );
141
+		wp_enqueue_style('lsx-currencies', LSX_CURRENCIES_URL.'assets/css/lsx-currencies.css', array(), LSX_CURRENCIES_VER);
142
+		wp_style_add_data('lsx-currencies', 'rtl', 'replace');
143 143
 	}
144 144
 
145 145
 	/**
@@ -149,9 +149,9 @@  discard block
 block discarded – undo
149 149
 	 */
150 150
 	public function get_available_symbols() {
151 151
 		$symbols = array();
152
-		if ( false !== lsx_currencies()->additional_currencies && ! empty( lsx_currencies()->additional_currencies ) ) {
153
-			foreach ( lsx_currencies()->additional_currencies as $key => $currency ) {
154
-				$symbols[ $key ] = lsx_currencies()->currency_symbols[ $key ];
152
+		if (false !== lsx_currencies()->additional_currencies && !empty(lsx_currencies()->additional_currencies)) {
153
+			foreach (lsx_currencies()->additional_currencies as $key => $currency) {
154
+				$symbols[$key] = lsx_currencies()->currency_symbols[$key];
155 155
 			}
156 156
 		}
157 157
 		return $symbols;
@@ -160,69 +160,69 @@  discard block
 block discarded – undo
160 160
 	/**
161 161
 	 * Adds in the required currency conversion tags
162 162
 	 */
163
-	public function price_filter( $return_html, $meta_key, $value, $before, $after ) {
164
-		if ( 'price' === $meta_key ) {
163
+	public function price_filter($return_html, $meta_key, $value, $before, $after) {
164
+		if ('price' === $meta_key) {
165 165
 			$additional_html = '';
166
-			$additional_prices = get_post_meta( get_the_ID(), 'additional_prices', false );
166
+			$additional_prices = get_post_meta(get_the_ID(), 'additional_prices', false);
167 167
 			$prefix = '<span class="amount lsx-currencies" ';
168 168
 
169
-			if ( true === lsx_currencies()->multi_prices && ! empty( $additional_prices ) ) {
170
-				foreach ( $additional_prices as $a_price ) {
171
-					$additional_html .= ' data-price-' . $a_price['currency'] . '="' . $a_price['amount'] . '"';
169
+			if (true === lsx_currencies()->multi_prices && !empty($additional_prices)) {
170
+				foreach ($additional_prices as $a_price) {
171
+					$additional_html .= ' data-price-'.$a_price['currency'].'="'.$a_price['amount'].'"';
172 172
 				}
173 173
 			}
174 174
 
175
-			$value = preg_replace( '/[^0-9.]+/', '', $value );
176
-			$decimals = substr_count( $value, '.' );
175
+			$value = preg_replace('/[^0-9.]+/', '', $value);
176
+			$decimals = substr_count($value, '.');
177 177
 
178
-			if ( false !== $decimals && $decimals > 1 ) {
178
+			if (false !== $decimals && $decimals > 1) {
179 179
 				$decimals--;
180 180
 				$decimals = (int) $decimals;
181
-				$value = preg_replace( '/' . preg_quote( '.', '/' ) . '/', '', $value, $decimals );
181
+				$value = preg_replace('/'.preg_quote('.', '/').'/', '', $value, $decimals);
182 182
 			}
183 183
 
184 184
 			$money_format = 2;
185
-			if ( false !== lsx_currencies()->remove_decimals ) {
185
+			if (false !== lsx_currencies()->remove_decimals) {
186 186
 				$money_format = 0;
187 187
 			}
188 188
 
189 189
 			$prefix .= '>';
190 190
 			$suffix = '</span>';
191 191
 
192
-			setlocale( LC_MONETARY, 'en_US' );
192
+			setlocale(LC_MONETARY, 'en_US');
193 193
 
194 194
 			// Work out the other tags.
195
-			$currency = '<span class="currency-icon ' . mb_strtolower( lsx_currencies()->base_currency ) . '">' . lsx_currencies()->base_currency . '</span>';
195
+			$currency = '<span class="currency-icon '.mb_strtolower(lsx_currencies()->base_currency).'">'.lsx_currencies()->base_currency.'</span>';
196 196
 
197
-			$value = ltrim( rtrim( $value ) );
197
+			$value = ltrim(rtrim($value));
198 198
 			
199
-			$for_value = number_format( (float) $value, $money_format );
200
-			$for_value = str_replace( array( '$', 'USD' ), '', $for_value );
199
+			$for_value = number_format((float) $value, $money_format);
200
+			$for_value = str_replace(array('$', 'USD'), '', $for_value);
201 201
 			
202
-			$amount = '<span class="value" data-price-' . lsx_currencies()->base_currency . '="' . trim( str_replace( array( '$', 'USD' ), '', $value ) ) . '" ' . $additional_html . '>' . str_replace( array( '$', 'USD' ), '', $for_value ) . '</span>';
202
+			$amount = '<span class="value" data-price-'.lsx_currencies()->base_currency.'="'.trim(str_replace(array('$', 'USD'), '', $value)).'" '.$additional_html.'>'.str_replace(array('$', 'USD'), '', $for_value).'</span>';
203 203
 
204 204
 			// Check for a price type and add that in.
205
-			$price_type = get_post_meta( get_the_ID(), 'price_type', true );
205
+			$price_type = get_post_meta(get_the_ID(), 'price_type', true);
206 206
 
207
-			switch ( $price_type ) {
207
+			switch ($price_type) {
208 208
 				case 'per_person_per_night':
209 209
 				case 'per_person_sharing':
210 210
 				case 'per_person_sharing_per_night':
211
-					$amount = $currency . $amount . ' ' . ucwords( str_replace( '_', ' ', $price_type ) );
211
+					$amount = $currency.$amount.' '.ucwords(str_replace('_', ' ', $price_type));
212 212
 				    break;
213 213
 
214 214
 				case 'total_percentage':
215
-					$amount .= '% ' . esc_html__( 'Off', 'lsx-currencies' );
216
-					$before = str_replace( 'from', '', $before );
215
+					$amount .= '% '.esc_html__('Off', 'lsx-currencies');
216
+					$before = str_replace('from', '', $before);
217 217
 				    break;
218 218
 
219 219
 				case 'none':
220 220
 				default:
221
-					$amount = $currency . $amount;
221
+					$amount = $currency.$amount;
222 222
 				    break;
223 223
 			}
224 224
 
225
-			$return_html = $before . $prefix . $amount . $suffix . $after;
225
+			$return_html = $before.$prefix.$amount.$suffix.$after;
226 226
 		}
227 227
 
228 228
 		return $return_html;
@@ -236,12 +236,12 @@  discard block
 block discarded – undo
236 236
 	 *
237 237
 	 * @return string
238 238
 	 */
239
-	public function wp_nav_menu_items_filter( $items, $args ) {
240
-		if ( '' !== lsx_currencies()->menus && lsx_currencies()->menus === $args->theme_location ) {
241
-			if ( 'top-menu' === $args->theme_location ) {
242
-				$items = $this->get_menu_html( $args ) . $items;
239
+	public function wp_nav_menu_items_filter($items, $args) {
240
+		if ('' !== lsx_currencies()->menus && lsx_currencies()->menus === $args->theme_location) {
241
+			if ('top-menu' === $args->theme_location) {
242
+				$items = $this->get_menu_html($args).$items;
243 243
 			} else {
244
-				$items = $items . $this->get_menu_html( $args );
244
+				$items = $items.$this->get_menu_html($args);
245 245
 			}
246 246
 		}
247 247
 		return $items;
@@ -254,38 +254,38 @@  discard block
 block discarded – undo
254 254
 	 *
255 255
 	 * @return string
256 256
 	 */
257
-	private function get_menu_html( $args ) {
258
-		if ( empty( lsx_currencies()->additional_currencies ) ) {
257
+	private function get_menu_html($args) {
258
+		if (empty(lsx_currencies()->additional_currencies)) {
259 259
 			return '';
260 260
 		}
261 261
 
262 262
 		$items = '';
263 263
 		$items .= '<li class="menu-item menu-item-currency menu-item-currency-current menu-item-has-children dropdown">';
264
-		$items .= isset( $args->before ) ? $args->before : '';
265
-		$items .= '<a class="current symbol-' . lsx_currencies()->switcher_symbol_position . '" href="#' . strtolower( $this->current_currency ) . '">';
266
-		$items .= isset( $args->link_before ) ? $args->link_before : '';
264
+		$items .= isset($args->before) ? $args->before : '';
265
+		$items .= '<a class="current symbol-'.lsx_currencies()->switcher_symbol_position.'" href="#'.strtolower($this->current_currency).'">';
266
+		$items .= isset($args->link_before) ? $args->link_before : '';
267 267
 
268
-		if ( ! empty( lsx_currencies()->display_flags ) && 'left' === lsx_currencies()->flag_position ) {
269
-			$items .= lsx_currencies()->get_currency_flag( $this->current_currency );
268
+		if (!empty(lsx_currencies()->display_flags) && 'left' === lsx_currencies()->flag_position) {
269
+			$items .= lsx_currencies()->get_currency_flag($this->current_currency);
270 270
 		}
271 271
 
272
-		if ( 'left' === lsx_currencies()->switcher_symbol_position ) {
273
-			$items .= '<span class="currency-icon ' . strtolower( $this->current_currency ) . '"></span>';
272
+		if ('left' === lsx_currencies()->switcher_symbol_position) {
273
+			$items .= '<span class="currency-icon '.strtolower($this->current_currency).'"></span>';
274 274
 		}
275 275
 
276 276
 		$items .= $this->current_currency;
277 277
 
278
-		if ( 'right' === lsx_currencies()->switcher_symbol_position ) {
279
-			$items .= '<span class="currency-icon ' . strtolower( $this->current_currency ) . '"></span>';
278
+		if ('right' === lsx_currencies()->switcher_symbol_position) {
279
+			$items .= '<span class="currency-icon '.strtolower($this->current_currency).'"></span>';
280 280
 		}
281 281
 
282
-		if ( ! empty( lsx_currencies()->display_flags ) && 'right' === lsx_currencies()->flag_position ) {
283
-			$items .= lsx_currencies()->get_currency_flag( $this->current_currency );
282
+		if (!empty(lsx_currencies()->display_flags) && 'right' === lsx_currencies()->flag_position) {
283
+			$items .= lsx_currencies()->get_currency_flag($this->current_currency);
284 284
 		}
285 285
 
286
-		$items .= isset( $args->link_after ) ? $args->link_after : '';
286
+		$items .= isset($args->link_after) ? $args->link_after : '';
287 287
 		$items .= '<span class="caret"></span></a>';
288
-		$items .= isset( $args->after ) ? $args->after : '';
288
+		$items .= isset($args->after) ? $args->after : '';
289 289
 		$items .= $this->render_sub_items();
290 290
 		$items .= '</li>';
291 291
 		return $items;
@@ -299,48 +299,48 @@  discard block
 block discarded – undo
299 299
 	 */
300 300
 	private function render_sub_items() {
301 301
 		$sub_items = '';
302
-		foreach ( lsx_currencies()->additional_currencies as $key => $currency ) {
302
+		foreach (lsx_currencies()->additional_currencies as $key => $currency) {
303 303
 			$hidden = '';
304 304
 			$class = '';
305 305
 
306
-			if ( $this->current_currency === $key ) {
306
+			if ($this->current_currency === $key) {
307 307
 				$hidden = 'style="display:none";';
308 308
 				$class = 'hidden';
309 309
 			}
310 310
 
311
-			$sub_items .= '<li ' . $hidden . ' class="' . $class . ' menu-item menu-item-currency ' . lsx_currencies()->switcher_symbol_position . '">';
312
-			$sub_items .= '<a class=" symbol-' . lsx_currencies()->switcher_symbol_position . '" href="#' . strtolower( $key ) . '">';
311
+			$sub_items .= '<li '.$hidden.' class="'.$class.' menu-item menu-item-currency '.lsx_currencies()->switcher_symbol_position.'">';
312
+			$sub_items .= '<a class=" symbol-'.lsx_currencies()->switcher_symbol_position.'" href="#'.strtolower($key).'">';
313 313
 
314
-			if ( ! empty( lsx_currencies()->display_flags ) && 'left' === lsx_currencies()->flag_position ) {
315
-				$sub_items .= lsx_currencies()->get_currency_flag( $key );
314
+			if (!empty(lsx_currencies()->display_flags) && 'left' === lsx_currencies()->flag_position) {
315
+				$sub_items .= lsx_currencies()->get_currency_flag($key);
316 316
 			}
317 317
 
318
-			if ( 'left' === lsx_currencies()->switcher_symbol_position ) {
319
-				$sub_items .= '<span class="currency-icon ' . strtolower( $key ) . '"></span>';
318
+			if ('left' === lsx_currencies()->switcher_symbol_position) {
319
+				$sub_items .= '<span class="currency-icon '.strtolower($key).'"></span>';
320 320
 			}
321 321
 
322
-			$sub_items .= ucwords( $key );
322
+			$sub_items .= ucwords($key);
323 323
 
324
-			if ( 'right' === lsx_currencies()->switcher_symbol_position ) {
325
-				$sub_items .= '<span class="currency-icon ' . strtolower( $key ) . '"></span>';
324
+			if ('right' === lsx_currencies()->switcher_symbol_position) {
325
+				$sub_items .= '<span class="currency-icon '.strtolower($key).'"></span>';
326 326
 			}
327 327
 
328
-			if ( ! empty( lsx_currencies()->display_flags ) && 'right' === lsx_currencies()->flag_position ) {
329
-				$sub_items .= lsx_currencies()->get_currency_flag( $key );
328
+			if (!empty(lsx_currencies()->display_flags) && 'right' === lsx_currencies()->flag_position) {
329
+				$sub_items .= lsx_currencies()->get_currency_flag($key);
330 330
 			}
331 331
 
332 332
 			$sub_items .= '</a></li>';
333 333
 		}
334 334
 
335
-		$sub_items = '<ul class="sub-menu submenu-currency dropdown-menu">' . $sub_items . '</ul>';
335
+		$sub_items = '<ul class="sub-menu submenu-currency dropdown-menu">'.$sub_items.'</ul>';
336 336
 		return $sub_items;
337 337
 	}
338 338
 
339 339
 	/**
340 340
 	 * Allow data params for Slick slider addon.
341 341
 	 */
342
-	public function wp_kses_allowed_html( $allowedtags, $context ) {
343
-		if ( ! isset( $allowedtags['span'] ) ) {
342
+	public function wp_kses_allowed_html($allowedtags, $context) {
343
+		if (!isset($allowedtags['span'])) {
344 344
 			$allowedtags['span'] = array();
345 345
 		}
346 346
 
@@ -387,11 +387,11 @@  discard block
 block discarded – undo
387 387
 	 * @param boolean $single
388 388
 	 * @return void
389 389
 	 */
390
-	public function filter_post_meta( $metadata = null, $object_id, $meta_key, $single ) {
391
-		if ( true === lsx_currencies()->convert_to_single && 'price' === $meta_key ) {
392
-			$meta_cache = wp_cache_get( $object_id, 'post_meta' );
390
+	public function filter_post_meta($metadata = null, $object_id, $meta_key, $single) {
391
+		if (true === lsx_currencies()->convert_to_single && 'price' === $meta_key) {
392
+			$meta_cache = wp_cache_get($object_id, 'post_meta');
393 393
 
394
-			if ( ! isset( $meta_cache[ $meta_key ] ) || '' === $meta_cache[ $meta_key ] ) {
394
+			if (!isset($meta_cache[$meta_key]) || '' === $meta_cache[$meta_key]) {
395 395
 				$metadata = '0';
396 396
 			}
397 397
 		}
Please login to merge, or discard this patch.