Completed
Push — master ( d8562c...7fa338 )
by Warwick
02:56 queued 12s
created

extras.php ➔ lsx_body_class()   F

Complexity

Conditions 15
Paths 384

Size

Total Lines 54

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 15
nc 384
nop 1
dl 0
loc 54
rs 2.7833
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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 ) {
0 ignored issues
show
Unused Code introduced by
The parameter $context is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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
		if ( isset( $post ) ) {
62
			$classes[] = $post->post_name;
63
		}
64
65
		if ( class_exists( 'LSX_Banners' ) || empty( apply_filters( 'lsx_banner_plugin_disable', false ) ) ) {
66
			$post_types = array( 'page', 'post' );
67
			$post_types = apply_filters( 'lsx_allowed_post_type_banners', $post_types );
68
69
			if ( is_singular( $post_types ) && has_post_thumbnail() ) {
70
				$classes[] = 'page-has-banner';
71
			}
72
		}
73
74
		if ( function_exists( 'tour_operator' ) ) {
75
			$post_types = array( 'page', 'post' );
0 ignored issues
show
Unused Code introduced by
$post_types is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
76
77
			$classes[] = 'to-active';
78
		}
79
80
		if ( has_nav_menu( 'top-menu' ) || has_nav_menu( 'top-menu-left' ) ) {
81
			$classes[] = 'has-top-menu';
82
		}
83
84
		$fixed_header = get_theme_mod( 'lsx_header_fixed', false );
85
86
		if ( false !== $fixed_header ) {
87
			$classes[] = 'top-menu-fixed';
88
		}
89
90
		$search_form  = get_theme_mod( 'lsx_header_search', false );
91
92
		if ( false !== $search_form ) {
93
			$classes[] = 'has-header-search';
94
		}
95
96
		$preloader_content  = get_theme_mod( 'lsx_preloader_content_status', false );
97
98
		if ( false !== $preloader_content ) {
99
			$classes[] = 'preloader-content-enable';
100
		}
101
102
		$register_enabled = get_option( 'users_can_register', false );
103
		if ( ( $register_enabled ) && is_page( 'my-account' ) && is_singular() ) {
104
			$classes[] = 'register-enabled';
105
		}
106
107
		return $classes;
108
	}
109
110
endif;
111
112
add_filter( 'body_class', 'lsx_body_class' );
113
114
if ( ! function_exists( 'lsx_embed_wrap' ) ) :
115
116
	/**
117
	 * Wrap embedded media as suggested by Readability.
118
	 *
119
	 * @package    lsx
120
	 * @subpackage extras
121
	 *
122
	 * @link https://gist.github.com/965956
123
	 * @link http://www.readability.com/publishers/guidelines#publisher
124
	 */
125
	function lsx_embed_wrap( $cache, $url, $attr = '', $post_id = '' ) {
0 ignored issues
show
Unused Code introduced by
The parameter $url is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $attr is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $post_id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
126
		if ( false !== strpos( $cache, '<iframe' ) ) {
127
			return '<div class="entry-content-asset">' . $cache . '</div>';
128
		}
129
130
		return $cache;
131
	}
132
133
endif;
134
135
add_filter( 'embed_oembed_html', 'lsx_embed_wrap', 10, 4 );
136
137
if ( ! function_exists( 'lsx_remove_self_closing_tags' ) ) :
138
139
	/**
140
	 * Remove unnecessary self-closing tags.
141
	 *
142
	 * @package    lsx
143
	 * @subpackage extras
144
	 */
145
	function lsx_remove_self_closing_tags( $input ) {
146
		return str_replace( ' />', '>', $input );
147
	}
148
149
endif;
150
151
add_filter( 'get_avatar',          'lsx_remove_self_closing_tags' ); // <img />
152
add_filter( 'comment_id_fields',   'lsx_remove_self_closing_tags' ); // <input />
153
add_filter( 'post_thumbnail_html', 'lsx_remove_self_closing_tags' ); // <img />
154
155
if ( ! function_exists( 'lsx_is_element_empty' ) ) :
156
157
	/**
158
	 * Checks if a Nav $element is empty or not.
159
	 *
160
	 * @package    lsx
161
	 * @subpackage extras
162
	 */
163
	function lsx_is_element_empty( $element ) {
164
		$element = trim( $element );
165
		return empty( $element ) ? false : true;
166
	}
