array( 'normal', 'hover' ), * 'background' => array( 'normal', 'hover' ), * 'border_radius', * 'padding' *) */ public static function get_default_settings() { return array( 'primary' => array( 'color' => array( 'normal' => '#ffffff', 'hover' => '#ffffff', ), 'background' => array( 'normal' => 'var(--palette_1)', 'hover' => 'var(--palette_3)', ), 'border_width' => array( 'unit' => 'px', 'min' => 0, 'max' => 10, 'value' => 0, ), 'border_color' => array( 'normal' => 'var(--palette_1)', 'hover' => 'var(--palette_3)', ), 'border_radius' => array( 'unit' => 'px', 'min' => 0, 'max' => 100, 'value' => 12, ), 'padding' => array( 'unit' => 'px', 'top' => 10, 'bottom' => 10, 'left' => 24, 'right' => 24, ), 'typography' => TypographyService::get_default_typography_value( array( 'font_style' => array( 'desktop' => array( 'weight' => 500, 'italic' => false, ), ), 'line_height' => array( 'desktop' => array( 'unit' => 'px', 'value' => 20, 'min' => 0, 'max' => 100, ), 'tablet' => null, 'mobile' => null, ), ) ), ), 'secondary' => array( 'color' => array( 'normal' => 'var(--palette_3)', 'hover' => '#ffffff', ), 'background' => array( 'normal' => '#ffffff', 'hover' => 'var(--palette_3)', ), 'border_width' => array( 'unit' => 'px', 'min' => 0, 'max' => 10, 'value' => 2, ), 'border_color' => array( 'normal' => 'var(--palette_3)', 'hover' => 'var(--palette_3)', ), 'border_radius' => array( 'unit' => 'px', 'min' => 0, 'max' => 100, 'value' => 12, ), 'padding' => array( 'unit' => 'px', 'top' => 10, 'bottom' => 10, 'left' => 24, 'right' => 24, ), 'typography' => TypographyService::get_default_typography_value( array( 'font_style' => array( 'desktop' => array( 'weight' => 500, 'italic' => false, ), ), 'line_height' => array( 'desktop' => array( 'unit' => 'px', 'value' => 20, 'min' => 0, 'max' => 100, ), 'tablet' => null, 'mobile' => null, ), ) ), ), ); } /** * Print out global css */ public static function print_css() { $settings = self::get_settings(); $css = ''; $variables = array(); foreach ( array( 'primary', 'secondary' ) as $key ) { $variables = array_merge( array( "--button-$key-color-normal:" . $settings[ $key ]['color']['normal'], "--button-$key-color-hover:" . $settings[ $key ]['color']['hover'], "--button-$key-background-normal:" . $settings[ $key ]['background']['normal'], "--button-$key-background-hover:" . $settings[ $key ]['background']['hover'], "--button-$key-border-color-normal:" . $settings[ $key ]['border_color']['normal'], "--button-$key-border-color-hover:" . $settings[ $key ]['border_color']['hover'], "--button-$key-border-radius:" . StylesDataHelpers::get_dimension_css( $settings[ $key ]['border_radius'] ), "--button-$key-border-width:" . StylesDataHelpers::get_dimension_css( $settings[ $key ]['border_width'] ), "--button-$key-padding:" . StylesDataHelpers::get_spacing_css( $settings[ $key ]['padding'] ), ), StylesDataHelpers::get_directions_spacing_css_variables( "--button-$key-padding", $settings[ $key ]['padding'] ), $variables ); } $css .= 'html{' . implode( ';', $variables ) . '}'; foreach ( array( 'primary', 'secondary' ) as $key ) { $variables = StylesDataHelpers::get_typography_css_variables( $settings[ $key ]['typography'], "--button-$key" ); foreach ( $variables as $device => $device_variables ) { $child_css = 'html{' . implode( ';', $device_variables ) . '}'; 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(); $button_settings = get_theme_mod( self::get_option_key(), $default_settings ); $button_settings = Helpers::recursive_wp_parse_args( $button_settings, $default_settings ); foreach ( array_keys( $button_settings ) as $key ) { if ( ! key_exists( $key, $default_settings ) ) { unset( $button_settings[ $key ] ); } } return $button_settings; } public static function save_settings( $data ) { $default_settings = self::get_default_settings(); $button_settings = Helpers::recursive_wp_parse_args( $data, $default_settings ); foreach ( array_keys( $button_settings ) as $key ) { if ( ! key_exists( $key, $default_settings ) ) { unset( $button_settings[ $key ] ); } } set_theme_mod( self::get_option_key(), $button_settings ); } /** * Returns background color object * * @return array * @example Returns object with these value * array( * 'normal' => string, * 'hover' => string, *) */ public static function get_primary_background_color() { $settings = self::get_settings(); return $settings['primary']['background']; } /** * Returns text color object * * @return array * @example Returns object with these value * array( * 'normal' => string, * 'hover' => string, *) */ public static function get_primary_text_color() { $settings = self::get_settings(); return $settings['primary']['color']; } /** * Returns border radius object * * @return array * @example Returns object with these value * array( * 'unit' => string, * 'value' => number * ) */ public static function get_primary_border_radius() { $settings = self::get_settings(); return $settings['primary']['border_radius']; } /** * Returns padding object * * @return array * @example Returns object with these value * array( * 'top' => number, * 'left' => number * 'bottom' => number * 'right' => number * ) */ public static function get_primary_padding() { $settings = self::get_settings(); return $settings['primary']['padding']; } /** * Returns background color object * * @return array * @example Returns object with these value * array( * 'normal' => string, * 'hover' => string, *) */ public static function get_secondary_background_color() { $settings = self::get_settings(); return $settings['secondary']['background']; } /** * Returns text color object * * @return array * @example Returns object with these value * array( * 'normal' => string, * 'hover' => string, *) */ public static function get_secondary_text_color() { $settings = self::get_settings(); return $settings['secondary']['color']; } /** * Returns border radius object * * @return array * @example Returns object with these value * array( * 'unit' => string, * 'value' => number * ) */ public static function get_secondary_border_radius() { $settings = self::get_settings(); return $settings['secondary']['border_radius']; } /** * Returns padding object * * @return array * @example Returns object with these value * array( * 'top' => number, * 'left' => number * 'bottom' => number * 'right' => number * ) */ public static function get_secondary_padding() { $settings = self::get_settings(); return $settings['secondary']['padding']; } }