PluginProbe
Customify / trunk
Customify vtrunk
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 trunk, at includes/filter-functions.php

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