PluginProbe
Kirki – Freeform Page Builder, Website Builder & Customizer / 6.2.5
Kirki – Freeform Page Builder, Website Builder & Customizer v6.2.5
6.3.0 6.2.5 6.2.4 6.2.3 6.2.2 6.2.1 6.2.0 6.1.1 6.1.0 6.0.14 6.0.13 6.0.12 6.0.11 6.0.10 6.0.9 6.0.8 6.0.7 6.0.6 6.0.5 6.0.4 6.0.3 6.0.2 6.0.1 3.1.3 3.1.4 All 56 releases
kirki / customizer / packages / modules / css / src / CSS / Property / Background_Position.php
Background_Position.php
76 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Handles CSS output for background-position.
4 *
5 * @package Kirki
6 * @subpackage Controls
7 * @copyright Copyright (c) 2023, Themeum
8 * @license https://opensource.org/licenses/MIT
9 * @since 2.2.0
10 */
11
12 namespace Kirki\Module\CSS\Property;
13
14 use Kirki\Module\CSS\Property;
15
16 /**
17 * Output overrides.
18 */
19 class Background_Position extends Property {
20
21 /**
22 * Modifies the value.
23 *
24 * @access protected
25 */
26 protected function process_value() {
27 $this->value = trim( $this->value );
28
29 // If you use calc() there, I suppose you know what you're doing.
30 // No need to process this any further, just exit.
31 if ( false !== strpos( $this->value, 'calc' ) ) {
32 return;
33 }
34
35 // If the value is initial or inherit, we don't need to do anything.
36 // Just exit.
37 if ( 'initial' === $this->value || 'inherit' === $this->value ) {
38 return;
39 }
40
41 $x_dimensions = [ 'left', 'center', 'right' ];
42 $y_dimensions = [ 'top', 'center', 'bottom' ];
43
44 // If there's a space, we have an X and a Y value.
45 if ( false !== strpos( $this->value, ' ' ) ) {
46 $xy = explode( ' ', $this->value );
47
48 $x = trim( $xy[0] );
49 $y = trim( $xy[1] );
50
51 // If x is not left/center/right, we need to sanitize it.
52 if ( ! in_array( $x, $x_dimensions, true ) ) {
53 $x = sanitize_text_field( $x );
54 }
55 if ( ! in_array( $y, $y_dimensions, true ) ) {
56 $y = sanitize_text_field( $y );
57 }
58 $this->value = $x . ' ' . $y;
59 return;
60 }
61 $x = 'center';
62 foreach ( $x_dimensions as $x_dimension ) {
63 if ( false !== strpos( $this->value, $x_dimension ) ) {
64 $x = $x_dimension;
65 }
66 }
67 $y = 'center';
68 foreach ( $y_dimensions as $y_dimension ) {
69 if ( false !== strpos( $this->value, $y_dimension ) ) {
70 $y = $y_dimension;
71 }
72 }
73 $this->value = $x . ' ' . $y;
74 }
75 }
76