-
Notifications
You must be signed in to change notification settings - Fork 4
/
functions.php
290 lines (249 loc) · 7.81 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
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
<?php
/**
* SMNTCS Retro functions and definitions
*
* @link https://developer.wordpress.org/themes/basics/theme-functions/
*
* @package WordPress
* @subpackage SMNTCS_Retro
* @since 1.0.0
*/
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which
* runs before the init hook. The init hook is too late for some features, such
* as indicating support for post thumbnails.
*
* @since 1.0.0
*/
function smntcs_retro_theme_support() {
/**
* Add default posts and comments RSS feed links to head.
*
* @since 1.0.0
*/
add_theme_support( 'automatic-feed-links' );
/**
* Add responsive embeds support.
*
* @since 1.8.0
*/
add_theme_support( 'responsive-embeds' );
/**
* Set content-width.
*
* @link https://codex.wordpress.org/Content_Width
*/
global $content_width;
if ( ! isset( $content_width ) ) {
// phpcs:ignore WPThemeReview.CoreFunctionality.PrefixAllGlobals.NonPrefixedVariableFound
$content_width = sprintf( '%dpx', get_theme_mod( 'smntcs_retro_site_width', '580' ) );
}
/**
* Enable support for post thumbnails on posts and pages.
*
* @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
*/
add_theme_support( 'post-thumbnails' );
/**
* Set post thumbnail size.
*
* @link https://developer.wordpress.org/reference/functions/set_post_thumbnail_size/
*/
set_post_thumbnail_size( get_theme_mod( 'smntcs_retro_site_width', '580' ), 9999 );
/**
* Enable title tag support.
*
* @link https://developer.wordpress.org/reference/functions/add_theme_support/
*/
add_theme_support( 'title-tag' );
/*
* Enable HTML5 support.
*
* @link https://developer.wordpress.org/reference/functions/add_theme_support/
*/
add_theme_support(
'html5',
array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
'script',
'style',
)
);
/*
* Load theme text domain.
*
* @link https://developer.wordpress.org/reference/functions/load_theme_textdomain/
*/
load_theme_textdomain( 'smntcs-retro' );
}
add_action( 'after_setup_theme', 'smntcs_retro_theme_support' );
/**
* Include required files.
*/
require get_template_directory() . '/inc/template-tags.php';
require get_template_directory() . '/inc/theme-colors.php';
require get_template_directory() . '/inc/customizer.php';
require get_template_directory() . '/inc/customizer-general-section.php';
require get_template_directory() . '/inc/customizer-archive-section.php';
require get_template_directory() . '/inc/customizer-page-section.php';
require get_template_directory() . '/inc/customizer-post-section.php';
/**
* Register and enqueue styles.
*
* @since 1.0.0
*/
function smntcs_retro_register_styles() {
// Note, the is_IE global variable is defined by WordPress and is used
// to detect if the current browser is internet explorer.
global $is_IE;
if ( $is_IE ) {
// If IE 11 or below, use a flattened stylesheet with static values replacing CSS Variables.
wp_enqueue_style( 'smntcs-retro-style', get_template_directory_uri() . '/assets/css/ie.css', array(), wp_get_theme()->get( 'Version' ) );
} else {
// If not IE, use the standard stylesheet.
wp_enqueue_style( 'smntcs-retro-style', get_template_directory_uri() . '/style.css', array(), wp_get_theme()->get( 'Version' ) );
}
wp_enqueue_style( 'smntcs-retro-search-style', get_template_directory_uri() . '/search.css', array(), wp_get_theme()->get( 'Version' ) );
// RTL styles.
wp_style_add_data( 'smntcs-retro-style', 'rtl', 'replace' );
}
add_action( 'wp_enqueue_scripts', 'smntcs_retro_register_styles' );
/**
* Register and enqueue scripts.
*
* @since 1.0.0
*/
function smntcs_retro_register_scripts() {
if ( ( ! is_admin() ) && is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
wp_enqueue_script( 'search-script', get_template_directory_uri() . '/assets/js/search.js', array(), '1.0.0', true );
}
add_action( 'wp_enqueue_scripts', 'smntcs_retro_register_scripts' );
/**
* Register navigation menu.
*
* @since 1.0.0
*/
function smntcs_retro_menus() {
$locations = array(
'primary' => __( 'Primary Menu', 'smntcs-retro' ),
'footer' => __( 'Footer Menu', 'smntcs-retro' ),
);
register_nav_menus( $locations );
}
add_action( 'init', 'smntcs_retro_menus' );
/**
* Register footer widget section
*
* @since 1.0.0
*/
function smntcs_retro_sidebars() {
register_sidebar(
array(
'id' => 'footer-sidebar-left',
'name' => __( 'Footer Sidebar Left', 'smntcs-retro' ),
'description' => __( 'Add widgets to the footer sidebar left.', 'smntcs-retro' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
)
);
register_sidebar(
array(
'id' => 'footer-sidebar-right',
'name' => __( 'Footer Sidebar Right', 'smntcs-retro' ),
'description' => __( 'Add widgets to the footer sidebar right.', 'smntcs-retro' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
)
);
}
add_action( 'widgets_init', 'smntcs_retro_sidebars' );
if ( ! function_exists( 'wp_body_open' ) ) {
/**
* Shim for wp_body_open, ensuring backwards compatibility with versions of WordPress older than 5.2.
*
* @since 1.0.0
*/
function wp_body_open() {
do_action( 'wp_body_open' );
}
}
/**
* Include a skip to content link at the top of the page so that users can bypass the menu.
*
* @since 1.0.0
*/
function smntcs_retro_skip_link() {
echo '<a class="skip-link screen-reader-text" href="#site-content">' . __( 'Skip to the content', 'smntcs-retro' ) . '</a>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- core trusts translations
}
add_action( 'wp_body_open', 'smntcs_retro_skip_link', 5 );
/**
* Sanitize checkbox field.
*
* @since 1.6.0
* @param bool $checked Whether or not a box is checked.
* @return bool True if checkbox is activated, othewise false
*/
function smntcs_retro_sanitize_checkbox( $checked ) {
return ( ( isset( $checked ) && true === $checked ) ? true : false );
}
/**
* Sanitize radio field.
*
* @param mixed $input The input to sanitize.
* @param mixed $setting The settings object.
* @return bool True if select field is valid, othewise false
*/
function smntcs_retro_sanitize_radio( $input, $setting ) {
$input = sanitize_key( $input );
$choices = $setting->manager->get_control( $setting->id )->choices;
return ( array_key_exists( $input, $choices ) ? $input : $setting->default );
}
/**
* Sanitize radio field.
*
* @param mixed $input The input to sanitize.
* @param mixed $setting The settings object.
* @return bool True if select field is valid, othewise false
*/
function smntcs_retro_sanitize_select( $input, $setting ) {
$input = sanitize_key( $input );
$choices = $setting->manager->get_control( $setting->id )->choices;
return ( array_key_exists( $input, $choices ) ? $input : $setting->default );
}
/**
* Add custom CSS to the site.
*
* @since 1.6.0
* @return void
*/
function smntcs_retro_wp_head() {
if ( get_theme_mod( 'smntcs_retro_centre_site' ) ) {
print( '<style type="text/css">body { margin: auto; }</style>' );
}
if ( get_theme_mod( 'smntcs_retro_site_width' ) ) {
printf( '<style type="text/css">body { max-width: %dpx; }</style>', (int) get_theme_mod( 'smntcs_retro_site_width' ) );
}
}
add_action( 'wp_head', 'smntcs_retro_wp_head' );
/**
* Load Dashicons on frontend.
*
* @since 1.13.0
* @return void
*/
function smntcs_retro_wp_enqueue_scripts() {
wp_enqueue_style( 'dashicons' );
}
add_action( 'wp_enqueue_scripts', 'smntcs_retro_wp_enqueue_scripts', 999 );