lsx_breadcrumbs()   B
last analyzed

Complexity

Conditions 9
Paths 5

Size

Total Lines 32
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 9
eloc 19
nc 5
nop 0
dl 0
loc 32
rs 8.0555
c 0
b 0
f 0
1
<?php
2
/**
3
 * LSX functions and definitions - Integrations - Template Tags
4
 *
5
 * @package    lsx
6
 * @subpackage template-tags
7
 */
8
9
if ( ! defined( 'ABSPATH' ) ) {
10
	exit;
11
}
12
13
if ( ! function_exists( 'lsx_breadcrumbs' ) ) :
14
15
	/**
16
	 * Breadcrumbs.
17
	 *
18
	 * @package    lsx
19
	 * @subpackage template-tags
20
	 */
21
	function lsx_breadcrumbs() {
22
		if ( ! function_exists( 'yoast_breadcrumb' ) && ! function_exists( 'woocommerce_breadcrumb' ) ) {
23
			return null;
24
		}
25
26
		$show_on_front = get_option( 'show_on_front' );
27
28
		if ( ( 'posts' === $show_on_front && is_home() ) || ( 'page' === $show_on_front && is_front_page() ) ) {
29
			return;
30
		}
31
32
		if ( function_exists( 'woocommerce_breadcrumb' ) ) {
33
			ob_start();
34
35
			woocommerce_breadcrumb(
36
				array(
37
					'wrap_before' => '<div class="breadcrumbs-container breadcrumbs-woocommerce"><div class="container"><div class="row"><div class="col-xs-12">',
38
					'wrap_after'  => '</div></div></div></div>',
39
					'before'      => '<span>',
40
					'after'       => '</span>',
41
				)
42
			);
43
44
			$output = ob_get_clean();
45
		} elseif ( function_exists( 'yoast_breadcrumb' ) ) {
46
			$output = yoast_breadcrumb( null, null, false );
47
			$output = '<div class="breadcrumbs-container breadcrumbs-yoast"><div class="container"><div class="row"><div class="col-xs-12">' . $output . '</div></div></div></div>';
48
		}
49
50
		$output = apply_filters( 'lsx_breadcrumbs', $output );
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $output does not seem to be defined for all execution paths leading up to this point.
Loading history...
51
52
		echo wp_kses_post( $output );
53
	}
54
55
endif;
56
57
add_action( 'lsx_header_after', 'lsx_breadcrumbs', 1 );
58
//add_action( 'lsx_banner_inner_bottom', 'lsx_breadcrumbs', 100 );
0 ignored issues
show
Coding Style introduced by
No space found before comment text; expected "// add_action( 'lsx_banner_inner_bottom', 'lsx_breadcrumbs', 100 );" but found "//add_action( 'lsx_banner_inner_bottom', 'lsx_breadcrumbs', 100 );"
Loading history...
Unused Code Comprehensibility introduced by
61% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
59
//add_action( 'lsx_global_header_inner_bottom', 'lsx_breadcrumbs', 100 );
0 ignored issues
show
Coding Style introduced by
No space found before comment text; expected "// add_action( 'lsx_global_header_inner_bottom', 'lsx_breadcrumbs', 100 );" but found "//add_action( 'lsx_global_header_inner_bottom', 'lsx_breadcrumbs', 100 );"
Loading history...
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
60
61
if ( ! function_exists( 'lsx_breadcrumbs_wpseo_seperator_filter' ) ) :
62
63
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$seperator" missing
Loading history...
64
	 * Replaces the seperator.
65
	 *
66
	 * @package    lsx
67
	 * @subpackage template-tags
68
	 */
69
	function lsx_breadcrumbs_wpseo_seperator_filter( $seperator ) {
70
		$seperator = '<i class="fa fa-angle-right" aria-hidden="true"></i>';
71
		return $seperator;
72
	}
73
74
endif;
75
76
add_filter( 'wpseo_breadcrumb_separator', 'lsx_breadcrumbs_wpseo_seperator_filter' );
77
78
if ( ! function_exists( 'lsx_breadcrumbs_woocommerce_seperator_filter' ) ) :
79
80
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$defaults" missing
Loading history...
81
	 * Replaces the seperator.
82
	 *
83
	 * @package    lsx
84
	 * @subpackage template-tags
85
	 */
86
	function lsx_breadcrumbs_woocommerce_seperator_filter( $defaults ) {
87
		$defaults['delimiter'] = '<i class="fa fa-angle-right" aria-hidden="true"></i>';
88
		return $defaults;
89
	}
