-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom-functions.php
More file actions
681 lines (620 loc) · 18.3 KB
/
custom-functions.php
File metadata and controls
681 lines (620 loc) · 18.3 KB
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
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
<?php
/**
* Necessary function, which can be used in making of theme
* for client or ThemeForest or helper plugin for page builder.
*/
/**
* Those two functions are for set and get attribute for html tag.
* Example:- for set attribute
* prefix_set_attribute([
* 'wrapper' => [
* 'class' => 'button-wrapper',
* ],
* 'align' => [
* 'class' => [
* 'button-icon',
* 'align-icon',
* ],
* ],
* 'img' => [
* 'src' => "https://github.com/iqbalrony/",
* ],
* ]);
* ---------------OR------------------
* prefix_set_attribute('wrapper','class','button-wrapper');
* prefix_set_attribute('align','class',array('button-icon','align-icon'));
* prefix_set_attribute('img','src',"https://github.com/iqbalrony/");
*
* Example:- for get attribute
* prefix_set_attribute('wrapper');
* prefix_set_attribute('align');
* prefix_set_attribute('img');
*/
$GLOBALS['prefix_render_attributes'] = array();
function prefix_set_attribute($element, $key = null, $value = null) {
global $prefix_render_attributes;
if (is_array($element)) {
foreach ($element as $element_key => $attributes) {
prefix_set_attribute($element_key, $attributes, null);
}
return;
}
if (is_array($key)) {
foreach ($key as $attribute_key => $attributes) {
prefix_set_attribute($element, $attribute_key, $attributes);
}
return;
}
if (empty($prefix_render_attributes[$element][$key])) {
$prefix_render_attributes[$element][$key] = [];
}
settype($value, 'array');
$prefix_render_attributes[$element][$key] = $value;
return $prefix_render_attributes;
}
function prefix_get_attribute_string($element) {
global $prefix_render_attributes;
if (empty($prefix_render_attributes[$element])) {
return '';
}
$attributes = array();
$attributes = $prefix_render_attributes[$element];
$rendered_attributes = [];
foreach ($attributes as $attribute_key => $attribute_values) {
if (is_array($attribute_values)) {
$attribute_values = implode(' ', $attribute_values);
}
$rendered_attributes[] = sprintf('%1$s="%2$s"', $attribute_key, esc_attr($attribute_values));
}
return implode(' ', $rendered_attributes);
}
/**
* Get all Post list
*/
if (!function_exists('prefix_get_all_posts')) {
function prefix_get_all_posts($posttype = 'post') {
$args = array(
'post_type' => $posttype,
'post_status' => 'publish',
'posts_per_page' => -1
);
$post_list = array();
if ($data = get_posts($args)) {
foreach ($data as $key) {
$post_list[$key->ID] = $key->post_title;
}
}
return $post_list;
}
}
/**
* Get all Taxonomy list
*/
if (!function_exists('prefix_get_taxonomy_list')) {
function prefix_get_taxonomy_list($taxonomy = 'category') {
$taxonomy_exist = taxonomy_exists($taxonomy);
if (!$taxonomy_exist) {
return;
}
$terms = get_terms(array(
'taxonomy' => $taxonomy,
'hide_empty' => false
));
$get_terms = array();
if (!empty($terms)) {
foreach ($terms as $term) :
$get_terms[$term->slug] = $term->name;
endforeach;
}
return $get_terms;
}
}
/**
* Get all Contact form 7 list
*/
if (!function_exists('prefix_get_contact_form7')) {
function prefix_get_contact_form7() {
if (!post_type_exists('wpcf7_contact_form')) {
return array();
}
$args = array(
'posts_per_page' => -1,
'post_type' => 'wpcf7_contact_form',
);
$posts_array = get_posts($args);
$posts_title = array();
//$posts_title = array('' => '-- Select form --', );
foreach ($posts_array as $post) {
$posts_title[$post->ID] = $post->post_title;
}
return $posts_title;
}
}
/**
* Function for ekoo
*/
if (!function_exists('prefix_ekoo')) {
function prefix_ekoo($item) {
return $item;
}
}
/**
* Function for Allow HTML Tag
*/
if (!function_exists('prefix_allowed_html')) {
function prefix_allowed_html($string) {
$allowed_html = array(
'div' => array(
'id' => array(),
'class' => array()
),
'p' => array(
'id' => array(),
'class' => array()
),
'span' => array(
'class' => array()
),
'img' => array(
'src' => array(),
'alt' => array(),
'class' => array()
),
'a' => array(
'href' => array(),
'title' => array(),
'class' => array()
),
'i' => array(
'class' => array()
),
'br' => array(),
'em' => array(),
'strong' => array(),
);
return wp_kses($string, $allowed_html);
}
}
/**
* Function for convert Hex To Rgb Color
*/
if (!function_exists('prefixHexToRgb')) {
function prefixHexToRgb($hex, $alpha = '', $type = 'string') {
if (!empty($hex) && strpos($hex, '#') != 0) {
return;
}
$hex = str_replace('#', '', $hex);
$length = strlen($hex);
$rgb['r'] = hexdec($length == 6 ? substr($hex, 0, 2) : ($length == 3 ? str_repeat(substr($hex, 0, 1), 2) : 0));
$rgb['g'] = hexdec($length == 6 ? substr($hex, 2, 2) : ($length == 3 ? str_repeat(substr($hex, 1, 1), 2) : 0));
$rgb['b'] = hexdec($length == 6 ? substr($hex, 4, 2) : ($length == 3 ? str_repeat(substr($hex, 2, 1), 2) : 0));
if (!empty($alpha)) {
$rgb['a'] = $alpha;
}
if ($type == 'string') {
if (!empty($alpha)) {
$rgb = 'rgba(' . implode(', ', $rgb) . ')';
} else {
$rgb = 'rgb(' . implode(', ', $rgb) . ')';
}
}
return $rgb;
}
}
/**
* Function for custom excerpt
*/
if (!function_exists('prefix_excerpt')) {
function prefix_excerpt($sl_length = '', $sl_sign = '') {
if (empty($sl_length)) {
$length = apply_filters('prefix_excerpt_length', 23);
} else {
$length = $sl_length;
}
if (empty($sl_sign)) {
$more = apply_filters('prefix_excerpt_more', '');
} else {
$more = $sl_sign;
}
printf('<p>%1$s</p>',
wp_trim_words(get_the_content(), $length, $more)
);
}
}
/**
* Register Google fonts.
*/
if (!function_exists('prefix_fonts_url')) {
function prefix_fonts_url() {
$fonts_url = '';
$fonts = array();
$subsets = 'latin,latin-ext';
/*translators: If there are characters in your language that are not supported by Merriweather, translate this to 'off'. Do not translate into your own language.*/
if ('off' !== _x('on', 'Muli: on or off', 'text_domain')) {
$fonts[] = 'Muli:400,600,700';
}
if ($fonts) {
$fonts_url = add_query_arg(array(
'family' => urlencode(implode('|', $fonts)),
'subset' => urlencode($subsets),
), 'https://fonts.googleapis.com/css');
}
return $fonts_url;
}
}
/**
* Function for get cmb2 Meta value
*/
if (!function_exists('prefix_page_option')) {
function prefix_page_option($uniq_id) {
if (defined('CMB2_LOADED') && !is_home() && !is_archive() && !is_search() && !is_404()) {
return get_post_meta(get_the_ID(), $uniq_id, true);
} else {
return '';
}
}
}
/**
* Function for Page Layout Option
*/
if (!function_exists('prefix_page_layout')) {
function prefix_page_layout() {
$prefix_customizer = get_theme_mod('prefix_page_layout', 'right');
$page_layout_option = prefix_page_option('_prefix_page_layout_option');
$prefix_page = !empty($page_layout_option) ? $page_layout_option : 'default';
$layout = $prefix_page;
if (empty($layout) || $layout == 'default') {
$layout = $prefix_customizer;
}
if (!is_active_sidebar('sidebar-1')) {
$layout = 'without';
}
return $layout;
}
}
/**
* Function for default blog paginations
*/
if (!function_exists('prefix_blog_paginations')) {
function prefix_blog_paginations() {
$args = array(
'prev_text' => '<i class="ti-angle-left"></i>',
'next_text' => '<i class="ti-angle-right"></i>',
'type' => 'list'
);
echo paginate_links($args);
}
}
/**
* Function for default blog paginations2
*/
if (!function_exists('prefix_blog_paginations2')) {
function prefix_blog_paginations2($the_query = '') {
if (empty($the_query)) {
global $wp_query;
$the_query = $wp_query;
}
$big = 999999999; // need an unlikely integer
$html = paginate_links(array(
'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
'format' => '/page/%#%',
'current' => max(1, get_query_var('paged')),
'total' => $the_query->max_num_pages,
'end_size' => 2,
'prev_text' => '<i class="ti-angle-left"></i>',
'next_text' => '<i class="ti-angle-right"></i>',
));
$pretext = '<i class="ti-angle-left"></i>';
$posttext = '<i class="ti-angle-right"></i>';
$pre_deco = '<a href="" class="prev page-numbers custom">' . $pretext . '</a>';
$post_deco = '<a href="" class="next page-numbers custom">' . $posttext . '</a>';
$paged = get_query_var('paged') ? absint(get_query_var('paged')) : 1;
if (1 === $paged) {
$html = $pre_deco . $html;
}
if ($the_query->max_num_pages == $paged) {
$html = $html . $post_deco;
}
if (1 != $the_query->max_num_pages) {
echo '<div class="custom-pagination">' . prefix_ekoo($html) . '</div>';
} else {
return;
}
}
}
/**
* Function for comments paginations
*/
if (!function_exists('prefix_comments_paginations')) {
function prefix_comments_paginations() {
$args = array(
'prev_text' => '<i class="ti-angle-left"></i>',
'next_text' => '<i class="ti-angle-right"></i>',
'type' => 'list'
);
paginate_comments_links($args);
}
}
/**
* Function for blog author
*/
if (!function_exists('prefix_blog_author')) {
function prefix_blog_author($style = '') {
if ('style-1' == $style) {
$span_tag = '<span>' . esc_html__('Posted By: ', 'text_domain') . '</span>';
} else {
$span_tag = '';
}
$author_id = get_post_field('post_author', get_the_ID());
$author_name = get_the_author_meta('display_name', $author_id);
$url = get_author_posts_url($author_id);
$author = '<div class="author">' . $span_tag . '<a href="' . esc_url($url) . '">' . esc_html($author_name) . '</a></div>';
print_r($author);
}
}
/**
* Function for post date
*/
if (!function_exists('prefix_post_on')) {
function prefix_post_on($style = '') {
if ('style-1' == $style) {
$span_tag = '<span>' . esc_html__('Posted : ', 'text_domain') . '</span>';
} else {
$span_tag = '';
}
$year = get_the_date('Y');
$month = get_the_time('m');
$day = get_the_time('d');
$url = get_day_link($year, $month, $day);
$date = '<div class="date">' . $span_tag . '<a href="' . esc_url($url) . '">' . esc_html(get_the_date('d M Y')) . '</a></div>';
print_r($date);
}
}
/**
* Function for post categories list
*/
if (!function_exists('prefix_cat_list')) {
function prefix_cat_list($style = '', $space = ', ') {
/* translators: used between list items, there is a space after the comma */
$categories_list = get_the_category_list($space);
$span_tag = '';
if ( 'style-1' == $style ) {
$span_tag = '<span>' . esc_html__('Categories: ', 'text_domain') . '</span>';
}
if ($categories_list) {
/* translators: 1: list of categories. */
printf('<div class="cat-links">%1$s %2$s</div>', $span_tag, $categories_list);
}
}
}
/**
* Function for post's single category (default category)
*/
if (!function_exists('prefix_single_cat')) {
function prefix_single_cat($style = '') {
if ('style-1' == $style) {
$span_tag = '<span>' . esc_html__('Category: ', 'text_domain') . '</span>';
} else {
$span_tag = '';
}
$cats = get_the_category(get_the_ID());
if (!empty($cats) && isset($cats[0]->name)) {
printf('<div class="single-cat">%1$s<a href="%2$s" class="cat-links">%3$s</a></div>', $span_tag, get_category_link($cats[0]->term_id), esc_html($cats[0]->name));
}
}
}
/**
* Function for show default post tags list
*/
if (!function_exists('prefix_tags_list')) {
function prefix_tags_list($style = '') {
if ('style-1' == $style) {
$span_tag = '<span>' . esc_html__('Tag: ', 'text_domain') . '</span>';
} else {
$span_tag = '';
}
/* translators: used between list items, there is a space after the comma */
$tags_list = get_the_tag_list('', ' ');
if ($tags_list) {
/* translators: 1: list of tags. */
printf('<div class="tags-links">%1$s %2$s</div>', $span_tag, $tags_list); // WPCS: XSS OK.
}
}
}
/**
* Function for get single taxonomy
*/
if (!function_exists('prefix_get_comment_number')) {
function prefix_get_comment_number($taxonomy = 'post_tag') {
$taxonomy_exist = taxonomy_exists($taxonomy);
if (!$taxonomy_exist) {
return;
}
$prefix_terms = get_the_terms(get_the_id(), $taxonomy);
$single_cat = '';
$i = 0;
if (is_array($prefix_terms)) {
foreach ($prefix_terms as $prefix_term) {
$prefix_link = get_term_link($prefix_term);
$prefix_term_name = $prefix_term->name;
$single_cat = sprintf('<div class="single-cat"><a href="%1$s" class="cat-links">%2$s </a></div>', $prefix_link, $prefix_term_name);
if ($i == 0) {
break;
}
}
}
return $single_cat;
}
}
/**
* Function for get comment number
*/
if (!function_exists('prefix_get_comment_number')) {
function prefix_get_comment_number($style = '', $link = true) {
$number = get_comments_number(get_the_ID());
if ('style-1' == $style) {
$span_tag = '<span>' . esc_html__('Comments: ', 'text_domain') . '</span>';
} else {
$span_tag = '';
}
if ($link == true) {
printf('<div class="comments-number">%1$s<a href="%2$s">%3$s</a></div>', $span_tag, get_comments_link(), $number);
} else {
printf('<div class="comments-number">%1$s%2$s</div>', $span_tag, $number);
}
}
}
/**
* Custom Archive Title modifier
*/
if (!function_exists('prefix_get_the_archive_title')) {
function prefix_get_the_archive_title() {
if (is_category()) {
/* translators: Category archive title. 1: Category name */
$title = single_cat_title('', false);
} elseif (is_tag()) {
/* translators: Tag archive title. 1: Tag name */
$title = single_tag_title('', false);
} elseif (is_author()) {
/* translators: Author archive title. 1: Author name */
$title = get_the_author();
} elseif (is_year()) {
/* translators: Yearly archive title. 1: Year */
$title = get_the_date(_x('Y', 'yearly archives date format', 'text_domain'));
} elseif (is_month()) {
/* translators: Monthly archive title. 1: Month name and year */
$title = get_the_date(_x('F Y', 'monthly archives date format', 'text_domain'));
} elseif (is_day()) {
/* translators: Daily archive title. 1: Date */
$title = get_the_date(_x('F j, Y', 'daily archives date format', 'text_domain'));
} elseif (is_post_type_archive()) {
/* translators: Post type archive title. 1: Post type name */
$title = post_type_archive_title('', false);
if (is_shop()) {
$title = woocommerce_page_title();
}
} elseif (is_tax()) {
$tax = get_taxonomy(get_queried_object()->taxonomy);
/* translators: Taxonomy term archive title. 1: Taxonomy singular name, 2: Current taxonomy term */
$title = sprintf(__('%1$s: %2$s', 'text_domain'), $tax->labels->singular_name, single_term_title('', false));
} else {
$title = esc_html__('Archives', 'text_domain');
}
/**
* Filters the archive title.
*
* @param string $title Archive title to be displayed.
*/
return apply_filters('prefix_get_the_archive_title', $title);
}
}
/**
* Function for breadcrumb title
*/
if (!function_exists('prefix_breadcrumb_title')) {
function prefix_breadcrumb_title() {
if (is_home() && is_front_page()) {
$breadcrumb_title = esc_html(get_bloginfo('title'));
} elseif (is_home() && !is_front_page()) {
$breadcrumb_title = get_the_title(get_option('page_for_posts'));
} elseif (is_archive()) {
$breadcrumb_title = prefix_get_the_archive_title();
} elseif (is_search()) {
$breadcrumb_title = esc_html__('Search Results for: ', 'text_domain') . esc_html(get_search_query());
} elseif (is_404()) {
$breadcrumb_title = esc_html__('404', 'text_domain');
} else {
$breadcrumb_title = get_the_title();
}
return $breadcrumb_title;
}
}
/**
* Breadcrumb
*/
if (!function_exists('prefix_breadcrumb')) {
function prefix_breadcrumb() {
echo '<ul class="prefix-breadcrumb-link"><li>';
if (!(is_home() && is_front_page())) {
printf("<a class='active' href='%s'><i class='fa fa-home'></i>" . esc_html__('Home', 'text_domain') . "</a><span class='breadcrumb-sperarator'>/</span>", esc_url(home_url()));
}
$name = get_bloginfo('name');
$desc = get_bloginfo('description');
//is_home means blog page.
if (is_home() && is_front_page()) { //home page and fornt page not set
echo esc_html($desc);
} elseif (!is_home() && is_front_page()) { //setting fornt page.
echo get_the_title();
} elseif (is_home() && !is_front_page()) { //setting blog page
$id = (get_option('page_for_posts') != '0') ? get_option('page_for_posts') : '';
echo get_the_title($id);
} elseif (is_search()) {
esc_html_e('Search Page', 'text_domain');
} elseif (is_404()) {
esc_html_e('404', 'text_domain');
} elseif (is_category()) {
echo single_term_title();
} elseif (is_singular()) {
$pt_name = get_post_type(get_the_ID());
$obj = get_post_type_object($pt_name);
$name = str_replace(array('_', '-'), array(' ', ' '), $pt_name);
if (is_single()) {
echo get_the_title();
} elseif (is_page()) {
echo get_the_title();
} else {
echo esc_html($name);
}
} elseif (is_archive()) {
echo prefix_get_the_archive_title();
}
echo '</li></ul>';
}
}
/**
* Breadcrumb area on/off
*/
if (!function_exists('prefix_breadcrumb_on_off')) {
function prefix_breadcrumb_on_off() {
$prefix_customizer = get_theme_mod('prefix_breadcrumb_on_off', 'show');
$page_breadcrumb_option = prefix_page_option('_prefix_breadcrumbs_on_off');
$prefix_page = !empty($page_breadcrumb_option) ? $page_breadcrumb_option : 'default';
$on_off = $prefix_page;
if ($on_off == 'on') {
$on_off = true;
} elseif ($on_off == 'off') {
$on_off = false;
} else {
$on_off = $prefix_customizer;
}
return $prefix_customizer;
}
}
/**
* Push extra link in wp nav menu
*/
add_filter('wp_nav_menu_items', 'prefix_push_menu', 10, 2);
function prefix_push_menu($items, $args) {
$signIn = get_theme_mod('prefix_header_sign', 'show');
$signInTxt = get_theme_mod('prefix_header_sign_txt', __('Sing in', 'text_domain'));
$signInurl = get_theme_mod('prefix_header_sign_url', '#');
if (($signIn == 'show' && !empty($signInTxt)) && $args->theme_location == 'text_domain-header-menu') {
$items = $items . '<li class="extra_push_item"><a href="' . esc_url($signInurl) . '">' . esc_html($signInTxt) . '</a></li>';
} else {
$items = '';
}
return $items;
}
/**
* get_wysiwyg_output
*/
if (!function_exists('prefix_get_wysiwyg_output')) {
function prefix_get_wysiwyg_output($meta_key) {
global $wp_embed;
$content = $wp_embed->autoembed($meta_key);
$content = $wp_embed->run_shortcode($content);
$content = do_shortcode($content);
$content = wpautop($content);
return $content;
}
}