Passed
Push — master ( b096e4...dcfecd )
by Chris
05:13
created

lsx_breadcrumbs()   B

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 );
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 );
59
//add_action( 'lsx_global_header_inner_bottom', 'lsx_breadcrumbs', 100 );
60
61
if ( ! function_exists( 'lsx_breadcrumbs_wpseo_seperator_filter' ) ) :
62
63
	/**
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
	/**
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(); ?>
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' );
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();
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 $args of sprintf() 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

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
	/**
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_site_identity' ) ) :
445
446
	/**
447
	 * Outputs either the Site Title or the Site Logo.
448
	 *
449
	 * @package    lsx
450
	 * @subpackage template-tags
451
	 */
452
	function lsx_site_identity() {
453
		if ( function_exists( 'has_custom_logo' ) && has_custom_logo() ) {
454
			if ( version_compare( get_bloginfo( 'version' ), '5.5', '<' ) ) {
455
				the_custom_logo();
456
			} else {
457
				echo wp_kses_post( '<a href="' . home_url() . '" class="custom-logo-link" rel="home">' . the_custom_logo() . '</a>' );
0 ignored issues
show
Bug introduced by
Are you sure the usage of the_custom_logo() is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
458
			}
459
		} else {
460
			if ( get_theme_mod( 'site_logo_header_text', 1 ) ) {
461
				lsx_site_title();
462
			}
463
		}
464
	}
465
466
endif;
467
468
if ( ! function_exists( 'lsx_navbar_header' ) ) :
469
	/**
470
	 * Outputs the Nav Menu.
471
	 *
472
	 * @package    lsx
473
	 * @subpackage template-tags
474
	 */
475
	function lsx_navbar_header() {
476
		$mobile_header_layout = get_theme_mod( 'lsx_header_mobile_layout', 'navigation-bar' );
477
		if ( 'hamburger' === $mobile_header_layout ) {
478
			?>
479
			<div class="navbar-header" itemscope itemtype="http://schema.org/WebPage">
480
				<?php
481
				lsx_header_search_form();
482
				lsx_site_identity();
483
				if ( has_nav_menu( 'primary' ) ) :
484
					?>
485
					<div class="wrapper-toggle" data-toggle="collapse" data-target=".primary-navbar">
486
						<button type="button" class="navbar-toggle">
487
							<span class="sr-only"><?php esc_html_e( 'Toggle navigation', 'lsx' ); ?></span>
488
							<span class="icon-bar icon-bar-1"></span>
489
							<span class="icon-bar icon-bar-2"></span>
490
							<span class="icon-bar icon-bar-3"></span>
491
						</button>
492
					</div>
493
					<?php
494
				endif;
495
				?>
496
			</div>
497
			<?php
498
		} else {
499
			?>
500
			<div class="navbar-header" itemscope itemtype="http://schema.org/WebPage">
501
				<?php
502
				if ( has_nav_menu( 'primary' ) ) :
503
					?>
504
					<div class="wrapper-toggle" data-toggle="collapse" data-target=".primary-navbar">
505
						<button type="button" class="navbar-toggle">
506
							<span class="sr-only"><?php esc_html_e( 'Toggle navigation', 'lsx' ); ?></span>
507
							<span class="icon-bar"></span>
508
							<span class="icon-bar"></span>
509
							<span class="icon-bar"></span>
510
							<span class="icon-bar"></span>
511
						</button>
512
						<span class="mobile-menu-title"><?php esc_html_e( 'Menu', 'lsx' ); ?></span>
513
					</div>
514
					<?php
515
				endif;
516
517
				lsx_site_identity();
518
				?>
519
			</div>
520
			<?php
521
		}
522
	}
523
524
endif;
525
526
add_action( 'lsx_nav_before', 'lsx_navbar_header' );
527
528
if ( ! function_exists( 'lsx_nav_menu' ) ) :
529
	/**
530
	 * Outputs the Nav Menu.
531
	 *
532
	 * @package    lsx
533
	 * @subpackage template-tags
534
	 */
