1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* LSX functions and definitions - Integrations - Extras |
4
|
|
|
* |
5
|
|
|
* @package lsx |
6
|
|
|
* @subpackage extras |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
10
|
|
|
exit; |
11
|
|
|
} |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Enable shortcode for text widget. |
15
|
|
|
* |
16
|
|
|
* @package lsx |
17
|
|
|
* @subpackage extras |
18
|
|
|
*/ |
19
|
|
|
add_filter( 'widget_text', 'shortcode_unautop' ); |
20
|
|
|
add_filter( 'widget_text', 'do_shortcode' ); |
21
|
|
|
|
22
|
|
|
if ( ! function_exists( 'lsx_kses_allowed_html' ) ) : |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Enable extra attributes (srcset, sizes) in img tag. |
26
|
|
|
* |
27
|
|
|
* @package lsx |
28
|
|
|
* @subpackage extras |
29
|
|
|
*/ |
30
|
|
|
function lsx_kses_allowed_html( $allowedtags, $context ) { |
|
|
|
|
31
|
|
|
$allowedtags['img']['srcset'] = true; |
32
|
|
|
$allowedtags['img']['sizes'] = true; |
33
|
|
|
|
34
|
|
|
$allowedtags['input']['name'] = true; |
35
|
|
|
$allowedtags['input']['type'] = true; |
36
|
|
|
$allowedtags['input']['value'] = true; |
37
|
|
|
$allowedtags['input']['class'] = true; |
38
|
|
|
$allowedtags['input']['id'] = true; |
39
|
|
|
$allowedtags['script']['type'] = true; |
40
|
|
|
return $allowedtags; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
endif; |
44
|
|
|
|
45
|
|
|
add_filter( 'wp_kses_allowed_html', 'lsx_kses_allowed_html', 10, 2 ); |
46
|
|
|
|
47
|
|
|
if ( ! function_exists( 'lsx_body_class' ) ) : |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Add and remove body_class() classes. |
51
|
|
|
* |
52
|
|
|
* @package lsx |
53
|
|
|
* @subpackage extras |
54
|
|
|
*/ |
55
|
|
|
function lsx_body_class( $classes ) { |
56
|
|
|
global $post; |
57
|
|
|
|
58
|
|
|
$header_layout = get_theme_mod( 'lsx_header_layout', 'inline' ); |
59
|
|
|
$classes[] = 'header-' . $header_layout; |
60
|
|
|
|
61
|
|
|
$mobile_header_layout = get_theme_mod( 'lsx_header_mobile_layout', 'navigation-bar' ); |
62
|
|
|
$classes[] = 'mobile-header-' . $mobile_header_layout; |
63
|
|
|
|
64
|
|
|
if ( isset( $post ) ) { |
65
|
|
|
$classes[] = $post->post_name; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
if ( class_exists( 'LSX_Banners' ) && empty( apply_filters( 'lsx_banner_plugin_disable', false ) ) ) { |
69
|
|
|
$post_types = array( 'page', 'post' ); |
70
|
|
|
$post_types = apply_filters( 'lsx_allowed_post_type_banners', $post_types ); |
71
|
|
|
|
72
|
|
|
$img_group = get_post_meta( $post->ID, 'image_group', true ); |
73
|
|
|
|
74
|
|
|
if ( is_singular( $post_types ) && ! empty( $img_group ) && is_array( $img_group ) && ! empty( $img_group['banner_image'] ) ) { |
75
|
|
|
$classes[] = 'page-has-banner'; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
if ( is_singular( $post_types ) && empty( $img_group['banner_image'] ) && ( ! has_post_thumbnail( $post->ID ) ) ) { |
79
|
|
|
$classes[] = 'page-has-no-banner'; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
if ( function_exists( 'tour_operator' ) ) { |
84
|
|
|
$post_types = array( 'page', 'post' ); |
|
|
|
|
85
|
|
|
|
86
|
|
|
$classes[] = 'to-active'; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
if ( has_nav_menu( 'top-menu' ) || has_nav_menu( 'top-menu-left' ) ) { |
90
|
|
|
$classes[] = 'has-top-menu'; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
$fixed_header = get_theme_mod( 'lsx_header_fixed', false ); |
94
|
|
|
|
95
|
|
|
if ( false !== $fixed_header ) { |
96
|
|
|
$classes[] = 'top-menu-fixed'; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
$search_form = get_theme_mod( 'lsx_header_search', false ); |
100
|
|
|
|
101
|
|
|
if ( false !== $search_form ) { |
102
|
|
|
$classes[] = 'has-header-search'; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
$preloader_content = get_theme_mod( 'lsx_preloader_content_status', false ); |
106
|
|
|
|
107
|
|
|
if ( false !== $preloader_content ) { |
108
|
|
|
$classes[] = 'preloader-content-enable'; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
$register_enabled = get_option( 'users_can_register', false ); |
112
|
|
|
if ( ( $register_enabled ) && is_page( 'my-account' ) && is_singular() ) { |
113
|
|
|
$classes[] = 'register-enabled'; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
return $classes; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
endif; |
120
|
|
|
|
121
|
|
|
add_filter( 'body_class', 'lsx_body_class' ); |
122
|
|
|
|
123
|
|
|
if ( ! function_exists( 'lsx_embed_wrap' ) ) : |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Wrap embedded media as suggested by Readability. |
127
|
|
|
* |
128
|
|
|
* @package lsx |
129
|
|
|
* @subpackage extras |
130
|
|
|
* |
131
|
|
|
* @link https://gist.github.com/965956 |
132
|
|
|
* @link http://www.readability.com/publishers/guidelines#publisher |
133
|
|
|
*/ |
134
|
|
|
function lsx_embed_wrap( $cache, $url, $attr = '', $post_id = '' ) { |
|
|
|
|
135
|
|
|
if ( false !== strpos( $cache, '<iframe' ) ) { |
136
|
|
|
return '<div class="entry-content-asset">' . $cache . '</div>'; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
return $cache; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
endif; |
143
|
|
|
|
144
|
|
|
add_filter( 'embed_oembed_html', 'lsx_embed_wrap', 10, 4 ); |
145
|
|
|
|
146
|
|
|
if ( ! function_exists( 'lsx_remove_self_closing_tags' ) ) : |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Remove unnecessary self-closing tags. |
150
|
|
|
* |
151
|
|
|
* @package lsx |
152
|
|
|
* @subpackage extras |
153
|
|
|
*/ |
154
|
|
|
function lsx_remove_self_closing_tags( $input ) { |
155
|
|
|
return str_replace( ' />', '>', $input ); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
endif; |
159
|
|
|
|
160
|
|
|
add_filter( 'get_avatar', 'lsx_remove_self_closing_tags' ); // <img /> |
161
|
|
|
add_filter( 'comment_id_fields', 'lsx_remove_self_closing_tags' ); // <input /> |
162
|
|
|
add_filter( 'post_thumbnail_html', 'lsx_remove_self_closing_tags' ); // <img /> |
163
|
|
|
|
164
|
|
|
if ( ! function_exists( 'lsx_is_element_empty' ) ) : |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* Checks if a Nav $element is empty or not. |
168
|
|
|
* |
169
|
|
|
* @package lsx |
170
|
|
|
* @subpackage extras |
171
|
|
|
*/ |
172
|
|
|
function lsx_is_element_empty( $element ) { |
173
|
|
|
$element = trim( $element ); |
174
|
|
|
return empty( $element ) ? false : true; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
endif; |
178
|
|
|
|
179
|
|
|
if ( ! function_exists( 'lsx_get_thumbnail' ) ) : |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* return the responsive images. |
183
|
|
|
* |
184
|
|
|
* @package lsx |
185
|
|
|
* @subpackage extras |
186
|
|
|
*/ |
187
|
|
|
function lsx_get_thumbnail( $size, $image_src = false ) { |
188
|
|
|
if ( false === $image_src ) { |
189
|
|
|
$post_id = get_the_ID(); |
190
|
|
|
$post_thumbnail_id = get_post_thumbnail_id( $post_id ); |
191
|
|
|
if ( empty( $post_thumbnail_id ) ) { |
192
|
|
|
$post_thumbnail_id = apply_filters( 'lsx_get_thumbnail_post_placeholder_id', $post_thumbnail_id, $post_id ); |
193
|
|
|
} |
194
|
|
|
} elseif ( false !== $image_src ) { |
195
|
|
|
if ( is_numeric( $image_src ) ) { |
196
|
|
|
$post_thumbnail_id = $image_src; |
197
|
|
|
} else { |
198
|
|
|
$post_thumbnail_id = lsx_get_attachment_id_from_src( $image_src ); |
199
|
|
|
if ( empty( $post_thumbnail_id ) ) { |
200
|
|
|
$post_thumbnail_id = apply_filters( 'lsx_get_thumbnail_post_placeholder_id', $post_thumbnail_id, $post_id ); |
|
|
|
|
201
|
|
|
} |
202
|
|
|
} |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
$size = apply_filters( 'lsx_thumbnail_size', $size ); |
206
|
|
|
$img = ''; |
207
|
|
|
$lazy_img = ''; |
208
|
|
|
$image_url = ''; |
|
|
|
|
209
|
|
|
|
210
|
|
|
if ( 'lsx-thumbnail-single' === $size || 'lsx-thumbnail-wide' === $size || 'lsx-thumbnail-square' === $size || 'thumbnail' === $size ) { |
211
|
|
|
$srcset = false; |
212
|
|
|
if ( ( ( 'team' === get_post_type() ) || ( 'testimonial' === get_post_type() ) ) && is_search() ) { |
213
|
|
|
$img = get_the_post_thumbnail_url( get_the_ID(), 'lsx-thumbnail-wide' ); |
214
|
|
|
} else { |
215
|
|
|
$temp_img = wp_get_attachment_image_src( $post_thumbnail_id, $size ); |
|
|
|
|
216
|
|
|
if ( ! empty( $temp_img ) ) { |
217
|
|
|
$img = $temp_img[0]; |
218
|
|
|
} |
219
|
|
|
} |
220
|
|
|
} else { |
221
|
|
|
$srcset = true; |
222
|
|
|
$img = wp_get_attachment_image_srcset( $post_thumbnail_id, $size ); |
223
|
|
|
|
224
|
|
|
$temp_lazy = wp_get_attachment_image_src( $post_thumbnail_id, $size ); |
225
|
|
|
if ( ! empty( $temp_lazy ) ) { |
226
|
|
|
$lazy_img = $temp_lazy[0]; |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
if ( empty( $img ) ) { |
230
|
|
|
$srcset = false; |
231
|
|
|
if ( ! empty( $lazy_img ) ) { |
232
|
|
|
$img = $lazy_img; |
233
|
|
|
} |
234
|
|
|
} |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
if ( '' !== $img ) { |
238
|
|
|
$image_url = $img; |
239
|
|
|
$img = '<img title="' . the_title_attribute( 'echo=0' ) . '" alt="' . the_title_attribute( 'echo=0' ) . '" class="attachment-responsive wp-post-image lsx-responsive" '; |
240
|
|
|
if ( $srcset ) { |
241
|
|
|
$img .= 'srcset="' . esc_attr( $image_url ) . '" '; |
242
|
|
|
} else { |
243
|
|
|
$img .= 'src="' . esc_url( $image_url ) . '" '; |
244
|
|
|
} |
245
|
|
|
$img .= '/>'; |
246
|
|
|
|
247
|
|
|
$img = apply_filters( 'lsx_lazyload_filter_images', $img ); |
248
|
|
|
$img = apply_filters( 'lsx_lazyload_slider_images', $img, $post_thumbnail_id, $size, $srcset, $image_url ); |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
return $img; |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
endif; |
255
|
|
|
|
256
|
|
|
if ( ! function_exists( 'lsx_thumbnail' ) ) : |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* Output the Resonsive Images. |
260
|
|
|
* |
261
|
|
|
* @package lsx |
262
|
|
|
* @subpackage extras |
263
|
|
|
*/ |
264
|
|
|
function lsx_thumbnail( $size = 'thumbnail', $image_src = false ) { |
265
|
|
|
echo wp_kses_post( lsx_get_thumbnail( $size, $image_src ) ); |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
endif; |
269
|
|
|
|
270
|
|
|
if ( ! function_exists( 'lsx_get_attachment_id_from_src' ) ) : |
271
|
|
|
|
272
|
|
|
/** |
273
|
|
|
* Gets the attachments ID from the src. |
274
|
|
|
* |
275
|
|
|
* @package lsx |
276
|
|
|
* @subpackage extras |
277
|
|
|
*/ |
278
|
|
|
function lsx_get_attachment_id_from_src( $image_src ) { |
279
|
|
|
$post_id = wp_cache_get( $image_src, 'lsx_get_attachment_id_from_src' ); |
280
|
|
|
|
281
|
|
|
if ( false === $post_id ) { |
282
|
|
|
global $wpdb; |
283
|
|
|
$post_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE guid='%s' LIMIT 1", $image_src ) ); |
284
|
|
|
wp_cache_set( $image_src, $post_id, 'lsx_get_attachment_id_from_src', 3600 ); |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
return $post_id; |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
endif; |
291
|
|
|
|
292
|
|
|
if ( ! function_exists( 'lsx_page_banner' ) ) : |
293
|
|
|
|
294
|
|
|
/** |
295
|
|
|
* Add Featured Image as Banner on Single Pages. |
296
|
|
|
* |
297
|
|
|
* @package lsx |
298
|
|
|
* @subpackage extras |
299
|
|
|
*/ |
300
|
|
|
function lsx_page_banner() { |
301
|
|
|
if ( true === apply_filters( 'lsx_page_banner_disable', false ) ) { |
302
|
|
|
return; |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
$post_types = array( 'page', 'post' ); |
306
|
|
|
$post_types = apply_filters( 'lsx_allowed_post_type_banners', $post_types ); |
307
|
|
|
|
308
|
|
|
if ( is_singular( $post_types ) && has_post_thumbnail() ) : |
309
|
|
|
$bg_image = ''; |
310
|
|
|
|
311
|
|
|
if ( has_post_thumbnail() ) { |
312
|
|
|
$temp_bg_image = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'full' ); |
313
|
|
|
if ( ! empty( $temp_bg_image ) ) { |
314
|
|
|
$bg_image = $temp_bg_image[0]; |
315
|
|
|
} |
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
if ( '' !== $bg_image ) : |
319
|
|
|
?> |
320
|
|
|
<div class="page-banner-wrap"> |
321
|
|
|
<div class="page-banner"> |
322
|
|
|
<?php lsx_banner_inner_top(); ?> |
323
|
|
|
|
324
|
|
|
<div class="page-banner-image" style="background-image:url(<?php echo esc_attr( $bg_image ); ?>);"></div> |
325
|
|
|
|
326
|
|
|
<div class="container"> |
327
|
|
|
<header class="page-header"> |
328
|
|
|
<h1 class="page-title"><?php the_title(); ?></h1> |
329
|
|
|
<?php lsx_banner_content(); ?> |
330
|
|
|
</header> |
331
|
|
|
</div> |
332
|
|
|
|
333
|
|
|
<?php lsx_banner_inner_bottom(); ?> |
334
|
|
|
</div> |
335
|
|
|
</div> |
336
|
|
|
<?php |
337
|
|
|
endif; |
338
|
|
|
endif; |
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
endif; |
342
|
|
|
|
343
|
|
|
add_filter( 'lsx_banner_disable', 'lsx_disable_banner_for_blocks' ); |
344
|
|
|
add_filter( 'lsx_global_header_disable', 'lsx_disable_banner_for_blocks' ); |
345
|
|
|
|
346
|
|
|
|
347
|
|
|
if ( ! function_exists( 'lsx_disable_banner_for_blocks' ) ) : |
348
|
|
|
|
349
|
|
|
/** |
350
|
|
|
* Disable the Banner if the page is using Blocks |
351
|
|
|
* |
352
|
|
|
* @package lsx |
353
|
|
|
* @subpackage extras |
354
|
|
|
* |
355
|
|
|
* @param $disable boolean |
356
|
|
|
* @return boolean |
357
|
|
|
*/ |
358
|
|
|
function lsx_disable_banner_for_blocks( $disable ) { |
359
|
|
|
$queried_object = get_queried_object_id(); |
360
|
|
|
$show_on_front = get_option( 'show_on_front' ); |
361
|
|
|
|
362
|
|
|
if ( 'page' === $show_on_front && (int) get_option( 'page_for_posts' ) === $queried_object ) { |
363
|
|
|
return $disable; |
364
|
|
|
} |
365
|
|
|
|
366
|
|
|
if ( function_exists( 'has_blocks' ) && has_blocks() && ( ! is_archive() ) ) { |
367
|
|
|
$disable = true; |
368
|
|
|
} |
369
|
|
|
|
370
|
|
|
// Single projects will still have banners. |
371
|
|
|
if ( function_exists( 'has_blocks' ) && has_blocks() && ( is_singular( 'project' ) ) ) { |
372
|
|
|
$disable = false; |
373
|
|
|
} |
374
|
|
|
return $disable; |
375
|
|
|
} |
376
|
|
|
|
377
|
|
|
endif; |
378
|
|
|
|
379
|
|
|
add_action( 'lsx_header_after', 'lsx_page_banner' ); |
380
|
|
|
|
381
|
|
|
if ( ! function_exists( 'lsx_form_submit_button' ) ) : |
382
|
|
|
|
383
|
|
|
/** |
384
|
|
|
* filter the Gravity Forms button type. |
385
|
|
|
* |
386
|
|
|
* @package lsx |
387
|
|
|
* @subpackage extras |
388
|
|
|
* |
389
|
|
|
* @param $button String |
390
|
|
|
* @param $form Object |
391
|
|
|
* @return String |
392
|
|
|
*/ |
393
|
|
|
function lsx_form_submit_button( $button, $form ) { |
|
|
|
|
394
|
|
|
return "<button class='btn btn-primary' id='gform_submit_button_{$form["id"]}'><span>Submit</span></button>"; |
395
|
|
|
} |
396
|
|
|
|
397
|
|
|
endif; |
398
|
|
|
|
399
|
|
|
add_filter( 'gform_submit_button', 'lsx_form_submit_button', 10, 2 ); |
400
|
|
|
|
401
|
|
|
if ( ! function_exists( 'lsx_excerpt_more' ) ) : |
402
|
|
|
|
403
|
|
|
/** |
404
|
|
|
* Replaces the excerpt "more" text by a link. |
405
|
|
|
* |
406
|
|
|
* @package lsx |
407
|
|
|
* @subpackage extras |
408
|
|
|
*/ |
409
|
|
|
function lsx_excerpt_more( $more ) { |
|
|
|
|
410
|
|
|
return '...'; |
411
|
|
|
} |
412
|
|
|
|
413
|
|
|
endif; |
414
|
|
|
|
415
|
|
|
add_filter( 'excerpt_more', 'lsx_excerpt_more' ); |
416
|
|
|
|
417
|
|
|
if ( ! function_exists( 'lsx_the_excerpt_filter' ) ) : |
418
|
|
|
|
419
|
|
|
/** |
420
|
|
|
* Add a continue reading link to the excerpt. |
421
|
|
|
* |
422
|
|
|
* @package lsx |
423
|
|
|
* @subpackage extras |
424
|
|
|
*/ |
425
|
|
|
function lsx_the_excerpt_filter( $excerpt ) { |
426
|
|
|
|
427
|
|
|
$post_formats = array( |
428
|
|
|
'aside' => 'aside', |
429
|
|
|
'gallery' => 'gallery', |
430
|
|
|
'link' => 'link', |
431
|
|
|
'image' => 'image', |
432
|
|
|
'quote' => 'quote', |
433
|
|
|
'status' => 'status', |
434
|
|
|
'video' => 'video', |
435
|
|
|
'audio' => 'audio', |
436
|
|
|
); |
437
|
|
|
|
438
|
|
|
$show_full_content = has_post_format( apply_filters( 'lsx_the_excerpt_filter_post_types', $post_formats ) ); |
439
|
|
|
|
440
|
|
|
if ( ! $show_full_content ) { |
441
|
|
|
if ( '' !== $excerpt && ! stristr( $excerpt, 'moretag' ) ) { |
442
|
|
|
$pagination = wp_link_pages( |
443
|
|
|
array( |
444
|
|
|
'before' => '<div class="lsx-postnav-wrapper"><div class="lsx-postnav">', |
445
|
|
|
'after' => '</div></div>', |
446
|
|
|
'link_before' => '<span>', |
447
|
|
|
'link_after' => '</span>', |
448
|
|
|
'echo' => 0, |
449
|
|
|
) |
450
|
|
|
); |
451
|
|
|
|
452
|
|
|
if ( ! empty( $pagination ) ) { |
453
|
|
|
$excerpt .= $pagination; |
454
|
|
|
} else { |
455
|
|
|
$excerpt_more = '<p><a class="moretag" href="' . esc_url( get_permalink() ) . '">' . esc_html__( 'Read More', 'lsx' ) . '</a></p>'; |
456
|
|
|
$excerpt .= apply_filters( 'excerpt_more_p', $excerpt_more ); |
457
|
|
|
} |
458
|
|
|
} |
459
|
|
|
} |
460
|
|
|
|
461
|
|
|
return $excerpt; |
462
|
|
|
} |
463
|
|
|
|
464
|
|
|
endif; |
465
|
|
|
|
466
|
|
|
add_filter( 'the_excerpt', 'lsx_the_excerpt_filter', 1, 20 ); |
467
|
|
|
|
468
|
|
|
if ( ! function_exists( 'lsx_full_width_widget_classes' ) ) : |
469
|
|
|
|
470
|
|
|
/** |
471
|
|
|
* Filter sidebar widget params, to add the widget_lsx_full_width_alt or widget_lsx_full_width classes to the text widget. |
472
|
|
|
* |
473
|
|
|
* @package lsx |
474
|
|
|
* @subpackage extras |
475
|
|
|
*/ |
476
|
|
|
function lsx_full_width_widget_classes( $params ) { |
477
|
|
|
if ( is_admin() ) { |
478
|
|
|
return $params; |
479
|
|
|
} |
480
|
|
|
|
481
|
|
|
global $wp_registered_widgets; |
482
|
|
|
|
483
|
|
|
$widget_id = $params[0]['widget_id']; |
484
|
|
|
$widget_name = $params[0]['widget_name']; |
485
|
|
|
|
486
|
|
|
if ( 'Text' === $widget_name ) { |
487
|
|
|
$wp_registered_widgets[ $widget_id ]['original_callback'] = $wp_registered_widgets[ $widget_id ]['callback']; |
488
|
|
|
$wp_registered_widgets[ $widget_id ]['callback'] = 'lsx_full_width_widget_custom_callback'; |
489
|
|
|
} |
490
|
|
|
|
491
|
|
|
return $params; |
492
|
|
|
} |
493
|
|
|
|
494
|
|
|
endif; |
495
|
|
|
|
496
|
|
|
add_filter( 'dynamic_sidebar_params', 'lsx_full_width_widget_classes' ); |
497
|
|
|
|
498
|
|
|
if ( ! function_exists( 'lsx_full_width_widget_custom_callback' ) ) : |
499
|
|
|
|
500
|
|
|
/** |
501
|
|
|
* Filter sidebar widget params, to add the widget_lsx_full_width_alt or widget_lsx_full_width classes to the text widget. |
502
|
|
|
* |
503
|
|
|
* @package lsx |
504
|
|
|
* @subpackage extras |
505
|
|
|
*/ |
506
|
|
|
function full_width_widget_custom_callback() { |
507
|
|
|
global $wp_registered_widgets; |
508
|
|
|
|
509
|
|
|
$original_callback_params = func_get_args(); |
510
|
|
|
$widget_id = $original_callback_params[0]['widget_id']; |
511
|
|
|
|
512
|
|
|
$original_callback = $wp_registered_widgets[ $widget_id ]['original_callback']; |
513
|
|
|
$wp_registered_widgets[ $widget_id ]['callback'] = $original_callback; |
514
|
|
|
|
515
|
|
|
$widget_id_base = $wp_registered_widgets[ $widget_id ]['callback'][0]->id_base; |
516
|
|
|
|
517
|
|
|
$widget_classname = ''; |
518
|
|
|
|
519
|
|
|
if ( is_callable( $original_callback ) ) { |
520
|
|
|
ob_start(); |
521
|
|
|
call_user_func_array( $original_callback, $original_callback_params ); |
522
|
|
|
$widget_output = ob_get_clean(); |
523
|
|
|
|
524
|
|
|
echo wp_kses_post( apply_filters( 'lsx_widget_output', $widget_output, $widget_id_base, $widget_classname, $widget_id ) ); |
525
|
|
|
} |
526
|
|
|
} |
527
|
|
|
|
528
|
|
|
endif; |
529
|
|
|
|
530
|
|
|
if ( ! function_exists( 'lsx_full_width_widget_output' ) ) : |
531
|
|
|
|
532
|
|
|
/** |
533
|
|
|
* Filter sidebar widget params, to add the widget_lsx_full_width_alt or widget_lsx_full_width classes to the text widget. |
534
|
|
|
* |
535
|
|
|
* @package lsx |
536
|
|
|
* @subpackage extras |
537
|
|
|
*/ |
538
|
|
|
function lsx_full_width_widget_output( $widget_output, $widget_id_base, $widget_id ) { |
|
|
|
|
539
|
|
|
if ( 'text' === $widget_id_base ) { |
540
|
|
|
if ( false !== strpos( $widget_output, '<div class="lsx-full-width-alt">' ) ) { |
541
|
|
|
$widget_output = str_replace( 'class="widget widget_text"', 'class="widget widget_text widget_lsx_full_width_alt"', $widget_output ); |
542
|
|
|
} elseif ( false !== strpos( $widget_output, '<div class="lsx-full-width">' ) ) { |
543
|
|
|
$widget_output = str_replace( 'class="widget widget_text"', 'class="widget widget_text widget_lsx_full_width"', $widget_output ); |
544
|
|
|
} |
545
|
|
|
} |
546
|
|
|
|
547
|
|
|
return $widget_output; |
548
|
|
|
} |
549
|
|
|
|
550
|
|
|
endif; |
551
|
|
|
|
552
|
|
|
add_filter( 'lsx_widget_output', 'lsx_full_width_widget_output', 10, 3 ); |
553
|
|
|
|
554
|
|
|
/** |
555
|
|
|
* Check if the content has a restricted post format that needs to show a full excerpt. |
556
|
|
|
*/ |
557
|
|
|
function lsx_post_format_force_content_on_list() { |
558
|
|
|
$post_formats = apply_filters( 'lsx_post_format_force_content_on_list', |
559
|
|
|
array( |
560
|
|
|
'video' => 'video', |
561
|
|
|
'audio' => 'audio', |
562
|
|
|
'quote' => 'quote', |
563
|
|
|
'link' => 'link', |
564
|
|
|
) |
565
|
|
|
); |
566
|
|
|
$return = false; |
567
|
|
|
if ( ! has_post_format( $post_formats ) ) { |
568
|
|
|
$return = true; |
569
|
|
|
} |
570
|
|
|
return $return; |
571
|
|
|
} |
572
|
|
|
|
573
|
|
|
/** |
574
|
|
|
* Remove the Hentry Class Every |
575
|
|
|
*/ |
576
|
|
|
function lsx_remove_hentry( $classes ) { |
577
|
|
|
if ( 'post' !== get_post_type() ) { |
578
|
|
|
$classes = array_diff( $classes, array( 'hentry' ) ); |
579
|
|
|
} |
580
|
|
|
return $classes; |
581
|
|
|
} |
582
|
|
|
add_filter( 'post_class', 'lsx_remove_hentry' ); |
583
|
|
|
|
584
|
|
|
/** |
585
|
|
|
* Strip Excerpts. |
586
|
|
|
*/ |
587
|
|
|
function lsx_strip_excerpt( $content ) { |
588
|
|
|
if ( is_search() || is_archive() || ( is_blog_installed() && ! is_single() && ! is_page() ) ) { |
589
|
|
|
$content = strip_shortcodes( $content ); |
590
|
|
|
$content = str_replace( ']]>', ']]>', $content ); |
591
|
|
|
$content = strip_tags( $content ); |
592
|
|
|
} |
593
|
|
|
return $content; |
594
|
|
|
} |
595
|
|
|
add_filter( 'the_content', 'lsx_strip_excerpt' ); |
596
|
|
|
|
597
|
|
|
/** |
598
|
|
|
* Disable Gutenberg for LSX Custom Post Types. |
599
|
|
|
*/ |
600
|
|
|
function lsx_disable_gutenberg_product_type( $is_enabled, $post_type ) { |
601
|
|
|
if ( 'testimonial' === $post_type || 'team' === $post_type || 'project' === $post_type ) { |
602
|
|
|
return false; |
603
|
|
|
} |
604
|
|
|
|
605
|
|
|
return $is_enabled; |
606
|
|
|
} |
607
|
|
|
add_filter( 'gutenberg_add_edit_link_for_post_type', 'lsx_disable_gutenberg_product_type', 10, 2 ); |
608
|
|
|
|
609
|
|
|
/** |
610
|
|
|
* Add the "Blog" link to the breadcrumbs |
611
|
|
|
* |
612
|
|
|
* @param $crumbs |
613
|
|
|
* @return array |
614
|
|
|
*/ |
615
|
|
|
function lsx_breadcrumbs_blog_link( $crumbs ) { |
616
|
|
|
|
617
|
|
|
$show_on_front = get_option( 'show_on_front' ); |
618
|
|
|
|
619
|
|
|
if ( 'page' === $show_on_front && ( is_category() || is_tag() ) ) { |
620
|
|
|
|
621
|
|
|
$blog_page = get_option( 'page_for_posts' ); |
622
|
|
|
if ( false !== $blog_page && '' !== $blog_page ) { |
623
|
|
|
|
624
|
|
|
$new_crumbs = array(); |
625
|
|
|
$new_crumbs[0] = $crumbs[0]; |
626
|
|
|
|
627
|
|
|
if ( function_exists( 'woocommerce_breadcrumb' ) ) { |
628
|
|
|
$new_crumbs[1] = array( |
629
|
|
|
0 => get_the_title( $blog_page ), |
630
|
|
|
1 => get_permalink( $blog_page ), |
631
|
|
|
); |
632
|
|
|
} else { |
633
|
|
|
$new_crumbs[1] = array( |
634
|
|
|
'text' => get_the_title( $blog_page ), |
635
|
|
|
'url' => get_permalink( $blog_page ), |
636
|
|
|
); |
637
|
|
|
} |
638
|
|
|
$new_crumbs[2] = $crumbs[1]; |
639
|
|
|
$crumbs = $new_crumbs; |
640
|
|
|
|
641
|
|
|
} |
642
|
|
|
} |
643
|
|
|
return $crumbs; |
644
|
|
|
} |
645
|
|
|
add_filter( 'wpseo_breadcrumb_links', 'lsx_breadcrumbs_blog_link', 30, 1 ); |
646
|
|
|
add_filter( 'woocommerce_get_breadcrumb', 'lsx_breadcrumbs_blog_link', 30, 1 ); |
647
|
|
|
|
648
|
|
|
/** |
649
|
|
|
* Cover template custom styles |
650
|
|
|
* |
651
|
|
|
* @return void |
652
|
|
|
*/ |
653
|
|
|
function lsx_cover_template_custom_enqueue() { |
654
|
|
|
|
655
|
|
|
if ( ! is_page_template( 'page-templates/template-cover.php' ) ) { |
656
|
|
|
return; |
657
|
|
|
} |
658
|
|
|
|
659
|
|
|
$cover_text_color = get_theme_mod( 'lsx_cover_template_overlay_text_color' ); |
660
|
|
|
|
661
|
|
|
$color_overlay_opacity = get_theme_mod( 'lsx_cover_template_overlay_opacity' ); |
662
|
|
|
$color_overlay_opacity = ( false === $color_overlay_opacity ) ? 80 : $color_overlay_opacity; |
663
|
|
|
$color_overlay_opacity = $color_overlay_opacity / 100; |
664
|
|
|
$color_overlay_classes .= $color_overlay_opacity; |
|
|
|
|
665
|
|
|
|
666
|
|
|
$custom_css = ".page-template-template-cover .entry-header .entry-title, .post-template-template-cover .entry-header .entry-title, .post-template-template-cover #primary .entry-categories-inner a, .page-template-template-cover #primary .entry-header *, .post-template-template-cover #primary .entry-header * {color: {$cover_text_color};} .page-template-template-cover .cover-header .cover-header-inner-wrapper .cover-header-inner .cover-color-overlay, .page-template-template-cover .cover-header .cover-header-inner-wrapper .cover-header-inner .cover-color-overlay::before, .post-template-template-cover .cover-header .cover-header-inner-wrapper .cover-header-inner .cover-color-overlay, .post-template-template-cover .cover-header .cover-header-inner-wrapper .cover-header-inner .cover-color-overlay::before {opacity: {$color_overlay_opacity};}"; |
667
|
|
|
wp_add_inline_style( 'lsx_main', $custom_css ); |
668
|
|
|
|
669
|
|
|
} |
670
|
|
|
add_action( 'wp_enqueue_scripts', 'lsx_cover_template_custom_enqueue' ); |
671
|
|
|
|
672
|
|
|
/** |
673
|
|
|
* Determines if the request is an REST API request. |
674
|
|
|
* |
675
|
|
|
* @return bool True if it's a REST API request, false otherwise. |
676
|
|
|
*/ |
677
|
|
|
function lsx_is_rest_api_request() { |
678
|
|
|
$rest_helper = LSX_Rest_Helper::get_instance(); |
679
|
|
|
return $rest_helper->is_rest_api_request(); |
680
|
|
|
} |
681
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.