-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy paththeme-functions.php
More file actions
366 lines (291 loc) · 8.39 KB
/
theme-functions.php
File metadata and controls
366 lines (291 loc) · 8.39 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
<?php
/**
* Necessary functions for this theme
*
* Eventually, some of the functionality here could be replaced by core features.
*
* @package Orchid_Store
*/
if ( ! function_exists( 'orchid_store_lite_fonts_url' ) ) {
/**
* Return Font's URL.
*
* @since 1.0.0
* @return string Fonts URL.
*/
function orchid_store_lite_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', 'Inter font: on or off', 'orchid-store' ) ) {
$fonts[] = 'Inter:400,500,600,700,800';
}
if ( $fonts ) {
$fonts_url = add_query_arg(
array(
'family' => urlencode( implode( '|', $fonts ) ), // phpcs:ignore
'subset' => urlencode( $subsets ), // phpcs:ignore
),
'https://fonts.googleapis.com/css'
);
}
return $fonts_url;
}
}
if ( ! function_exists( 'orchid_store_breadcrumb_trail' ) ) {
/**
* Shows a breadcrumb for all types of pages. This is a wrapper function for the Breadcrumb_Trail class,
* which should be used in theme templates.
*
* @since 0.1.0
* @access public
* @param array $args Arguments to pass to Breadcrumb_Trail.
*/
function orchid_store_breadcrumb_trail( $args = array() ) {
$breadcrumb = apply_filters( 'breadcrumb_trail_object', null, $args );
if ( ! is_object( $breadcrumb ) ) {
$breadcrumb = new orchid_store_Breadcrumb_Trail( $args );
}
return $breadcrumb->trail();
}
}
if ( ! function_exists( 'orchid_store_navigation_fallback' ) ) {
/**
* Callback function for primary menu.
*
* @since 1.0.0
*/
function orchid_store_navigation_fallback() {
?>
<ul class="primary-menu">
<?php
wp_list_pages(
array(
'title_li' => '',
'depth' => 4,
)
);
?>
</ul><!-- .primary-menu -->
<?php
}
}
if ( ! function_exists( 'orchid_store_special_menu_fallback' ) ) {
/**
* Callback function for special menu.
*
* @since 1.0.0
*/
function orchid_store_special_menu_fallback() {
if ( ! class_exists( 'WooCommerce' ) ) {
?>
<ul class="category-navigation-list">
<?php
wp_list_pages(
array(
'title_li' => '',
'depth' => 2,
)
);
?>
</ul><!-- .primary-menu -->
<?php
} else {
$product_categories = orchid_store_all_product_categories();
if ( ! empty( $product_categories ) ) {
?>
<ul class="category-navigation-list">
<?php
foreach ( $product_categories as $product_category ) {
?>
<li>
<a
href="<?php echo esc_url( get_term_link( $product_category->term_id, 'product_cat' ) ); ?>"
title="<?php echo esc_attr( $product_category->name ); ?>"
>
<?php echo esc_html( $product_category->name ); ?>
</a>
</li>
<?php
}
?>
</ul><!-- .primary-menu -->
<?php
}
}
}
}
if ( ! function_exists( 'orchid_store_thumbnail_alt_text' ) ) {
/**
* Function to get post thumbnail alt text value.
*
* @since 1.0.0
*
* @param int $post_id Post id.
*/
function orchid_store_thumbnail_alt_text( $post_id ) {
$post_thumbnail_id = get_post_thumbnail_id( $post_id );
$alt_text = '';
if ( $post_thumbnail_id ) {
$alt_text = get_post_meta( $post_thumbnail_id, '_wp_attachment_image_alt', true );
}
if ( $alt_text ) {
echo esc_attr( $alt_text );
} else {
the_title_attribute();
}
}
}
if ( ! function_exists( 'orchid_store_sidebar_position' ) ) {
/**
* Function to position sidebar according to the customization value.
*
* @since 1.0.0
*/
function orchid_store_sidebar_position() {
$sidebar_position = '';
$is_global_sidebar = orchid_store_get_option( 'enable_global_sidebar_position' );
if ( class_exists( 'WooCommerce' ) && is_woocommerce() ) {
if ( ! is_active_sidebar( 'woocommerce-sidebar' ) ) {
$sidebar_position = 'none';
} elseif ( $is_global_sidebar ) {
$sidebar_position = orchid_store_get_option( 'global_sidebar_position' );
} else {
if ( is_shop() || is_product_category() || is_product_tag() ) {
$sidebar_position = get_theme_mod( 'orchid_store_field_woocommerce_sidebar_position', 'right' );
}
if ( is_product() ) {
$sidebar_position = get_theme_mod( 'orchid_store_field_woocommerce_product_sidebar_position', 'right' );
}
}
} elseif (
class_exists( 'WooCommerce' ) &&
(
is_cart() ||
is_checkout() ||
is_account_page() ||
(
defined( 'YITH_WCWL' ) &&
is_page( get_option( 'yith_wcwl_wishlist_page_id' ) )
)
)
) {
$sidebar_position = 'none';
} elseif ( ! is_active_sidebar( 'sidebar-1' ) ) {
$sidebar_position = 'none';
} elseif ( $is_global_sidebar ) {
$sidebar_position = orchid_store_get_option( 'global_sidebar_position' );
} else {
if ( is_home() ) {
$sidebar_position = orchid_store_get_option( 'blog_sidebar_position' );
}
if ( is_archive() ) {
$sidebar_position = orchid_store_get_option( 'archive_sidebar_position' );
}
if ( is_search() ) {
$sidebar_position = orchid_store_get_option( 'search_sidebar_position' );
}
if ( is_single() ) {
if ( orchid_store_get_option( 'enable_post_common_sidebar_position' ) ) {
$sidebar_position = orchid_store_get_option( 'post_sidebar_position' );
} else {
$sidebar_position = get_post_meta( get_the_ID(), 'orchid_store_sidebar_position', true );
if ( ! $sidebar_position ) {
$sidebar_position = 'right';
}
}
}
if ( is_page() ) {
if ( orchid_store_get_option( 'enable_page_common_sidebar_position' ) ) {
$sidebar_position = orchid_store_get_option( 'page_sidebar_position' );
} else {
$sidebar_position = get_post_meta( get_the_ID(), 'orchid_store_sidebar_position', true );
if ( ! $sidebar_position ) {
$sidebar_position = 'right';
}
}
}
}
return $sidebar_position;
}
}
if ( ! function_exists( 'orchid_store_excerpt_length' ) ) {
/**
* Modifies the length of post excerpt.
*
* @param int $length Post excerpt's length.
*/
function orchid_store_excerpt_length( $length ) {
if ( is_admin() ) {
return $length;
}
$excerpt_length = orchid_store_get_option( 'excerpt_length' );
if ( absint( $excerpt_length ) > 0 ) {
$length = absint( $excerpt_length );
}
return $length;
}
add_filter( 'excerpt_length', 'orchid_store_excerpt_length' );
}
if ( ! function_exists( 'orchid_store_excerpt_more' ) ) {
/**
* Modifies the trailing string of post excerpt.
*
* @param string $more Post excerpt's trailing string.
*/
function orchid_store_excerpt_more( $more ) {
return ( is_admin() ) ? $more : '';
}
add_filter( 'excerpt_more', 'orchid_store_excerpt_more' );
}
if ( ! function_exists( 'orchid_store_default_archive_widget' ) ) {
/**
* Modifies the archive HTML link content.
*
* @param string $link_html The archive HTML link content.
*/
function orchid_store_default_archive_widget( $link_html ) {
$link_html = str_replace( '</a> (', '</a> <span class="count">(', $link_html );
$link_html = str_replace( ')', ')</span>', $link_html );
return $link_html;
}
add_filter( 'get_archives_link', 'orchid_store_default_archive_widget' );
}
if ( ! function_exists( 'orchid_store_cat_count_span' ) ) {
/**
* Modifies the HTML output of a taxonomy list.
*
* @since 1.0.0
*
* @param string $output HTML output.
*/
function orchid_store_cat_count_span( $output ) {
$output = str_replace( '</a> (', '</a><span class="count">(', $output );
$output = str_replace( ')', ')</span>', $output );
return $output;
}
add_filter( 'wp_list_categories', 'orchid_store_cat_count_span' );
}
if ( ! function_exists( 'orchid_store_get_alt_text_of_image' ) ) {
/**
* Get alt text for the image.
*
* @param string $image_url Image URL.
* @return string $alt The alt text.
*/
function orchid_store_get_alt_text_of_image( $image_url ) {
// Get attachment id of the image.
$attachment_id = attachment_url_to_postid( $image_url );
// Get the alt text from the attachment meta.
$alt = get_post_meta( $attachment_id, '_wp_attachment_image_alt', true );
// If alt is empty then get the post title of the attachment by attachment id.
if ( ! $alt ) {
$attachment_post = get_post( $attachment_id );
if ( $attachment_post ) {
$alt = $attachment_post->post_title;
}
}
return ( $alt ) ? $alt : '';
}
}