'borderTopLeftRadius', 'borderRadiusTopRight' => 'borderTopRightRadius', 'borderRadiusBottomRight' => 'borderBottomRightRadius', 'borderRadiusBottomLeft' => 'borderBottomLeftRadius', ]; foreach ( self::$devices as $device ) { foreach ( $border_radius_attributes as $old_attribute_name => $new_attribute_name ) { $setting_name = $old_attribute_name . $device; if ( $settings[ $setting_name ] || is_numeric( $settings[ $setting_name ] ) ) { $unit = is_numeric( $settings[ $setting_name ] ) ? $settings['borderRadiusUnit'] : ''; $settings['borders'][ $new_attribute_name . $device ] = $settings[ $setting_name ] . $unit; } } } $border_width_attributes = [ 'borderSizeTop' => 'borderTopWidth', 'borderSizeRight' => 'borderRightWidth', 'borderSizeBottom' => 'borderBottomWidth', 'borderSizeLeft' => 'borderLeftWidth', ]; foreach ( self::$devices as $device ) { foreach ( $border_width_attributes as $old_attribute_name => $new_attribute_name ) { $setting_name = $old_attribute_name . $device; if ( $settings[ $setting_name ] || is_numeric( $settings[ $setting_name ] ) ) { $unit = is_numeric( $settings[ $setting_name ] ) ? 'px' : ''; $settings['borders'][ $new_attribute_name . $device ] = $settings[ $setting_name ] . $unit; $border_style_name = str_replace( 'Width', 'Style', $new_attribute_name ); $settings['borders'][ $border_style_name . $device ] = 'solid'; if ( ! empty( $settings['borderColor'] ) ) { $border_color_name = str_replace( 'Width', 'Color', $new_attribute_name ); $settings['borders'][ $border_color_name ] = isset( $settings['borderColorOpacity'] ) ? generateblocks_hex2rgba( $settings['borderColor'], $settings['borderColorOpacity'] ) : $settings['borderColor']; } if ( ! empty( $settings['borderColorHover'] ) ) { $border_color_hover_name = str_replace( 'Width', 'ColorHover', $new_attribute_name ); $settings['borders'][ $border_color_hover_name ] = isset( $settings['borderColorHoverOpacity'] ) ? generateblocks_hex2rgba( $settings['borderColorHover'], $settings['borderColorHoverOpacity'] ) : $settings['borderColorHover']; } if ( ! empty( $settings['borderColorCurrent'] ) ) { $border_color_current_name = str_replace( 'Width', 'ColorCurrent', $new_attribute_name ); $settings['borders'][ $border_color_current_name ] = $settings['borderColorCurrent']; } } } } return $settings; } /** * Map our old typography attributes. * * @param array $settings Existing settings. * @return array Mapped spacing settings. */ public static function map_typography( $settings ) { if ( ! empty( $settings['typography'] ) ) { return $settings; } $old_attributes = [ 'fontFamily', 'fontSize', 'lineHeight', 'letterSpacing', 'fontWeight', 'textTransform', 'alignment', ]; foreach ( self::$devices as $device ) { foreach ( $old_attributes as $attribute ) { $setting_name = $attribute . $device; if ( isset( $settings[ $setting_name ] ) && ( $settings[ $setting_name ] || is_numeric( $settings[ $setting_name ] ) ) ) { $unit = ''; switch ( $attribute ) { case 'fontSize': $unit = $settings['fontSizeUnit']; break; case 'lineHeight': $unit = $settings['lineHeightUnit']; break; case 'letterSpacing': $unit = 'em'; break; } // textAlign used to be called "alignment". if ( 'alignment' === $attribute ) { $settings['typography'][ 'textAlign' . $device ] = $settings[ $setting_name ]; continue; } $settings['typography'][ $setting_name ] = $settings[ $setting_name ] . $unit; } } } return $settings; } }