array( 'normal', 'hover' ), * 'background' => array( 'normal', 'hover' ), * 'border_radius', * 'padding' *) */ public static function get_default_settings() { return array( 'background_color' => array( 'normal' => '#ffffff', 'hover' => '#ffffff', ), 'text_color' => array( 'normal' => 'var(--wp--preset--color--brandy-primary-text)', 'hover' => 'var(--wp--preset--color--brandy-primary-text)', ), 'typography' => TypographyService::get_default_typography_value(), 'border' => array( 'width' => array( 'unit' => 'px', 'value' => 1, 'min' => 0, 'max' => 5, ), 'color' => array( 'normal' => '#ACB6BF', 'hover' => '#7B8A99', 'focus' => '#272829', ), 'radius' => array( 'unit' => 'px', 'value' => 9, 'min' => 0, 'max' => 100, ), ), 'padding' => array( 'unit' => 'px', 'top' => 14, 'right' => 14, 'bottom' => 14, 'left' => 14, 'is_constraints' => true, ), ); } /** * Print out global css */ public static function print_css() { $settings = self::get_settings(); $css = ' :root { --input-border-color-normal: ' . $settings['border']['color']['normal'] . '; --input-border-color-hover: ' . $settings['border']['color']['hover'] . '; --input-border-color-focus: ' . $settings['border']['color']['focus'] . '; --input-border-radius: ' . StylesDataHelpers::get_dimension_css( $settings['border']['radius'] ) . '; } input[type="text"], input[type="tel"], input[type="url"], input[type="email"], input[type="number"], input[type="password"], input[type="search"], textarea { background-color: ' . $settings['background_color']['normal'] . '; color: ' . $settings['text_color']['normal'] . '; width: 100%; border-width: ' . StylesDataHelpers::get_dimension_css( $settings['border']['width'] ) . '; border-color: var(--input-border-color-normal); border-style: solid; border-radius: var(--input-border-radius); outline-width: ' . StylesDataHelpers::get_dimension_css( $settings['border']['width'] ) . '; outline-color: transparent; outline-style: solid; padding: ' . StylesDataHelpers::get_spacing_css( $settings['padding'] ) . '; box-shadow: none; transition-property: outline, border; transition-duration: var(--theme-input-transition-duration); transition-timing-function: ease-in-out; transition-delay: 0s; } input[type="text"]:hover, input[type="tel"]:hover, input[type="url"]:hover, input[type="email"]:hover, input[type="number"]:hover, input[type="password"]:hover, input[type="search"]:hover, textarea:hover { border-color: var(--input-border-color-hover); color: ' . $settings['text_color']['hover'] . '; background-color: ' . $settings['background_color']['hover'] . '; } input[type="text"]:focus, input[type="tel"]:focus, input[type="url"]:focus, input[type="email"]:focus, input[type="number"]:focus, input[type="password"]:focus, input[type="search"]:focus, textarea:focus { outline-color: var(--input-border-color-focus); border-color: transparent; outline-width: calc(' . StylesDataHelpers::get_dimension_css( $settings['border']['width'] ) . ' + 1px); outline-style: solid; color: ' . ( $settings['text_color']['focus'] ?? $settings['text_color']['normal'] ) . '; background-color: ' . ( $settings['background_color']['focus'] ?? $settings['background_color']['normal'] ) . '; } input[type="text"]::placeholder, input[type="tel"]::placeholder, input[type="url"]::placeholder, input[type="email"]::placeholder, input[type="number"]::placeholder, input[type="password"]::placeholder, input[type="search"]::placeholder, textarea::placeholder { color: ' . $settings['text_color']['normal'] . '; opacity: 0.5; } input[type="text"]::-ms-input-placeholder, input[type="tel"]::-ms-input-placeholder, input[type="url"]::-ms-input-placeholder, input[type="email"]::-ms-input-placeholder, input[type="number"]::-ms-input-placeholder, input[type="password"]::-ms-input-placeholder, input[type="search"]::-ms-input-placeholder, textarea::-ms-input-placeholder { color: ' . $settings['text_color']['normal'] . '; } '; $variables = StylesDataHelpers::get_typography_css_variables( $settings['typography'], 'input[type="text"], input[type="tel"], input[type="url"], input[type="email"], input[type="number"], input[type="password"], input[type="search"], textarea' ); foreach ( $variables as $device => $device_variables ) { $child_css = ''; foreach ( $device_variables as $selector => $value ) { $child_css .= $selector . '{' . implode( ';', $value ) . '}'; } if ( 'tablet' === $device ) { $child_css = DynamicCss::wrap_tablet_responsive( $child_css ); } if ( 'mobile' === $device ) { $child_css = DynamicCss::wrap_mobile_responsive( $child_css ); } $css .= $child_css; } echo wp_kses_post( $css ); } /** * Returns settings * * @return array * @example Returns object with these value * array( * 'color' => array( 'normal', 'hover' ), * 'background_color' => array( 'normal', 'hover' ), * 'border_radius', * 'padding' *) */ public static function get_settings() { $default_settings = self::get_default_settings(); $input_settings = get_theme_mod( self::get_option_key(), $default_settings ); $input_settings = Helpers::recursive_wp_parse_args( $input_settings, $default_settings ); foreach ( array_keys( $input_settings ) as $key ) { if ( ! key_exists( $key, $default_settings ) ) { unset( $input_settings[ $key ] ); } } return $input_settings; } public static function save_settings( $data ) { $default_settings = self::get_default_settings(); $input_settings = Helpers::recursive_wp_parse_args( $data, $default_settings ); foreach ( array_keys( $input_settings ) as $key ) { if ( ! key_exists( $key, $default_settings ) ) { unset( $input_settings[ $key ] ); } } set_theme_mod( self::get_option_key(), $input_settings ); } }