Issues (130)

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.

includes/vendors/class.product-vendors-widget.php (6 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 21 and the first side effect is on line 12.

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
/**
3
 * Bootstraps the Vendor system
4
 *
5
 * @package     PrintCenter\Vendor\Widget
6
 * @since       1.0.0
7
 */
8
9
10
// Exit if accessed directly
11
if( ! defined( 'ABSPATH' ) ) {
12
	exit;
13
}
14
15
16
/**
17
 * Vendor info widget
18
 *
19
 * @since       1.0.0
20
 */
21
class WooCommerce_Product_Vendors_Widget extends WP_Widget {
22
23
24
	/**
25
	 * @access      private
26
	 * @var         string $widget_cssclass CSS classes for the widget instance
27
	 */
28
	private $widget_cssclass;
29
30
31
	/**
32
	 * @access      private
33
	 * @var         string $widget_description Description for the widget instance
34
	 */
35
	private $widget_description;
36
37
38
	/**
39
	 * @access      private
40
	 * @var         string $widget_idbase ID base for the widget instance
41
	 */
42
	private $widget_idbase;
43
44
45
	/**
46
	 * @access      private
47
	 * @var         string $widget_title Title for the widget instance
48
	 */
49
	private $widget_title;
50
51
	/**
52
	 * Get things started
53
	 *
54
	 * @access      public
55
	 * @since       1.0.0
56
	 * @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...
57
	 */
58
	public function __construct() {
59
		// Widget variable settings
60
		$this->widget_cssclass    = 'widget_product_vendors';
61
		$this->widget_description = __( 'Display selected or current product vendor info.', 'printcenter' );
62
		$this->widget_idbase      = 'product_vendors';
63
		$this->widget_title       = __( 'WooCommerce Product Vendors', 'printcenter' );
64
65
		// Widget settings
66
		$widget_ops = array( 'classname' => $this->widget_cssclass, 'description' => $this->widget_description );
67
68
		// Widget control settings
69
		$control_ops = array( 'width' => 250, 'height' => 350, 'id_base' => $this->widget_idbase );
70
71
		// Create the widget
72
		parent::__construct( $this->widget_idbase, $this->widget_title, $widget_ops, $control_ops );
73
	}
74
75
76
	/**
77
	 * Display the widget on the frontend
78
	 *
79
	 * @access      public
80
	 * @since       1.0.0
81
	 * @param       array $args Widget arguments
82
	 * @param       array $instance Widget settings for this instance
83
	 * @return      void
84
	 */
85
	public function widget( $args, $instance ) {
86
		extract( $args, EXTR_SKIP );
87
88
		$vendor_id = false;
89
		$vendors   = false;
90
91
		// Only show current vendor widget when showing a vendor's product(s)
92
		$show_widget = true;
93
94
		if( $instance['vendor'] == 'current' ) {
95
			if( is_singular( 'product' ) ) {
96
				global $post;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
97
				$vendors = printcenter_get_product_vendors( $post->ID );
98
				if( ! $vendors ) {
99
					$show_widget = false;
100
				}
101
			}
102
103
			if( is_archive() && ! is_tax( 'shop_vendor' ) ) {
104
				$show_widget = false;
105
			}
106
		} else {
107
			$vendors = array(
108
				printcenter_get_vendor( $instance['vendor'] )
109
			);
110
		}
111
112
		if( $show_widget ) {
113
			if( is_tax( 'shop_vendor' ) ) {
114
				$vendor_id = get_queried_object()->term_id;
115
				if( $vendor_id ) {
116
					$vendors = array(
117
						printcenter_get_vendor( $vendor_id )
118
					);
119
				}
120
			}
121
122
			if( $vendors ) {
123
				// Set up widget title
124
				if( $instance['title'] ) {
125
					$title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
126
				} else {
127
					$title = false;
128
				}
129
130
				// Before widget (defined by themes)
131
				echo $before_widget;
132
133
				// Display the widget title if one was input (before and after defined by themes).
134
				if ( $title ) { echo $before_title . $title . $after_title; }
135
136
				// Widget content
137
				$html = '';
138
139
				foreach( $vendors as $vendor ) {
0 ignored issues
show
The expression $vendors of type boolean|array<integer,ob...ject<stdClass>|false"}> is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
140
					$html .= '<h4>' . $vendor->title . '</h4>';
141
					$html .= '<p>' . $vendor->description . '</p>';
142
					$html .= '<p><a href="' . esc_attr( $vendor->url ) . '" title"' . sprintf( __( 'More products from %1$s', 'printcenter' ), $vendor->title ) . '">' . sprintf( __( 'More products from %1$s', 'printcenter' ), $vendor->title ) . '</a></p>';
143
				}
144
145
				// Action for plugins/themes to hook onto
146
				do_action( $this->widget_cssclass . '_top' );
147
148
				echo $html;
149
150
				// Action for plugins/themes to hook onto
151
				do_action( $this->widget_cssclass . '_bottom' );
152
153
				// After widget (defined by themes).
154
				echo $after_widget;
155
			}
156
		}
157
	}
158
159
160
	/**
161
	 * Method to update the settings from the form() method
162
	 *
163
	 * @access      public
164
	 * @since       1.0.0
165
	 * @param       array $new_instance New settings
166
	 * @param       array $old_instance Previous settings
167
	 * @return      array Updated settings
168
	 */
169
	public function update ( $new_instance, $old_instance ) {
170
		$instance = $old_instance;
171
172
		// Sanitise inputs
173
		$instance['title']  = strip_tags( $new_instance['title'] );
174
		$instance['vendor'] = esc_attr( $new_instance['vendor'] );
175
176
		return $instance;
177
	}
178
179
180
	/**
181
	 * The form on the widget control in the widget administration area
182
	 *
183
	 * @access      public
184
	 * @since       1.0.0
185
	 * @param       array $instance The settings for this instance.
186
	 * @return      void
187
	 */
188
	public function form( $instance ) {
189
190
		// Set up the default widget settings
191
		$defaults = array(
192
			'title'  => '',
193
			'vendor' => 'current'
194
		);
195
196
		$instance = wp_parse_args( (array) $instance, $defaults );
197
198
		// Set up vendor options
199
		$vendors        = printcenter_get_vendors();
200
		$vendor_options = '<option value="current" ' . selected( $instance['vendor'], 'current', false ) . '>' . __( 'Current vendor(s)', 'printcenter' ) . '</option>';
201
202
		foreach( $vendors as $vendor ) {
0 ignored issues
show
The expression $vendors of type boolean is not traversable.
Loading history...
203
			$vendor_options .= '<option value="' . esc_attr( $vendor->ID ) . '" ' . selected( $instance['vendor'], $vendor->ID, false ) . '>' . esc_html( $vendor->title ) . '</option>';
204
		}
205
		?>
206
		<p>
207
			<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title (optional):', 'printcenter' ); ?></label>
208
			<input type="text" name="<?php echo $this->get_field_name( 'title' ); ?>"  value="<?php echo $instance['title']; ?>" class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" />
209
		</p>
210
		<p>
211
			<label for="<?php echo $this->get_field_id( 'vendor' ); ?>"><?php _e( 'Vendor:', 'printcenter' ); ?></label>
212
			<select name="<?php echo $this->get_field_name( 'vendor' ); ?>" class="widefat" id="<?php echo $this->get_field_id( 'vendor' ); ?>">
213
				<?php echo $vendor_options; ?>
214
			</select><br/><br/>
215
			<span class="description"><?php _e( '\'Current vendor(s)\' will display the details of the vendors whose product(s) are being viewed at the time. It will not show on other pages.', 'printcenter' ); ?></span>
216
		</p>
217
	<?php
218
	}
219
}
220
add_action( 'widgets_init', create_function( '', 'return register_widget("WooCommerce_Product_Vendors_Widget");' ), 1 );
0 ignored issues
show
Security Best Practice introduced by
The use of create_function is highly discouraged, better use a closure.

create_function can pose a great security vulnerability as it is similar to eval, and could be used for arbitrary code execution. We highly recommend to use a closure instead.

// Instead of
$function = create_function('$a, $b', 'return $a + $b');

// Better use
$function = function($a, $b) { return $a + $b; }
Loading history...
221