forked from bootscore/bootscore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
494 lines (399 loc) · 16.9 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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
<?php
/**
* Bootscore functions and definitions
*
* @link https://developer.wordpress.org/themes/basics/theme-functions/
*
* @package Bootscore
*/
// WooCommerce
//require get_template_directory() . '/woocommerce/woocommerce-functions.php';
// WooCommerce END
// Register Bootstrap 5 Nav Walker
if (!function_exists('register_navwalker')) :
function register_navwalker() {
require_once('inc/class-bootstrap-5-navwalker.php');
// Register Menus
register_nav_menu('main-menu', 'Main menu');
register_nav_menu('footer-menu', 'Footer menu');
}
endif;
add_action('after_setup_theme', 'register_navwalker');
// Register Bootstrap 5 Nav Walker END
// Register Comment List
if (!function_exists('register_comment_list')) :
function register_comment_list() {
// Register Comment List
require_once('inc/comment-list.php');
}
endif;
add_action('after_setup_theme', 'register_comment_list');
// Register Comment List END
if (!function_exists('bootscore_setup')) :
/**
* 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.
*/
function bootscore_setup() {
/*
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
* If you're building a theme based on Bootscore, use a find and replace
* to change 'bootscore' to the name of your theme in all the template files.
*/
load_theme_textdomain('bootscore', get_template_directory() . '/languages');
// Add default posts and comments RSS feed links to head.
add_theme_support('automatic-feed-links');
/*
* Let WordPress manage the document title.
* By adding theme support, we declare that this theme does not use a
* hard-coded <title> tag in the document head, and expect WordPress to
* provide it for us.
*/
add_theme_support('title-tag');
/*
* 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');
/*
* Switch default core markup for search form, comment form, and comments
* to output valid HTML5.
*/
add_theme_support('html5', array(
'comment-form',
'comment-list',
'gallery',
'caption',
));
// Add theme support for selective refresh for widgets.
add_theme_support('customize-selective-refresh-widgets');
}
endif;
add_action('after_setup_theme', 'bootscore_setup');
/**
* Set the content width in pixels, based on the theme's design and stylesheet.
*
* Priority 0 to make it available to lower priority callbacks.
*
* @global int $content_width
*/
function bootscore_content_width() {
// This variable is intended to be overruled from themes.
// Open WPCS issue: {@link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1043}.
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
$GLOBALS['content_width'] = apply_filters('bootscore_content_width', 640);
}
add_action('after_setup_theme', 'bootscore_content_width', 0);
/**
* Register widget area.
*
* @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
*/
// Widgets
if (!function_exists('bootscore_widgets_init')) :
function bootscore_widgets_init() {
// Top Nav
register_sidebar(array(
'name' => esc_html__('Top Nav', 'bootscore'),
'id' => 'top-nav',
'description' => esc_html__('Add widgets here.', 'bootscore'),
'before_widget' => '<div class="ms-3">',
'after_widget' => '</div>',
'before_title' => '<div class="widget-title d-none">',
'after_title' => '</div>'
));
// Top Nav End
// Top Nav Search
register_sidebar(array(
'name' => esc_html__('Top Nav Search', 'bootscore'),
'id' => 'top-nav-search',
'description' => esc_html__('Add widgets here.', 'bootscore'),
'before_widget' => '<div class="top-nav-search">',
'after_widget' => '</div>',
'before_title' => '<div class="widget-title d-none">',
'after_title' => '</div>'
));
// Top Nav Search End
// Sidebar
register_sidebar(array(
'name' => esc_html__('Sidebar', 'bootscore'),
'id' => 'sidebar-1',
'description' => esc_html__('Add widgets here.', 'bootscore'),
'before_widget' => '<section id="%1$s" class="widget %2$s card card-body mb-4 bg-light border-0">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title card-title border-bottom py-2">',
'after_title' => '</h2>',
));
// Sidebar End
// Top Footer
register_sidebar(array(
'name' => esc_html__('Top Footer', 'bootscore'),
'id' => 'top-footer',
'description' => esc_html__('Add widgets here.', 'bootscore'),
'before_widget' => '<div class="footer_widget mb-5">',
'after_widget' => '</div>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>'
));
// Top Footer End
// Footer 1
register_sidebar(array(
'name' => esc_html__('Footer 1', 'bootscore'),
'id' => 'footer-1',
'description' => esc_html__('Add widgets here.', 'bootscore'),
'before_widget' => '<div class="footer_widget mb-4">',
'after_widget' => '</div>',
'before_title' => '<h2 class="widget-title h4">',
'after_title' => '</h2>'
));
// Footer 1 End
// Footer 2
register_sidebar(array(
'name' => esc_html__('Footer 2', 'bootscore'),
'id' => 'footer-2',
'description' => esc_html__('Add widgets here.', 'bootscore'),
'before_widget' => '<div class="footer_widget mb-4">',
'after_widget' => '</div>',
'before_title' => '<h2 class="widget-title h4">',
'after_title' => '</h2>'
));
// Footer 2 End
// Footer 3
register_sidebar(array(
'name' => esc_html__('Footer 3', 'bootscore'),
'id' => 'footer-3',
'description' => esc_html__('Add widgets here.', 'bootscore'),
'before_widget' => '<div class="footer_widget mb-4">',
'after_widget' => '</div>',
'before_title' => '<h2 class="widget-title h4">',
'after_title' => '</h2>'
));
// Footer 3 End
// Footer 4
register_sidebar(array(
'name' => esc_html__('Footer 4', 'bootscore'),
'id' => 'footer-4',
'description' => esc_html__('Add widgets here.', 'bootscore'),
'before_widget' => '<div class="footer_widget mb-4">',
'after_widget' => '</div>',
'before_title' => '<h2 class="widget-title h4">',
'after_title' => '</h2>'
));
// Footer 4 End
// 404 Page
register_sidebar(array(
'name' => esc_html__('404 Page', 'bootscore'),
'id' => '404-page',
'description' => esc_html__('Add widgets here.', 'bootscore'),
'before_widget' => '<div class="mb-4">',
'after_widget' => '</div>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>'
));
// 404 Page End
}
add_action('widgets_init', 'bootscore_widgets_init');
endif;
// Widgets END
// Shortcode in HTML-Widget
add_filter('widget_text', 'do_shortcode');
// Shortcode in HTML-Widget End
//Enqueue scripts and styles
function bootscore_scripts() {
// Get modification time. Enqueue files with modification date to prevent browser from loading cached scripts and styles when file content changes.
$modificated_bootscoreCss = (file_exists(get_template_directory() . '/css/main.css')) ? date('YmdHi', filemtime(get_template_directory() . '/css/main.css')) : 1;
$modificated_styleCss = date('YmdHi', filemtime(get_stylesheet_directory() . '/style.css'));
$modificated_fontawesomeCss = date('YmdHi', filemtime(get_template_directory() . '/fontawesome/css/all.min.css'));
$modificated_bootstrapJs = date('YmdHi', filemtime(get_template_directory() . '/js/lib/bootstrap.bundle.min.js'));
$modificated_themeJs = date('YmdHi', filemtime(get_template_directory() . '/js/theme.js'));
// bootScore
require_once 'inc/scss-compiler.php';
bootscore_compile_scss();
wp_enqueue_style('main', get_template_directory_uri() . '/css/main.css', array(), $modificated_bootscoreCss);
// Style CSS
wp_enqueue_style('bootscore-style', get_stylesheet_uri(), array(), $modificated_styleCss);
// Fontawesome
wp_enqueue_style('fontawesome', get_template_directory_uri() . '/fontawesome/css/all.min.css', array(), $modificated_fontawesomeCss);
// Bootstrap JS
wp_enqueue_script('bootstrap', get_template_directory_uri() . '/js/lib/bootstrap.bundle.min.js', array(), $modificated_bootstrapJs, true);
// Theme JS
wp_enqueue_script('bootscore-script', get_template_directory_uri() . '/js/theme.js', array('jquery'), $modificated_themeJs, true);
// IE Warning
wp_localize_script('bootscore-script', 'bootscore', array(
'ie_title' => __('Internet Explorer detected', 'bootscore'),
'ie_limited_functionality' => __('This website will offer limited functionality in this browser.', 'bootscore'),
'ie_modern_browsers_1' => __('Please use a modern and secure web browser like', 'bootscore'),
'ie_modern_browsers_2' => __(' <a href="https://www.mozilla.org/firefox/" target="_blank">Mozilla Firefox</a>, <a href="https://www.google.com/chrome/" target="_blank">Google Chrome</a>, <a href="https://www.opera.com/" target="_blank">Opera</a> ', 'bootscore'),
'ie_modern_browsers_3' => __('or', 'bootscore'),
'ie_modern_browsers_4' => __(' <a href="https://www.microsoft.com/edge" target="_blank">Microsoft Edge</a> ', 'bootscore'),
'ie_modern_browsers_5' => __('to display this site correctly.', 'bootscore'),
));
// IE Warning End
if (is_singular() && comments_open() && get_option('thread_comments')) {
wp_enqueue_script('comment-reply');
}
}
add_action('wp_enqueue_scripts', 'bootscore_scripts');
//Enqueue scripts and styles END
// Preload Font Awesome
add_filter('style_loader_tag', 'bootscore_fa_preload');
function bootscore_fa_preload($tag) {
$tag = preg_replace("/id='fontawesome-css'/", "id='fontawesome-css' online=\"if(media!='all')media='all'\"", $tag);
return $tag;
}
// Preload Font Awesome END
/**
* Custom template tags for this theme.
*/
require get_template_directory() . '/inc/template-tags.php';
/**
* Functions which enhance the theme by hooking into WordPress.
*/
require get_template_directory() . '/inc/template-functions.php';
/**
* Load Jetpack compatibility file.
*/
if (defined('JETPACK__VERSION')) {
require get_template_directory() . '/inc/jetpack.php';
}
// Amount of posts/products in category
if (!function_exists('wpsites_query')) :
function wpsites_query($query) {
if ($query->is_archive() && $query->is_main_query() && !is_admin()) {
$query->set('posts_per_page', 24);
}
}
add_action('pre_get_posts', 'wpsites_query');
endif;
// Amount of posts/products in category END
// Pagination Categories
if (!function_exists('bootscore_pagination')) :
function bootscore_pagination($pages = '', $range = 2) {
$showitems = ($range * 2) + 1;
global $paged;
// default page to one if not provided
if(empty($paged)) $paged = 1;
if ($pages == '') {
global $wp_query;
$pages = $wp_query->max_num_pages;
if (!$pages)
$pages = 1;
}
if (1 != $pages) {
echo '<nav aria-label="Page navigation" role="navigation">';
echo '<span class="sr-only">Page navigation</span>';
echo '<ul class="pagination justify-content-center ft-wpbs mb-4">';
if ($paged > 2 && $paged > $range + 1 && $showitems < $pages)
echo '<li class="page-item"><a class="page-link" href="' . get_pagenum_link(1) . '" aria-label="First Page">«</a></li>';
if ($paged > 1 && $showitems < $pages)
echo '<li class="page-item"><a class="page-link" href="' . get_pagenum_link($paged - 1) . '" aria-label="Previous Page">‹</a></li>';
for ($i = 1; $i <= $pages; $i++) {
if (1 != $pages && (!($i >= $paged + $range + 1 || $i <= $paged - $range - 1) || $pages <= $showitems))
echo ($paged == $i) ? '<li class="page-item active"><span class="page-link"><span class="sr-only">Current Page </span>' . $i . '</span></li>' : '<li class="page-item"><a class="page-link" href="' . get_pagenum_link($i) . '"><span class="sr-only">Page </span>' . $i . '</a></li>';
}
if ($paged < $pages && $showitems < $pages)
echo '<li class="page-item"><a class="page-link" href="' . get_pagenum_link(($paged === 0 ? 1 : $paged) + 1) . '" aria-label="Next Page">›</a></li>';
if ($paged < $pages - 1 && $paged + $range - 1 < $pages && $showitems < $pages)
echo '<li class="page-item"><a class="page-link" href="' . get_pagenum_link($pages) . '" aria-label="Last Page">»</a></li>';
echo '</ul>';
echo '</nav>';
// Uncomment this if you want to show [Page 2 of 30]
// echo '<div class="pagination-info mb-5 text-center">[ <span class="text-muted">Page</span> '.$paged.' <span class="text-muted">of</span> '.$pages.' ]</div>';
}
}
endif;
//Pagination Categories END
// Pagination Buttons Single Posts
add_filter('next_post_link', 'post_link_attributes');
add_filter('previous_post_link', 'post_link_attributes');
function post_link_attributes($output) {
$code = 'class="page-link"';
return str_replace('<a href=', '<a ' . $code . ' href=', $output);
}
// Pagination Buttons Single Posts END
// Excerpt to pages
add_post_type_support('page', 'excerpt');
// Excerpt to pages END
// Breadcrumb
if (!function_exists('the_breadcrumb')) :
function the_breadcrumb() {
if (!is_home()) {
echo '<nav class="breadcrumb mb-4 mt-2 bg-light py-2 px-3 small rounded">';
echo '<a href="' . home_url('/') . '">' . ('<i class="fa-solid fa-house"></i>') . '</a><span class="divider"> / </span>';
if (is_category() || is_single()) {
the_category(' <span class="divider"> / </span> ');
if (is_single()) {
echo ' <span class="divider"> / </span> ';
the_title();
}
} elseif (is_page()) {
echo the_title();
}
echo '</nav>';
}
}
add_filter('breadcrumbs', 'breadcrumbs');
endif;
// Breadcrumb END
// Comment Button
if (!function_exists('bootscore_comment_button')) :
function bootscore_comment_button($args) {
$args['class_submit'] = 'btn btn-outline-primary'; // since WP 4.1
return $args;
}
add_filter('comment_form_defaults', 'bootscore_comment_button');
endif;
// Comment Button END
// Password protected form
if (!function_exists('bootscore_pw_form')) :
function bootscore_pw_form() {
$output = '
<form action="' . get_option('siteurl') . '/wp-login.php?action=postpass" method="post" class="form-inline">' . "\n"
. '<input name="post_password" type="password" size="" class="form-control me-2 my-1" placeholder="' . __('Password', 'bootscore') . '"/>' . "\n"
. '<input type="submit" class="btn btn-outline-primary my-1" name="Submit" value="' . __('Submit', 'bootscore') . '" />' . "\n"
. '</p>' . "\n"
. '</form>' . "\n";
return $output;
}
add_filter("the_password_form", "bootscore_pw_form");
endif;
// Password protected form END
// Allow HTML in term (category, tag) descriptions
foreach (array('pre_term_description') as $filter) {
remove_filter($filter, 'wp_filter_kses');
if (!current_user_can('unfiltered_html')) {
add_filter($filter, 'wp_filter_post_kses');
}
}
foreach (array('term_description') as $filter) {
remove_filter($filter, 'wp_kses_data');
}
// Allow HTML in term (category, tag) descriptions END
// Allow HTML in author bio
remove_filter('pre_user_description', 'wp_filter_kses');
add_filter('pre_user_description', 'wp_filter_post_kses');
// Allow HTML in author bio END
// Hook after #primary
function bs_after_primary() {
do_action('bs_after_primary');
}
// Hook after #primary END
// Open links in comments in new tab
if (!function_exists('bs_comment_links_in_new_tab')) :
function bs_comment_links_in_new_tab($text) {
return str_replace('<a', '<a target="_blank" rel=”nofollow”', $text);
}
add_filter('comment_text', 'bs_comment_links_in_new_tab');
endif;
// Open links in comments in new tab END
// Disable Gutenberg blocks in widgets (WordPress 5.8)
// Disables the block editor from managing widgets in the Gutenberg plugin.
add_filter('gutenberg_use_widgets_block_editor', '__return_false');
// Disables the block editor from managing widgets.
add_filter('use_widgets_block_editor', '__return_false');
// Disable Gutenberg blocks in widgets (WordPress 5.8) END