535
	function lsx_nav_menu() {
536
		if ( has_nav_menu( 'primary' ) ) :
537
			?>
538
			<nav class="primary-navbar collapse navbar-collapse">
539
				<?php
540
					wp_nav_menu(
541
						array(
542
							'theme_location' => 'primary',
543
							'depth'          => 3,
544
							'container'      => false,
545
							'menu_class'     => 'nav navbar-nav',
546
							'walker'         => new LSX_Bootstrap_Navwalker(),
547
						)
548
					);
549
				?>
550
			</nav>
551
			<?php
552
		endif;
553
	}
554
endif;
555
556
if ( ! function_exists( 'lsx_sitemap_loops' ) ) {
557
	/**
558
	 * Outputs the loops on the sitemap
559
	 *
560
	 * @package    lsx
561
	 * @subpackage template-tags
562
	 */
563
	function lsx_sitemap_loops() {
564
		$sitemap_loops  = array(
565
			'page'     => array(
566
				'type'      => 'post_type',
567
				'label'     => __( 'Pages', 'lsx' ),
568
				'heirarchy' => true,
569
			),
570
			'post'     => array(
571
				'type'  => 'post_type',
572
				'label' => __( 'Posts', 'lsx' ),
573
			),
574
			'category' => array(
575
				'type'      => 'taxonomy',
576
				'label'     => __( 'Categories', 'lsx' ),
577
				'heirarchy' => true,
578
			),
579
		);
580
		$post_type_args = array(
581
			'public'   => true,
582
			'_builtin' => false,
583
			'show_ui'  => true,
584
		);
585
		$post_types     = get_post_types( $post_type_args, 'objects' );
586
		if ( ! empty( $post_types ) ) {
587
			foreach ( $post_types as $post_type_key => $post_type_obj ) {
588
				$sitemap_loops[ $post_type_key ] = array(
589
					'type'  => 'post_type',
590
					'label' => $post_type_obj->label,
591
				);
592
			}
593
		}
594
		$taxonomy_args = array(
595
			'public'   => true,
596
			'_builtin' => false,
597
			'show_ui'  => true,
598
		);
599
		$taxonomies    = get_taxonomies( $taxonomy_args, 'objects' );
600
		if ( ! empty( $taxonomies ) ) {
601
			foreach ( $taxonomies as $tax_key => $tax_obj ) {
602
				$sitemap_loops[ $tax_key ] = array(
603
					'type'  => 'taxonomy',
604
					'label' => $tax_obj->label,
605
				);
606
			}
607
		}
608
		$sitemap_loops = apply_filters( 'lsx_sitemap_loops_list', $sitemap_loops );
609
		foreach ( $sitemap_loops as $sitemap_key => $sitemap_values ) {
610
			if ( 'post_type' === $sitemap_values['type'] ) {
611
				if ( isset( $sitemap_values['heirarchy'] ) && true === $sitemap_values['heirarchy'] ) {
612
					lsx_sitemap_pages( $sitemap_key, $sitemap_values['label'] );
613
				} else {
614
					lsx_sitemap_custom_post_type( $sitemap_key, $sitemap_values['label'] );
615
				}
616
			} else {
617
				if ( isset( $sitemap_values['heirarchy'] ) && true === $sitemap_values['heirarchy'] ) {
618
					lsx_sitemap_taxonomy( $sitemap_key, $sitemap_values['label'], true );
619
				} else {
620
					lsx_sitemap_taxonomy( $sitemap_key, $sitemap_values['label'], false );
621
				}
622
			}
623
		}
624
	}
625
}
626
627
if ( ! function_exists( 'lsx_sitemap_pages' ) ) :
628
629
	/**
630
	 * Outputs Pages for the Sitemap Template.
631
	 *
632
	 * @package    lsx
633
	 * @subpackage template-tags
634
	 */
