Completed
Push — master ( baabf5...12a59e )
by Warwick
03:22
created

layout.php ➔ lsx_post_header()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 0
dl 0
loc 24
rs 9.536
c 0
b 0
f 0
1
<?php
2
/**
3
 * LSX functions and definitions - Layout.
4
 *
5
 * @package    lsx
6
 * @subpackage layout
7
 */
8
9
if ( ! defined( 'ABSPATH' ) ) {
10
	exit;
11
}
12
13
if ( ! function_exists( 'lsx_layout_selector' ) ) :
14
15
	/**
16
	 * Layout selector.
17
	 *
18
	 * @package    lsx
19
	 * @subpackage layout
20
	 */
21
	function lsx_layout_selector( $class, $area = 'site' ) {
0 ignored issues
show
Unused Code introduced by
The parameter $area 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...
22
		$return_class = '';
23
		$layout       = get_theme_mod( 'lsx_layout', '2cr' );
24
		$layout       = apply_filters( 'lsx_layout', $layout );
25
		$default_size = 'sm';
26
		$size         = apply_filters( 'lsx_bootstrap_column_size', $default_size );
27
28
		switch ( $layout ) {
29
			case '1c':
30
				$main_class    = 'col-' . $size . '-12';
31
				$sidebar_class = 'col-' . $size . '-12';
32
				break;
33 View Code Duplication
			case '2cr':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
34
				$main_class    = 'col-' . $size . '-8';
35
				$sidebar_class = 'col-' . $size . '-4';
36
				break;
37
			case '2cl':
38
				$main_class    = 'col-' . $size . '-8 col-' . $size . '-push-4';
39
				$sidebar_class = 'col-' . $size . '-4 col-' . $size . '-pull-8';
40
				break;
41 View Code Duplication
			default:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
42
				$main_class    = 'col-' . $size . '-8';
43
				$sidebar_class = 'col-' . $size . '-4';
44
				break;
45
		}
46
47
		if ( 'main' === $class ) {
48
			$return_class = apply_filters( 'lsx_layout_selector', $main_class, $class, $layout, $size );
49
		}
50
51
		if ( 'sidebar' === $class ) {
52
			$return_class = apply_filters( 'lsx_layout_selector', $sidebar_class, $class, $layout, $size );
53
		}
54
55
		return $return_class;
56
	}
57
58
endif;
59
60
if ( ! function_exists( 'lsx_main_class' ) ) :
61
62
	/**
63
	 * .main classes.
64
	 *
65
	 * @package    lsx
66
	 * @subpackage layout
67
	 */
68
	function lsx_main_class() {
69
		return lsx_layout_selector( 'main' );
70
	}
71
72
endif;
73
74
if ( ! function_exists( 'lsx_sidebar_class' ) ) :
75
76
	/**
77
	 * .sidebar classes.
78
	 *
79
	 * @package    lsx
80
	 * @subpackage layout
81
	 */
82
	function lsx_sidebar_class() {
83
		return lsx_layout_selector( 'sidebar' );
84
	}
85
86
endif;
87
88 View Code Duplication
if ( ! function_exists( 'lsx_header_classes' ) ) :
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
89
90
	/**
91
	 * Output the classes for the header.
92
	 *
93
	 * @package    lsx
94
	 * @subpackage layout
95
	 */
96
	function lsx_header_classes( $additional = false ) {
97
		$classes = 'banner navbar navbar-default';
98
99
		if ( false !== $additional ) {
100
			$classes .= ' ' . $additional;
101
		}
102
103
		echo esc_attr( $classes );
104
	}
105
106
endif;
107
108 View Code Duplication
if ( ! function_exists( 'lsx_top_menu_classes' ) ) :
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
109
110
	/**
111
	 * Output the classes for the top-menu.
112
	 *
113
	 * @package    lsx
114
	 * @subpackage layout
115
	 */
116
	function lsx_top_menu_classes( $additional = false ) {
117
		$classes = 'top-menu-default';
118
119
		if ( false !== $additional ) {
120
			$classes .= ' ' . $additional;
121
		}
122
123
		echo esc_attr( $classes );
124
	}
