-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
587 lines (514 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
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
<?php
/**
* Logovo functions and definitions
*
* @link https://developer.wordpress.org/themes/basics/theme-functions/
*
* @package Logovo
* @since Logovo 1.0.0
*/
if (! defined('ABSPATH')) {
exit; // Exit if accessed directly.
}
/**
* Define Constants
*/
define('LOGOVO_THEME_VERSION', '1.9.7');
define('LOGOVO_THEME_DIR', trailingslashit(get_template_directory()));
define('LOGOVO_THEME_URI', trailingslashit(esc_url(get_template_directory_uri())));
define('LOGOVO_THEME_ASSETS_URI', LOGOVO_THEME_URI . 'dist');
/**
* Setup theme media.
*/
require LOGOVO_THEME_DIR . 'inc/theme-media.php';
/**
* Enqueues scripts and styles
*/
require LOGOVO_THEME_DIR . 'inc/classes/class-inspiro-enqueue-scripts.php';
/**
* Setup custom wp-admin options pages
*/
require LOGOVO_THEME_DIR . 'inc/classes/class-inspiro-custom-wp-admin-menu.php';
/**
* Additional features to include custom WP pointer function
*/
require LOGOVO_THEME_DIR . 'inc/classes/class-inspiro-wp-admin-menu-pointer.php';
/**
* Functions and definitions.
*/
require LOGOVO_THEME_DIR . 'inc/classes/class-inspiro-after-setup-theme.php';
/**
* Handle SVG icons.
*/
require LOGOVO_THEME_DIR . 'inc/classes/class-inspiro-svg-icons.php';
/**
* Implement the Custom Header feature.
*/
require LOGOVO_THEME_DIR . 'inc/custom-header.php';
/**
* Custom template tags for this theme.
*/
require LOGOVO_THEME_DIR . 'inc/template-tags.php';
/**
* Additional features to allow styling of the templates.
*/
require LOGOVO_THEME_DIR . 'inc/template-functions.php';
/**
* Custom Template WC functions
*/
require LOGOVO_THEME_DIR . 'inc/wc-custom-functions.php';
/**
* Custom template shortcode tags for this theme
*/
// require LOGOVO_THEME_DIR . 'inc/shortcodes.php';
/**
* Customizer additions.
*/
require LOGOVO_THEME_DIR . 'inc/classes/class-inspiro-font-family-manager.php';
require LOGOVO_THEME_DIR . 'inc/classes/class-inspiro-fonts-manager.php';
require LOGOVO_THEME_DIR . 'inc/customizer-functions.php';
require LOGOVO_THEME_DIR . 'inc/customizer/class-inspiro-customizer-control-base.php';
require LOGOVO_THEME_DIR . 'inc/customizer/class-inspiro-customizer.php';
/**
* SVG icons functions and filters.
*/
require LOGOVO_THEME_DIR . 'inc/icon-functions.php';
/**
* Theme admin notices and info page
*/
if (is_admin()) {
require LOGOVO_THEME_DIR . 'inc/admin-notice.php';
require LOGOVO_THEME_DIR . 'inc/admin/admin-api.php';
if (current_user_can('manage_options')) {
require LOGOVO_THEME_DIR . 'inc/classes/class-inspiro-notices.php';
require LOGOVO_THEME_DIR . 'inc/classes/class-inspiro-notice-review.php';
}
}
/**
* Inline theme css generated dynamically
*/
require LOGOVO_THEME_DIR . 'inc/dynamic-css/body.php';
require LOGOVO_THEME_DIR . 'inc/dynamic-css/logo.php';
require LOGOVO_THEME_DIR . 'inc/dynamic-css/headings.php';
require LOGOVO_THEME_DIR . 'inc/dynamic-css/hero-header-title.php';
require LOGOVO_THEME_DIR . 'inc/dynamic-css/hero-header-desc.php';
require LOGOVO_THEME_DIR . 'inc/dynamic-css/hero-header-button.php';
require LOGOVO_THEME_DIR . 'inc/dynamic-css/main-menu.php';
require LOGOVO_THEME_DIR . 'inc/dynamic-css/mobile-menu.php';
/**
* @since 1.0.0
*
* @param string $filename The file name.
* @param string $filetype The file type [css|js].
* @param string $folder The folder name.
* @return string The full assets url.
*/
function inspiro_get_assets_uri($filename, $filetype, $folder = 'assets/')
{
$assets_uri = '';
// Directory and Extension.
$js_uri = LOGOVO_THEME_URI . $folder . 'js/';
$css_uri = LOGOVO_THEME_URI . $folder . 'css/';
if ($filetype === 'css') {
$assets_uri = $css_uri . $filename . '.' . $filetype;
} elseif ($filetype === 'js') {
$assets_uri = $js_uri . $filename . '.' . $filetype;
}
return $assets_uri;
}
/**
* 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 logovo_theme_support()
{
// Add default posts and comments RSS feed links to head.
add_theme_support('automatic-feed-links');
// disable comments feed
add_filter('feed_links_show_comments_feed', '__return_false');
/*
* 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');
remove_image_size('1536x1536');
remove_image_size('2048x2048');
}
add_action('after_setup_theme', 'logovo_theme_support');
/**
* Disable medium_large imag sizes
*/
add_filter('intermediate_image_sizes', function ($sizes) {
return array_diff($sizes, ['medium_large']);
});
/* DISABLE MAX IMAGE SIZE THRESHOLD
================================================== */
add_filter('big_image_size_threshold', '__return_false');
/**
* Add preconnect for Google Fonts.
*
* @since Inspiro 1.0.0
*
* @param array $urls URLs to print for resource hints.
* @param string $relation_type The relation type the URLs are printed.
* @return array URLs to print for resource hints.
*/
function inspiro_resource_hints($urls, $relation_type)
{
if (wp_style_is('inspiro-fonts', 'queue') && 'preconnect' === $relation_type) {
$urls[] = array(
'href' => 'https://fonts.gstatic.com',
'crossorigin',
);
}
return $urls;
}
add_filter('wp_resource_hints', 'inspiro_resource_hints', 10, 2);
/**
* Register widget area.
*
* @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
*/
function inspiro_widgets_init()
{
register_sidebar(
array(
'name' => __('Sidebar', 'inspiro'),
'id' => 'sidebar',
'description' => __('Main sidebar that is displayed on the right and can be toggled by clicking on the menu icon.', 'inspiro'),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '<div class="clear"></div></div>',
'before_title' => '<h3 class="title">',
'after_title' => '</h3>',
)
);
register_sidebar(
array(
'name' => __('Blog Sidebar', 'inspiro'),
'id' => 'blog-sidebar',
'description' => __('Add widgets here to appear in your sidebar on blog posts and archive pages.', 'inspiro'),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="title">',
'after_title' => '</h2>',
)
);
register_sidebar(
array(
'name' => __('Footer 1', 'inspiro'),
'id' => 'footer_1',
'description' => __('Add widgets here to appear in your footer.', 'inspiro'),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="title">',
'after_title' => '</h2>',
)
);
register_sidebar(
array(
'name' => __('Footer 2', 'inspiro'),
'id' => 'footer_2',
'description' => __('Add widgets here to appear in your footer.', 'inspiro'),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="title">',
'after_title' => '</h2>',
)
);
register_sidebar(
array(
'name' => __('Footer 3', 'inspiro'),
'id' => 'footer_3',
'description' => __('Add widgets here to appear in your footer.', 'inspiro'),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="title">',
'after_title' => '</h2>',
)
);
register_sidebar(
array(
'name' => __('Footer 4', 'inspiro'),
'id' => 'footer_4',
'description' => __('Add widgets here to appear in your footer.', 'inspiro'),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="title">',
'after_title' => '</h2>',
)
);
register_sidebar(
array(
'name' => __('Header Social Icons', 'inspiro'),
'id' => 'header_social',
'description' => __('Widget area in the header. Install the "Social Icons Widget by WPZOOM" plugin and add the widget here.', 'inspiro'),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="title"><span>',
'after_title' => '</span></h3>',
)
);
register_sidebar(
array(
'name' => __('Footer Instagram Bar', 'inspiro'),
'id' => 'footer_instagram_section',
'description' => __('Widget area for "Instagram widget by WPZOOM".', 'inspiro'),
'before_widget' => '<section class="widget %2$s" id="%1$s">',
'after_widget' => '<div class="clear"></div></section>',
'before_title' => '<h3 class="title">',
'after_title' => '</h3>',
)
);
}
add_action('widgets_init', 'inspiro_widgets_init');
/**
* Replaces "[...]" (appended to automatically generated excerpts) with ... and
* a 'Read more' link.
*
* @since Inspiro 1.0.0
*
* @param string $link Link to single post/page.
* @return string 'Read more' link prepended with an ellipsis.
*/
function inspiro_excerpt_more($link)
{
if (is_admin()) {
return $link;
}
$link = sprintf(
'<p class="link-more"><a href="%1$s" class="more-link">%2$s</a></p>',
esc_url(get_permalink(get_the_ID())),
/* translators: %s: Post title. */
sprintf(__('Read more<span class="screen-reader-text"> "%s"</span>', 'inspiro'), get_the_title(get_the_ID()))
);
return ' … ' . $link;
}
add_filter('excerpt_more', 'inspiro_excerpt_more');
/**
* Filters the `sizes` value in the header image markup.
*
* @since Inspiro 1.0.0
*
* @param string $html The HTML image tag markup being filtered.
* @param object $header The custom header object returned by 'get_custom_header()'.
* @param array $attr Array of the attributes for the image tag.
* @return string The filtered header image HTML.
*/
function inspiro_header_image_tag($html, $header, $attr)
{
if (isset($attr['sizes'])) {
$html = str_replace($attr['sizes'], '100vw', $html);
}
return $html;
}
add_filter('get_header_image_tag', 'inspiro_header_image_tag', 10, 3);
/**
* Add custom image sizes attribute to enhance responsive image functionality
* for post thumbnails.
*
* @since Inspiro 1.0.0
*
* @param array $attr Attributes for the image markup.
* @param int $attachment Image attachment ID.
* @param array $size Registered image size or flat array of height and width dimensions.
* @return array The filtered attributes for the image markup.
*/
function inspiro_post_thumbnail_sizes_attr($attr, $attachment, $size)
{
if (is_archive() || is_search() || is_home()) {
$attr['sizes'] = '(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px';
} else {
$attr['sizes'] = '100vw';
}
return $attr;
}
add_filter('wp_get_attachment_image_attributes', 'inspiro_post_thumbnail_sizes_attr', 10, 3);
/**
* Modifies tag cloud widget arguments to display all tags in the same font size
* and use list format for better accessibility.
*
* @since Inspiro 1.0.0
*
* @param array $args Arguments for tag cloud widget.
* @return array The filtered arguments for tag cloud widget.
*/
function inspiro_widget_tag_cloud_args($args)
{
$args['largest'] = 1;
$args['smallest'] = 1;
$args['unit'] = 'em';
$args['format'] = 'list';
return $args;
}
add_filter('widget_tag_cloud_args', 'inspiro_widget_tag_cloud_args');
/**
* Gets unique ID.
*
* This is a PHP implementation of Underscore's uniqueId method. A static variable
* contains an integer that is incremented with each call. This number is returned
* with the optional prefix. As such the returned value is not universally unique,
* but it is unique across the life of the PHP process.
*
* @since Inspiro 1.0.0
*
* @see wp_unique_id() Themes requiring WordPress 5.0.3 and greater should use this instead.
*
* @param string $prefix Prefix for the returned ID.
* @return string Unique ID.
*/
function inspiro_unique_id($prefix = '')
{
static $id_counter = 0;
if (function_exists('wp_unique_id')) {
return wp_unique_id($prefix);
}
return $prefix . (string) ++$id_counter;
}
/**
* Show custom logo or blog title and description (backward compatibility)
*/
function inspiro_custom_logo()
{
has_custom_logo() ? the_custom_logo() : printf('<a href="%1$s" title="%2$s" class="custom-logo-text">%3$s</a>', esc_url(home_url()), esc_html(get_bloginfo('description')), esc_html(inspiro_get_theme_mod('custom_logo_text')));
}
/**
* Displays the sidebar after the openning <body> tag.
*/
function display_sidebar_body_open()
{
get_sidebar();
}
add_action('wp_body_open', 'display_sidebar_body_open');
if (! function_exists('inspiro_comment')) {
/**
* Custom Comments Template
*
* @param string $comment Comment text.
* @param array $args Comment args.
* @param boolean $depth Comment depth.
* @return void
*/
function inspiro_comment($comment, $args, $depth)
{
$GLOBALS['comment'] = $comment; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
switch ($comment->comment_type):
case '':
case 'comment':
?>
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
<div id="comment-<?php comment_ID(); ?>">
<div class="comment-author vcard">
<?php echo get_avatar($comment, 50); ?>
<?php printf('<cite class="fn">%s</cite>', get_comment_author_link()); ?>
<div class="comment-meta commentmetadata"><a
href="<?php echo esc_url(get_comment_link($comment->comment_ID)); ?>">
<?php
/* translators: %1$s: Comment date %2$s: Comment time */
printf(__('%1$s @ %2$s', 'inspiro'), get_comment_date(), get_comment_time()); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
?>
</a>
<?php
comment_reply_link(
array_merge(
$args,
array(
'depth' => $depth,
'max_depth' => $args['max_depth'],
'reply_text' => __('Reply', 'inspiro'),
'before' => ' · ',
)
)
);
?>
<?php edit_comment_link(__('Edit', 'inspiro'), ' · '); ?>
</div>
<!-- .comment-meta .commentmetadata -->
</div>
<!-- .comment-author .vcard -->
<?php if ('0' === $comment->comment_approved) : ?>
<em class="comment-awaiting-moderation"><?php esc_html_e('Your comment is awaiting moderation.', 'inspiro'); ?></em>
<br />
<?php endif; ?>
<div class="comment-body"><?php comment_text(); ?></div>
</div><!-- #comment-<?php comment_ID(); ?> -->
<?php
break;
case 'pingback':
case 'trackback':
?>
<li class="post pingback">
<p><?php esc_html_e('Pingback:', 'inspiro'); ?><?php comment_author_link(); ?><?php edit_comment_link(__('(Edit)', 'inspiro'), ' '); ?></p>
<?php
break;
endswitch;
}
}
/**
* WooCommerce compatibility.
*/
if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) {
add_theme_support('woocommerce');
add_theme_support('wc-product-gallery-zoom');
add_theme_support('wc-product-gallery-lightbox');
add_theme_support('wc-product-gallery-slider');
}
if (! function_exists('inspiro_get_prop')) :
/**
* Get a specific property of an array without needing to check if that property exists.
*
* Provide a default value if you want to return a specific value if the property is not set.
*
* @since 1.3.0
* @access public
* @author Gravity Forms - Easiest Tool to Create Advanced Forms for Your WordPress-Powered Website.
* @link https://www.gravityforms.com/
*
* @param array $array Array from which the property's value should be retrieved.
* @param string $prop Name of the property to be retrieved.
* @param string $default Optional. Value that should be returned if the property is not set or empty. Defaults to null.
*
* @return null|string|mixed The value
*/
function inspiro_get_prop($array, $prop, $default = null)
{
if (! is_array($array) && ! (is_object($array) && $array instanceof ArrayAccess)) {
return $default;
}
if ((isset($array[$prop]) && false === $array[$prop])) {
return false;
}
if (isset($array[$prop])) {
$value = $array[$prop];
} else {
$value = '';
}
return empty($value) && null !== $default ? $default : $value;
}
endif;
if (! function_exists('inspiro_get_page_by_title')) {
function inspiro_get_page_by_title($page_title)
{
$posts = get_posts(
array(
'post_type' => 'page',
'title' => $page_title,
'post_status' => 'all',
'numberposts' => 1,
'update_post_term_cache' => false,
'update_post_meta_cache' => false,
'orderby' => 'post_date ID',
'order' => 'ASC',
)
);
if (! empty($posts)) {
$page_got_by_title = $posts[0];
} else {
$page_got_by_title = null;
}
return $page_got_by_title;
}
}