Issues (896)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

widget-woothemes-sensei-category-courses.php (8 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 15 and the first side effect is on line 2.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly.
3
4
/**
5
 * Sensei Category Courses Widget
6
 *
7
 * A WooThemes Sensei Category Courses widget to display a list of Courses in a Course Category.
8
 *
9
 * @package Views
10
 * @subpackage Widgets
11
 * @author Automattic
12
 *
13
 * @since 1.1.0
14
 */
15
class WooThemes_Sensei_Category_Courses_Widget extends WP_Widget {
16
	protected $woo_widget_cssclass;
17
	protected $woo_widget_description;
18
	protected $woo_widget_idbase;
19
	protected $woo_widget_title;
20
21
	/**
22
	 * Constructor function.
23
	 * @since  1.1.0
24
	 * @return  void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
25
	 */
26 View Code Duplication
	public function __construct() {
0 ignored issues
show
This method seems to be duplicated in 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...
27
		/* Widget variable settings. */
28
		$this->woo_widget_cssclass = 'widget_sensei_category_courses';
29
		$this->woo_widget_description = __( 'This widget will output a list of Courses for a specific category.', 'woothemes-sensei' );
30
		$this->woo_widget_idbase = 'sensei_category_courses';
31
		$this->woo_widget_title = __( 'Sensei - Category Courses', 'woothemes-sensei' );
32
33
		/* Widget settings. */
34
		$widget_ops = array( 'classname' => $this->woo_widget_cssclass, 'description' => $this->woo_widget_description );
35
36
		/* Widget control settings. */
37
		$control_ops = array( 'width' => 250, 'height' => 350, 'id_base' => $this->woo_widget_idbase );
38
39
		/* Create the widget. */
40
		parent::__construct( $this->woo_widget_idbase, $this->woo_widget_title, $widget_ops, $control_ops );
41
42
	} // End __construct()
43
44
	/**
45
	 * Display the widget on the frontend.
46
	 * @since  1.1.0
47
	 * @param  array $args     Widget arguments.
48
	 * @param  array $instance Widget settings for this instance.
49
	 * @return void
50
	 */
51
	public function widget( $args, $instance ) {
52
53
        $before_widget = $args[ 'before_widget' ];
54
        $before_title  = $args[ 'before_title' ];
55
        $after_title   = $args[ 'after_title' ];
56
        $after_widget  = $args[ 'after_widget' ];
57
58
		/* Our variables from the widget settings. */
59
		$title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base );
60
61
		/* Before widget (defined by themes). */
62
		echo $before_widget;
63
64
		/* Display the widget title if one was input (before and after defined by themes). */
65
		if ( $title ) { echo $before_title . $title . $after_title; }
66
67
		/* Widget content. */
68
		// Add actions for plugins/themes to hook onto.
69
		do_action( $this->woo_widget_cssclass . '_top' );
70
71
		if ( 0 < intval( $instance['course_category'] ) ) {
72
			$this->load_component( $instance );
73
		} // End If Statement
74
75
		// Add actions for plugins/themes to hook onto.
76
		do_action( $this->woo_widget_cssclass . '_bottom' );
77
78
		/* After widget (defined by themes). */
79
		echo $after_widget;
80
81
	} // End widget()
82
83
	/**
84
	 * Method to update the settings from the form() method.
85
	 * @since  1.1.0
86
	 * @param  array $new_instance New settings.
87
	 * @param  array $old_instance Previous settings.
88
	 * @return array               Updated settings.
89
	 */
90 View Code Duplication
	public function update ( $new_instance, $old_instance ) {
0 ignored issues
show
This method seems to be duplicated in 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...
91
		$instance = $old_instance;
92
93
		/* Strip tags for title and name to remove HTML (important for text inputs). */
94
		$instance['title'] = strip_tags( $new_instance['title'] );
95
96
		/* The select box is returning a text value, so we escape it. */
97
		$instance['course_category'] = esc_attr( $new_instance['course_category'] );
98
99
		/* Strip tags for limit to remove HTML (important for text inputs). */
100
		$instance['limit'] = strip_tags( $new_instance['limit'] );
101
102
103
		return $instance;
104
	} // End update()
105
106
	/**
107
	 * The form on the widget control in the widget administration area.
108
	 * Make use of the get_field_id() and get_field_name() function when creating your form elements. This handles the confusing stuff.
109
	 * @since  1.1.0
110
	 * @param  array $instance The settings for this instance.
111
	 * @return void
112
	 */
113
    public function form( $instance ) {
114
115
		/* Set up some default widget settings. */
116
		/* Make sure all keys are added here, even with empty string values. */
117
		$defaults = array(
118
						'title' => '',
119
						'course_category' => 0,
120
						'limit' => 3
121
					);
122
123
		$instance = wp_parse_args( (array) $instance, $defaults );
124
?>
125
		<!-- Widget Title: Text Input -->
126
		<p>
127
			<label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php _e( 'Title (optional):', 'woothemes-sensei' ); ?></label>
128
			<input type="text" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>"  value="<?php echo esc_attr( $instance['title'] ); ?>" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" />
129
		</p>
130
		<!-- Widget Course Category: Select Input -->
131
		<p>
132
			<label for="<?php echo esc_attr( $this->get_field_id( 'course_category' ) ); ?>"><?php _e( 'Course Category:', 'woothemes-sensei' ); ?></label>
133
			<?php
134
			$cat_args = array( 'hierarchical' => true, 'show_option_none' => __( 'Select Category:', 'woothemes-sensei' ), 'taxonomy' => 'course-category', 'orderby' => 'name', 'selected' => intval( $instance['course_category'] ), 'id' => $this->get_field_id( 'course_category' ), 'name' => $this->get_field_name( 'course_category' ), 'class' => 'widefat' );
135
			wp_dropdown_categories(apply_filters('widget_course_categories_dropdown_args', $cat_args));
136
			?>
137
		</p>
138
		<!-- Widget Limit: Text Input -->
139
		<p>
140
			<label for="<?php echo esc_attr( $this->get_field_id( 'limit' ) ); ?>"><?php _e( 'Number of Courses (optional):', 'woothemes-sensei' ); ?></label>
141
			<input type="text" name="<?php echo esc_attr( $this->get_field_name( 'limit' ) ); ?>"  value="<?php echo esc_attr( $instance['limit'] ); ?>" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'limit' ) ); ?>" />
