Passed
Push — master ( 832775...4a9978 )
by Virginia
55s queued 10s
created

layout.php ➔ lsx_author_extra_info()   F

Complexity

Conditions 16
Paths 521

Size

Total Lines 75

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 16
nc 521
nop 0
dl 0
loc 75
rs 2.0652
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

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

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

Commonly applied refactorings include:

1
<?php
2
/**
3
 * LSX functions and definitions - 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
	 * Layout selector.
16
	 *
17
	 * @package    lsx
18
	 * @subpackage layout
19
	 */
20
	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...
21
		$return_class = '';
22
		$layout       = get_theme_mod( 'lsx_layout', '1c' );
23
		$layout       = apply_filters( 'lsx_layout', $layout );
24
		$default_size = 'sm';
25
		$size         = apply_filters( 'lsx_bootstrap_column_size', $default_size );
26
27
		switch ( $layout ) {
28
			case '1c':
29
				$main_class    = 'col-' . $size . '-12';
30
				$sidebar_class = 'col-' . $size . '-12';
31
				break;
32 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...
33
				$main_class    = 'col-' . $size . '-8';
34
				$sidebar_class = 'col-' . $size . '-4';
35
				break;
36
			case '2cl':
37
				$main_class    = 'col-' . $size . '-8 col-' . $size . '-push-4';
38
				$sidebar_class = 'col-' . $size . '-4 col-' . $size . '-pull-8';
39
				break;
40 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...
41
				$main_class    = 'col-' . $size . '-8';
42
				$sidebar_class = 'col-' . $size . '-4';
43
				break;
44
		}
45
46
		if ( 'main' === $class ) {
47
			$return_class = apply_filters( 'lsx_layout_selector', $main_class, $class, $layout, $size );
48
		}
49
50
		if ( 'sidebar' === $class ) {
51
			$return_class = apply_filters( 'lsx_layout_selector', $sidebar_class, $class, $layout, $size );
52
		}
53
54
		return $return_class;
55
	}
56
endif;
57
58
if ( ! function_exists( 'lsx_main_class' ) ) :
59
	/**
60
	 * .main classes.
61
	 *
62
	 * @package    lsx
63
	 * @subpackage layout
64
	 */
65
	function lsx_main_class() {
66
		return lsx_layout_selector( 'main' );
67
	}
68
endif;
69
70
if ( ! function_exists( 'lsx_sidebar_class' ) ) :
71
	/**
72
	 * .sidebar classes.
73
	 *
74
	 * @package    lsx
75
	 * @subpackage layout
76
	 */
77
	function lsx_sidebar_class() {
78
		return lsx_layout_selector( 'sidebar' );
79
	}
80
endif;
81
82 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...
83
	/**
84
	 * Output the classes for the header.
85
	 *
86
	 * @package    lsx
87
	 * @subpackage layout
88
	 */
89
	function lsx_header_classes( $additional = false ) {
90
		$classes = 'banner navbar navbar-default';
91
92
		if ( false !== $additional ) {
93
			$classes .= ' ' . $additional;
94
		}
95
96
		echo esc_attr( $classes );
97
	}
98
endif;
99
100 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...
101
	/**
102
	 * Output the classes for the top-menu.
103
	 *
104
	 * @package    lsx
105
	 * @subpackage layout
106
	 */
107
	function lsx_top_menu_classes( $additional = false ) {
108
		$classes = 'top-menu-default';
109
110
		if ( false !== $additional ) {
111
			$classes .= ' ' . $additional;
112
		}
113
114
		echo esc_attr( $classes );
115
	}
116
endif;
117
118
if ( ! function_exists( 'lsx_add_footer_sidebar_area' ) ) :
119
	/**
120
	 * Output the Footer CTA and/pr Footer Widgets.
121
	 *
122
	 * @package    lsx
123
	 * @subpackage layout
124
	 */
