1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Handles CSS output for dimensions fields. |
4
|
|
|
* |
5
|
|
|
* @package Kirki |
6
|
|
|
* @subpackage Controls |
7
|
|
|
* @copyright Copyright (c) 2017, Aristeides Stathopoulos |
8
|
|
|
* @license http://opensource.org/licenses/https://opensource.org/licenses/MIT |
9
|
|
|
* @since 2.2.0 |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Output overrides. |
14
|
|
|
*/ |
15
|
|
|
class Kirki_Output_Field_Dimensions extends Kirki_Output { |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Processes a single item from the `output` array. |
19
|
|
|
* |
20
|
|
|
* @access protected |
21
|
|
|
* @param array $output The `output` item. |
22
|
|
|
* @param array $value The field's value. |
23
|
|
|
*/ |
24
|
|
|
protected function process_output( $output, $value ) { |
25
|
|
|
|
26
|
|
|
$output = wp_parse_args( $output, array( |
27
|
|
|
'element' => '', |
28
|
|
|
'property' => '', |
29
|
|
|
'media_query' => 'global', |
30
|
|
|
'prefix' => '', |
31
|
|
|
'suffix' => '', |
32
|
|
|
) ); |
33
|
|
|
|
34
|
|
|
if ( is_array( $value ) ) { |
35
|
|
|
foreach ( $value as $key => $sub_value ) { |
36
|
|
|
|
37
|
|
|
$property = ( empty( $output['property'] ) ) ? $key : $output['property'] . '-' . $key; |
38
|
|
|
if ( isset( $output['choice'] ) && $output['property'] ) { |
39
|
|
|
if ( $key === $output['choice'] ) { |
40
|
|
|
$property = $output['property']; |
41
|
|
|
} else { |
42
|
|
|
continue; |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
if ( false !== strpos( $output['property'], '%%' ) ) { |
46
|
|
|
$property = str_replace( '%%', $key, $output['property'] ); |
47
|
|
|
} |
48
|
|
|
$this->styles[ $output['media_query'] ][ $output['element'] ][ $property ] = $output['prefix'] . $this->process_property_value( $property, $value[ $key ] ) . $output['suffix']; |
49
|
|
|
} |
50
|
|
|
} elseif ( isset( $output['choice'] ) ) { |
51
|
|
|
if ( false !== strpos( $output['property'], '%%' ) ) { |
52
|
|
|
$output['property'] = str_replace( '%%', $key, $output['property'] ); |
|
|
|
|
53
|
|
|
} |
54
|
|
|
$this->styles[ $output['media_query'] ][ $output['element'] ][ $output['property'] ] = $output['prefix'] . $this->process_property_value( $output['property'], $value ) . $output['suffix']; |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
This error can happen if you refactor code and forget to move the variable initialization.
Let’s take a look at a simple example:
The above code is perfectly fine. Now imagine that we re-order the statements:
In that case,
$x
would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.