90
91
endif;
92
93
add_filter( 'woocommerce_breadcrumb_defaults', 'lsx_breadcrumbs_woocommerce_seperator_filter' );
94
95
if ( ! function_exists( 'lsx_site_title' ) ) :
96
97
	/**
98
	 * Displays logo when applicable.
99
	 *
100
	 * @package    lsx
101
	 * @subpackage template-tags
102
	 */
103
	function lsx_site_title() {
104
		?>
105
			<div class="site-branding">
106
				<h1 class="site-title"><a title="<?php bloginfo( 'name' ); ?>" href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></h1>
107
				<p class="site-description"><?php bloginfo( 'description' ); ?></p>
108
			</div>
109
		<?php
110
	}
111
112
endif;
113
114
if ( ! function_exists( 'lsx_post_meta_list_top' ) ) :
115
116
	/**
117
	 * Add customizable post meta (post list - above title).
118
	 *
119
	 * @package    lsx
120
	 * @subpackage template-tags
121
	 */
122
	function lsx_post_meta_list_top() {
123
		?>
124
		<div class="post-meta post-meta-top">
125
			<?php //lsx_post_meta_avatar(); ?>
0 ignored issues
show
Coding Style introduced by
No space found before comment text; expected "// lsx_post_meta_avatar();" but found "//lsx_post_meta_avatar();"
Loading history...
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
126
			<?php lsx_post_meta_author(); ?>
127
			<?php lsx_post_meta_date(); ?>
128
			<div class="clearfix"></div>
129
		</div>
130
		<?php
131
	}
132
133
endif;
134
135
if ( ! function_exists( 'lsx_post_meta_single_top' ) ) :
136
137
	/**
138
	 * Add customizable post meta (single post - above title).
139
	 *
140
	 * @package    lsx
141
	 * @subpackage template-tags
142
	 */
143
	function lsx_post_meta_single_top() {
144
		?>
145
		<div class="post-meta post-meta-top">
146
			<?php lsx_post_meta_top(); ?>
147
			<div class="clearfix"></div>
148
		</div>
149
		<?php
150
	}
151
152
endif;
153
154
//add_action( 'lsx_post_meta_top', 'lsx_post_meta_avatar' );
0 ignored issues
show
Coding Style introduced by
No space found before comment text; expected "// add_action( 'lsx_post_meta_top', 'lsx_post_meta_avatar' );" but found "//add_action( 'lsx_post_meta_top', 'lsx_post_meta_avatar' );"
Loading history...
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
155
add_action( 'lsx_post_meta_top', 'lsx_post_meta_author' );
156
add_action( 'lsx_post_meta_top', 'lsx_post_meta_date' );
157
add_action( 'lsx_post_meta_top', 'lsx_post_meta_category' );
158
159
if ( ! function_exists( 'lsx_post_meta_single_bottom' ) ) :
160
161
	/**
162
	 * Add customizable post meta (single post - below title).
163
	 *
164
	 * @package    lsx
165
	 * @subpackage template-tags
166
	 */
167
	function lsx_post_meta_single_bottom() {
168
		?>
169
		<div class="post-meta">
170
			<?php lsx_post_meta_category(); ?>
171
			<div class="clearfix"></div>
172
		</div>
173
		<?php
174
	}
175
176
endif;
177
178
if ( ! function_exists( 'lsx_post_meta_avatar' ) ) :
179
180
	/**
181
	 * Add customizable post meta: author's avatar.
182
	 *
183
	 * @package    lsx
184
	 * @subpackage template-tags
185
	 */
