-
Notifications
You must be signed in to change notification settings - Fork 1
/
functions.php
327 lines (276 loc) · 12 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
<?php
//Load Main Scripts
function enqueue_crafted_brew_scripts()
{
wp_enqueue_script('Ajax-Popper', 'https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js', false, null, true, null);
wp_enqueue_script('Bootstrap-4.1.3', 'https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js', array('jquery'), null, true, null);
wp_enqueue_script('font-awesome', 'https://use.fontawesome.com/releases/v5.1.0/js/all.js', false, null, null, false);
wp_enqueue_script('crafted-brew-scripts', get_template_directory_uri() . '/lib/js/craftedBrew.js', array('jquery'), null, true, null);
wp_enqueue_script('parallax', get_template_directory_uri() . '/lib/js/parallax.min.js', array('jquery'), null, true, null);
//wp_enqueue_script('cookie-js', get_template_directory_uri() . '/lib/js/cookie.min.js', false, null, true, null);
}
add_action('wp_enqueue_scripts', 'enqueue_crafted_brew_scripts');
//Load CSS
function enqueue_crafted_brew_styles()
{
wp_enqueue_style('bootstrap-4.1.3', 'https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css', array(), null);
wp_enqueue_style('crafted-brew-styles', get_template_directory_uri() . '/style.css', array(), null);
}
add_action('wp_enqueue_scripts', 'enqueue_crafted_brew_styles');
add_action('wp_head', 'remove_all_wpseo_og', 1);
function remove_all_wpseo_og() {
if ( eme_is_events_page() ) {
remove_action( 'wpseo_head', array( $GLOBALS['wpseo_og'], 'opengraph' ), 30 );
}
}
add_action('wp_head', 'remove_all_wpseo_twitter', 1);
function remove_all_wpseo_twitter() {
if ( eme_is_events_page() ) {
remove_action( 'wpseo_head' , array( 'WPSEO_Twitter' , 'get_instance' ) , 40 );
}
}
//Add Custom Page Titles to Events Made Easy
add_action("wp_head", function () {
if (eme_is_single_event_page()) {
$extra_headers_format = get_option('eme_event_html_headers_format');
if (!empty($extra_headers_format)) {
remove_action( 'wp_head', '_wp_render_title_tag', 1 );
}
}
}, 0); // priority 0 to be launched before the call of "_wp_render_title_tag"
//Title tag support
add_theme_support( 'title-tag' );
//Remove attribute from javascript url's
add_action('wp_loaded', 'prefix_output_buffer_start');
function prefix_output_buffer_start() {
ob_start("prefix_output_callback");
}
add_action('shutdown', 'prefix_output_buffer_end');
function prefix_output_buffer_end() {
ob_end_flush();
}
function prefix_output_callback($buffer) {
return preg_replace( "%[ ]type=[\'\"]text\/(javascript|css)[\'\"]%", '', $buffer );
}
//Hide admin bar from front of site
show_admin_bar(false);
//Allow post and page "featured image"
add_theme_support('post-thumbnails');
//Disable posts -- for now
function remove_posts_menu() {
remove_menu_page('edit.php');
}
add_action('admin_menu', 'remove_posts_menu');
// add tag support to pages
function tags_support_all()
{
register_taxonomy_for_object_type('post_tag', 'page');
}
//Change WP Emails and email address away from "WordPress" as sender
function blueEarl_mail_name( $email ){
return 'Blue Earl Brewing'; // new email name from sender.
}
add_filter( 'wp_mail_from_name', 'blueEarl_mail_name' );
function blueEarl_mail_from ($email ){
return '[email protected]'; // new email address from sender.
}
add_filter( 'wp_mail_from', 'blueEarl_mail_from' );
// ensure all tags are included in queries
function tags_support_query($wp_query)
{
if ($wp_query->get('tag'))
$wp_query->set('post_type', 'any');
}
// tag hooks
add_action('init', 'tags_support_all');
add_action('pre_get_posts', 'tags_support_query');
// Register Nav Menus
register_nav_menus(array(
$location => $description
));
// Register Custom Navigation Walker
require_once get_template_directory() . '/class-wp-bootstrap-navwalker.php';
register_nav_menus( array(
'primary' => __( 'Primary Menu', 'crafted-brew-wordpress-theme' ),
) );
// Nav Walker
//WordPress Fluid Images Bootstrap 4.1.0
function bootstrap_fluid_images($html)
{
$classes = 'img-fluid';
if (preg_match('/<img.*? class="/', $html)) {
$html = preg_replace('/(<img.*? class=".*?)(".*?\/>)/', '$1 ' . $classes . '$2', $html);
} else {
$html = preg_replace('/(<img.*?)(\/>)/', '$1 class="' . $classes . '"$2', $html);
}
$html = preg_replace('/(width|height)=\"\d*\"\s/', "", $html);
return $html;
}
add_filter('the_content', 'bootstrap_fluid_images', 10);
add_filter('post_thumbnail_html', 'bootstrap_fluid_images', 10);
//begin blog page read more button
function excerpt_read_more_link($output)
{
global $post;
return $output . '<a class="btn btn-lg btn-warning text-uppercase" href="' . get_permalink() . '">Read More <i class="fas fa-angle-double-right fa-fw fa-lg"></i></a>';
}
add_filter('the_excerpt', 'excerpt_read_more_link');
//end blog page read more button
//begin pagination
function crafted_brew_pagination($pages = '', $range = 1)
{
$showitems = ($range * 2) + 1;
global $paged;
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='Blog Navigation pagination'>";
echo "<ul class='pagination justify-content-center'>";
echo "<li class='page-item'>";
if ($paged > 2 && $paged > $range + 1 && $showitems < $pages)
echo "<a class='page-link' aria-label='First Page' href='" . get_pagenum_link(1) . "'>
<i class='fas fa-angle-double-left fa-lg'></i>
<span class='sr-only'>go to first page</span>
</a>";
echo "</li>";
echo "<li class='page-item'>";
if ($paged > 1 && $showitems < $pages)
echo "<a class='page-link' href='" . get_pagenum_link($paged - 1) . "'>
<i class='fas fa-angle-left fa-lg'></i>
<span class='sr-only'>go to previous page</span>
</a>";
echo "</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-link'>" . $i . "</li>" : "<a href='" . get_pagenum_link($i) . "' class='page-link' >" . $i . "</a>";
}
}
if ($paged < $pages && $showitems < $pages)
echo "<a class='page-link' aria-label='Next Page' href='" . get_pagenum_link($paged + 1) . "'>
<i class='fas fa-angle-right fa-lg'></i>
<span class='sr-only'>go to next page</span>
</a>";
if ($paged < $pages - 1 && $paged + $range - 1 < $pages && $showitems < $pages)
echo "<a class='page-link' aria-label='Last Page' href='" . get_pagenum_link($pages) . "'>
<i class='fas fa-angle-double-right fa-lg'></i>
<span class='sr-only'>go to last page</span>
</a>";
global $wp_query;
echo "</ul></nav>";
}
}
//end pagination
//Style login page logo
function my_login_logo() { ?>
<style type="text/css">
.login h1 a {
background-image: url(<?php echo get_stylesheet_directory_uri(); ?>/lib/img/blue-earl-brewing.png) !important;
background-size: contain !important;
width: 200px !important;
height: 210px !important
}
body {
}
a:focus {
box-shadow: none;
}
.login form {
background: transparent;
}
.login form::before {
display: block;
content: "Website Administration Area";
margin-top: -20px;
padding-bottom: 20px;
font-size: 18px;
text-align: center;
}
.login label {
font-size: 18px;
font-weight: bold;
color: white;
}
</style>
<?php }
add_action( 'login_enqueue_scripts', 'my_login_logo' );
function my_login_logo_url() {
return home_url();
}
add_filter( 'login_headerurl', 'my_login_logo_url' );
function my_login_logo_url_title() {
return 'Blue Earl Brewing';
}
add_filter( 'login_headertitle', 'my_login_logo_url_title' );
/* End Style Login */
/**
* Disable the emoji's
*/
function disable_emojis() {
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );
remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
add_filter( 'tiny_mce_plugins', 'disable_emojis_tinymce' );
add_filter( 'wp_resource_hints', 'disable_emojis_remove_dns_prefetch', 10, 2 );
}
add_action( 'init', 'disable_emojis' );
function disable_emojis_tinymce( $plugins ) {
if ( is_array( $plugins ) ) {
return array_diff( $plugins, array( 'wpemoji' ) );
} else {
return array();
}
}
function disable_emojis_remove_dns_prefetch( $urls, $relation_type ) {
if ( 'dns-prefetch' == $relation_type ) {
$emoji_svg_url = apply_filters( 'emoji_svg_url', 'https://s.w.org/images/core/emoji/2/svg/' );
$urls = array_diff( $urls, array( $emoji_svg_url ) );
}
return $urls;
}
//ADMIN SECTION FAVICON ITEMS TO <head> SECTION
function craftedBrew_Favicon() {
echo '<link rel="Icon" type="image/x-icon" href="https://blueearlbrewing.com/wp-content/themes/crafted-brew-wordpress-theme/lib/img/favicon-32x32.png" />
<link rel="Shortcut Icon" type="image/x-icon" href="https://blueearlbrewing.com/wp-content/themes/crafted-brew-wordpress-theme/lib/img/favicon-32x32.png" />';
}
add_action( 'login_head', 'craftedBrew_Favicon' );
add_action( 'admin_head', 'craftedBrew_Favicon' );
function register_custom_menu_page() {
add_menu_page('Blue Earl Training Videos', 'Training Videos', 'add_users', 'blueEarl_training_vids', '_custom_menu_page', 'dashicons-video-alt3', 50);
}
add_action('admin_menu', 'register_custom_menu_page');
//Training videos
function _custom_menu_page(){
echo "
<h1>Blue Earl Training Videos</h1><br />
<p>If you would like to request a tutorial video, <a href='mailto:[email protected]'>contact Ben here</a></p>
<h3>Video 1: Events Made Easy</h3>
<video id='eventsMadeEasy' poster='https://blueearlbrewing.com/wp-content/themes/crafted-brew-wordpress-theme/lib/vids/eme-training.png' width='640' height='360' src='https://blueearlbrewing.com/wp-content/themes/crafted-brew-wordpress-theme/lib/vids/eventsMadeEasy.mp4' controls='controls' preload='none'></video>
<br />
<h3 style='color:#ff0000;'>VERY IMPORTANT!</h3>
<p><strong>Use the FEATURED IMAGE for all event images. Do not click the add-media button! This will cause errors with the programming of the featured events on the home page.<br />
<img src='https://blueearlbrewing.com/wp-content/uploads/2018/10/featured-image.png'></strong></p>
<br />
<hr style='border-top:3px solid'>
<h3>Video 2: Featured Home Page Events</h3>
<video id='featuredEvents' poster='https://blueearlbrewing.com/wp-content/themes/crafted-brew-wordpress-theme/lib/vids/featured-event.png' width='640' height='360' src='https://blueearlbrewing.com/wp-content/themes/crafted-brew-wordpress-theme/lib/vids/featured-events.mp4' controls='controls' preload='none'></video>
<br />
<br />
<hr style='border-top:3px solid'>
<h3>Video 3: Store Locator</h3>
<video id='soreLocator' poster='https://blueearlbrewing.com/wp-content/themes/crafted-brew-wordpress-theme/lib/vids/store-locator.png' width='640' height='360' src='https://blueearlbrewing.com/wp-content/themes/crafted-brew-wordpress-theme/lib/vids/store-locator.mp4' controls='controls' preload='none'></video>
<br />
<br />
<hr style='border-top:3px solid'>
";
}