PluginProbe
Customify / 2.10.2
Customify v2.10.2
2.10.9 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.7.1 1.3.0 1.3.1 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.6.0 1.6.0.1 1.6.5 1.7.0 1.7.1 All 77 releases
customify / includes / filter-functions.php

filter-functions.php in Customify 2.10.2, at includes/filter-functions.php

226 lines 4.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Functions that can be used in the Customify config for filtering values.
4 *
5 * Think modifying colors, etc.
6 */
7
8 if ( ! function_exists( 'pixcloud_adjust_color_brightness' ) ) {
9 /**
10 * Adjust a hex color brightness
11 * Allows us to create hover styles for custom link colors
12 *
13 * Taken from the Storefront theme by Automattic: https://github.com/woocommerce/storefront
14 *
15 * @param string $hex hex color e.g. #111111.
16 * @param integer $steps factor by which to brighten/darken ranging from -255 (darken) to 255 (brighten).
17 *
18 * @return string brightened/darkened hex color
19 */
20 function pixcloud_adjust_color_brightness( $hex, $steps ) {
21 // Steps should be between -255 and 255. Negative = darker, positive = lighter.
22 $steps = max( - 255, min( 255, $steps ) );
23
24 // Format the hex color string.
25 $hex = str_replace( '#', '', $hex );
26
27 if ( 3 == strlen( $hex ) ) {
28 $hex = str_repeat( substr( $hex, 0, 1 ), 2 ) . str_repeat( substr( $hex, 1, 1 ), 2 ) . str_repeat( substr( $hex, 2, 1 ), 2 );
29 }
30
31 // Get decimal values.
32 $r = hexdec( substr( $hex, 0, 2 ) );
33 $g = hexdec( substr( $hex, 2, 2 ) );
34 $b = hexdec( substr( $hex, 4, 2 ) );
35
36 // Adjust number of steps and keep it inside 0 to 255.
37 $r = max( 0, min( 255, $r + $steps ) );
38 $g = max( 0, min( 255, $g + $steps ) );
39 $b = max( 0, min( 255, $b + $steps ) );
40
41 $r_hex = str_pad( dechex( $r ), 2, '0', STR_PAD_LEFT );
42 $g_hex = str_pad( dechex( $g ), 2, '0', STR_PAD_LEFT );
43 $b_hex = str_pad( dechex( $b ), 2, '0', STR_PAD_LEFT );
44
45 return '#' . $r_hex . $g_hex . $b_hex;
46 }
47 }
48
49 if ( ! function_exists( 'pixcloud_negate' ) ) {
50 /**
51 * Negate the value.
52 *
53 * @param int|float $value
54 *
55 * @return int|float
56 */
57 function pixcloud_negate( $value ) {
58 if ( ! is_numeric( $value ) ) {
59 return $value;
60 }
61
62 return - $value;
63 }
64 }
65
66 if ( ! function_exists( 'pixcloud_min' ) ) {
67 /**
68 * Ensure that value is at least the $min value.
69 *
70 * @param int|float $value
71 * @param int|float $min
72 *
73 * @return int|float
74 */
75 function pixcloud_min( $value, $min ) {
76 if ( ! is_numeric( $value ) || ! is_numeric( $min ) ) {
77 return $value;
78 }
79
80 if ( $value < $min ) {
81 return $min;
82 }
83
84 return $value;
85 }
86 }
87
88 if ( ! function_exists( 'pixcloud_max' ) ) {
89 /**
90 * Ensure that value is at most the $max value.
91 *
92 * @param int|float $value
93 * @param int|float $max
94 *
95 * @return int|float
96 */
97 function pixcloud_max( $value, $max ) {
98 if ( ! is_numeric( $value ) || ! is_numeric( $max ) ) {
99 return $value;
100 }
101
102 if ( $value > $max ) {
103 return $max;
104 }
105
106 return $value;
107 }
108 }
109
110 if ( ! function_exists( 'pixcloud_min_max' ) ) {
111 /**
112 * Ensure that value is between $min and $max.
113 *
114 * @param int|float $value
115 * @param int|float $min
116 * @param int|float $max
117 *
118 * @return int|float
119 */
120 function pixcloud_min_max( $value, $min, $max ) {
121 if ( ! is_numeric( $value ) || ! is_numeric( $min ) || ! is_numeric( $max ) ) {
122 return $value;
123 }
124
125 if ( $value < $min ) {
126 $value = $min;
127 }
128
129 if ( $value > $max ) {
130 $value = $max;
131 }
132
133 return $value;
134 }
135 }
136
137 if ( ! function_exists( 'pixcloud_add' ) ) {
138 /**
139 * Add something to the value.
140 *
141 * @param int|float $value
142 * @param int|float $add
143 *
144 * @return int|float
145 */
146 function pixcloud_add( $value, $add ) {
147 if ( ! is_numeric( $value ) || ! is_numeric( $add ) ) {
148 return $value;
149 }
150
151 return $value + $add;
152 }
153 }
154
155 if ( ! function_exists( 'pixcloud_substract' ) ) {
156 /**
157 * Substract something from the value.
158 *
159 * @param int|float $value
160 * @param int|float $substract
161 *
162 * @return int|float
163 */
164 function pixcloud_substract( $value, $substract ) {
165 if ( ! is_numeric( $value ) || ! is_numeric( $substract ) ) {
166 return $value;
167 }
168
169 return $value - $substract;
170 }
171 }
172
173 if ( ! function_exists( 'pixcloud_multiply' ) ) {
174 /**
175 * Multiply the value.
176 *
177 * @param int|float $value
178 * @param int|float $multiply
179 *
180 * @return int|float
181 */
182 function pixcloud_multiply( $value, $multiply ) {
183 if ( ! is_numeric( $value ) || ! is_numeric( $multiply ) ) {
184 return $value;
185 }
186
187 return $value * $multiply;
188 }
189 }
190
191 if ( ! function_exists( 'pixcloud_divide' ) ) {
192 /**
193 * Divide the value.
194 *
195 * @param int|float $value
196 * @param int|float $divide
197 *
198 * @return int|float
199 */
200 function pixcloud_divide( $value, $divide ) {
201 if ( ! is_numeric( $value ) || ! is_numeric( $divide ) || empty( $divide ) ) {
202 return $value;
203 }
204
205 return $value / $divide;
206 }
207 }
208
209 if ( ! function_exists( 'pixcloud_modulo' ) ) {
210 /**
211 * Divide the value and get the remainder.
212 *
213 * @param int|float $value
214 * @param int|float $divide
215 *
216 * @return int|float
217 */
218 function pixcloud_modulo( $value, $divide ) {
219 if ( ! is_numeric( $value ) || ! is_numeric( $divide ) || empty( $divide ) ) {
220 return $value;
221 }
222
223 return $value % $divide;
224 }
225 }
226