635
	function lsx_sitemap_pages( $forced_type = '', $label = '' ) {
636
		$page_args = array(
637
			'depth'        => 3,
638
			'title_li'     => '',
639
			'echo'         => 1,
640
			'sort_column'  => 'menu_order, post_title',
641
			'post_type'    => $forced_type,
642
			'item_spacing' => 'preserve',
643
		);
644
		echo '<h2>' . esc_html( $label ) . '</h2>';
645
		echo '<ul>';
646
		wp_list_pages( $page_args );
647
		echo '</ul>';
648
	}
649
650
endif;
651
652
if ( ! function_exists( 'lsx_sitemap_custom_post_type' ) ) :
653
654
	/**
655
	 * Outputs a custom post type section.
656
	 *
657
	 * @package    lsx
658
	 * @subpackage template-tags
659
	 */
660
	function lsx_sitemap_custom_post_type( $forced_type = '', $label = '' ) {
661
		if ( '' !== $forced_type ) {
662
			$post_types = array( $forced_type );
663
		} else {
664
			$args       = array(
665
				'public'   => true,
666
				'_builtin' => false,
667
			);
668
			$post_types = get_post_types( $args, 'names' );
669
		}
670
671
		foreach ( $post_types as $post_type ) {
672
			$post_type_args = array(
673
				'post_type'      => 'page',
674
				'posts_per_page' => 99,
675
				'post_status'    => 'publish',
676
				'post_type'      => $post_type,
677
			);
678
679
			$post_type_items  = new WP_Query( $post_type_args );
680
			$post_type_object = get_post_type_object( $post_type );
681
682
			if ( '' !== $label ) {
683
				$title = $label;
684
			} elseif ( ! empty( $post_type_object ) ) {
685
				$title = $post_type_object->labels->name;
686
			} else {
687
				$title = ucwords( $post_type );
688
			}
689
690
			if ( $post_type_items->have_posts() ) {
691
				echo '<h2>' . esc_html( $title ) . '</h2>';
692
				echo '<ul>';
693
694
				while ( $post_type_items->have_posts() ) {
695
					$post_type_items->the_post();
696
					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_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

696
					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...
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

696
					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...
697
				}
698
699
				echo '</ul>';
700
				wp_reset_postdata();
701
			}
702
		}
703
	}
704
705
endif;
706
707
/**
708
 * Sitemap Travel Style
709
 *
710
 * @return void
711
 */
712
function lsx_sitemap_taxonomy( $taxonomy = '', $label = '', $hierarchical = false ) {
713
	if ( '' !== $taxonomy ) {
714
715
		$tax_args   = array(
716
			'echo'                => 0,
717
			'depth'               => 0,
718
			'hide_empty'          => 1,
719
			'hide_title_if_empty' => false,
720
			'hierarchical'        => $hierarchical,
721
			'separator'           => '<br />',
722
			'show_count'          => 0,
723
			'show_option_none'    => __( 'None', 'lsx' ),
724
			'style'               => 'list',
725
			'taxonomy'            => $taxonomy,
726
			'title_li'            => '',
727
		);
728
		$categories = wp_list_categories( $tax_args );
729
		if ( ! empty( $categories ) ) {
730
			echo '<div class="sitemap-rows">';
731
			echo '<h2>' . wp_kses_post( $label ) . '</h2>';
732
			echo '<ul>';
733
			echo wp_kses_post( $categories );
734
			echo '</ul>';
735
			echo '</div>';
736
		}
737
	}
738
}
739
740
if ( ! function_exists( 'lsx_sitemap_taxonomy_clouds' ) ) :
741
742
	/**
743
	 * Outputs the public taxonomies.
744
	 *
745
	 * @package    lsx
746
	 * @subpackage template-tags
747
	 */