125
	function lsx_add_footer_sidebar_area() {
126
		if ( is_active_sidebar( 'sidebar-footer-cta' ) ) : ?>
127
			<div id="footer-cta">
128
				<div class="container">
129
					<div class="lsx-full-width">
130
						<div class="lsx-hero-unit">
131
							<?php dynamic_sidebar( 'sidebar-footer-cta' ); ?>
132
						</div>
133
					</div>
134
				</div>
135
			</div>
136
		<?php endif; ?>
137
138
		<?php if ( is_active_sidebar( 'sidebar-footer' ) ) : ?>
139
			<div id="footer-widgets">
140
				<div class="container">
141
					<div class="row">
142
						<?php dynamic_sidebar( 'sidebar-footer' ); ?>
143
					</div>
144
				</div>
145
			</div>
146
		<?php endif;
147
	}
148
	add_action( 'lsx_footer_before', 'lsx_add_footer_sidebar_area' );
149
endif;
150
151
if ( ! function_exists( 'lsx_global_header' ) ) :
152
	/**
153
	 * Displays the global header.
154
	 *
155
	 * @package    lsx
156
	 * @subpackage layout
157
	 */
158
	function lsx_global_header() {
159
		$show_on_front  = get_option( 'show_on_front' );
160
		$queried_object = get_queried_object();
161
		$default_size   = 'sm';
162
		$size           = apply_filters( 'lsx_bootstrap_column_size', $default_size );
163
164
		//Pages have their own banner function 'lsx_page_banner()'
165
		if ( function_exists( 'is_woocommerce' ) && ( is_woocommerce() || is_checkout() || is_cart() || is_account_page() ) ) {
166
			return;
167
		}
168
169
		if ( true === apply_filters( 'lsx_global_header_disable', false ) ) :
170
			// Display only the breadcrumbs
171
			?>
172
			<div class="archive-header-wrapper banner-global col-<?php echo esc_attr( $size ); ?>-12">
173
				<?php lsx_global_header_inner_bottom(); ?>
174
			</div>
175
			<?php
176
		elseif ( is_page() && ( 'page' !== $show_on_front || ! is_front_page() ) ) :
177
			?>
178
			<div class="archive-header-wrapper banner-page col-<?php echo esc_attr( $size ); ?>-12">
179
				<?php lsx_global_header_inner_bottom(); ?>
180
				<header class="archive-header">
181
					<h1 class="archive-title"><?php the_title(); ?></h1>
182
				</header>
183
184
			</div>
185
			<?php
186
		elseif ( is_single() && ! is_singular( 'post' ) ) :
187
			?>
188
			<div class="archive-header-wrapper banner-single col-<?php echo esc_attr( $size ); ?>-12">
189
				<?php lsx_global_header_inner_bottom(); ?>
190
				<header class="archive-header">
191
					<h1 class="archive-title"><?php echo wp_kses_post( apply_filters( 'lsx_global_header_title', get_the_title() ) ); ?></h1>
192
				</header>
193
194
			</div>
195
			<?php
196
		elseif ( is_search() ) :
197
			?>
198
			<div class="archive-header-wrapper banner-search col-<?php echo esc_attr( $size ); ?>-12">
199
				<?php lsx_global_header_inner_bottom(); ?>
200
				<header class="archive-header">
201
					<h1 class="archive-title">
202
						<?php
203
							printf(
204
								/* Translators: %s: search term/query */
205
								esc_html__( 'Search Results for: %s', 'lsx' ),
206
								'<span>' . get_search_query() . '</span>'
207
							);
208
						?>
209
					</h1>
210
				</header>
211
212
			</div>
213
			<?php
214
		elseif ( is_author() ) :
215
			$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...
216
			$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...
217
			$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...
218
			?>
219
			<div class="archive-header-wrapper col-<?php echo esc_attr( $size ); ?>-12">
220
				<?php lsx_global_header_inner_bottom(); ?>
221
				<header class="archive-header">
222
					<h1 class="archive-title"><?php the_archive_title(); ?></h1>
223
				</header>
224
225
			</div>
226
			<?php
227
		elseif ( is_archive() ) :
228
			?>
229
			<div class="archive-header-wrapper banner-archive col-<?php echo esc_attr( $size ); ?>-12">
230
				<?php lsx_global_header_inner_bottom(); ?>
231
				<header class="archive-header">
232
					<h1 class="archive-title">
233
						<?php if ( has_post_format() && ! is_category() && ! is_tag() && ! is_date() && ! is_tax( 'post_format' ) ) { ?>
234
							<?php the_archive_title( esc_html__( 'Type:', 'lsx' ) ); ?>
235
						<?php } else { ?>
236
							<?php echo wp_kses_post( apply_filters( 'lsx_global_header_title', get_the_archive_title() ) ); ?>
237
						<?php } ?>
238
					</h1>
239
240
					<?php the_archive_description(); ?>
241
				</header>
242
			</div>
243
			<?php
244
		elseif ( 'page' === $show_on_front && (int) get_option( 'page_for_posts' ) === $queried_object->ID ) :
245
			?>
246
			<div class="archive-header-wrapper banner-page col-<?php echo esc_attr( $size ); ?>-12">
247
				<?php lsx_global_header_inner_bottom(); ?>
248
				<header class="archive-header">
249
					<h1 class="archive-title"><?php esc_html_e( 'Blog', 'lsx' ); ?></h1>
250
				</header>
251
252
			</div>
253
			<?php
254
		elseif ( ! is_singular( 'post' ) ) :
255
			// Display only the breadcrumbs
256
			?>
257
			<div class="archive-header-wrapper banner-singular col-<?php echo esc_attr( $size ); ?>-12">
258
				<?php lsx_global_header_inner_bottom(); ?>
259
			</div>
260
			<?php
261
		endif;
262
	}
