lsx_widget_area_init()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 42
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 32
nc 1
nop 0
dl 0
loc 42
rs 9.408
c 0
b 0
f 0
1
<?php
2
/**
3
 * LSX functions and definitions - Widgets.
4
 *
5
 * @package    lsx
6
 * @subpackage widgets
7
 */
8
9
if ( ! defined( 'ABSPATH' ) ) {
10
	exit;
11
}
12
13
if ( ! function_exists( 'lsx_widget_area_init' ) ) :
14
15
	/**
16
	 * Register widgetized area and update sidebar with default widgets.
17
	 *
18
	 * @package    lsx
19
	 * @subpackage widgets
20
	 */
21
	function lsx_widget_area_init() {
22
		register_sidebar(
23
			array(
24
				'name'          => esc_html__( 'Home', 'lsx' ),
25
				'id'            => 'sidebar-home',
26
				'before_widget' => '<aside id="%1$s" class="widget %2$s">',
27
				'after_widget'  => '</aside>',
28
				'before_title'  => '<h3 class="widget-title">',
29
				'after_title'   => '</h3>',
30
			)
31
		);
32
33
		register_sidebar(
34
			array(
35
				'name'          => esc_html__( 'Sidebar', 'lsx' ),
36
				'id'            => 'sidebar-1',
37
				'before_widget' => '<aside id="%1$s" class="widget %2$s">',
38
				'after_widget'  => '</aside>',
39
				'before_title'  => '<h3 class="widget-title">',
40
				'after_title'   => '</h3>',
41
			)
42
		);
43
44
		register_sidebar(
45
			array(
46
				'name'          => esc_html__( 'Footer', 'lsx' ),
47
				'id'            => 'sidebar-footer',
48
				'before_widget' => '<div class="styler"><aside id="%1$s" class="widget %2$s">',
49
				'after_widget'  => '</aside></div>',
50
				'before_title'  => '<h3 class="widget-title">',
51
				'after_title'   => '</h3>',
52
			)
53
		);
54
55
		register_sidebar(
56
			array(
57
				'name'          => esc_html__( 'Footer Call to Action', 'lsx' ),
58
				'id'            => 'sidebar-footer-cta',
59
				'before_widget' => '<aside id="%1$s" class="widget %2$s">',
60
				'after_widget'  => '</aside>',
61
				'before_title'  => '<h3 class="widget-title">',
62
				'after_title'   => '</h3>',
63
			)
64
		);
65
	}
66
67
endif;
68
69
add_action( 'widgets_init', 'lsx_widget_area_init' );
70
71
if ( ! function_exists( 'lsx_sidebar_footer_params' ) ) :
72
73
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$params" missing
Loading history...
74
	 * Register widgetized area and update sidebar with default widgets.
75
	 *
76
	 * @package    lsx
77
	 * @subpackage widgets
78
	 * @return $params
0 ignored issues
show
Documentation Bug introduced by
The doc comment $params at position 0 could not be parsed: Unknown type name '$params' at position 0 in $params.
Loading history...
79
	 */
80
	function lsx_sidebar_footer_params( $params ) {
81
		$sidebar_id = $params[0]['id'];
82
83
		if ( 'sidebar-footer' === $sidebar_id ) {
84
			$total_widgets              = wp_get_sidebars_widgets();
85
			$sidebar_widgets            = count( $total_widgets[ $sidebar_id ] );
86
			$params[0]['before_widget'] = str_replace( 'class="styler', 'class="col-md-' . floor( 12 / $sidebar_widgets ), $params[0]['before_widget'] );
87
		}
88
89
		return $params;
90
	}
91
92
endif;
93
94
add_filter( 'dynamic_sidebar_params', 'lsx_sidebar_footer_params' );
95