-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcolor-scheme.php
More file actions
156 lines (136 loc) · 5.22 KB
/
color-scheme.php
File metadata and controls
156 lines (136 loc) · 5.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
// https://deluxeblogtips.com/add-color-schemes-wordpress-theme/
class slow_atoms_Color_Scheme {
public function __construct() {
add_action( 'customize_register', array( $this, 'customizer_register' ) );
add_action( 'customize_controls_enqueue_scripts', array( $this, 'customize_js' ) );
add_action( 'customize_controls_print_footer_scripts', array( $this, 'color_scheme_template' ) );
// TODO: do we need this add_action( 'customize_preview_init', array( $this, 'customize_preview_js' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'output_css' ) );
}
public function customizer_register( WP_Customize_Manager $wp_customize ) {}
public function customize_js() {
wp_enqueue_script( 'slow-atoms-color-scheme', get_template_directory_uri() . '/inc/js/color-scheme.js', array( 'customize-controls', 'iris', 'underscore', 'wp-util' ), '', true );
wp_localize_script( 'slow-atoms-color-scheme', 'SlowAtomsColorScheme', $this->get_color_schemes() );
}
public function color_scheme_template() {
$colors = array(
'slow_atoms_primary_theme_color' => '{{ data.slow_atoms_primary_theme_color }}',
'slow_atoms_secondary_theme_color' => '{{ data.slow_atoms_secondary_theme_color }}',
'slow_atoms_navbar_link_color' => '{{ data.slow_atoms_navbar_link_color }}',
'slow_atoms_accent_color' => '{{ data.slow_atoms_accent_color }}',
'footer_bg_color' => '{{ data.footer_bg_color }}',
'highlight_color' => '{{ data.highlight_color }}',
);
?>
<script type="text/html" id="tmpl-slow-atoms-color-scheme">
<?php echo $this->get_css( $colors ); ?>
</script>
<?php
}
public function customize_preview_js() {
// TODO: do we need this wp_enqueue_script( 'slow-atoms-color-scheme-preview', get_template_directory_uri() . '/inc/js/color-scheme-preview.js', array( 'customize-preview' ), '', true );
}
public function output_css() {
$colors = $this->get_color_scheme();
if ( $this->is_custom ) {
wp_add_inline_style( 'slow-atoms-style', $this->get_css( $colors ) );
}
}
public $options = array(
'slow_atoms_primary_theme_color',
'slow_atoms_secondary_theme_color',
'slow_atoms_navbar_link_color',
'slow_atoms_accent_color',
'footer_bg_color',
'highlight_color',
);
public function get_color_schemes() {
return array(
'default' => array(
'label' => __( 'Classic', 'slow_atoms' ),
'colors' => array(
'#333342',
'#003882',
'#ffffff',
'#ff00ee',
'#222b30',
'#e67e22',
),
),
'green' => array(
'label' => __( 'Green', 'slow_atoms' ),
'colors' => array(
'#334c32',
'#845a50',
'#ffffff',
'#22e500',
'#9d5f00',
'#dd8500',
),
),
'orange' => array(
'label' => __( 'Orange', 'slow_atoms' ),
'colors' => array(
'#dd8500',
'#845a50',
'#ffffff',
'#890024',
'#9d5f00',
'#dd8500',
),
),
'red' => array(
'label' => __( 'Red', 'slow_atoms' ),
'colors' => array(
'#7f2a2a',
'#000033',
'#ffffff',
'#ff0044',
'#9d5f00',
'#dd8500',
),
),
// Other color schemes
);
}
public $is_custom = false;
public function get_color_scheme() {
$color_schemes = $this->get_color_schemes();
$color_scheme = get_theme_mod( 'color_scheme' );
$color_scheme = isset( $color_schemes[$color_scheme] ) ? $color_scheme : 'default';
if ( 'default' != $color_scheme ) {
$this->is_custom = true;
}
$colors = array_map( 'strtolower', $color_schemes[$color_scheme]['colors'] );
foreach ( $this->options as $k => $option ) {
$color = get_theme_mod( $option );
if ( $color && strtolower( $color ) != $colors[$k] ) {
$colors[$k] = $color;
$this->is_custom = true;
}
}
return $colors;
// var_dump($colors);
}
public function get_css( $colors ) {
$css = "
a { color: %1\$s}
button, input[type=submit], .button {
background: %2\$s;
}
.section h2 span,
.number {
color: %6\$s;
}
.section--dark,
.services-1 {
background-color: %4\$s;
}
.footer {
background: %5\$s;
}";
// More CSS
return vsprintf( $css, $colors );
}
}