Passed
Push — lsx-wp6 ( 4c21d3 )
by
unknown
04:54
created

LSX_Sensei_Lesson::lsx_sensei_lesson_sidebar()   B

Complexity

Conditions 9
Paths 4

Size

Total Lines 7
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 9
eloc 6
nc 4
nop 0
dl 0
loc 7
rs 8.0555
c 1
b 0
f 0
1
<?php
2
/**
3
 * LSX Sensei Lesson Class
4
 *
5
 * @package    lsx
6
 * @subpackage sensei
7
 */
8
9
if ( ! defined( 'ABSPATH' ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
10
	exit; // Exit if accessed directly.
11
}
12
13
/**
14
 * LSX Sensei Lesson Class
15
 */
16
class LSX_Sensei_Lesson {
17
18
	/**
19
	 * Instance of class.
20
	 *
21
	 * @var self
22
	 */
23
	private static $instance;
24
25
	/**
26
	 * Constructor.
27
	 */
28
	public function __construct() {
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
29
		add_action( 'init', array( $this, 'init' ) );
30
		add_action( 'widgets_init', array( $this, 'lsx_widget_area_sensei_init' ), 100 );
31
		add_filter( 'body_class', array( $this, 'lsx_widget_area_sensei_is_active' ) );
32
	} // End __construct()
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
33
34
	/**
35
	 * Fetches an instance of the class.
36
	 *
37
	 * @return self
38
	 */
39
	public static function instance() {
40
		if ( ! self::$instance ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
41
			self::$instance = new self();
42
		}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
43
		return self::$instance;
44
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
45
46
	/**
47
	 * Run our changes.
48
	 */
49
	public function init() {
50
		add_action( 'lsx_content_top', array( $this, 'lsx_sensei_lesson_sidebar' ) );
51
52
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
53
54
	/**
55
	 * Register a sidebar when Sensei Participants or Sensei Progress plugins are active.
56
	 *
57
	 * @return void
58
	 */
59
	public function lsx_widget_area_sensei_init() {
60
		if ( class_exists( 'Sensei_Course_Participants' ) || class_exists( 'Sensei_Course_Progress' ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
61
			register_sidebar( array(
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
62
				'name'          => esc_html__( 'LSX Sensei Sidebar', 'lsx' ),
63
				'id'            => 'lsx-sensei-sidebar',
64
				'before_widget' => '<aside id="%1$s" class="widget %2$s">',
65
				'after_widget'  => '</aside>',
66
				'before_title'  => '<h3 class="widget-title">',
67
				'after_title'   => '</h3>',
68
			) );
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
69
		}
70
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
71
72
	/**
73
	 * Widget Area for sensei.
74
	 *
75
	 * @param [type] $classes
0 ignored issues
show
Documentation Bug introduced by
The doc comment [type] at position 0 could not be parsed: Unknown type name '[' at position 0 in [type].
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
76
	 * @return classes
77
	 */
78
	public function lsx_widget_area_sensei_is_active( $classes ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 blank lines after opening function brace; 1 found
Loading history...
79
80
		if ( class_exists( 'Sensei_Lesson' ) && is_active_sidebar( 'lsx-sensei-sidebar' ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
81
			$classes[] = 'lsx-sensei-sidebar-active';
82
		}
83
84
		return $classes;
85
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
86
87
	/**
88
	 * Adds the widget content to the lesson template if the lsx-sensei-sidebar is active.
89
	 *
90
	 * @return void
91
	 */
92
	public function lsx_sensei_lesson_sidebar() {
93
		if ( class_exists( 'Sensei_Lesson' ) && ( class_exists( 'Sensei_Course_Participants' ) || class_exists( 'Sensei_Course_Progress' ) ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
94
			if ( ( is_single() && ( is_singular( 'lesson' ) ) ) || ( is_single() && ( is_singular( 'quiz' ) ) ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
95
				if ( is_active_sidebar( 'lsx-sensei-sidebar' ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
96
					echo '<div id="secondary" class="widget-area lsx-sensei-sidebar">';
97
					dynamic_sidebar( 'lsx-sensei-sidebar' );
98
					echo '</div>';
99
				}
100
			}
101
		}
102
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
103
104
} // End Class
105
$lsx_sensei_lesson = LSX_Sensei_Lesson::instance();
106