-
Notifications
You must be signed in to change notification settings - Fork 4
/
functions.php
266 lines (220 loc) · 9.77 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
<?php
/**
* Bootstrap Basic theme
*
* @package bootstrap-basic
*/
/**
* Required WordPress variable.
*/
if (!isset($content_width)) {
$content_width = 1170;
}
/**
* The Bootstrap Basic main class.
*/
require_once get_template_directory() . '/inc/BootstrapBasic.php';
/**
* Register commonly use scripts and styles.
*/
$BootstrapBasic = new \BootstrapBasic();
unset($BootstrapBasic);
if (!function_exists('bootstrapBasicSetup')) {
/**
* Setup theme and register support wp features.
*/
function bootstrapBasicSetup()
{
/**
* Make theme available for translation
* Translations can be filed in the /languages/ directory
*
* copy from underscores theme
*/
load_theme_textdomain('bootstrap-basic', get_template_directory() . '/languages');
// add theme support title-tag
add_theme_support('title-tag');
// add theme support post and comment automatic feed links
add_theme_support('automatic-feed-links');
// enable support for post thumbnail or feature image on posts and pages
add_theme_support('post-thumbnails');
// allow the use of html5 markup
// @link https://codex.wordpress.org/Theme_Markup
add_theme_support('html5', array('caption', 'comment-form', 'comment-list', 'gallery', 'search-form'));
// add support menu
register_nav_menus(array(
'primary' => __('Primary Menu', 'bootstrap-basic'),
));
// add post formats support
add_theme_support('post-formats', array('aside', 'image', 'video', 'quote', 'link'));
// add support custom background
add_theme_support(
'custom-background',
apply_filters(
'bootstrap_basic_custom_background_args',
array(
'default-color' => 'ffffff',
'default-image' => '',
)
)
);
// @since 1.1 or WordPress 5.0+
// make gutenberg support. --------------------------------------------------------------------------------------
// @link https://wordpress.org/gutenberg/handbook/extensibility/theme-support/ reference.
// add wide alignment ( https://wordpress.org/gutenberg/handbook/designers-developers/developers/themes/theme-support/#wide-alignment )
add_theme_support('align-wide');
// support default block styles for front-end ( https://wordpress.org/gutenberg/handbook/designers-developers/developers/themes/theme-support/#default-block-styles )
add_theme_support('wp-block-styles');
// support editor styles ( https://wordpress.org/gutenberg/handbook/designers-developers/developers/themes/theme-support/#editor-styles )
// this one make appearance in editor more close to Bootstrap 3.
add_theme_support('editor-styles');
// support responsive embeds for front-end ( https://wordpress.org/gutenberg/handbook/designers-developers/developers/themes/theme-support/#responsive-embedded-content )
add_theme_support('responsive-embeds');
// end make gutenberg support. ---------------------------------------------------------------------------------
}// bootstrapBasicSetup
}
add_action('after_setup_theme', 'bootstrapBasicSetup');
if (!function_exists('bootstrapBasicWidgetsInit')) {
/**
* Register widget areas
*/
function bootstrapBasicWidgetsInit()
{
register_sidebar(array(
'name' => __('Sidebar right', 'bootstrap-basic'),
'id' => 'sidebar-right',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>',
));
register_sidebar(array(
'name' => __('Sidebar left', 'bootstrap-basic'),
'id' => 'sidebar-left',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>',
));
register_sidebar(array(
'name' => __('Header right', 'bootstrap-basic'),
'id' => 'header-right',
'description' => __('Header widget area on the right side next to site title.', 'bootstrap-basic'),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>',
));
register_sidebar(array(
'name' => __('Navigation bar right', 'bootstrap-basic'),
'id' => 'navbar-right',
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => '',
));
register_sidebar(array(
'name' => __('Footer left', 'bootstrap-basic'),
'id' => 'footer-left',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>',
));
register_sidebar(array(
'name' => __('Footer right', 'bootstrap-basic'),
'id' => 'footer-right',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>',
));
}// bootstrapBasicWidgetsInit
}
add_action('widgets_init', 'bootstrapBasicWidgetsInit');
if (!function_exists('bootstrapBasicEnqueueScripts')) {
/**
* Enqueue scripts & styles
*
* @global \WP_Scripts $wp_scripts
*/
function bootstrapBasicEnqueueScripts()
{
global $wp_scripts;
$Theme = wp_get_theme();
$themeVersion = $Theme->get('Version');
unset($Theme);
wp_enqueue_style('bootstrap-style');
wp_enqueue_style('bootstrap-theme-style', get_template_directory_uri() . '/css/bootstrap-theme.min.css', array(), '3.4.1');
wp_enqueue_style('fontawesome-style', get_template_directory_uri() . '/css/font-awesome.min.css', array(), '4.7.0');
wp_enqueue_style('main-style', get_template_directory_uri() . '/css/main.css', array(), $themeVersion);
// check if there are any calendar widget block.
if (bootstrapBasicHasWidgetBlock('calendar') === true) {
// if theme using widget blocks.
// enqueue css to fix calendar widget block to render as non widget block.
// if you would like it to be render as new widget block, please dequeue this handle.
wp_enqueue_style('bootstrapbasic-widgetblocks-calendar', get_template_directory_uri() . '/css/widget-blocks/calendar.css', array(), $themeVersion);
}
// js that is useful for development.
wp_enqueue_script('modernizr-script', get_template_directory_uri() . '/js/vendor/modernizr.min.js', array(), '3.6.0-20190314', true);
// js that is useful for old browsers.
wp_register_script('respond-script', get_template_directory_uri() . '/js/vendor/respond.min.js', array(), '1.4.2', true);
$wp_scripts->add_data('respond-script', 'conditional', 'lt IE 9');
wp_enqueue_script('respond-script');
wp_register_script('html5-shiv-script', get_template_directory_uri() . '/js/vendor/html5shiv.min.js', array(), '3.7.3', true);
$wp_scripts->add_data('html5-shiv-script', 'conditional', 'lte IE 9');
wp_enqueue_script('html5-shiv-script');
if (is_singular() && get_option('thread_comments')) {
wp_enqueue_script('comment-reply');
}
wp_enqueue_script('bootstrap-script');
wp_enqueue_script('main-script', get_template_directory_uri() . '/js/main.js', array('jquery'), $themeVersion, true);
wp_enqueue_style('bootstrap-basic-style', get_stylesheet_uri(), array(), $themeVersion);
// move jquery to bottom ( https://wordpress.stackexchange.com/a/225936/41315 )
$wp_scripts->add_data('jquery', 'group', 1);
$wp_scripts->add_data('jquery-core', 'group', 1);
$wp_scripts->add_data('jquery-migrate', 'group', 1);
}// bootstrapBasicEnqueueScripts
}
add_action('wp_enqueue_scripts', 'bootstrapBasicEnqueueScripts');
/**
* admin page displaying help.
*/
if (is_admin()) {
require get_template_directory() . '/inc/BootstrapBasicAdminHelp.php';
$bbsc_adminhelp = new BootstrapBasicAdminHelp();
add_action('admin_menu', array($bbsc_adminhelp, 'themeHelpMenu'));
unset($bbsc_adminhelp);
}
/**
* Make WordPress 5 (Gutenberg) editor support Bootstrap CSS.
*/
require_once get_template_directory() . '/inc/BootstrapBasicWp5.php';
$BbWp5 = new BootstrapBasicWp5();
unset($BbWp5);
/**
* Custom template tags for this theme.
*/
require get_template_directory() . '/inc/template-tags.php';
/**
* Custom functions that act independently of the theme templates.
*/
require get_template_directory() . '/inc/extras.php';
/**
* Custom dropdown menu and navbar in walker class
*/
require get_template_directory() . '/inc/BootstrapBasicMyWalkerNavMenu.php';
/**
* Template functions
*/
require get_template_directory() . '/inc/template-functions.php';
/**
* --------------------------------------------------------------
* Theme widget & widget hooks
* --------------------------------------------------------------
*/
require get_template_directory() . '/inc/widgets/BootstrapBasicAutoRegisterWidgets.php';
$BootstrapBasicAutoRegisterWidgets = new BootstrapBasicAutoRegisterWidgets();
$BootstrapBasicAutoRegisterWidgets->registerAll();
unset($BootstrapBasicAutoRegisterWidgets);
require get_template_directory() . '/inc/template-widgets-hook.php';