forked from m-e-h/material-gaze
/
functions.php
116 lines (104 loc) · 4.48 KB
/
functions.php
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
<?php
/**
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU
* General Public License as published by the Free Software Foundation; either version 2 of the License,
* or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU General Public License along with this program; if not, write
* to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/* Add the child theme setup function to the 'after_setup_theme' hook. */
add_action( 'after_setup_theme', 'material_gaze_theme_setup' );
/**
* Setup function. All child themes should run their setup within this function. The idea is to add/remove
* filters and actions after the parent theme has been set up. This function provides you that opportunity.
*
* @since 1.0.0
* @access public
* @return void
*/
function material_gaze_theme_setup() {
/* Add a custom background to overwrite the defaults. */
add_theme_support(
'custom-background',
array(
'default-color' => 'eeeeee',
'default-image' => '',
)
);
/* Add a custom header to overwrite the defaults. */
add_theme_support(
'custom-header',
array(
'default-text-color' => 'ffffff',
'default-image' => '%2$s/images/headers/blue.jpg',
'random-default' => false,
'wp-head-callback' => 'material_gaze_custom_header_wp_head',
)
);
/* Register default headers. */
register_default_headers(
array(
'blue' => array(
'url' => '%2$s/images/headers/blue.jpg',
'thumbnail_url' => '%2$s/images/headers/blue-thumb.jpg',
'description' => __( 'default', 'material-gaze' )
),
'red' => array(
'url' => '%2$s/images/headers/red.jpg',
'thumbnail_url' => '%2$s/images/headers/red-thumb.jpg',
'description' => __( 'red', 'material-gaze' )
),
)
);
/* Custom editor stylesheet. */
add_editor_style( '//fonts.googleapis.com/css?family=Roboto:400,300,300italic,400italic,500,700|Roboto+Condensed:400,300,700' );
/* Filter to add custom default backgrounds (supported by the framework). */
add_filter( 'hybrid_default_backgrounds', 'material_gaze_default_backgrounds' );
/* Add a custom default color for the "primary" color option. */
add_filter( 'theme_mod_color_primary', 'material_gaze_color_primary' );
/* Load stylesheets. */
add_action( 'wp_enqueue_scripts', 'material_gaze_enqueue_styles', 0 );
}
/**
* Add a default custom color for the theme's "primary" color option.
*
* @since 1.0.0
* @access public
* @param string $hex
* @return string
*/
function material_gaze_color_primary( $hex ) {
return $hex ? $hex : '2196F3';
}
function material_gaze_enqueue_styles() {
wp_enqueue_style( 'material-gaze-fonts', '//fonts.googleapis.com/css?family=Roboto:400,300,300italic,400italic,500,700|Roboto+Condensed:400,300,700' );
}
add_action( 'wp_head', 'material_gaze_wp_head' );
function material_gaze_wp_head() {
$style = '';
$hex = get_theme_mod( 'color_primary', '' );
$style .= "#menu-primary .search-form .search-toggle, .display-header-text #header { background: #{$hex}; } ";
$style .= "input[type='date']:focus, input[type='datetime']:focus, input[type='datetime-local']:focus, input[type='email']:focus, input[type='month']:focus, input[type='number']:focus, input[type='password']:focus, input[type='search']:focus, input[type='tel']:focus, input[type='text']:focus, input[type='time']:focus, input[type='url']:focus, input[type='week']:focus,
textarea:focus, select:focus { border-bottom-color: #{$hex}; box-shadow: 0 1px 0 0 #{$hex}; } ";
echo "\n" . '<style type="text/css">' . trim( $style ) . '</style>' . "\n";
}
function material_gaze_custom_header_wp_head() {
if ( !display_header_text() )
return;
$hex = get_header_textcolor();
if ( empty( $hex ) )
return;
$style = "body.custom-header #branding, #site-title { color: #{$hex}; }";
echo "\n" . '<style type="text/css" id="custom-header-css">' . trim( $style ) . '</style>' . "\n";
}
/**
* Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
*/
function material_gaze_customize_preview_js() {
wp_enqueue_script( 'material_gaze_customizer', trailingslashit( CHILD_THEME_URI ) . 'js/customizer.js', array( 'customize-preview' ), '20130508', true );
}
add_action( 'customize_preview_init', 'material_gaze_customize_preview_js' );