167
168
endif;
169
170
if ( ! function_exists( 'lsx_get_thumbnail' ) ) :
171
172
	/**
173
	 * return the responsive images.
174
	 *
175
	 * @package    lsx
176
	 * @subpackage extras
177
	 */
178
	function lsx_get_thumbnail( $size, $image_src = false ) {
179
		if ( false === $image_src ) {
180
			$post_id           = get_the_ID();
181
			$post_thumbnail_id = get_post_thumbnail_id( $post_id );
182
		} elseif ( false !== $image_src ) {
183
			if ( is_numeric( $image_src ) ) {
184
				$post_thumbnail_id = $image_src;
185
			} else {
186
				$post_thumbnail_id = lsx_get_attachment_id_from_src( $image_src );
187
			}
188
		}
189
190
		$size = apply_filters( 'lsx_thumbnail_size', $size );
191
		$img       = '';
192
		$lazy_img  = '';
193
		$image_url = '';
0 ignored issues
show
Unused Code introduced by
$image_url is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
194
195
		if ( 'lsx-thumbnail-single' === $size || 'lsx-thumbnail-wide' === $size || 'lsx-thumbnail-square' === $size || 'thumbnail' === $size ) {
196
			$srcset = false;
197
			$temp_img    = wp_get_attachment_image_src( $post_thumbnail_id, $size );
0 ignored issues
show
Bug introduced by
The variable $post_thumbnail_id does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
198
			if ( ! empty( $temp_img ) ) {
199
				$img    = $temp_img[0];
200
			}
201
		} else {
202
			$srcset = true;
203
			$img = wp_get_attachment_image_srcset( $post_thumbnail_id, $size );
204
205
			$temp_lazy = wp_get_attachment_image_src( $post_thumbnail_id, $size );
206
			if ( ! empty( $temp_lazy ) ) {
207
				$lazy_img = $temp_lazy[0];
208
			}
209
210
			if ( empty( $img ) ) {
211
				$srcset = false;
212
				if ( ! empty( $lazy_img ) ) {
213
					$img = $lazy_img;
214
				}
215
			}
216
		}
217
218
		if ( '' !== $img ) {
219
			$image_url = $img;
220
			$img = '<img alt="' . the_title_attribute( 'echo=0' ) . '" class="attachment-responsive wp-post-image lsx-responsive" ';
221
			if ( $srcset ) {
222
				$img .= 'srcset="' . esc_attr( $image_url ) . '" ';
223
			} else {
224
				$img .= 'src="' . esc_url( $image_url ) . '" ';
225
			}
226
			$img .= '/>';
227
228
			$img = apply_filters( 'lsx_lazyload_filter_images', $img );
229
			$img = apply_filters( 'lsx_lazyload_slider_images', $img, $post_thumbnail_id, $size, $srcset, $image_url );
230
		}
231
232
		return $img;
233
	}
234
235
endif;
236
237
if ( ! function_exists( 'lsx_thumbnail' ) ) :
238
239
	/**
240
	 * Output the Resonsive Images.
241
	 *
242
	 * @package    lsx
243
	 * @subpackage extras
244
	 */
245
	function lsx_thumbnail( $size = 'thumbnail', $image_src = false ) {
246
		echo wp_kses_post( lsx_get_thumbnail( $size, $image_src ) );
247
	}
248
249
endif;
250
251
if ( ! function_exists( 'lsx_get_attachment_id_from_src' ) ) :
252
253
	/**
254
	 * Gets the attachments ID from the src.
255
	 *
256
	 * @package    lsx
257
	 * @subpackage extras
258
	 */
259
	function lsx_get_attachment_id_from_src( $image_src ) {
260
		$post_id = wp_cache_get( $image_src, 'lsx_get_attachment_id_from_src' );
261
262
		if ( false === $post_id ) {
263
			global $wpdb;
264
			$post_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE guid='%s' LIMIT 1", $image_src ) );
265
			wp_cache_set( $image_src, $post_id, 'lsx_get_attachment_id_from_src', 3600 );
266
		}
267
268
		return $post_id;
269
	}
270
271
endif;
272
273
if ( ! function_exists( 'lsx_page_banner' ) ) :
274
275
	/**
276
	 * Add Featured Image as Banner on Single Pages.
277
	 *
278
	 * @package    lsx
279
	 * @subpackage extras
280
	 */