125
126
endif;
127
128
if ( ! function_exists( 'lsx_add_footer_sidebar_area' ) ) :
129
130
	/**
131
	 * Output the Footer CTA and/pr Footer Widgets.
132
	 *
133
	 * @package    lsx
134
	 * @subpackage layout
135
	 */
136
	function lsx_add_footer_sidebar_area() {
137
		if ( is_active_sidebar( 'sidebar-footer-cta' ) ) : ?>
138
			<div id="footer-cta">
139
				<div class="container">
140
					<div class="lsx-full-width">
141
						<div class="lsx-hero-unit">
142
							<?php dynamic_sidebar( 'sidebar-footer-cta' ); ?>
143
						</div>
144
					</div>
145
				</div>
146
			</div>
147
		<?php endif; ?>
148
149
		<?php if ( is_active_sidebar( 'sidebar-footer' ) ) : ?>
150
			<div id="footer-widgets">
151
				<div class="container">
152
					<div class="row">
153
						<?php dynamic_sidebar( 'sidebar-footer' ); ?>
154
					</div>
155
				</div>
156
			</div>
157
		<?php endif;
158
	}
159
160
	add_action( 'lsx_footer_before', 'lsx_add_footer_sidebar_area' );
161
162
endif;
163
164
if ( ! function_exists( 'lsx_global_header' ) ) :
165
166
	/**
167
	 * Displays the global header.
168
	 *
169
	 * @package    lsx
170
	 * @subpackage layout
171
	 */
172
	function lsx_global_header() {
173
		// if ( true === apply_filters( 'lsx_global_header_disable', false ) ) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
46% 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...
174
		// 	return;
175
		// }
176
177
		$show_on_front  = get_option( 'show_on_front' );
178
		$queried_object = get_queried_object();
179
		$default_size   = 'sm';
180
		$size           = apply_filters( 'lsx_bootstrap_column_size', $default_size );
181
182
		if ( true === apply_filters( 'lsx_global_header_disable', false ) ) :
183
			// Display only the breadcrumbs
184
			?>
185
			<div class="archive-header-wrapper col-<?php echo esc_attr( $size ); ?>-12">
186
				<?php lsx_global_header_inner_bottom(); ?>
187
			</div>
188
			<?php
189
		elseif ( is_page() && ( 'page' !== $show_on_front || ! is_front_page() ) ) :
190
			?>
191
			<div class="archive-header-wrapper col-<?php echo esc_attr( $size ); ?>-12">
192
				<header class="archive-header">
193
					<h1 class="archive-title"><?php the_title(); ?></h1>
194
				</header>
195
196
				<?php lsx_global_header_inner_bottom(); ?>
197
			</div>
198
			<?php
199
		elseif ( is_single() && ! is_singular( 'post' ) ) :
200
			?>
201
			<div class="archive-header-wrapper col-<?php echo esc_attr( $size ); ?>-12">
202
				<header class="archive-header">
203
					<h1 class="archive-title"><?php the_title(); ?></h1>
204
				</header>
205
206
				<?php lsx_global_header_inner_bottom(); ?>
207
			</div>
208
			<?php
209
		elseif ( is_search() ) :
210
			?>
211
			<div class="archive-header-wrapper col-<?php echo esc_attr( $size ); ?>-12">
212
				<header class="archive-header">
213
					<h1 class="archive-title">
214
						<?php
215
							printf(
216
								/* Translators: %s: search term/query */
217
								esc_html__( 'Search Results for: %s', 'lsx' ),
218
								'<span>' . get_search_query() . '</span>'
219
							);
220
						?>
221
					</h1>
222
				</header>
223
224
				<?php lsx_global_header_inner_bottom(); ?>
225
			</div>
226
			<?php
227
		elseif ( is_author() ) :
228
			$author = get_the_author();
0 ignored issues
show
Unused Code introduced by
$author 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...
229
			$author_avatar = get_avatar( get_the_author_meta( 'ID' ), 256 );
0 ignored issues
show
Unused Code introduced by
$author_avatar 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...
230
			$author_bio = get_the_archive_description();
0 ignored issues
show
Unused Code introduced by
$author_bio 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...
231
			?>
232
			<div class="archive-header-wrapper col-<?php echo esc_attr( $size ); ?>-12">
233
				<header class="archive-header">
234
					<h1 class="archive-title"><?php the_archive_title(); ?></h1>
235
				</header>
236
237
				<?php lsx_global_header_inner_bottom(); ?>
238
			</div>
239
			<?php
240
		elseif ( is_archive() ) :
241
			?>
242
			<div class="archive-header-wrapper col-<?php echo esc_attr( $size ); ?>-12">
243
				<header class="archive-header">
244
					<h1 class="archive-title">
245
						<?php if ( has_post_format() && ! is_category() && ! is_tag() && ! is_date() && ! is_tax( 'post_format' ) ) { ?>
246
							<?php the_archive_title( esc_html__( 'Type:', 'lsx' ) ); ?>
247
						<?php } else { ?>
248
							<?php the_archive_title(); ?>
249
						<?php } ?>
250
					</h1>
251
252
					<?php the_archive_description(); ?>
253
				</header>
254
255
				<?php lsx_global_header_inner_bottom(); ?>
256
			</div>
257
			<?php
258
		elseif ( 'page' === $show_on_front && (int) get_option( 'page_for_posts' ) === $queried_object->ID ) :
259
			?>
260
			<div class="archive-header-wrapper col-<?php echo esc_attr( $size ); ?>-12">
261
				<header class="archive-header">
262
					<h1 class="archive-title"><?php esc_html_e( 'Blog', 'lsx' ); ?></h1>
263
				</header>
264
265
				<?php lsx_global_header_inner_bottom(); ?>
266
			</div>
267
			<?php
268
		elseif ( ! is_singular( 'post' ) ) :
269
			// Display only the breadcrumbs
270
			?>
271
			<div class="archive-header-wrapper col-<?php echo esc_attr( $size ); ?>-12">
272
				<?php lsx_global_header_inner_bottom(); ?>
273
			</div>
274
			<?php
275
		endif;
276
	}
