forked from ThematoSoup/Sticky-Header
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sticky-header-settings.php
executable file
·199 lines (186 loc) · 5.02 KB
/
sticky-header-settings.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
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<?php
/**
* Handles Customizer options.
*
* @package Sticky_Header
* @author ThematoSoup <[email protected]>
* @license GPL-2.0+
* @link http://thematosoup.com
* @copyright 2013 ThematoSoup
*/
add_action( 'customize_register', 'thsp_sticky_header_customize_register' );
/**
* Registers all Customizer options.
*
* @since 1.0.0
*/
function thsp_sticky_header_customize_register( $wp_customize ) {
$thsp_plugin_slug = 'thsp-sticky-header';
// Define Number custom control
if ( class_exists( 'WP_Customize_Control') ) :
class Sticky_Header_Number_Control extends WP_Customize_Control {
public $type = 'number';
public function render_content() { ?>
<label>
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
<input class="small-text" type="number" value="<?php echo esc_attr( $this->value() ); ?>" <?php $this->link(); ?> />
</label>
<?php }
}
endif;
$wp_customize->add_section(
'thsp_sticky_header',
array(
'title' => __( 'Sticky Header by ThematoSoup', $thsp_plugin_slug ),
'priority' => 1
)
);
// Upload Sticky Header logo
$wp_customize->add_setting(
'thsp_sticky_header[logo]',
array(
'default' => '',
'sanitize_callback' => 'esc_url_raw',
'type' => 'option',
'capability' => 'edit_theme_options',
)
);
$wp_customize->add_control(
new WP_Customize_Image_Control(
$wp_customize,
'thsp_sticky_header[logo]',
array(
'label' => __( 'Logo (image height should be 30px)', $thsp_plugin_slug ),
'section' => 'thsp_sticky_header',
'settings' => 'thsp_sticky_header[logo]',
)
)
);
// Sticky Header menu
$menus = wp_get_nav_menus();
if ( $menus ) :
$choices = array( 0 => __( '— Select a menu —' ) );
foreach ( $menus as $menu ) :
$choices[ $menu->term_id ] = wp_html_excerpt( $menu->name, 40, '…' );
endforeach;
$wp_customize->add_setting(
'thsp_sticky_header[menu]',
array(
'sanitize_callback' => 'absint',
'theme_supports' => 'menus',
'type' => 'option',
'capability' => 'edit_theme_options',
)
);
$wp_customize->add_control(
'thsp_sticky_header[menu]',
array(
'label' => __( 'Menu', $thsp_plugin_slug ),
'section' => 'thsp_sticky_header',
'type' => 'select',
'choices' => $choices,
)
);
endif;
// Sticky Header background color
$wp_customize->add_setting(
'thsp_sticky_header[background_color]',
array(
'default' => '#181818',
'sanitize_callback' => 'wp_filter_nohtml_kses',
'type' => 'option',
'capability' => 'edit_theme_options',
)
);
$wp_customize->add_control(
new WP_Customize_Color_Control(
$wp_customize,
'thsp_sticky_header[background_color]',
array(
'label' => __( 'Background color', $thsp_plugin_slug ),
'section' => 'thsp_sticky_header',
'settings' => 'thsp_sticky_header[background_color]',
)
)
);
// Sticky Header text color
$wp_customize->add_setting(
'thsp_sticky_header[text_color]',
array(
'default' => '#f9f9f9',
'sanitize_callback' => 'wp_filter_nohtml_kses',
'type' => 'option',
'capability' => 'edit_theme_options',
)
);
$wp_customize->add_control(
new WP_Customize_Color_Control(
$wp_customize,
'thsp_sticky_header[text_color]',
array(
'label' => __( 'Text color', $thsp_plugin_slug ),
'section' => 'thsp_sticky_header',
'settings' => 'thsp_sticky_header[text_color]',
)
)
);
// Sticky Header show at
$wp_customize->add_setting(
'thsp_sticky_header[show_at]',
array(
'default' => '200',
'sanitize_callback' => 'wp_filter_nohtml_kses',
'type' => 'option',
'capability' => 'edit_theme_options',
)
);
$wp_customize->add_control(
new Sticky_Header_Number_Control(
$wp_customize,
'thsp_sticky_header[show_at]',
array(
'label' => __( 'Make visible when scrolled to (in pixels)', $thsp_plugin_slug ),
'section' => 'thsp_sticky_header',
'settings' => 'thsp_sticky_header[show_at]',
)
)
);
// Sticky Header hide if narrower than
$wp_customize->add_setting(
'thsp_sticky_header[hide_if_narrower]',
array(
'default' => '600',
'sanitize_callback' => 'wp_filter_nohtml_kses',
'type' => 'option',
'capability' => 'edit_theme_options',
)
);
$wp_customize->add_control(
new Sticky_Header_Number_Control(
$wp_customize,
'thsp_sticky_header[hide_if_narrower]',
array(
'label' => __( 'Hide if screen is narrower than (in pixels)', $thsp_plugin_slug ),
'section' => 'thsp_sticky_header',
'settings' => 'thsp_sticky_header[hide_if_narrower]',
)
)
);
}
/**
* Returns plugin settings.
*
* @since 1.0.0
*
* @return array Merged array of plugin settings and plugin defaults.
*/
function thsp_sticky_header_get_settings() {
$plugin_defaults = array(
'background_color' => '#181818',
'text_color' => '#f9f9f9',
'show_at' => '200',
'hide_if_narrower' => '600'
);
$plugin_settings = get_option( 'thsp_sticky_header' );
return wp_parse_args( $plugin_settings, $plugin_defaults );
}