Issues (1182)

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/admin/class-wc-admin-notices.php (3 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
2
/**
3
 * Display notices in admin
4
 *
5
 * @author      WooThemes
6
 * @category    Admin
7
 * @package     WooCommerce/Admin
8
 * @version     2.3.0
9
 */
10
11
if ( ! defined( 'ABSPATH' ) ) {
12
	exit;
13
}
14
15
/**
16
 * WC_Admin_Notices Class.
17
 */
18
class WC_Admin_Notices {
19
20
	/**
21
	 * Stores notices.
22
	 * @var array
23
	 */
24
	private static $notices = array();
25
26
	/**
27
	 * Array of notices - name => callback.
28
	 * @var array
29
	 */
30
	private static $core_notices = array(
31
		'install'             => 'install_notice',
32
		'update'              => 'update_notice',
33
		'updating'            => 'updating_notice',
34
		'template_files'      => 'template_file_check_notice',
35
		'theme_support'       => 'theme_check_notice',
36
		'legacy_shipping'     => 'legacy_shipping_notice',
37
		'no_shipping_methods' => 'no_shipping_methods_notice',
38
		'simplify_commerce'   => 'simplify_commerce_notice',
39
	);
40
41
	/**
42
	 * Constructor.
43
	 */
44
	public static function init() {
45
		self::$notices = get_option( 'woocommerce_admin_notices', array() );
46
47
		add_action( 'switch_theme', array( __CLASS__, 'reset_admin_notices' ) );
48
		add_action( 'woocommerce_installed', array( __CLASS__, 'reset_admin_notices' ) );
49
		add_action( 'wp_loaded', array( __CLASS__, 'hide_notices' ) );
50
		add_action( 'shutdown', array( __CLASS__, 'store_notices' ) );
51
52
		if ( current_user_can( 'manage_woocommerce' ) ) {
53
			add_action( 'admin_print_styles', array( __CLASS__, 'add_notices' ) );
54
		}
55
	}
56
57
	/**
58
	 * Store notices to DB
59
	 */
60
	public static function store_notices() {
61
		update_option( 'woocommerce_admin_notices', self::get_notices() );
62
	}
63
64
	/**
65
	 * Get notices
66
	 * @return array
67
	 */
68
	public static function get_notices() {
69
		return self::$notices;
70
	}
71
72
	/**
73
	 * Remove all notices.
74
	 */
75
	public static function remove_all_notices() {
76
		self::$notices = array();
77
	}
78
79
	/**
80
	 * Reset notices for themes when switched or a new version of WC is installed.
81
	 */
82
	public static function reset_admin_notices() {
83 View Code Duplication
		if ( ! current_theme_supports( 'woocommerce' ) && ! in_array( get_option( 'template' ), wc_get_core_supported_themes() ) ) {
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...
84
			self::add_notice( 'theme_support' );
85
		}
86
87
		$simplify_options = get_option( 'woocommerce_simplify_commerce_settings', array() );
88
		$location         = wc_get_base_location();
89
90
		if ( ! class_exists( 'WC_Gateway_Simplify_Commerce_Loader' ) && ! empty( $simplify_options['enabled'] ) && 'yes' === $simplify_options['enabled'] && in_array( $location['country'], apply_filters( 'woocommerce_gateway_simplify_commerce_supported_countries', array( 'US', 'IE' ) ) ) ) {
91
			WC_Admin_Notices::add_notice( 'simplify_commerce' );
92
		}
93
94
		self::add_notice( 'template_files' );
95
	}
96
97
	/**
98
	 * Show a notice.
99
	 * @param string $name
100
	 */
101
	public static function add_notice( $name ) {
102
		self::$notices = array_unique( array_merge( self::get_notices(), array( $name ) ) );
103
	}
104
105
	/**
106
	 * Remove a notice from being displayed.
107
	 * @param  string $name
108
	 */
109
	public static function remove_notice( $name ) {
110
		self::$notices = array_diff( self::get_notices(), array( $name ) );
111
		delete_option( 'woocommerce_admin_notice_' . $name );
112
	}
113
114
	/**
115
	 * See if a notice is being shown.
116
	 * @param  string  $name
117
	 * @return boolean
118
	 */
119
	public static function has_notice( $name ) {
120
		return in_array( $name, self::get_notices() );
121
	}
122
123
	/**
124
	 * Hide a notice if the GET variable is set.
125
	 */
126
	public static function hide_notices() {
127
		if ( isset( $_GET['wc-hide-notice'] ) && isset( $_GET['_wc_notice_nonce'] ) ) {
128
			if ( ! wp_verify_nonce( $_GET['_wc_notice_nonce'], 'woocommerce_hide_notices_nonce' ) ) {
129
				wp_die( __( 'Action failed. Please refresh the page and retry.', 'woocommerce' ) );
130
			}
131
132
			if ( ! current_user_can( 'manage_woocommerce' ) ) {
133
				wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce' ) );
134
			}
135
136
			$hide_notice = sanitize_text_field( $_GET['wc-hide-notice'] );
137
			self::remove_notice( $hide_notice );
138
			do_action( 'woocommerce_hide_' . $hide_notice . '_notice' );
139
		}
140
	}
141
142
	/**
143
	 * Add notices + styles if needed.
144
	 */
145
	public static function add_notices() {
146
		$notices = self::get_notices();
147
148
		if ( ! empty( $notices ) ) {
149
			wp_enqueue_style( 'woocommerce-activation', plugins_url(  '/assets/css/activation.css', WC_PLUGIN_FILE ) );
150
			foreach ( $notices as $notice ) {
151
				if ( ! empty( self::$core_notices[ $notice ] ) && apply_filters( 'woocommerce_show_admin_notice', true, $notice ) ) {
152
					add_action( 'admin_notices', array( __CLASS__, self::$core_notices[ $notice ] ) );
153
				} else {
154
					add_action( 'admin_notices', array( __CLASS__, 'output_custom_notices' ) );
155
				}
156
			}
157
		}
158
	}
159
160
	/**
161
	 * Add a custom notice.
162
	 * @param string $name
163
	 * @param string $notice_html
164
	 */
165
	public static function add_custom_notice( $name, $notice_html ) {
166
		self::add_notice( $name );
167
		update_option( 'woocommerce_admin_notice_' . $name, wp_kses_post( $notice_html ) );
168
	}
169
170
	/**
171
	 * Output any stored custom notices.
172
	 */
173
	public static function output_custom_notices() {
174
		$notices = self::get_notices();
175
176
		if ( ! empty( $notices ) ) {
177
			foreach ( $notices as $notice ) {
178
				if ( empty( self::$core_notices[ $notice ] ) ) {
179
					$notice_html = get_option( 'woocommerce_admin_notice_' . $notice );
180
181
					if ( $notice_html ) {
182
						include( 'views/html-notice-custom.php' );
183
					}
184
				}
185
			}
186
		}
187
	}
188
189
	/**
190
	 * If we need to update, include a message with the update button.
191
	 */
192
	public static function update_notice() {
193
		include( 'views/html-notice-update.php' );
194
	}
195
196
	/**
197
	 * If we are updating, show progress.
198
	 */
199
	public static function updating_notice() {
200
		if ( version_compare( get_option( 'woocommerce_db_version' ), WC_VERSION, '<' ) ) {
201
			include( 'views/html-notice-updating.php' );
202
		} else {
203
			include( 'views/html-notice-updated.php' );
204
		}
205
	}
206
207
	/**
208
	 * If we have just installed, show a message with the install pages button.
209
	 */
210
	public static function install_notice() {
211
		include( 'views/html-notice-install.php' );
212
	}
213
214
	/**
215
	 * Show the Theme Check notice.
216
	 */
217
	public static function theme_check_notice() {
218 View Code Duplication
		if ( ! current_theme_supports( 'woocommerce' ) && ! in_array( get_option( 'template' ), wc_get_core_supported_themes() ) ) {
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...
219
			include( 'views/html-notice-theme-support.php' );
220
		} else {
221
			self::remove_notice( 'theme_support' );
222
		}
223
	}
224
225
	/**
226
	 * Show a notice highlighting bad template files.
227
	 */
228
	public static function template_file_check_notice() {
229
		$core_templates = WC_Admin_Status::scan_template_files( WC()->plugin_path() . '/templates' );
230
		$outdated       = false;
231
232
		foreach ( $core_templates as $file ) {
233
234
			$theme_file = false;
235 View Code Duplication
			if ( file_exists( get_stylesheet_directory() . '/' . $file ) ) {
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...
236
				$theme_file = get_stylesheet_directory() . '/' . $file;
237
			} elseif ( file_exists( get_stylesheet_directory() . '/woocommerce/' . $file ) ) {
238
				$theme_file = get_stylesheet_directory() . '/woocommerce/' . $file;
239
			} elseif ( file_exists( get_template_directory() . '/' . $file ) ) {
240
				$theme_file = get_template_directory() . '/' . $file;
241
			} elseif( file_exists( get_template_directory() . '/woocommerce/' . $file ) ) {
242
				$theme_file = get_template_directory() . '/woocommerce/' . $file;
243
			}
244
245
			if ( $theme_file !== false ) {
246
				$core_version  = WC_Admin_Status::get_file_version( WC()->plugin_path() . '/templates/' . $file );
247
				$theme_version = WC_Admin_Status::get_file_version( $theme_file );
248
249
				if ( $core_version && $theme_version && version_compare( $theme_version, $core_version, '<' ) ) {
250
					$outdated = true;
251
					break;
252
				}
253
			}
254
		}
255
256
		if ( $outdated ) {
257
			include( 'views/html-notice-template-check.php' );
258
		} else {
259
			self::remove_notice( 'template_files' );
260
		}
261
	}
262
263
	/**
264
	 * Show a notice asking users to convert to shipping zones.
265
	 */
266
	public static function legacy_shipping_notice() {
267
		$maybe_load_legacy_methods = array( 'flat_rate', 'free_shipping', 'international_delivery', 'local_delivery', 'local_pickup' );
268
		$enabled                   = false;
269
270
		foreach ( $maybe_load_legacy_methods as $method ) {
271
			$options = get_option( 'woocommerce_' . $method . '_settings' );
272
			if ( $options && isset( $options['enabled'] ) && 'yes' === $options['enabled'] ) {
273
				$enabled = true;
274
			}
275
		}
276
277
		if ( $enabled ) {
278
			include( 'views/html-notice-legacy-shipping.php' );
279
		} else {
280
			self::remove_notice( 'template_files' );
281
		}
282
	}
283
284
	/**
285
	 * No shipping methods.
286
	 */
287
	public static function no_shipping_methods_notice() {
288
		if ( wc_shipping_enabled() && ( empty( $_GET['page'] ) || empty( $_GET['tab'] ) || 'wc-settings' !== $_GET['page'] || 'shipping' !== $_GET['tab'] ) ) {
289
			global $wpdb;
290
291
			$product_count = wp_count_posts( 'product' );
292
			$method_count  = wc_get_shipping_method_count();
293
294
			if ( $product_count->publish > 0 && 0 === $method_count ) {
295
				include( 'views/html-notice-no-shipping-methods.php' );
296
			}
297
298
			if ( $method_count > 0 ) {
299
				self::remove_notice( 'no_shipping_methods' );
300
			}
301
		}
302
	}
303
304
	/**
305
	 * Simplify Commerce is being removed from core.
306
	 */
307
	public static function simplify_commerce_notice() {
308
		$location = wc_get_base_location();
309
310
		if ( class_exists( 'WC_Gateway_Simplify_Commerce_Loader' ) || ! in_array( $location['country'], apply_filters( 'woocommerce_gateway_simplify_commerce_supported_countries', array( 'US', 'IE' ) ) ) ) {
311
			self::remove_notice( 'simplify_commerce' );
312
			return;
313
		}
314
		if ( empty( $_GET['action'] ) ) {
315
			include( 'views/html-notice-simplify-commerce.php' );
316
		}
317
	}
318
}
319
320
WC_Admin_Notices::init();
321