263
	add_action( 'lsx_content_wrap_before', 'lsx_global_header' );
264
endif;
265
266
if ( ! function_exists( 'lsx_author_extra_info' ) ) :
267
	/**
268
	 * Displays the author extra info.
269
	 *
270
	 * @package    lsx
271
	 * @subpackage layout
272
	 */
273
	function lsx_author_extra_info() {
274
		$default_size   = 'sm';
275
		$size           = apply_filters( 'lsx_bootstrap_column_size', $default_size );
276
277
		if ( is_author() ) :
278
			$author_id         = get_the_author_meta( 'ID' );
279
			$author            = get_the_author();
280
			$author_avatar     = get_avatar( $author_id, 400 );
281
			$author_bio        = get_the_archive_description();
282
			$author_url        = get_the_author_meta( 'url', $author_id );
283
			$author_email      = get_the_author_meta( 'email', $author_id );
284
			$author_facebook   = get_the_author_meta( 'facebook', $author_id );
285
			$author_linkedin   = get_the_author_meta( 'linkedin', $author_id );
286
			$author_twitter    = get_the_author_meta( 'twitter', $author_id );
287
			$author_googleplus = get_the_author_meta( 'googleplus', $author_id );
288
			?>
289
			<div class="col-<?php echo esc_attr( $size ); ?>-12">
290
				<div class="archive-author-data">
291
					<div class="row">
292
						<?php if ( ! empty( $author_avatar ) ) : ?>
293
							<div class="col-xs-12 col-sm-4 col-md-3">
294
							<figure class="archive-author-avatar"><?php echo wp_kses_post( $author_avatar ); ?></figure>
295
							</div>
296
						<?php endif; ?>
297
						<div class="col-xs-12 col-sm-8 col-md-9">
298
							<a class="back-to-blog" href="<?php echo ( esc_url( get_post_type_archive_link( 'post' ) ) ); ?>"><?php echo esc_html__( 'Back To Blog', 'lsx' ); ?></a>
299
							<!-- Name -->
300
							<h2 class="archive-author-title">
301
								<?php
302
								if ( '' !== $author ) {
303
									echo esc_html( $author );
304
								}
305
								?>
306
							</h2>
307
							<!-- Social -->
308
							<?php if ( ! empty( $author_url ) || ! empty( $author_email ) || ! empty( $author_facebook ) || ! empty( $author_twitter ) || ! empty( $author_googleplus ) ) : ?>
309
								<div class="archive-author-social-links">
310
									<?php if ( ! empty( $author_url ) ) : ?>
311
										<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>
312
									<?php endif; ?>
313
314
									<?php if ( ! empty( $author_email ) ) : ?>
315
										<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>
316
									<?php endif; ?>
317
318
									<?php if ( ! empty( $author_facebook ) ) : ?>
319
										<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>
320
									<?php endif; ?>
321
322
									<?php if ( ! empty( $author_twitter ) ) : ?>
323
										<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>
324
									<?php endif; ?>
325
326
									<?php if ( ! empty( $author_linkedin ) ) : ?>
327
										<a href="<?php echo esc_url( $author_linkedin ); ?>" target="_blank" rel="nofollow noreferrer noopener" class="archive-author-social-link archive-author-social-link-linkedin"><i class="fa fa-linkedin" aria-hidden="true"></i></a>
328
									<?php endif; ?>
329
330
									<?php if ( ! empty( $author_googleplus ) ) : ?>
331
										<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>
332
									<?php endif; ?>
333
								</div>
334
							<?php endif; ?>
335
336
							<!-- Bio -->
337
							<?php if ( ! empty( $author_bio ) ) : ?>
338
								<p class="archive-author-bio"><?php echo wp_kses_post( $author_bio ); ?></p>
339
							<?php endif; ?>
340
						</div>
341
					</div>
342
				</div>
343
				<h2><?php echo esc_html__( 'Posts', 'lsx' ); ?></h2>
344
			</div>
345
			<?php
346
		endif;
347
	}