281
	function lsx_page_banner() {
282
		if ( true === apply_filters( 'lsx_page_banner_disable', false ) ) {
283
			return;
284
		}
285
286
		$post_types = array( 'page', 'post' );
287
		$post_types = apply_filters( 'lsx_allowed_post_type_banners', $post_types );
288
289
		if ( is_singular( $post_types ) && has_post_thumbnail() ) :
290
			$bg_image = '';
291
292
			if ( has_post_thumbnail() ) {
293
				$temp_bg_image = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'full' );
294
				if ( ! empty( $temp_bg_image ) ) {
295
					$bg_image = $temp_bg_image[0];
296
				}
297
			}
298
299
			if ( '' !== $bg_image ) :
300
				?>
301
					<div class="page-banner-wrap">
302
						<div class="page-banner">
303
							<?php lsx_banner_inner_top(); ?>
304
305
							<div class="page-banner-image" style="background-image:url(<?php echo esc_attr( $bg_image ); ?>);"></div>
306
307
							<div class="container">
308
								<header class="page-header">
309
									<h1 class="page-title"><?php the_title(); ?></h1>
310
									<?php lsx_banner_content(); ?>
311
								</header>
312
							</div>
313
314
							<?php lsx_banner_inner_bottom(); ?>
315
						</div>
316
					</div>
317
				<?php
318
			endif;
319
		endif;
320
	}
321
322
endif;
323
324
add_filter( 'lsx_banner_disable', 'lsx_disable_banner_for_blocks' );
325
add_filter( 'lsx_global_header_disable', 'lsx_disable_banner_for_blocks' );
326
327
328
if ( ! function_exists( 'lsx_disable_banner_for_blocks' ) ) :
329
330
	/**
331
	 * Disable the Banner if the page is using Blocks
332
	 *
333
	 * @package    lsx
334
	 * @subpackage extras
335
	 *
336
	 * @param  $disable boolean
337
	 * @return boolean
338
	 */
339
	function lsx_disable_banner_for_blocks( $disable ) {
340
		$queried_object = get_queried_object_id();
341
		$show_on_front  = get_option( 'show_on_front' );
342
343
		if ( 'page' === $show_on_front && (int) get_option( 'page_for_posts' ) === $queried_object ) {
344
			return $disable;
345
		}
346
347
		if ( function_exists( 'has_blocks' ) && has_blocks() && ( ! is_archive() ) ) {
348
			$disable = true;
349
		}
350
		return $disable;
351
	}
352
353
endif;
354
355
add_action( 'lsx_header_after', 'lsx_page_banner' );
356
357
if ( ! function_exists( 'lsx_form_submit_button' ) ) :
358
359
	/**
360
	 * filter the Gravity Forms button type.
361
	 *
362
	 * @package    lsx
363
	 * @subpackage extras
364
	 *
365
	 * @param  $button String
366
	 * @param  $form   Object
367
	 * @return String
368
	 */
369
	function lsx_form_submit_button( $button, $form ) {
0 ignored issues
show
Unused Code introduced by
The parameter $button is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
370
		return "<button class='btn btn-primary' id='gform_submit_button_{$form["id"]}'><span>Submit</span></button>";
371
	}
372
373
endif;
374
375
add_filter( 'gform_submit_button', 'lsx_form_submit_button', 10, 2 );
376
377
if ( ! function_exists( 'lsx_excerpt_more' ) ) :
378
379
	/**
380
	 * Replaces the excerpt "more" text by a link.
381
	 *
382
	 * @package    lsx
383
	 * @subpackage extras
384
	 */
385
	function lsx_excerpt_more( $more ) {
0 ignored issues
show
Unused Code introduced by
The parameter $more is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
386
		return '...';
387
	}
388
389
endif;
390
391
add_filter( 'excerpt_more', 'lsx_excerpt_more' );
392
393
if ( ! function_exists( 'lsx_the_excerpt_filter' ) ) :
394
395
	/**
396
	 * Add a continue reading link to the excerpt.
397
	 *
398
	 * @package    lsx
399
	 * @subpackage extras
400
	 */
