Passed
Push — master ( 0db704...ff60ed )
by Chris
04:09
created

Frontend::wp_kses_allowed_html()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 37
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 33
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 37
rs 9.392
1
<?php
2
/**
3
 * LSX Currency Frontend Class
4
 *
5
 * @package   LSX Currencies
6
 * @author    LightSpeed
7
 * @license   GPL3
8
 * @link
9
 * @copyright 2019 LightSpeed
10
 */
11
12
namespace lsx\currencies\classes;
13
14
/**
15
 * The frontend classes
16
 */
17
class Frontend {
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() {
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
51
		if ( ! is_admin() ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
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
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
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 ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
69
			self::$instance = new self();
70
		}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
71
		return self::$instance;
72
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
73
74
	/**
75
	 * Constructor
76
	 */
77
	public function set_defaults() {
78
		$this->rates_message = esc_html__( 'Error: API key isn\'t set.', 'lsx-currencies' );
0 ignored issues
show
Documentation Bug introduced by
The property $rates_message was declared of type boolean, but esc_html__('Error: API k...et.', 'lsx-currencies') is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
79
		$this->rates = get_transient( 'lsx_currencies_rates' );
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 9 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
80
		if ( false === $this->rates ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
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 ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
85
				$this->rates_message = $rates->get_error_message();
86
			} elseif ( ! empty( $decoded_rates->error ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
87
				$this->rates_message = $decoded_rates->description;
88
			} elseif ( empty( $rates ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
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
		}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
99
		$this->current_currency = isset( $_COOKIE['lsx_currencies_choice'] ) ? sanitize_key( $_COOKIE['lsx_currencies_choice'] ) : lsx_currencies()->base_currency;
0 ignored issues
show
Documentation Bug introduced by
It seems like IssetNode ? sanitize_key...encies()->base_currency can also be of type string. However, the property $current_currency is declared as type boolean. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
100
		$this->current_currency = strtoupper( $this->current_currency );
101
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
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';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 7 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
112
		$src = '';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 10 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
113
		$script_debug = false;
114
		if ( defined( 'SCRIPT_DEBUG' ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
115
			$prefix = '';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 7 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
116
			$src = 'src/';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 10 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
117
			$script_debug = true;
118
		}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
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;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
122
		$current_currency = $this->current_currency;
123
		if ( true === lsx_currencies()->convert_to_single ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
124
			$current_currency = $base_currency;
125
		}
126
127
		$params = apply_filters( 'lsx_currencies_js_params', array(
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
Coding Style introduced by
For multi-line function calls, each argument should be on a separate line.

For a function calls that spawns multiple lines, the coding style suggests to split arguments to separate lines like this:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
);
Loading history...
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
		));
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
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
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
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 ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
153
			foreach ( lsx_currencies()->additional_currencies as $key => $currency ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
154
				$symbols[ $key ] = lsx_currencies()->currency_symbols[ $key ];
155
			}
156
		}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
157
		return $symbols;
158
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
159
160
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$return_html" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$meta_key" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$value" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$before" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$after" missing
Loading history...
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 ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
165
			$additional_html = '';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
166
			$additional_prices = get_post_meta( get_the_ID(), 'additional_prices', false );
0 ignored issues
show
Bug introduced by
It seems like get_the_ID() can also be of type false; however, parameter $post_id of get_post_meta() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

166
			$additional_prices = get_post_meta( /** @scrutinizer ignore-type */ get_the_ID(), 'additional_prices', false );
Loading history...
167
			$prefix = '<span class="amount lsx-currencies" ';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 12 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
168
169
			if ( true === lsx_currencies()->multi_prices && ! empty( $additional_prices ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
170
				foreach ( $additional_prices as $a_price ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
171
					$additional_html .= ' data-price-' . $a_price['currency'] . '="' . $a_price['amount'] . '"';
172
				}
173
			}
174
175
			$value = preg_replace( '/[^0-9.]+/', '', $value );
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
176
			$decimals = substr_count( $value, '.' );
177
178
			if ( false !== $decimals && $decimals > 1 ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
179
				$decimals--;
180
				$decimals = (int) $decimals;
181
				$value = preg_replace( '/' . preg_quote( '.', '/' ) . '/', '', $value, $decimals );
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
182
			}
183
184
			$money_format = '%i';
185
			if ( false !== lsx_currencies()->remove_decimals ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
186
				$money_format = '%.0n';
187
			}
188
189
			$prefix .= '>';
190
			$suffix = '</span>';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
191
192
			setlocale( LC_MONETARY, 'en_US' );
193
194
			// Work out the other tags
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
195
			$currency = '<span class="currency-icon ' . mb_strtolower( lsx_currencies()->base_currency ) . '">' . lsx_currencies()->base_currency . '</span>';
196
			$amount = '<span class="value" data-price-' . lsx_currencies()->base_currency . '="' . trim( str_replace( array( '$', 'USD' ), '', money_format( (float) $money_format, ltrim( rtrim( $value ) ) ) ) ) . '" ' . $additional_html . '>' . str_replace( array( '$', 'USD' ), '', money_format( $money_format, ltrim( rtrim( $value ) ) ) ) . '</span>';
0 ignored issues
show
Bug introduced by
ltrim(rtrim($value)) of type string is incompatible with the type double expected by parameter $number of money_format(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

196
			$amount = '<span class="value" data-price-' . lsx_currencies()->base_currency . '="' . trim( str_replace( array( '$', 'USD' ), '', money_format( (float) $money_format, /** @scrutinizer ignore-type */ ltrim( rtrim( $value ) ) ) ) ) . '" ' . $additional_html . '>' . str_replace( array( '$', 'USD' ), '', money_format( $money_format, ltrim( rtrim( $value ) ) ) ) . '</span>';
Loading history...
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
introduced by
Function money_format() is deprecated since PHP 7.4; Use NumberFormatter::formatCurrency() instead
Loading history...
Deprecated Code introduced by
Function money_format() has been deprecated
Loading history...
197
198
			// Check for a price type and add that in.
199
			$price_type = get_post_meta( get_the_ID(), 'price_type', true );
200
201
			switch ( $price_type ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
202
				case 'per_person_per_night':
203
				case 'per_person_sharing':
204
				case 'per_person_sharing_per_night':
205
					$amount = $currency . $amount . ' ' . ucwords( str_replace( '_', ' ', $price_type ) );
206
				    break;
207
208
				case 'total_percentage':
209
					$amount .= '% ' . esc_html__( 'Off', 'lsx-currencies' );
210
					$before = str_replace( 'from', '', $before );
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
211
				    break;
212
213
				case 'none':
214
				default:
215
					$amount = $currency . $amount;
216
				    break;
217
			}
218
219
			$return_html = $before . $prefix . $amount . $suffix . $after;
220
		}
221
222
		return $return_html;
223
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
224
225
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$items" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$args" missing
Loading history...
226
	 * Filter on the 'wp_nav_menu_items' hook, that potentially adds a currency switcher to the item of some menus.
227
	 *
228
	 * @param $items string
0 ignored issues
show
Coding Style introduced by
Missing parameter name
Loading history...
229
	 * @param $args object
0 ignored issues
show
Coding Style introduced by
Missing parameter name
Loading history...
230
	 *
231
	 * @return string
232
	 */
233
	public function wp_nav_menu_items_filter( $items, $args ) {
234
		if ( '' !== lsx_currencies()->menus && lsx_currencies()->menus === $args->theme_location ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
235
			if ( 'top-menu' === $args->theme_location ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
236
				$items = $this->get_menu_html( $args ) . $items;
237
			} else {
238
				$items = $items . $this->get_menu_html( $args );
239
			}
240
		}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
241
		return $items;
242
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
243
244
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$args" missing
Loading history...
245
	 * Returns the HTML string of the language switcher for a given menu.
246
	 *
247
	 * @param $args object
0 ignored issues
show
Coding Style introduced by
Missing parameter name
Loading history...
248
	 *
249
	 * @return string
250
	 */
251
	private function get_menu_html( $args ) {
252
		if ( empty( lsx_currencies()->additional_currencies ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
253
			return '';
254
		}
255
256
		$items = '';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
257
		$items .= '<li class="menu-item menu-item-currency menu-item-currency-current menu-item-has-children dropdown">';
258
		$items .= isset( $args->before ) ? $args->before : '';
259
		$items .= '<a class="current symbol-' . lsx_currencies()->switcher_symbol_position . '" href="#' . strtolower( $this->current_currency ) . '">';
260
		$items .= isset( $args->link_before ) ? $args->link_before : '';
261
262
		if ( ! empty( lsx_currencies()->display_flags ) && 'left' === lsx_currencies()->flag_position ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
263
			$items .= lsx_currencies()->get_currency_flag( $this->current_currency );
264
		}
265
266
		if ( 'left' === lsx_currencies()->switcher_symbol_position ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
267
			$items .= '<span class="currency-icon ' . strtolower( $this->current_currency ) . '"></span>';
268
		}
269
270
		$items .= $this->current_currency;
271
272
		if ( 'right' === lsx_currencies()->switcher_symbol_position ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
273
			$items .= '<span class="currency-icon ' . strtolower( $this->current_currency ) . '"></span>';
274
		}
275
276
		if ( ! empty( lsx_currencies()->display_flags ) && 'right' === lsx_currencies()->flag_position ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
277
			$items .= lsx_currencies()->get_currency_flag( $this->current_currency );
278
		}
279
280
		$items .= isset( $args->link_after ) ? $args->link_after : '';
281
		$items .= '<span class="caret"></span></a>';
282
		$items .= isset( $args->after ) ? $args->after : '';
283
		$items .= $this->render_sub_items();
284
		$items .= '</li>';
285
		return $items;
286
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
287
	/**
288
	 * Returns the HTML string of the language switcher for a given menu.
289
	 *
290
	 * @param object $args
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Superfluous parameter comment
Loading history...
291
	 *
292
	 * @return string
293
	 */
294
	private function render_sub_items() {
295
		$sub_items = '';
296
		foreach ( lsx_currencies()->additional_currencies as $key => $currency ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
297
			$hidden = '';
298
			$class = '';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
299
300
			if ( $this->current_currency === $key ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
301
				$hidden = 'style="display:none";';
302
				$class = 'hidden';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
303
			}
304
305
			$sub_items .= '<li ' . $hidden . ' class="' . $class . ' menu-item menu-item-currency ' . lsx_currencies()->switcher_symbol_position . '">';
306
			$sub_items .= '<a class=" symbol-' . lsx_currencies()->switcher_symbol_position . '" href="#' . strtolower( $key ) . '">';
307
308
			if ( ! empty( lsx_currencies()->display_flags ) && 'left' === lsx_currencies()->flag_position ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
309
				$sub_items .= lsx_currencies()->get_currency_flag( $key );
310
			}
311
312
			if ( 'left' === lsx_currencies()->switcher_symbol_position ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
313
				$sub_items .= '<span class="currency-icon ' . strtolower( $key ) . '"></span>';
314
			}
315
316
			$sub_items .= ucwords( $key );
317
318
			if ( 'right' === lsx_currencies()->switcher_symbol_position ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
319
				$sub_items .= '<span class="currency-icon ' . strtolower( $key ) . '"></span>';
320
			}
321
322
			if ( ! empty( lsx_currencies()->display_flags ) && 'right' === lsx_currencies()->flag_position ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
323
				$sub_items .= lsx_currencies()->get_currency_flag( $key );
324
			}
325
326
			$sub_items .= '</a></li>';
327
		}
328
329
		$sub_items = '<ul class="sub-menu submenu-currency dropdown-menu">' . $sub_items . '</ul>';
330
		return $sub_items;
331
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
332
333
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$allowedtags" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$context" missing
Loading history...
334
	 * Allow data params for Slick slider addon.
335
	 */
336
	public function wp_kses_allowed_html( $allowedtags, $context ) {
337
		if ( ! isset( $allowedtags['span'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
338
			$allowedtags['span'] = array();
339
		}
340
341
		$allowedtags['span']['data-price-AUD'] = true;
342
		$allowedtags['span']['data-price-BRL'] = true;
343
		$allowedtags['span']['data-price-GBP'] = true;
344
		$allowedtags['span']['data-price-BWP'] = true;
345
		$allowedtags['span']['data-price-CAD'] = true;
346
		$allowedtags['span']['data-price-CNY'] = true;
347
		$allowedtags['span']['data-price-EUR'] = true;
348
		$allowedtags['span']['data-price-HKD'] = true;
349
		$allowedtags['span']['data-price-INR'] = true;
350
		$allowedtags['span']['data-price-IDR'] = true;
351
		$allowedtags['span']['data-price-ILS'] = true;
352
		$allowedtags['span']['data-price-JPY'] = true;
353
		$allowedtags['span']['data-price-KES'] = true;
354
		$allowedtags['span']['data-price-LAK'] = true;
355
		$allowedtags['span']['data-price-MWK'] = true;
356
		$allowedtags['span']['data-price-MYR'] = true;
357
		$allowedtags['span']['data-price-MZN'] = true;
358
		$allowedtags['span']['data-price-NAD'] = true;
359
		$allowedtags['span']['data-price-NZD'] = true;
360
		$allowedtags['span']['data-price-NOK'] = true;
361
		$allowedtags['span']['data-price-RUB'] = true;
362
		$allowedtags['span']['data-price-SGD'] = true;
363
		$allowedtags['span']['data-price-ZAR'] = true;
364
		$allowedtags['span']['data-price-SEK'] = true;
365
		$allowedtags['span']['data-price-CHF'] = true;
366
		$allowedtags['span']['data-price-TZS'] = true;
367
		$allowedtags['span']['data-price-USD'] = true;
368
		$allowedtags['span']['data-price-AED'] = true;
369
		$allowedtags['span']['data-price-ZMW'] = true;
370
		$allowedtags['span']['data-price-ZWL'] = true;
371
372
		return $allowedtags;
373
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
374
375
	/**
376
	 * Allow empty prices if the convert to single currency is active.
377
	 *
378
	 * @param null $metadata
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $metadata is correct as it would always require null to be passed?
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 4 spaces after parameter type; 1 found
Loading history...
379
	 * @param string $object_id
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
380
	 * @param string $meta_key
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
381
	 * @param boolean $single
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
382
	 * @return void
0 ignored issues
show
Coding Style introduced by
Function return type is void, but function contains return statement
Loading history...
383
	 */
384
	public function filter_post_meta( $metadata = null, $object_id, $meta_key, $single ) {
385
		if ( true === lsx_currencies()->convert_to_single && 'price' === $meta_key ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
386
			$meta_cache = wp_cache_get( $object_id, 'post_meta' );
387
388
			if ( ! isset( $meta_cache[ $meta_key ] ) || '' === $meta_cache[ $meta_key ] ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
389
				$metadata = '0';
390
			}
391
		}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
392
		return $metadata;
393
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
394
}
395