142
		</p>
143
144
<?php
145
	} // End form()
146
147
	/**
148
	 * Load the output.
149
	 * @param  array $instance.
0 ignored issues
show
There is no parameter named $instance.. Did you maybe mean $instance?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
150
	 * @since  1.1.0
151
	 * @return void
152
	 */
153
	protected function load_component ( $instance ) {
154
155
156
		$posts_array = array();
0 ignored issues
show
$posts_array 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...
157
		$post_args = array(	'post_type' 		=> 'course',
158
							'posts_per_page' 		=> intval( $instance[ 'limit' ] ),
159
							'orderby'         	=> 'menu_order date',
160
    						'order'           	=> 'ASC',
161
    						'post_status'       => 'publish',
162
							'suppress_filters' 	=> 0,
163
							);
164
165
		$post_args[ 'tax_query' ] = array(
166
											array(
167
												'taxonomy' => 'course-category',
168
												'field' => 'id',
169
												'terms' => intval( $instance['course_category'] )
170
											)
171
										);
172
173
		$posts_array = get_posts( $post_args );
174
175
		if ( count( $posts_array ) > 0 ) { ?>
176
			<ul>
177 View Code Duplication
			<?php foreach ($posts_array as $post_item){
0 ignored issues
show
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...
178
		    	$post_id = absint( $post_item->ID );
179
		    	$post_title = $post_item->post_title;
180
		    	$user_info = get_userdata( absint( $post_item->post_author ) );
181
		    	$author_link = get_author_posts_url( absint( $post_item->post_author ) );
182
		    	$author_display_name = $user_info->display_name;
183
		    	$author_id = $post_item->post_author;
0 ignored issues
show
$author_id 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...
184
		    ?>
185
		    	<li class="fix">
186
		    		<?php do_action( 'sensei_course_image', $post_id ); ?>
187
		    		<a href="<?php echo esc_url( get_permalink( $post_id ) ); ?>" title="<?php echo esc_attr( $post_title ); ?>"><?php echo $post_title; ?></a>
188
		    		<br />
189
		    		<?php if ( isset( Sensei()->settings->settings[ 'course_author' ] ) && ( Sensei()->settings->settings[ 'course_author' ] ) ) { ?>
190
    					<span class="course-author"><?php _e( 'by ', 'woothemes-sensei' ); ?><a href="<?php echo esc_url( $author_link ); ?>" title="<?php echo esc_attr( $author_display_name ); ?>"><?php echo esc_html( $author_display_name ); ?></a></span>
191
    					<br />
192
    				<?php } // End If Statement ?>
193
    				<span class="course-lesson-count"><?php echo Sensei()->course->course_lesson_count( $post_id ) . '&nbsp;' .  __( 'Lessons', 'woothemes-sensei' ); ?></span>
194
    				<br />
195
    				<?php sensei_simple_course_price( $post_id ); ?>
196
		    	</li>
197
		    <?php } // End For Loop ?>
198
			</ul>
199
		<?php } // End If Statement
200
	} // End load_component()
201
} // End Class