401
	function lsx_the_excerpt_filter( $excerpt ) {
402
403
		$post_formats = array(
404
			'aside'   => 'aside',
405
			'gallery' => 'gallery',
406
			'link'    => 'link',
407
			'image'   => 'image',
408
			'quote'   => 'quote',
409
			'status'  => 'status',
410
			'video'   => 'video',
411
			'audio'   => 'audio',
412
		);
413
414
		$show_full_content = has_post_format( apply_filters( 'lsx_the_excerpt_filter_post_types', $post_formats ) );
415
416
		if ( ! $show_full_content ) {
417
			if ( '' !== $excerpt && ! stristr( $excerpt, 'moretag' ) ) {
418
				$pagination = wp_link_pages( array(
419
					'before'      => '<div class="lsx-postnav-wrapper"><div class="lsx-postnav">',
420
					'after'       => '</div></div>',
421
					'link_before' => '<span>',
422
					'link_after'  => '</span>',
423
					'echo'        => 0,
424
				) );
425
426
				if ( ! empty( $pagination ) ) {
427
					$excerpt .= $pagination;
428
				} else {
429
					$excerpt_more = '<p><a class="moretag" href="' . esc_url( get_permalink() ) . '">' . esc_html__( 'Read More', 'lsx' ) . '</a></p>';
430
					$excerpt .= apply_filters( 'excerpt_more_p', $excerpt_more );
431
				}
432
			}
433
		}
434
435
		return $excerpt;
436
	}
437
438
endif;
439
440
add_filter( 'the_excerpt', 'lsx_the_excerpt_filter' , 1 , 20 );
441
442
if ( ! function_exists( 'lsx_full_width_widget_classes' ) ) :
443
444
	/**
445
	 * Filter sidebar widget params, to add the widget_lsx_full_width_alt or widget_lsx_full_width classes to the text widget.
446
	 *
447
	 * @package    lsx
448
	 * @subpackage extras
449
	 */
450
	function lsx_full_width_widget_classes( $params ) {
451
		if ( is_admin() ) {
452
			return $params;
453
		}
454
455
		global $wp_registered_widgets;
456
457
		$widget_id   = $params[0]['widget_id'];
458
		$widget_name = $params[0]['widget_name'];
459
460
		if ( 'Text' === $widget_name ) {
461
			$wp_registered_widgets[ $widget_id ]['original_callback'] = $wp_registered_widgets[ $widget_id ]['callback'];
462
			$wp_registered_widgets[ $widget_id ]['callback'] = 'lsx_full_width_widget_custom_callback';
463
		}
464
465
		return $params;
466
	}
467
468
endif;
469
470
add_filter( 'dynamic_sidebar_params', 'lsx_full_width_widget_classes' );
471
472
if ( ! function_exists( 'lsx_full_width_widget_custom_callback' ) ) :
473
474
	/**
475
	 * Filter sidebar widget params, to add the widget_lsx_full_width_alt or widget_lsx_full_width classes to the text widget.
476
	 *
477
	 * @package    lsx
478
	 * @subpackage extras
479
	 */
480
	function full_width_widget_custom_callback() {
481
		global $wp_registered_widgets;
482
483
		$original_callback_params = func_get_args();
484
		$widget_id = $original_callback_params[0]['widget_id'];
485
486
		$original_callback = $wp_registered_widgets[ $widget_id ]['original_callback'];
487
		$wp_registered_widgets[ $widget_id ]['callback'] = $original_callback;
488
489
		$widget_id_base = $wp_registered_widgets[ $widget_id ]['callback'][0]->id_base;
490
491
		$widget_classname = '';
492
493
		if ( is_callable( $original_callback ) ) {
494
			ob_start();
495
			call_user_func_array( $original_callback, $original_callback_params );
496
			$widget_output = ob_get_clean();
497
498
			echo wp_kses_post( apply_filters( 'lsx_widget_output', $widget_output, $widget_id_base, $widget_classname, $widget_id ) );
499
		}
500
	}
501
502
endif;
503
504
if ( ! function_exists( 'lsx_full_width_widget_output' ) ) :
505
506
	/**
507
	 * Filter sidebar widget params, to add the widget_lsx_full_width_alt or widget_lsx_full_width classes to the text widget.
508
	 *
509
	 * @package    lsx
510
	 * @subpackage extras
511
	 */