277
278
	add_action( 'lsx_content_wrap_before', 'lsx_global_header' );
279
280
endif;
281
282
if ( ! function_exists( 'lsx_author_extra_info' ) ) :
283
284
	/**
285
	 * Displays the author extra info.
286
	 *
287
	 * @package    lsx
288
	 * @subpackage layout
289
	 */
290
	function lsx_author_extra_info() {
291
		$default_size   = 'sm';
292
		$size           = apply_filters( 'lsx_bootstrap_column_size', $default_size );
293
294
		if ( is_author() ) :
295
			$author_id         = get_the_author_meta( 'ID' );
296
			$author            = get_the_author();
297
			$author_avatar     = get_avatar( $author_id, 256 );
298
			$author_bio        = get_the_archive_description();
299
			$author_url        = get_the_author_meta( 'url', $author_id );
300
			$author_email      = get_the_author_meta( 'email', $author_id );
301
			$author_facebook   = get_the_author_meta( 'facebook', $author_id );
302
			$author_twitter    = get_the_author_meta( 'twitter', $author_id );
303
			$author_googleplus = get_the_author_meta( 'googleplus', $author_id );
304
			?>
305
			<div class="col-<?php echo esc_attr( $size ); ?>-12">
306
				<div class="archive-author-data">
307
					<figure class="archive-author-avatar"><?php echo wp_kses_post( $author_avatar ); ?></figure>
308
309
					<?php if ( ! empty( $author_url ) || ! empty( $author_email ) || ! empty( $author_facebook ) || ! empty( $author_twitter ) || ! empty( $author_googleplus ) ) : ?>
310
						<div class="archive-author-social-links">
311
							<?php if ( ! empty( $author_url ) ) : ?>
312
								<a href="<?php echo esc_url( $author_url ); ?>" target="_blank" rel="nofollow noreferrer noopener" class="archive-author-social-link archive-author-social-link-url"><i class="fa fa-link" aria-hidden="true"></i></a>
313
							<?php endif; ?>
314
315
							<?php if ( ! empty( $author_email ) ) : ?>
316
								<a href="mailto:<?php echo esc_attr( $author_email ); ?>" class="archive-author-social-link archive-author-social-link-email"><i class="fa fa-envelope" aria-hidden="true"></i></a>
317
							<?php endif; ?>
318
319
							<?php if ( ! empty( $author_facebook ) ) : ?>
320
								<a href="<?php echo esc_url( $author_facebook ); ?>" target="_blank" rel="nofollow noreferrer noopener" class="archive-author-social-link archive-author-social-link-facebook"><i class="fa fa-facebook" aria-hidden="true"></i></a>
321
							<?php endif; ?>
322
323
							<?php if ( ! empty( $author_twitter ) ) : ?>
324
								<a href="https://twitter.com/<?php echo esc_attr( $author_twitter ); ?>" target="_blank" rel="nofollow noreferrer noopener" class="archive-author-social-link archive-author-social-link-twitter"><i class="fa fa-twitter" aria-hidden="true"></i></a>
325
							<?php endif; ?>
326
327
							<?php if ( ! empty( $author_googleplus ) ) : ?>
328
								<a href="<?php echo esc_url( $author_googleplus ); ?>" target="_blank" rel="nofollow noreferrer noopener" class="archive-author-social-link archive-author-social-link-googleplus"><i class="fa fa-google-plus" aria-hidden="true"></i></a>
329
							<?php endif; ?>
330
						</div>
331
					<?php endif; ?>
332
333
					<?php if ( ! empty( $author_bio ) ) : ?>
334
						<h2 class="archive-author-title text-center"><?php esc_html_e( 'About the author', 'lsx' ); ?></h2>
335
						<p class="archive-author-bio"><?php echo wp_kses_post( $author_bio ); ?></p>
336
					<?php endif; ?>
337
338
					<h2 class="archive-author-posts text-center">
339
						<?php
340
							printf(
341
								/* Translators: %s: author name */
342
								esc_html__( 'All posts by %s', 'lsx' ),
343
								esc_html( $author )
344
							);
345
						?>
346
					</h2>
347
				</div>
348
			</div>
349
			<?php
350
		endif;
351
	}