348
	add_action( 'lsx_content_wrap_before', 'lsx_author_extra_info', 11 );
349
endif;
350
351
if ( ! function_exists( 'lsx_post_header' ) ) :
352
	/**
353
	 * Displays the post header.
354
	 *
355
	 * @package    lsx
356
	 * @subpackage layout
357
	 */
358
	function lsx_post_header() {
359
		$default_size  = 'sm';
360
		$size          = apply_filters( 'lsx_bootstrap_column_size', $default_size );
361
362
		if ( is_singular( 'post' ) ) :
363
			$format = get_post_format();
364
365
			if ( false === $format ) {
366
				$format = 'standard';
367
			}
368
369
			$format = lsx_translate_format_to_fontawesome( $format );
370
			?>
371
			<div class="archive-header-wrapper col-<?php echo esc_attr( $size ); ?>-12">
372
				<header class="archive-header">
373
					<h1 class="archive-title">
374
						<i class="format-link fa fa-<?php echo esc_attr( $format ); ?>"></i>
375
						<span><?php the_title(); ?></span>
376
					</h1>
377
				</header>
378
			</div>
379
			<?php
380
		endif;
381
	}
382
	add_action( 'lsx_entry_top', 'lsx_post_header' );
383
endif;
384
385
if ( ! function_exists( 'lsx_add_viewport_meta_tag' ) ) :
386
	/**
387
	 * Add Viewport Meta Tag to head.
388
	 *
389
	 * @package    lsx
390
	 * @subpackage layout
391
	 */
392
	function lsx_add_viewport_meta_tag() {
393
		?>
394
		<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=0">
395
		<?php
396
	}
397
	add_action( 'wp_head', 'lsx_add_viewport_meta_tag' );
398
endif;
399
400
if ( ! function_exists( 'lsx_header_search_form' ) ) :
401
	/**
402
	 * Add a search form to just above the nav menu.
403
	 *
404
	 * @package    lsx
405
	 * @subpackage layout
406
	 */
407
	function lsx_header_search_form() {
408
		$search_form = get_theme_mod( 'lsx_header_search', false );
409
410
		if ( false !== $search_form || is_customize_preview() ) {
411
			get_search_form( true );
412
		}
413
	}
414
	add_action( 'lsx_nav_before', 'lsx_header_search_form', 0 );
415
endif;
416
417
// Add entry meta to single post if active
418
if ( ! function_exists( 'lsx_add_entry_meta' ) ) :
419
	function lsx_add_entry_meta() {
420
		if ( is_single() && is_singular( 'post' ) ) {
421
			?>
422
			<div class="entry-meta">
423
				<?php lsx_post_meta_single_top(); ?>
424
			</div><!-- .entry-meta -->
425
			<?php
426
		}
427
	}
428
	add_action( 'lsx_entry_top', 'lsx_add_entry_meta', 999 );
429
endif;
430