512
	function lsx_full_width_widget_output( $widget_output, $widget_id_base, $widget_id ) {
0 ignored issues
show
Unused Code introduced by
The parameter $widget_id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
513
		if ( 'text' === $widget_id_base ) {
514
			if ( false !== strpos( $widget_output, '<div class="lsx-full-width-alt">' ) ) {
515
				$widget_output = str_replace( 'class="widget widget_text"', 'class="widget widget_text widget_lsx_full_width_alt"', $widget_output );
516
			} elseif ( false !== strpos( $widget_output, '<div class="lsx-full-width">' ) ) {
517
				$widget_output = str_replace( 'class="widget widget_text"', 'class="widget widget_text widget_lsx_full_width"', $widget_output );
518
			}
519
		}
520
521
		return $widget_output;
522
	}
523
524
endif;
525
526
add_filter( 'lsx_widget_output', 'lsx_full_width_widget_output', 10, 3 );
527
528
/**
529
 * Check if the content has a restricted post format that needs to show a full excerpt.
530
 */
531
function lsx_post_format_force_content_on_list() {
532
	$post_formats = apply_filters( 'lsx_post_format_force_content_on_list',
533
		array(
534
				'video' => 'video',
535
				'audio' => 'audio',
536
				'quote' => 'quote',
537
				'link' => 'link',
538
			)
539
	);
540
	$return = false;
541
	if ( ! has_post_format( $post_formats ) ) {
542
		$return = true;
543
	}
544
	return $return;
545
}
546
547
/**
548
 * Remove the Hentry Class Every
549
 */
550
function lsx_remove_hentry( $classes ) {
551
	if ( 'post' !== get_post_type() ) {
552
		$classes = array_diff( $classes, array( 'hentry' ) );
553
	}
554
	return $classes;
555
}
556
add_filter( 'post_class','lsx_remove_hentry' );
557
558
/**
559
 * Strip Excerpts.
560
 *
561
 */
562
function lsx_strip_excerpt( $content ) {
563
	if ( is_search() || is_archive() || ( is_blog_installed() && ! is_single() && ! is_page() ) ) {
564
		$content = strip_shortcodes( $content );
565
		$content = str_replace( ']]>', ']]&gt;', $content );
566
		$content = strip_tags( $content );
567
	}
568
	return $content;
569
}
570
add_filter( 'the_content', 'lsx_strip_excerpt' );
571
572
/**
573
 * Disable Gutenberg for LSX Custom Post Tpes.
574
 *
575
 */
576
function lsx_disable_gutenberg_product_type( $is_enabled, $post_type ) {
577
	if ( 'testimonial' === $post_type || 'team' === $post_type || 'project' === $post_type ) {
578
		return false;
579
	}
580
581
	return $is_enabled;
582
}
583
add_filter( 'gutenberg_add_edit_link_for_post_type', 'lsx_disable_gutenberg_product_type', 10, 2 );
584
585
/**
586
 * Add the "Blog" link to the breadcrumbs
587
 * @param $crumbs
588
 * @return array
589
 */
590
function lsx_breadcrumbs_blog_link( $crumbs ) {
591
592
	$show_on_front = get_option( 'show_on_front' );
593
594
	if ( 'page' === $show_on_front && ( is_category() || is_tag() ) ) {
595
596
		$blog_page = get_option( 'page_for_posts' );
597
		if ( false !== $blog_page && '' !== $blog_page ) {
598
599
			$new_crumbs = array();
600
			$new_crumbs[0] = $crumbs[0];
601
602
			if ( function_exists( 'woocommerce_breadcrumb' ) ) {
603
				$new_crumbs[1] = array(
604
					0	=> get_the_title( $blog_page ),
605
					1	=> get_permalink( $blog_page ),
606
				);
607
			} else {
608
				$new_crumbs[1] = array(
609
					'text'	=> get_the_title( $blog_page ),
610
					'url'	=> get_permalink( $blog_page ),
611
				);
612
			}
613
			$new_crumbs[2] = $crumbs[1];
614
			$crumbs = $new_crumbs;
615
616
		}
617
	}
618
	return $crumbs;
619
}
620
add_filter( 'wpseo_breadcrumb_links', 'lsx_breadcrumbs_blog_link', 30, 1 );
621
add_filter( 'woocommerce_get_breadcrumb', 'lsx_breadcrumbs_blog_link', 30, 1 );
622