352
353
	add_action( 'lsx_content_wrap_before', 'lsx_author_extra_info', 11 );
354
355
endif;
356
357
if ( ! function_exists( 'lsx_post_header' ) ) :
358
359
	/**
360
	 * Displays the post header.
361
	 *
362
	 * @package    lsx
363
	 * @subpackage layout
364
	 */
365
	function lsx_post_header() {
366
		$default_size  = 'sm';
367
		$size          = apply_filters( 'lsx_bootstrap_column_size', $default_size );
368
369
		if ( is_singular( 'post' ) ) :
370
			$format = get_post_format();
371
372
			if ( false === $format ) {
373
				$format = 'standard';
374
			}
375
376
			$format = lsx_translate_format_to_fontawesome( $format );
377
			?>
378
			<div class="archive-header-wrapper col-<?php echo esc_attr( $size ); ?>-12">
379
				<header class="archive-header">
380
					<h1 class="archive-title">
381
						<i class="format-link fa fa-<?php echo esc_attr( $format ); ?>"></i>
382
						<span><?php the_title(); ?></span>
383
					</h1>
384
				</header>
385
			</div>
386
			<?php
387
		endif;
388
	}
389
390
	add_action( 'lsx_entry_top', 'lsx_post_header' );
391
392
endif;
393
394
if ( ! function_exists( 'lsx_add_viewport_meta_tag' ) ) :
395
396
	/**
397
	 * Add Viewport Meta Tag to head.
398
	 *
399
	 * @package    lsx
400
	 * @subpackage layout
401
	 */
402
	function lsx_add_viewport_meta_tag() {
403
		?>
404
		<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=0">
405
		<?php
406
	}
407
408
	add_action( 'wp_head', 'lsx_add_viewport_meta_tag' );
409
410
endif;
411
412
if ( ! function_exists( 'lsx_header_search_form' ) ) :
413
414
	/**
415
	 * Add a search form to just above the nav menu.
416
	 *
417
	 * @package    lsx
418
	 * @subpackage layout
419
	 */
420
	function lsx_header_search_form() {
421
		$search_form = get_theme_mod( 'lsx_header_search', false );
422
423
		if ( false !== $search_form || is_customize_preview() ) {
424
			get_search_form( true );
425
		}
426
	}
427
428
	add_action( 'lsx_nav_before', 'lsx_header_search_form', 0 );
429
430
endif;
431