-
Notifications
You must be signed in to change notification settings - Fork 7
/
functions.php
375 lines (312 loc) · 14.4 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
<?php
/*
* Custom functions, support, custom post types and more.
*/
/*------------------------------------*\
External Modules/Files
\*------------------------------------*/
// Load any external files you have here
/*------------------------------------*\
Theme Support
\*------------------------------------*/
if( function_exists('acf_add_options_page') ) {
acf_add_options_page();
}
if (!isset($content_width))
{
$content_width = 900;
}
function cc_mime_types($mimes) {
$mimes['svg'] = 'image/svg+xml';
$mimes['exe'] = 'application/exe';
$mimes['ai'] = 'application/postscript';
$mimes['eps'] = 'application/postscript';
// Override WP incorrect MIME type for PGP keys in ASC format
unset( $mimes['txt|asc|c|cc|h|srt'] );
$mimes['txt|c|cc|h|srt'] = 'text/plain';
$mimes['asc'] = 'application/pgp-keys';
return $mimes;
}
add_filter('upload_mimes', 'cc_mime_types');
add_action('admin_head', 'custom_styles');
function custom_styles() {
// "global" field set and big section block indicators
echo '<style>
.field-content_sections .acf-fields {
border-bottom: 3px solid #666;
}
</style>';
}
if (function_exists('add_theme_support'))
{
// Add Menu Support
// add_theme_support('menus');
// Add Thumbnail Theme Support
add_theme_support('post-thumbnails');
add_image_size('news_thumb', 680, 280, true); // Large Thumbnail
// Enables post and comment RSS feed links to head
add_theme_support('automatic-feed-links');
// Localisation Support
load_theme_textdomain('html5blank', get_template_directory() . '/languages');
}
/*------------------------------------*\
Functions
\*------------------------------------*/
function theme_scripts()
{
if ($GLOBALS['pagenow'] != 'wp-login.php' && !is_admin()) {
//Cannot register custom jQuery without deregistering Wordpress version first. Wordpress version works fine, only enqueue is required.
//wp_register_script('jquery', get_template_directory_uri() . '/assets/libs/jquery.min.js',[],false,true);
wp_enqueue_script('jquery');
wp_register_script('modernizr', get_template_directory_uri() . '/assets/libs/modernizr.js',[],false,true);
wp_enqueue_script('modernizr');
wp_register_script('bootstrap', get_template_directory_uri() . '/assets/libs/bootstrap.js',[],'4.3.1-0',true);
wp_enqueue_script('bootstrap');
wp_register_script('fancybox','https://cdn.jsdelivr.net/gh/fancyapps/[email protected]/dist/jquery.fancybox.min.js',[],false,true);
wp_enqueue_script('fancybox');
wp_register_script('slick', get_template_directory_uri() . '/assets/libs/slick.js',[],false,true);
wp_enqueue_script('slick');
wp_register_script('scrollreveal', get_template_directory_uri() . '/assets/libs/scrollreveal.min.js',[],false,true);
wp_enqueue_script('scrollreveal');
wp_register_script('countup', get_template_directory_uri() . '/assets/libs/countup.js',[],false,true);
wp_enqueue_script('countup');
wp_register_script('waypoints', get_template_directory_uri() . '/assets/libs/waypoints-with-inview.js',[],false,true);
wp_enqueue_script('waypoints');
wp_register_script('selectric', get_template_directory_uri() . '/assets/libs/jquery.selectric.js',[],false,true);
wp_enqueue_script('selectric');
// change to vue.min.js for prod to get rid of debugger
//wp_register_script('vue','https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js',[],false,true);
wp_register_script('vue','https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.min.js',[],false,true);
wp_enqueue_script('vue');
wp_register_script('trustpilot','https://widget.trustpilot.com/bootstrap/v5/tp.widget.bootstrap.min.js',[],false,true);
wp_enqueue_script('trustpilot');
wp_register_script('dash', get_template_directory_uri() . '/assets/dash.js',[],'1.68',true);
wp_enqueue_script('dash');
wp_register_script('vue-buyspend', get_template_directory_uri() . '/assets/vue-buyspend.js',[],'1.21',true);
wp_enqueue_script('vue-buyspend');
wp_register_script('vue-proposals', get_template_directory_uri() . '/assets/vue-proposals.js',[],false,true);
wp_enqueue_script('vue-proposals');
wp_register_script('vue-team', get_template_directory_uri() . '/assets/vue-team.js',[],false,true);
wp_enqueue_script('vue-team');
if (is_page_template( 'page-downloads.php' || 'page-lg.php' )) {
wp_register_script('platform', get_template_directory_uri() . '/assets/libs/platform.js',[],false,false);
wp_enqueue_script('platform');
}
if (is_page_template( 'page-downloads.php' )) {
wp_register_script('downloads', get_template_directory_uri() . '/assets/downloads.js',[],'1.22',false);
wp_enqueue_script('downloads');
$translation_array = array(
'download_windows' => __( 'Download for Windows' ),
'download_macos' => __( 'Download for macOS'),
'download_linux' => __('Download for Linux'),
'download_android' => __('Download for Android'),
'download_ios' => __('Download for iOS')
);
wp_localize_script( 'downloads', 'download_texts', $translation_array );
}
}
}
// Load HTML5 Blank styles
function theme_styles()
{
wp_register_style('bootstrapcss', get_template_directory_uri() . '/assets/libs/bootstrap-rtl.css', array(), '4.3.1-0', 'all');
wp_enqueue_style('bootstrapcss');
wp_register_style('slick', get_template_directory_uri() . '/assets/libs/slick.css', array(), '1.0', 'all');
wp_enqueue_style('slick');
wp_register_style('selectric', get_template_directory_uri() . '/assets/libs/selectric.css', array(), '1.0', 'all');
wp_enqueue_style('selectric');
wp_register_style('fancyboxcss', 'https://cdn.jsdelivr.net/gh/fancyapps/[email protected]/dist/jquery.fancybox.min.css', '1.0', 'all');
wp_enqueue_style('fancyboxcss');
// Remove time() and replace with static version number after strophy finishes fixing CSS
wp_register_style('dashcss', get_template_directory_uri() . '/assets/dash.css', array(), '1.73', 'all');
wp_enqueue_style('dashcss');
}
// Sort exchange list page in alphabetical order: https://www.advancedcustomfields.com/resources/how-to-sorting-a-repeater-field/
function my_acf_load_exchanges_value( $value, $post_id, $field ) {
$order = array();
if( empty($value) ) {
return $value;
}
foreach( $value as $i => $row ) {
$order[ $i ] = $row['field_5bd68218140e4'];
}
array_multisort( $order, SORT_ASC, $value );
return $value;
}
add_filter('acf/load_value/name=full_list_vendors', 'my_acf_load_exchanges_value', 10, 3);
// Sort versions list page in reverse alphabetical order
function my_acf_load_lg_content_value( $value, $post_id, $field ) {
$order = array();
if( empty($value) ) {
return $value;
}
if (get_field('reverse_sort_order')) {
foreach( $value as $i => $row ) {
$order[ $i ] = $row['field_5bc58abeada0a'];
}
array_multisort( $order, SORT_DESC, $value );
return $value;
} else {
return $value;
}
}
add_filter('acf/load_value/name=content_sections', 'my_acf_load_lg_content_value', 10, 3);
// Remove the <div> surrounding the dynamic navigation to cleanup markup
function my_wp_nav_menu_args($args = '')
{
$args['container'] = false;
return $args;
}
// Remove Injected classes, ID's and Page ID's from Navigation <li> items
function my_css_attributes_filter($var)
{
return is_array($var) ? array() : '';
}
// Remove invalid rel attribute values in the categorylist
function remove_category_rel_from_category_list($thelist)
{
return str_replace('rel="category tag"', 'rel="tag"', $thelist);
}
// Add page slug to body class, love this - Credit: Starkers Wordpress Theme
function add_slug_to_body_class($classes)
{
global $post;
if (is_home()) {
$key = array_search('blog', $classes);
if ($key > -1) {
unset($classes[$key]);
}
} elseif (is_page()) {
$classes[] = sanitize_html_class($post->post_name);
} elseif (is_singular()) {
$classes[] = sanitize_html_class($post->post_name);
}
return $classes;
}
// Remove wp_head() injected Recent Comment styles
function my_remove_recent_comments_style()
{
global $wp_widget_factory;
remove_action('wp_head', array(
$wp_widget_factory->widgets['WP_Widget_Recent_Comments'],
'recent_comments_style'
));
}
// Pagination for paged posts, Page 1, Page 2, Page 3, with Next and Previous Links, No plugin
function html5wp_pagination()
{
global $wp_query;
$big = 999999999;
echo paginate_links(array(
'base' => str_replace($big, '%#%', get_pagenum_link($big)),
'format' => '?paged=%#%',
'current' => max(1, get_query_var('paged')),
'total' => $wp_query->max_num_pages
));
}
// Custom Excerpts
function html5wp_index($length) // Create 20 Word Callback for Index page Excerpts, call using html5wp_excerpt('html5wp_index');
{
return 20;
}
// Create 40 Word Callback for Custom Post Excerpts, call using html5wp_excerpt('html5wp_custom_post');
function html5wp_custom_post($length)
{
return 40;
}
// Create the Custom Excerpts callback
function html5wp_excerpt($length_callback = '', $more_callback = '')
{
global $post;
if (function_exists($length_callback)) {
add_filter('excerpt_length', $length_callback);
}
if (function_exists($more_callback)) {
add_filter('excerpt_more', $more_callback);
}
$output = wp_trim_excerpt();
$output = apply_filters('wptexturize', $output);
$output = apply_filters('convert_chars', $output);
$output = '<p>' . $output . '</p>';
echo $output;
}
// End of post excerpt
function html5_blank_view_article($more)
{
global $post;
// return '... <a class="view-article" href="' . get_permalink($post->ID) . '">' . __('View Article', 'html5blank') . '</a>';
return "...";
}
// Remove Admin bar
function remove_admin_bar()
{
return false;
}
// Remove 'text/css' from our enqueued stylesheet
function html5_style_remove($tag)
{
return preg_replace('~\s+type=["\'][^"\']++["\']~', '', $tag);
}
// Remove thumbnail width and height dimensions that prevent fluid images in the_thumbnail
function remove_thumbnail_dimensions( $html )
{
$html = preg_replace('/(width|height)=\"\d*\"\s/', "", $html);
return $html;
}
// Custom Gravatar in Settings > Discussion
function html5blankgravatar ($avatar_defaults)
{
$myavatar = get_template_directory_uri() . '/img/gravatar.jpg';
$avatar_defaults[$myavatar] = "Custom Gravatar";
return $avatar_defaults;
}
// Load css file only for Home Page
function load_home_styles() {
if ( is_front_page() ) {
wp_enqueue_style( 'home-css', get_template_directory_uri() . '/assets/home.css', array(), '1.71', 'all' );
}
}
add_action( 'wp_enqueue_scripts', 'load_home_styles' );
/*------------------------------------*\
Actions + Filters + ShortCodes
\*------------------------------------*/
// Add Actions
add_action('wp_enqueue_scripts', 'theme_scripts'); // Add Custom Scripts to wp_head. This should be done in wp_enqueue_scripts, not init.
add_action('wp_enqueue_scripts', 'theme_styles'); // Add Theme Stylesheet
add_action('widgets_init', 'my_remove_recent_comments_style'); // Remove inline Recent Comment Styles from wp_head()
add_action('init', 'html5wp_pagination'); // Add our HTML5 Pagination
// Remove Actions
remove_action('wp_head', 'feed_links_extra', 3); // Display the links to the extra feeds such as category feeds
remove_action('wp_head', 'feed_links', 2); // Display the links to the general feeds: Post and Comment Feed
remove_action('wp_head', 'rsd_link'); // Display the link to the Really Simple Discovery service endpoint, EditURI link
remove_action('wp_head', 'wlwmanifest_link'); // Display the link to the Windows Live Writer manifest file.
remove_action('wp_head', 'index_rel_link'); // Index link
remove_action('wp_head', 'parent_post_rel_link', 10, 0); // Prev link
remove_action('wp_head', 'start_post_rel_link', 10, 0); // Start link
remove_action('wp_head', 'adjacent_posts_rel_link', 10, 0); // Display relational links for the posts adjacent to the current post.
remove_action('wp_head', 'wp_generator'); // Display the XHTML generator that is generated on the wp_head hook, WP version
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);
remove_action('wp_head', 'rel_canonical');
remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0);
remove_action( 'wp_head', 'wp_oembed_add_discovery_links', 10 ); // Display the oEmbed discovery links
remove_action( 'wp_head', 'wp_oembed_add_host_js' ); // Include link to wp-embed.min.js
remove_action('rest_api_init', 'wp_oembed_register_route'); // Register REST API
remove_filter('oembed_dataparse', 'wp_filter_oembed_result', 10);
// Add Filters
add_filter('avatar_defaults', 'html5blankgravatar'); // Custom Gravatar in Settings > Discussion
add_filter('body_class', 'add_slug_to_body_class'); // Add slug to body class (Starkers build)
add_filter('widget_text', 'do_shortcode'); // Allow shortcodes in Dynamic Sidebar
add_filter('widget_text', 'shortcode_unautop'); // Remove <p> tags in Dynamic Sidebars (better!)
add_filter('wp_nav_menu_args', 'my_wp_nav_menu_args'); // Remove surrounding <div> from WP Navigation
add_filter('the_category', 'remove_category_rel_from_category_list'); // Remove invalid rel attribute
add_filter('the_excerpt', 'shortcode_unautop'); // Remove auto <p> tags in Excerpt (Manual Excerpts only)
add_filter('the_excerpt', 'do_shortcode'); // Allows Shortcodes to be executed in Excerpt (Manual Excerpts only)
add_filter('excerpt_more', 'html5_blank_view_article'); // Add 'View Article' button instead of [...] for Excerpts
add_filter('show_admin_bar', 'remove_admin_bar'); // Remove Admin bar
add_filter('style_loader_tag', 'html5_style_remove'); // Remove 'text/css' from enqueued stylesheet
add_filter('post_thumbnail_html', 'remove_thumbnail_dimensions', 10); // Remove width and height dynamic attributes to thumbnails
add_filter('image_send_to_editor', 'remove_thumbnail_dimensions', 10); // Remove width and height dynamic attributes to post images
add_filter ('ssp_use_geo_redirect', '__return_false' ); // Turn off the language redirect
// Remove Filters
remove_filter('the_excerpt', 'wpautop'); // Remove <p> tags from Excerpt altogether
?>