748
	function lsx_sitemap_taxonomy_clouds() {
749
		$taxonomy_args = array(
750
			'public'   => true,
751
			'_builtin' => false,
752
		);
753
754
		$taxonomies = get_taxonomies( $taxonomy_args );
755
756
		if ( ! empty( $taxonomies ) ) {
757
			foreach ( $taxonomies as $taxonomy_id => $taxonomy ) {
758
				$tag_cloud = wp_tag_cloud(
759
					array(
760
						'taxonomy' => $taxonomy_id,
761
						'echo'     => false,
762
					)
763
				);
764
765
				if ( ! empty( $tag_cloud ) ) {
766
					echo '<h2>' . esc_html( $taxonomy ) . '</h2>';
767
					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 array; 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

767
					echo '<aside id="' . esc_attr( $taxonomy_id ) . '" class="widget widget_' . esc_attr( $taxonomy_id ) . '">' . esc_html( /** @scrutinizer ignore-type */ $tag_cloud ) . '</aside>';
Loading history...
768
				}
769
			}
770
		}
771
	}
772
773
endif;
774
775
if ( ! function_exists( 'lsx_add_top_menu' ) ) :
776
777
	/**
778
	 * Adds our top menu to the theme.
779
	 *
780
	 * @package    lsx
781
	 * @subpackage template-tags
782
	 */
783
	function lsx_add_top_menu() {
784
		if ( has_nav_menu( 'top-menu' ) || has_nav_menu( 'top-menu-left' ) ) :
785
			?>
786
			<div id="top-menu" class="<?php lsx_top_menu_classes(); ?>">
787
				<div class="container">
788
					<?php if ( has_nav_menu( 'top-menu' ) ) : ?>
789
						<nav class="top-menu">
790
							<?php
791
								wp_nav_menu(
792
									array(
793
										'theme_location' => 'top-menu',
794
										'walker'         => new LSX_Bootstrap_Navwalker(),
795
									)
796
								);
797
							?>
798
						</nav>
799
					<?php endif; ?>
800
801
					<?php if ( has_nav_menu( 'top-menu-left' ) ) : ?>
802
						<nav class="top-menu pull-left">
803
							<?php
804
								wp_nav_menu(
805
									array(
806
										'theme_location' => 'top-menu-left',
807
										'walker'         => new LSX_Bootstrap_Navwalker(),
808
									)
809
								);
810
							?>
811
						</nav>
812
					<?php endif; ?>
813
				</div>
814
			</div>
815
			<?php
816
		endif;
817
	}
818
819
endif;
820
821
add_action( 'lsx_header_before', 'lsx_add_top_menu' );
822
823
if ( ! function_exists( 'lsx_get_my_url' ) ) :
824
825
	/**
826
	 * Return URL from a link in the content.
827
	 *
828
	 * @package    lsx
829
	 * @subpackage template-tags
830
	 */
831
	function lsx_get_my_url() {
832
		if ( ! preg_match( '/^<a\s[^>]*?href=[\'"](.+?)[\'"]$/is', get_the_content(), $matches ) ) {
833
			return false;
834
		}
835
836
		return esc_url_raw( $matches[1] );
837
	}
838
839
endif;
840
841
if ( ! function_exists( 'lsx_get_template_part' ) ) :
842
843
	/**
844
	 * Gets a custom template part if the filters is populated,  or does the normal WP get_content_part()
845
	 *
846
	 * @package    lsx
847
	 * @subpackage template-tags
848
	 */
849
	function lsx_get_template_part() {
850
		$custom_template = apply_filters( 'lsx_get_template_part', '' );
851
		if ( '' !== $custom_template && file_exists( $custom_template ) ) {
852
			include $custom_template;
853
		} else {
854
			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

854
			get_template_part( 'partials/content', /** @scrutinizer ignore-type */ get_post_format() );
Loading history...
855
		}
856
	}
857
858
endif;
859
860
861