Passed
Pull Request — master (#351)
by Virginia
02:09
created

extras.php ➔ lsx_disable_banner_for_blocks()   B

Complexity

Conditions 9
Paths 5

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

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