186
	function lsx_post_meta_avatar() {
187
		$author        = get_the_author();
0 ignored issues
show
Unused Code introduced by
The assignment to $author is dead and can be removed.
Loading history...
188
		$author_id     = get_the_author_meta( 'ID' );
189
		$author_avatar = get_avatar( $author_id, 80 );
190
		$author_url    = get_author_posts_url( $author_id );
0 ignored issues
show
Bug introduced by
$author_id of type string is incompatible with the type integer expected by parameter $author_id of get_author_posts_url(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

190
		$author_url    = get_author_posts_url( /** @scrutinizer ignore-type */ $author_id );
Loading history...
191
192
		printf(
193
			'<a href="%1$s" class="post-meta-avatar">%2$s</a>',
194
			esc_url( $author_url ),
195
			wp_kses_post( $author_avatar )
0 ignored issues
show
Bug introduced by
It seems like $author_avatar can also be of type false; however, parameter $data of wp_kses_post() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

195
			wp_kses_post( /** @scrutinizer ignore-type */ $author_avatar )
Loading history...
196
		);
197
	}
198
199
endif;
200
201
if ( ! function_exists( 'lsx_post_meta_date' ) ) :
202
203
	/**
204
	 * Add customizable post meta: post date.
205
	 *
206
	 * @package    lsx
207
	 * @subpackage template-tags
208
	 */
209
	function lsx_post_meta_date() {
210
		$time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
211
212
		$time_string = sprintf(
213
			$time_string,
214
			esc_attr( get_the_date( 'c' ) ),
0 ignored issues
show
Bug introduced by
It seems like get_the_date('c') can also be of type false; however, parameter $text of esc_attr() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

214
			esc_attr( /** @scrutinizer ignore-type */ get_the_date( 'c' ) ),
Loading history...
215
			get_the_date(),
0 ignored issues
show
Bug introduced by
It seems like get_the_date() can also be of type false; however, parameter $values of sprintf() does only seem to accept double|integer|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

215
			/** @scrutinizer ignore-type */ get_the_date(),
Loading history...
216
			esc_attr( get_the_modified_date( 'c' ) ),
217
			get_the_modified_date()
218
		);
219
220
		printf(
221
			'<span class="post-meta-time updated"><a href="%1$s" rel="bookmark">%2$s</a></span>',
222
			esc_url( get_permalink() ),
0 ignored issues
show
Bug introduced by
It seems like get_permalink() can also be of type false; however, parameter $url of esc_url() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

222
			esc_url( /** @scrutinizer ignore-type */ get_permalink() ),
Loading history...
223
			wp_kses_post( $time_string )
224
		);
225
	}
226
227
endif;
228
229
if ( ! function_exists( 'lsx_post_meta_author' ) ) :
230
231
	/**
232
	 * Add customizable post meta: post author.
233
	 *
234
	 * @package    lsx
235
	 * @subpackage template-tags
236
	 */
237
	function lsx_post_meta_author() {
238
		$author     = get_the_author();
239
		$author_url = get_author_posts_url( get_the_author_meta( 'ID' ) );
0 ignored issues
show
Bug introduced by
get_the_author_meta('ID') of type string is incompatible with the type integer expected by parameter $author_id of get_author_posts_url(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

239
		$author_url = get_author_posts_url( /** @scrutinizer ignore-type */ get_the_author_meta( 'ID' ) );
Loading history...
240
241
		if ( empty( $author ) ) {
242
			global $post;
243
244
			$author     = get_user_by( 'ID', $post->post_author );
245
			$author     = $author->display_name;
246
			$author_url = get_author_posts_url( $post->post_author );
247
		}
248
249
		printf(
250
			'<span class="vcard post-meta-author"><span>%1$s</span> <span class="fn"><a href="%2$s">%3$s</a>, </span></span>',
251
			esc_html__( 'By ', 'lsx' ),
252
			esc_url( $author_url ),
253
			esc_html( $author )
254
		);
255
	}
256
257
endif;
258
259
if ( ! function_exists( 'lsx_post_meta_category' ) ) :
260
261
	/**
262
	 * Add customizable post meta: post category(ies).
263
	 *
264
	 * @package    lsx
265
	 * @subpackage template-tags
266
	 */
267
	function lsx_post_meta_category() {
268
		$post_categories = wp_get_post_categories( get_the_ID() );
0 ignored issues
show
Bug introduced by
It seems like get_the_ID() can also be of type false; however, parameter $post_id of wp_get_post_categories() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

268
		$post_categories = wp_get_post_categories( /** @scrutinizer ignore-type */ get_the_ID() );
Loading history...
269
		$cats            = array();
270
271
		foreach ( $post_categories as $c ) {
272
			$cat = get_category( $c );
273
			/* Translators: %s: category name */
274
			$cats[] = '<a href="' . esc_url( get_category_link( $cat->term_id ) ) . '" title="' . sprintf( esc_html__( 'View all posts in %s', 'lsx' ), $cat->name ) . '">' . $cat->name . '</a>';
0 ignored issues
show
Bug introduced by
The property term_id does not seem to exist on WP_Error.
Loading history...
Bug introduced by
The property name does not seem to exist on WP_Error.
Loading history...
275
		}
276
277
		if ( ! empty( $cats ) ) {
278
			?>
279
			<span class="post-meta-categories"><span><?php esc_html_e( 'Posted in: ', 'lsx' ); ?></span> <?php echo wp_kses_post( implode( ', ', $cats ) ); ?></span>
280
			<?php
281
		}
282
	}
283
284
endif;
285
286
if ( ! function_exists( 'lsx_post_tags' ) ) :
287
288
	/**
289
	 * Add customizable post meta: post tag(s).
290
	 *
291
	 * @package    lsx
292
	 * @subpackage template-tags
293
	 */
294
	function lsx_post_tags() {
295
		if ( has_tag() ) :
296
			?>
297
			<div class="post-tags">
298
				<span><?php echo esc_html__( 'Tags: ', 'lsx' ); ?></span><?php echo wp_kses_post( get_the_tag_list( '' ) ); ?>
299
			</div>
300
			<?php
301
		endif;
302
	}
303
304
endif;
305
306
add_action( 'lsx_content_post_tags', 'lsx_post_tags', 10 );
307
308
if ( ! function_exists( 'lsx_sharing_output' ) ) :
309
310
	/**
311
	 * Display sharing buttons.
312
	 *
313
	 * @package    lsx
314
	 * @subpackage template-tags
315
	 */
316
	function lsx_sharing_output() {
317
		global $lsx_sharing;
318
		echo wp_kses_post( $lsx_sharing->sharing_buttons() );
319
	}
320
321
endif;
322
323
add_action( 'lsx_content_sharing', 'lsx_sharing_output', 20 );
324
325
if ( ! function_exists( 'lsx_translate_format_to_fontawesome' ) ) :
326
327
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$format" missing
Loading history...
328
	 * Translate post format to Font Awesome class.
329
	 *
330
	 * @package    lsx
331
	 * @subpackage template-tags
332
	 */
333
	function lsx_translate_format_to_fontawesome( $format ) {
334
		switch ( $format ) {
335
			case 'image':
336
				$format = 'camera';
337
				break;
338
			case 'video':
339
				$format = 'play';
340
				break;
341
			case 'gallery':
342
				$format = 'picture-o';
343
				break;
344
			case 'audio':
345
				$format = 'volume-up';
346
				break;
347
			case 'link':
348
				$format = 'link';
349
				break;
350
			case 'quote':
351
				$format = 'quote-right';
352
				break;
353
			case 'aside':
354
				$format = 'circle-o';
355
				break;
356
			default:
357
				$format = 'file-text-o';
358
				break;
359
		}
360
361
		return $format;
362
	}
363
364
endif;
365
366
if ( ! function_exists( 'lsx_paging_nav' ) ) :
367
368
	/**
369
	 * Display navigation to next/previous set of posts when applicable.
370
	 *
371
	 * @package    lsx
372
	 * @subpackage template-tags
373
	 */
374
	function lsx_paging_nav() {
375
		global $wp_query;
376
377
		if ( $wp_query->max_num_pages < 2 ) {
378
			return;
379
		}
380
381
		if ( true === apply_filters( 'lsx_paging_nav_disable', false ) ) {
382
			return true;
383
		} elseif ( current_theme_supports( 'infinite-scroll' ) && class_exists( 'The_Neverending_Home_Page' ) ) {
384
			return true;
385
		} else {
386
			$html  = '';
387
			$html .= '<div class="lsx-pagination-wrapper">' . PHP_EOL;
388
			$html .= '<div class="lsx-breaker"></div>' . PHP_EOL;
389
			$html .= '<div class="lsx-pagination">' . PHP_EOL;
390
			$html .= paginate_links(
391
				array(
392
					'base'      => str_replace( 999999999, '%#%', esc_url( get_pagenum_link( 999999999 ) ) ),
393
					'format'    => '?paged=%#%',
394
					'total'     => $wp_query->max_num_pages,
395
					'current'   => max( 1, intval( get_query_var( 'paged' ) ) ),
396
					'prev_text' => '<span class="meta-nav">&larr;</span> ' . esc_html__( 'Previous', 'lsx' ),
397
					'next_text' => esc_html__( 'Next', 'lsx' ) . ' <span class="meta-nav">&rarr;</span>',
398
				)
399
			);
400
			$html .= '</div>' . PHP_EOL;
401
			$html .= '</div>' . PHP_EOL;
402
403
			echo wp_kses_post( $html );
404
		}
405
	}
406
407
endif;
408
409
if ( ! function_exists( 'lsx_post_nav' ) ) :
410
411
	/**
412
	 * Display navigation to next/previous post when applicable.
413
	 *
414
	 * @package    lsx
415
	 * @subpackage template-tags
416
	 */
417
	function lsx_post_nav() {
418
		$previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( false, '', true );
419
		$next     = get_adjacent_post( false, '', false );
420
421
		if ( ! $next && ! $previous ) {
422
			return;
423
		}
424
425
		$default_size = 'sm';
426
		$size         = apply_filters( 'lsx_bootstrap_column_size', $default_size );
427
		?>
428
		<nav class="navigation post-navigation" role="navigation">
429
			<div class="lsx-breaker"></div>
430
			<div class="nav-links pager row">
431
				<div class="previous <?php echo 'col-' . esc_attr( $size ) . '-6'; ?>">
432
					<?php previous_post_link( '%link', '<p class="nav-links-description">' . esc_html_x( 'Previous Post', 'Previous post link', 'lsx' ) . '</p><h3>%title</h3>' ); ?>
433
				</div>
434
				<div class="next <?php echo 'col-' . esc_attr( $size ) . '-6'; ?>">
435
					<?php next_post_link( '%link', '<p class="nav-links-description">' . esc_html_x( 'Next Post', 'Next post link', 'lsx' ) . '</p><h3>%title</h3>' ); ?>
436
				</div>
437
			</div><!-- .nav-links -->
438
		</nav><!-- .navigation -->
439
		<?php
440
	}
441
442
endif;
443
444
if ( ! function_exists( 'lsx_cover_custom_logo' ) ) :
445
446
	/**
447
	 * Outputs the Custom Logo on the Cover page if available.
448
	 *
449
	 * @package    lsx
450
	 * @subpackage template-tags
451
	 */
452
	function lsx_cover_custom_logo() {
453
		if ( is_page_template( 'page-templates/template-cover.php' ) ) {
454
455
			$custom_logo_id = get_theme_mod( 'lsx_cover_template_alt_logo' );
456
457
			if ( $custom_logo_id ) {
458
459
				$site_url   = home_url();
460
				$site_title = get_bloginfo( 'name' );
461
				$image      = wp_get_attachment_image_src( $custom_logo_id , 'full' );
0 ignored issues
show
Coding Style introduced by
Space found before comma in argument list
Loading history...
462
463
				echo '<a href="' . $site_url . '" class="custom-logo-link" rel="home"><img class="custom-logo" src="' . $image[0] . '" width="' . $image[1] . '" height="' . $image[2] . '" loading="eager" alt="' . $site_title . '"></a>';
0 ignored issues
show
introduced by
All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '$site_url'.
Loading history...
introduced by
All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '$image[0]'.
Loading history...
introduced by
All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '$image[1]'.
Loading history...
introduced by
All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '$image[2]'.
Loading history...
introduced by
All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '$site_title'.
Loading history...
464
465
			} else {
466
				the_custom_logo();
467
			}
0 ignored issues
show
introduced by
Blank line found after control structure
Loading history...
468
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
469
470
		}
471
	}
472
473
endif;
474
475
if ( ! function_exists( 'lsx_site_identity' ) ) :
476
477
	/**
478
	 * Outputs either the Site Title or the Site Logo.
479
	 *
480
	 * @package    lsx
481
	 * @subpackage template-tags
482
	 */
483
	function lsx_site_identity() {
484
		if ( function_exists( 'has_custom_logo' ) && has_custom_logo() ) {
485
			if ( is_page_template( 'page-templates/template-cover.php' ) ) {
486
				lsx_cover_custom_logo();
487
			} else {
488
				the_custom_logo();
489
			}
490
		} else {
491
			if ( get_theme_mod( 'site_logo_header_text', 1 ) ) {
492
				lsx_site_title();
493
			}
494
		}
495
	}
496
497
endif;
498
499
if ( ! function_exists( 'lsx_navbar_header' ) ) :
500
	/**
501
	 * Outputs the Nav Menu.
502
	 *
503
	 * @package    lsx
504
	 * @subpackage template-tags
505
	 */
506
	function lsx_navbar_header() {
507
		$mobile_header_layout = get_theme_mod( 'lsx_header_mobile_layout', 'navigation-bar' );
508
		if ( 'hamburger' === $mobile_header_layout ) {
509
			?>
510
			<div class="navbar-header" itemscope itemtype="http://schema.org/WebPage">
511
				<?php
512
				lsx_header_search_form();
513
				lsx_site_identity();
514
				if ( has_nav_menu( 'primary' ) ) :
515
					?>
516
					<div class="wrapper-toggle" data-toggle="collapse" data-target=".primary-navbar">
517
						<button type="button" class="navbar-toggle">
518
							<span class="sr-only"><?php esc_html_e( 'Toggle navigation', 'lsx' ); ?></span>
519
							<span class="icon-bar icon-bar-1"></span>
520
							<span class="icon-bar icon-bar-2"></span>
521
							<span class="icon-bar icon-bar-3"></span>
522
						</button>
523
					</div>
524
					<?php
525
				endif;
526
				?>
527
			</div>
528
			<?php
529
		} else {
530
			?>
531
			<div class="navbar-header" itemscope itemtype="http://schema.org/WebPage">
532
				<?php
533
				if ( has_nav_menu( 'primary' ) ) :
534
					?>
535
					<div class="wrapper-toggle" data-toggle="collapse" data-target=".primary-navbar">
536
						<button type="button" class="navbar-toggle">
537
							<span class="sr-only"><?php esc_html_e( 'Toggle navigation', 'lsx' ); ?></span>
538
							<span class="icon-bar"></span>
539
							<span class="icon-bar"></span>
540
							<span class="icon-bar"></span>
541
							<span class="icon-bar"></span>
542
						</button>
543
						<span class="mobile-menu-title"><?php esc_html_e( 'Menu', 'lsx' ); ?></span>
544
					</div>
545
					<?php
546
				endif;
547
548
				lsx_site_identity();
549
				?>
550
			</div>
551
			<?php
552
		}
553
	}
554
555
endif;
556
557
add_action( 'lsx_nav_before', 'lsx_navbar_header' );
558
559
if ( ! function_exists( 'lsx_nav_menu' ) ) :
560
	/**
561
	 * Outputs the Nav Menu.
562
	 *
563
	 * @package    lsx
564
	 * @subpackage template-tags
565
	 */
566
	function lsx_nav_menu() {
567
		if ( has_nav_menu( 'primary' ) ) :
568
			?>
569
			<nav class="primary-navbar collapse navbar-collapse">
570
				<?php
571
					wp_nav_menu(
572
						array(
573
							'theme_location' => 'primary',
574
							'depth'          => 3,
575
							'container'      => false,
576
							'menu_class'     => 'nav navbar-nav',
577
							'walker'         => new LSX_Bootstrap_Navwalker(),
578
						)
579
					);
580
				?>
581
			</nav>
582
			<?php
583
		endif;
584
	}
585
endif;
586
587
if ( ! function_exists( 'lsx_sitemap_loops' ) ) {
588
	/**
589
	 * Outputs the loops on the sitemap
590
	 *
591
	 * @package    lsx
592
	 * @subpackage template-tags
593
	 */
594
	function lsx_sitemap_loops() {
595
		$sitemap_loops  = array(
596
			'page'     => array(
597
				'type'      => 'post_type',
598
				'label'     => __( 'Pages', 'lsx' ),
599
				'heirarchy' => true,
600
			),
601
			'post'     => array(
602
				'type'  => 'post_type',
603
				'label' => __( 'Posts', 'lsx' ),
604
			),
605
			'category' => array(
606
				'type'      => 'taxonomy',
607
				'label'     => __( 'Categories', 'lsx' ),
608
				'heirarchy' => true,
609
			),
610
		);
611
		$post_type_args = array(
612
			'public'   => true,
613
			'_builtin' => false,
614
			'show_ui'  => true,
615
		);
616
		$post_types     = get_post_types( $post_type_args, 'objects' );
617
		if ( ! empty( $post_types ) ) {
618
			foreach ( $post_types as $post_type_key => $post_type_obj ) {
619
				$sitemap_loops[ $post_type_key ] = array(
620
					'type'  => 'post_type',
621
					'label' => $post_type_obj->label,
622
				);
623
			}
624
		}
625
		$taxonomy_args = array(
626
			'public'   => true,
627
			'_builtin' => false,
628
			'show_ui'  => true,
629
		);
630
		$taxonomies    = get_taxonomies( $taxonomy_args, 'objects' );
631
		if ( ! empty( $taxonomies ) ) {
632
			foreach ( $taxonomies as $tax_key => $tax_obj ) {
633
				$sitemap_loops[ $tax_key ] = array(
634
					'type'  => 'taxonomy',
635
					'label' => $tax_obj->label,
636
				);
637
			}
638
		}
639
		$sitemap_loops = apply_filters( 'lsx_sitemap_loops_list', $sitemap_loops );
640
		foreach ( $sitemap_loops as $sitemap_key => $sitemap_values ) {
641
			if ( 'post_type' === $sitemap_values['type'] ) {
642
				if ( isset( $sitemap_values['heirarchy'] ) && true === $sitemap_values['heirarchy'] ) {
643
					lsx_sitemap_pages( $sitemap_key, $sitemap_values['label'] );
644
				} else {
645
					lsx_sitemap_custom_post_type( $sitemap_key, $sitemap_values['label'] );
646
				}
647
			} else {
648
				if ( isset( $sitemap_values['heirarchy'] ) && true === $sitemap_values['heirarchy'] ) {
649
					lsx_sitemap_taxonomy( $sitemap_key, $sitemap_values['label'], true );
650
				} else {
651
					lsx_sitemap_taxonomy( $sitemap_key, $sitemap_values['label'], false );
652
				}
653
			}
654
		}
655
	}
656
}
657
658
if ( ! function_exists( 'lsx_sitemap_pages' ) ) :
659
660
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$forced_type" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$label" missing
Loading history...
661
	 * Outputs Pages for the Sitemap Template.
662
	 *
663
	 * @package    lsx
664
	 * @subpackage template-tags
665
	 */
666
	function lsx_sitemap_pages( $forced_type = '', $label = '' ) {
667
		$page_args = array(
668
			'depth'        => 3,
669
			'title_li'     => '',
670
			'echo'         => 1,
671
			'sort_column'  => 'menu_order, post_title',
672
			'post_type'    => $forced_type,
673
			'item_spacing' => 'preserve',
674
		);
675
		echo '<h2>' . esc_html( $label ) . '</h2>';
676
		echo '<ul>';
677
		wp_list_pages( $page_args );
678
		echo '</ul>';
679
	}
680
681
endif;
682
683
if ( ! function_exists( 'lsx_sitemap_custom_post_type' ) ) :
684
685
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$forced_type" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$label" missing
Loading history...
686
	 * Outputs a custom post type section.
687
	 *
688
	 * @package    lsx
689
	 * @subpackage template-tags
690
	 */
691
	function lsx_sitemap_custom_post_type( $forced_type = '', $label = '' ) {
692
		if ( '' !== $forced_type ) {
693
			$post_types = array( $forced_type );
694
		} else {
695
			$args       = array(
696
				'public'   => true,
697
				'_builtin' => false,
698
			);
699
			$post_types = get_post_types( $args, 'names' );
700
		}
701
702
		foreach ( $post_types as $post_type ) {
703
			$post_type_args = array(
704
				'post_type'      => 'page',
705
				'posts_per_page' => 99,
706
				'post_status'    => 'publish',
707
				'post_type'      => $post_type,
708
			);
709
710
			$post_type_items  = new WP_Query( $post_type_args );
711
			$post_type_object = get_post_type_object( $post_type );
712
713
			if ( '' !== $label ) {
714
				$title = $label;
715
			} elseif ( ! empty( $post_type_object ) ) {
716
				$title = $post_type_object->labels->name;
717
			} else {
718
				$title = ucwords( $post_type );
719
			}
720
721
			if ( $post_type_items->have_posts() ) {
722
				echo '<h2>' . esc_html( $title ) . '</h2>';
723
				echo '<ul>';
724
725
				while ( $post_type_items->have_posts() ) {
726
					$post_type_items->the_post();
727
					echo '<li class="' . esc_attr( get_post_type() ) . '_item ' . esc_attr( get_post_type() ) . '-item-' . esc_attr( get_the_ID() ) . '"><a href="' . esc_url( get_permalink() ) . '" title="">' . get_the_title() . '</a></li>';
0 ignored issues
show
Bug introduced by
It seems like get_the_ID() can also be of type false; however, parameter $text of esc_attr() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

727
					echo '<li class="' . esc_attr( get_post_type() ) . '_item ' . esc_attr( get_post_type() ) . '-item-' . esc_attr( /** @scrutinizer ignore-type */ get_the_ID() ) . '"><a href="' . esc_url( get_permalink() ) . '" title="">' . get_the_title() . '</a></li>';
Loading history...
introduced by
All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found 'get_the_title'.
Loading history...
Bug introduced by
It seems like get_permalink() can also be of type false; however, parameter $url of esc_url() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

727
					echo '<li class="' . esc_attr( get_post_type() ) . '_item ' . esc_attr( get_post_type() ) . '-item-' . esc_attr( get_the_ID() ) . '"><a href="' . esc_url( /** @scrutinizer ignore-type */ get_permalink() ) . '" title="">' . get_the_title() . '</a></li>';
Loading history...
728
				}
729
730
				echo '</ul>';
731
				wp_reset_postdata();
732
			}
733
		}
734
	}
735
736
endif;
737
738
/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$taxonomy" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$label" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$hierarchical" missing
Loading history...
739
 * Sitemap Travel Style
740
 *
741
 * @return void
742
 */
743
function lsx_sitemap_taxonomy( $taxonomy = '', $label = '', $hierarchical = false ) {
744
	if ( '' !== $taxonomy ) {
745
746
		$tax_args   = array(
747
			'echo'                => 0,
748
			'depth'               => 0,
749
			'hide_empty'          => 1,
750
			'hide_title_if_empty' => false,
751
			'hierarchical'        => $hierarchical,
752
			'separator'           => '<br />',
753
			'show_count'          => 0,
754
			'show_option_none'    => __( 'None', 'lsx' ),
755
			'style'               => 'list',
756
			'taxonomy'            => $taxonomy,
757
			'title_li'            => '',
758
		);
759
		$categories = wp_list_categories( $tax_args );
760
		if ( ! empty( $categories ) ) {
761
			echo '<div class="sitemap-rows">';
762
			echo '<h2>' . wp_kses_post( $label ) . '</h2>';
763
			echo '<ul>';
764
			echo wp_kses_post( $categories );
765
			echo '</ul>';
766
			echo '</div>';
767
		}
768
	}
769
}
770
771
if ( ! function_exists( 'lsx_sitemap_taxonomy_clouds' ) ) :
772
773
	/**
774
	 * Outputs the public taxonomies.
775
	 *
776
	 * @package    lsx
777
	 * @subpackage template-tags
778
	 */
779
	function lsx_sitemap_taxonomy_clouds() {
780
		$taxonomy_args = array(
781
			'public'   => true,
782
			'_builtin' => false,
783
		);
784
785
		$taxonomies = get_taxonomies( $taxonomy_args );
786
787
		if ( ! empty( $taxonomies ) ) {
788
			foreach ( $taxonomies as $taxonomy_id => $taxonomy ) {
789
				$tag_cloud = wp_tag_cloud(
790
					array(
791
						'taxonomy' => $taxonomy_id,
792
						'echo'     => false,
793
					)
794
				);
795
796
				if ( ! empty( $tag_cloud ) ) {
797
					echo '<h2>' . esc_html( $taxonomy ) . '</h2>';
798
					echo '<aside id="' . esc_attr( $taxonomy_id ) . '" class="widget widget_' . esc_attr( $taxonomy_id ) . '">' . esc_html( $tag_cloud ) . '</aside>';
0 ignored issues
show
Bug introduced by
It seems like $tag_cloud can also be of type string[]; however, parameter $text of esc_html() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

798
					echo '<aside id="' . esc_attr( $taxonomy_id ) . '" class="widget widget_' . esc_attr( $taxonomy_id ) . '">' . esc_html( /** @scrutinizer ignore-type */ $tag_cloud ) . '</aside>';
Loading history...
799
				}
800
			}
801
		}
802
	}
803
804
endif;
805
806
if ( ! function_exists( 'lsx_add_top_menu' ) ) :
807
808
	/**
809
	 * Adds our top menu to the theme.
810
	 *
811
	 * @package    lsx
812
	 * @subpackage template-tags
813
	 */
814
	function lsx_add_top_menu() {
815
		if ( has_nav_menu( 'top-menu' ) || has_nav_menu( 'top-menu-left' ) ) :
816
			?>
817
			<div id="top-menu" class="<?php lsx_top_menu_classes(); ?>">
818
				<div class="container">
819
					<?php if ( has_nav_menu( 'top-menu' ) ) : ?>
820
						<nav class="top-menu">
821
							<?php
822
								wp_nav_menu(
823
									array(
824
										'theme_location' => 'top-menu',
825
										'walker'         => new LSX_Bootstrap_Navwalker(),
826
									)
827
								);
828
							?>
829
						</nav>
830
					<?php endif; ?>
831
832
					<?php if ( has_nav_menu( 'top-menu-left' ) ) : ?>
833
						<nav class="top-menu pull-left">
834
							<?php
835
								wp_nav_menu(
836
									array(
837
										'theme_location' => 'top-menu-left',
838
										'walker'         => new LSX_Bootstrap_Navwalker(),
839
									)
840
								);
841
							?>
842
						</nav>
843
					<?php endif; ?>
844
				</div>
845
			</div>
846
			<?php
847
		endif;
848
	}
849
850
endif;
851
852
add_action( 'lsx_header_before', 'lsx_add_top_menu' );
853
854
if ( ! function_exists( 'lsx_get_my_url' ) ) :
855
856
	/**
857
	 * Return URL from a link in the content.
858
	 *
859
	 * @package    lsx
860
	 * @subpackage template-tags
861
	 */
862
	function lsx_get_my_url() {
863
		if ( ! preg_match( '/^<a\s[^>]*?href=[\'"](.+?)[\'"]$/is', get_the_content(), $matches ) ) {
864
			return false;
865
		}
866
867
		return esc_url_raw( $matches[1] );
868
	}
869
870
endif;
871
872
if ( ! function_exists( 'lsx_get_template_part' ) ) :
873
874
	/**
875
	 * Gets a custom template part if the filters is populated,  or does the normal WP get_content_part()
876
	 *
877
	 * @package    lsx
878
	 * @subpackage template-tags
879
	 */
880
	function lsx_get_template_part() {
881
		$custom_template = apply_filters( 'lsx_get_template_part', '' );
882
		if ( '' !== $custom_template && file_exists( $custom_template ) ) {
883
			include $custom_template;
884
		} else {
885
			get_template_part( 'partials/content', get_post_format() );
0 ignored issues
show
Bug introduced by
It seems like get_post_format() can also be of type false; however, parameter $name of get_template_part() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

885
			get_template_part( 'partials/content', /** @scrutinizer ignore-type */ get_post_format() );
Loading history...
886
		}
887
	}
888
889
endif;
890
891
892