| @@ -5,8 +5,9 @@ | ||
| 5 | 5 | exit; |
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | use ABlocks\Classes\ControlBaseAbstract; |
| 9 | +use ABlocks\Controls\Color; | |
| 9 | 10 | |
| 10 | 11 | class Border extends ControlBaseAbstract { |
| 11 | 12 | public static function get_attribute_default_value( $is_responsive = false ) { |
| 12 | 13 | |
| @@ -176,9 +177,9 @@ | ||
| 176 | 177 | ] |
| 177 | 178 | ]; |
| 178 | 179 | } |
| 179 | 180 | public static function get_css( $attribute_value, $property = '', $device = '' ) { |
| 180 | - $value = wp_parse_args( $attribute_value, self::get_attribute_default_value( true ) ); | |
| 181 | + $value = wp_parse_args( $attribute_value, self::responsive_defaults() ); | |
| 181 | 182 | $css = []; |
| 182 | 183 | |
| 183 | 184 | // Separate handling of width units |
| 184 | 185 | if ( $device ) { |
| @@ -190,30 +191,44 @@ | ||
| 190 | 191 | } else { |
| 191 | 192 | $widthUnit = $value['unitWidth']; |
| 192 | 193 | } |
| 193 | 194 | |
| 194 | - // Handle width | |
| 195 | - if ( $value[ 'isLinkedWidth' . $device ] ) { | |
| 196 | - if ( '' !== $value[ 'commonWidth' . $device ] ) { | |
| 197 | - $css['border-width'] = $value[ 'commonWidth' . $device ] . $widthUnit; | |
| 195 | + // Handle width. Read every device-suffixed member through device_member(): | |
| 196 | + // a custom breakpoint (or the generator's value-less probe suffix) has no | |
| 197 | + // key of its own in the control's defaults, and indexing it directly is | |
| 198 | + // what produced "Undefined array key …" notices on every page. | |
| 199 | + if ( self::device_member( $value, 'isLinkedWidth', $device ) ) { | |
| 200 | + $commonWidth = self::device_member( $value, 'commonWidth', $device ); | |
| 201 | + if ( '' !== $commonWidth ) { | |
| 202 | + $css['border-width'] = $commonWidth . $widthUnit; | |
| 198 | 203 | } |
| 199 | 204 | } else { |
| 200 | - $topWidth = ! empty( $value[ 'topWidth' . $device ] ) ? $value[ 'topWidth' . $device ] : 0; | |
| 201 | - $rightWidth = ! empty( $value[ 'rightWidth' . $device ] ) ? $value[ 'rightWidth' . $device ] : 0; | |
| 202 | - $bottomWidth = ! empty( $value[ 'bottomWidth' . $device ] ) ? $value[ 'bottomWidth' . $device ] : 0; | |
| 203 | - $leftWidth = ! empty( $value[ 'leftWidth' . $device ] ) ? $value[ 'leftWidth' . $device ] : 0; | |
| 205 | + $topWidth = self::device_member( $value, 'topWidth', $device ); | |
| 206 | + $rightWidth = self::device_member( $value, 'rightWidth', $device ); | |
| 207 | + $bottomWidth = self::device_member( $value, 'bottomWidth', $device ); | |
| 208 | + $leftWidth = self::device_member( $value, 'leftWidth', $device ); | |
| 204 | 209 | |
| 205 | - $borderWidth = $topWidth . $widthUnit . ' ' . $rightWidth . $widthUnit . ' ' . $bottomWidth . $widthUnit . ' ' . $leftWidth . $widthUnit; | |
| 210 | + // Only emit border-width when at least one side was actually set — | |
| 211 | + // otherwise every unlinked border produced "border-width:0px 0px 0px 0px". | |
| 212 | + $has_width = '' !== $topWidth || '' !== $rightWidth || '' !== $bottomWidth || '' !== $leftWidth; | |
| 213 | + if ( $has_width ) { | |
| 214 | + $topWidth = ! empty( $topWidth ) ? $topWidth : 0; | |
| 215 | + $rightWidth = ! empty( $rightWidth ) ? $rightWidth : 0; | |
| 216 | + $bottomWidth = ! empty( $bottomWidth ) ? $bottomWidth : 0; | |
| 217 | + $leftWidth = ! empty( $leftWidth ) ? $leftWidth : 0; | |
| 206 | 218 | |
| 207 | - $css['border-width'] = $borderWidth; | |
| 208 | - } | |
| 219 | + $borderWidth = $topWidth . $widthUnit . ' ' . $rightWidth . $widthUnit . ' ' . $bottomWidth . $widthUnit . ' ' . $leftWidth . $widthUnit; | |
| 209 | 220 | |
| 221 | + $css['border-width'] = $borderWidth; | |
| 222 | + } | |
| 223 | + }//end if | |
| 224 | + | |
| 210 | 225 | // Handle border style and color |
| 211 | 226 | if ( '' !== $value['borderStyle'] && 'default' !== $value['borderStyle'] ) { |
| 212 | 227 | $css['border-style'] = $value['borderStyle']; |
| 213 | 228 | } |
| 214 | 229 | if ( '' !== $value['borderColor'] ) { |
| 215 | - $css['border-color'] = $value['borderColor']; | |
| 230 | + $css['border-color'] = Color::get_css( $value['borderColor'] ); | |
| 216 | 231 | } |
| 217 | 232 | |
| 218 | 233 | // Separate handling of radius units |
| 219 | 234 | if ( $device ) { |
| @@ -226,25 +241,26 @@ | ||
| 226 | 241 | $radiusUnit = $value['unitRadius']; |
| 227 | 242 | } |
| 228 | 243 | |
| 229 | 244 | // Handle radius |
| 230 | - if ( $value[ 'isLinkedRadius' . $device ] ) { | |
| 231 | - if ( '' !== $value[ 'commonRadius' . $device ] ) { | |
| 232 | - $css['border-radius'] = $value[ 'commonRadius' . $device ] . $radiusUnit; | |
| 245 | + if ( self::device_member( $value, 'isLinkedRadius', $device ) ) { | |
| 246 | + $commonRadius = self::device_member( $value, 'commonRadius', $device ); | |
| 247 | + if ( '' !== $commonRadius ) { | |
| 248 | + $css['border-radius'] = $commonRadius . $radiusUnit; | |
| 233 | 249 | } |
| 234 | 250 | } else { |
| 235 | - if ( '' !== $value[ 'topRadius' . $device ] ) { | |
| 236 | - $css['border-top-left-radius'] = $value[ 'topRadius' . $device ] . $radiusUnit; | |
| 251 | + $corners = [ | |
| 252 | + 'topRadius' => 'border-top-left-radius', | |
| 253 | + 'rightRadius' => 'border-top-right-radius', | |
| 254 | + 'bottomRadius' => 'border-bottom-right-radius', | |
| 255 | + 'leftRadius' => 'border-bottom-left-radius', | |
| 256 | + ]; | |
| 257 | + foreach ( $corners as $member => $property_name ) { | |
| 258 | + $corner = self::device_member( $value, $member, $device ); | |
| 259 | + if ( '' !== $corner ) { | |
| 260 | + $css[ $property_name ] = $corner . $radiusUnit; | |
| 261 | + } | |
| 237 | 262 | } |
| 238 | - if ( '' !== $value[ 'rightRadius' . $device ] ) { | |
| 239 | - $css['border-top-right-radius'] = $value[ 'rightRadius' . $device ] . $radiusUnit; | |
| 240 | - } | |
| 241 | - if ( '' !== $value[ 'bottomRadius' . $device ] ) { | |
| 242 | - $css['border-bottom-right-radius'] = $value[ 'bottomRadius' . $device ] . $radiusUnit; | |
| 243 | - } | |
| 244 | - if ( '' !== $value[ 'leftRadius' . $device ] ) { | |
| 245 | - $css['border-bottom-left-radius'] = $value[ 'leftRadius' . $device ] . $radiusUnit; | |
| 246 | - } | |
| 247 | 263 | } |
| 248 | 264 | |
| 249 | 265 | // Handle transition duration |
| 250 | 266 | if ( self::has_value( $value['transitionDuration'] ) ) { |
| @@ -267,10 +283,11 @@ | ||
| 267 | 283 | |
| 268 | 284 | if ( ! empty( $value['borderStyleH'] ) && 'default' !== $value['borderStyleH'] ) { |
| 269 | 285 | // Handle hover width |
| 270 | 286 | if ( ! empty( $value[ 'isLinkedWidthH' . $device ] ) ) { |
| 271 | - if ( '' !== $value[ 'commonWidthH' . $device ] ) { | |
| 272 | - $css['border-width'] = $value[ 'commonWidthH' . $device ] . $widthUnit; | |
| 287 | + $commonWidthH = self::device_member( $value, 'commonWidthH', $device ); | |
| 288 | + if ( '' !== $commonWidthH ) { | |
| 289 | + $css['border-width'] = $commonWidthH . $widthUnit; | |
| 273 | 290 | } |
| 274 | 291 | } else { |
| 275 | 292 | $topWidth = ! empty( $value[ 'topWidthH' . $device ] ) ? $value[ 'topWidthH' . $device ] : 0; |
| 276 | 293 | $rightWidth = ! empty( $value[ 'rightWidthH' . $device ] ) ? $value[ 'rightWidthH' . $device ] : 0; |
| @@ -281,11 +298,11 @@ | ||
| 281 | 298 | } |
| 282 | 299 | |
| 283 | 300 | // Handle hover border color |
| 284 | 301 | if ( ! empty( $value['borderColorH'] ) ) { |
| 285 | - $css['border-color'] = $value['borderColorH']; | |
| 302 | + $css['border-color'] = Color::get_css( $value['borderColorH'] ); | |
| 286 | 303 | } |
| 287 | - } | |
| 304 | + }//end if | |
| 288 | 305 | |
| 289 | 306 | // Handle hover border style |
| 290 | 307 | if ( ! empty( $value['borderStyleH'] ) && 'default' !== $value['borderStyleH'] ) { |
| 291 | 308 | $css['border-style'] = $value['borderStyleH']; |