lightspeeddevelopment /
lsx-customizer
| 1 | <?php |
||
| 2 | if ( ! class_exists( 'LSX_Customizer_Colour_Button_CTA' ) ) { |
||
| 3 | |||
| 4 | /** |
||
| 5 | * LSX Customizer Colour Button CTA Class |
||
| 6 | * |
||
| 7 | * @package LSX Customizer |
||
| 8 | * @author LightSpeed |
||
| 9 | * @license GPL3 |
||
| 10 | * @link |
||
| 11 | * @copyright 2016 LightSpeed |
||
| 12 | */ |
||
| 13 | class LSX_Customizer_Colour_Button_CTA extends LSX_Customizer_Colour { |
||
| 14 | |||
| 15 | /** |
||
| 16 | * Constructor. |
||
| 17 | * |
||
| 18 | * @since 1.0.0 |
||
| 19 | */ |
||
| 20 | public function __construct() { |
||
| 21 | add_action( 'after_switch_theme', array( $this, 'set_theme_mod' ) ); |
||
| 22 | add_action( 'customize_save_after', array( $this, 'set_theme_mod' ) ); |
||
| 23 | |||
| 24 | add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_css' ), 2999 ); |
||
| 25 | } |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Assign CSS to theme mod. |
||
| 29 | * |
||
| 30 | * @since 1.0.0 |
||
| 31 | */ |
||
| 32 | public function set_theme_mod() { |
||
| 33 | $theme_mods = $this->get_theme_mods(); |
||
| 34 | $styles = $this->get_css( $theme_mods ); |
||
| 35 | |||
| 36 | set_theme_mod( 'lsx_customizer_colour__button_cta_theme_mod', $styles ); |
||
| 37 | } |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Enqueues front-end CSS. |
||
| 41 | * |
||
| 42 | * @since 1.0.0 |
||
| 43 | */ |
||
| 44 | public function enqueue_css() { |
||
| 45 | $styles_from_theme_mod = get_theme_mod( 'lsx_customizer_colour__button_cta_theme_mod' ); |
||
| 46 | |||
| 47 | if ( is_customize_preview() || false === $styles_from_theme_mod ) { |
||
| 48 | $theme_mods = $this->get_theme_mods(); |
||
| 49 | $styles = $this->get_css( $theme_mods ); |
||
| 50 | |||
| 51 | if ( false === $styles_from_theme_mod ) { |
||
| 52 | set_theme_mod( 'lsx_customizer_colour__button_cta_theme_mod', $styles ); |
||
| 53 | } |
||
| 54 | } else { |
||
| 55 | $styles = $styles_from_theme_mod; |
||
| 56 | } |
||
| 57 | |||
| 58 | wp_add_inline_style( 'lsx-customizer', $styles ); |
||
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Get CSS theme mods. |
||
| 63 | * |
||
| 64 | * @since 1.0.0 |
||
| 65 | */ |
||
| 66 | public function get_theme_mods() { |
||
| 67 | $colors = parent::get_color_scheme(); |
||
| 68 | |||
| 69 | return apply_filters( 'lsx_customizer_colours_button_cta', array( |
||
| 70 | 'button_cta_background_color' => get_theme_mod( 'button_cta_background_color', $colors['button_cta_background_color'] ), |
||
| 71 | 'button_cta_background_hover_color' => get_theme_mod( 'button_cta_background_hover_color', $colors['button_cta_background_hover_color'] ), |
||
| 72 | 'button_cta_text_color' => get_theme_mod( 'button_cta_text_color', $colors['button_cta_text_color'] ), |
||
| 73 | 'button_cta_text_color_hover' => get_theme_mod( 'button_cta_text_color_hover', $colors['button_cta_text_color_hover'] ), |
||
| 74 | 'button_cta_shadow' => get_theme_mod( 'button_cta_shadow', $colors['button_cta_shadow'] ), |
||
| 75 | ) ); |
||
| 76 | } |
||
| 77 | |||
| 78 | /** |
||
|
0 ignored issues
–
show
Coding Style
Documentation
introduced
by
Loading history...
|
|||
| 79 | * Returns CSS. |
||
| 80 | * |
||
| 81 | * @since 1.0.0 |
||
| 82 | */ |
||
| 83 | function get_css( $colors ) { |
||
| 84 | global $customizer_colour_names; |
||
| 85 | |||
| 86 | $colors_template = array(); |
||
| 87 | |||
| 88 | foreach ( $customizer_colour_names as $key => $value ) { |
||
| 89 | $colors_template[ $key ] = ''; |
||
| 90 | } |
||
| 91 | |||
| 92 | $colors = wp_parse_args( $colors, $colors_template ); |
||
| 93 | |||
| 94 | if ( empty( $colors['button_cta_text_color'] ) |
||
| 95 | || empty( $colors['button_cta_text_color_hover'] ) |
||
| 96 | || empty( $colors['button_cta_background_color'] ) |
||
| 97 | || empty( $colors['button_cta_background_hover_color'] ) |
||
| 98 | || empty( $colors['button_cta_shadow'] ) ) { |
||
| 99 | return ''; |
||
| 100 | } |
||
| 101 | |||
| 102 | $css = ' |
||
| 103 | @import "' . get_template_directory() . '/assets/css/scss/global/mixins/button"; |
||
| 104 | |||
| 105 | /** |
||
| 106 | * LSX Customizer - Button CTA |
||
| 107 | */ |
||
| 108 | @include custom-cta-buttons-colours ( |
||
| 109 | $color: ' . $colors['button_cta_text_color'] . ', |
||
| 110 | $color-hover: ' . $colors['button_cta_text_color_hover'] . ', |
||
| 111 | $bg: ' . $colors['button_cta_background_color'] . ', |
||
| 112 | $bg-hover: ' . $colors['button_cta_background_hover_color'] . ', |
||
| 113 | $shadow: ' . $colors['button_cta_shadow'] . ' |
||
| 114 | ); |
||
| 115 | '; |
||
| 116 | |||
| 117 | $css = apply_filters( 'lsx_customizer_colour_selectors_button_cta', $css, $colors ); |
||
| 118 | $css = parent::scss_to_css( $css ); |
||
| 119 | |||
| 120 | return $css; |
||
| 121 | } |
||
| 122 | |||
| 123 | } |
||
| 124 | |||
| 125 | } |
||
| 126 |