This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * WooCommerce Shipping Settings |
||
4 | * |
||
5 | * @package WooCommerce/Admin |
||
6 | * @version 2.6.0 |
||
7 | */ |
||
8 | |||
9 | defined( 'ABSPATH' ) || exit; |
||
10 | |||
11 | if ( class_exists( 'WC_Settings_Shipping', false ) ) { |
||
12 | return new WC_Settings_Shipping(); |
||
13 | } |
||
14 | |||
15 | /** |
||
16 | * WC_Settings_Shipping. |
||
17 | */ |
||
18 | class WC_Settings_Shipping extends WC_Settings_Page { |
||
19 | |||
20 | /** |
||
21 | * Constructor. |
||
22 | */ |
||
23 | public function __construct() { |
||
24 | $this->id = 'shipping'; |
||
25 | $this->label = __( 'Shipping', 'woocommerce' ); |
||
26 | |||
27 | parent::__construct(); |
||
28 | } |
||
29 | |||
30 | /** |
||
31 | * Add this page to settings. |
||
32 | * |
||
33 | * @param array $pages Current pages. |
||
34 | * @return array|mixed |
||
35 | */ |
||
36 | public function add_settings_page( $pages ) { |
||
37 | return wc_shipping_enabled() ? parent::add_settings_page( $pages ) : $pages; |
||
38 | } |
||
39 | |||
40 | /** |
||
41 | * Get sections. |
||
42 | * |
||
43 | * @return array |
||
44 | */ |
||
45 | 2 | public function get_sections() { |
|
46 | $sections = array( |
||
47 | 2 | '' => __( 'Shipping zones', 'woocommerce' ), |
|
48 | 2 | 'options' => __( 'Shipping options', 'woocommerce' ), |
|
49 | 2 | 'classes' => __( 'Shipping classes', 'woocommerce' ), |
|
50 | ); |
||
51 | |||
52 | 2 | if ( ! defined( 'WC_INSTALLING' ) ) { |
|
53 | // Load shipping methods so we can show any global options they may have. |
||
54 | $shipping_methods = WC()->shipping()->load_shipping_methods(); |
||
55 | |||
56 | View Code Duplication | foreach ( $shipping_methods as $method ) { |
|
57 | if ( ! $method->has_settings() ) { |
||
58 | continue; |
||
59 | } |
||
60 | $title = empty( $method->method_title ) ? ucfirst( $method->id ) : $method->method_title; |
||
61 | $sections[ strtolower( $method->id ) ] = esc_html( $title ); |
||
62 | } |
||
63 | } |
||
64 | |||
65 | 2 | return apply_filters( 'woocommerce_get_sections_' . $this->id, $sections ); |
|
66 | } |
||
67 | |||
68 | /** |
||
69 | * Get settings array. |
||
70 | * |
||
71 | * @param string $current_section Current section. |
||
72 | * @return array |
||
73 | */ |
||
74 | 2 | public function get_settings( $current_section = '' ) { |
|
75 | 2 | $settings = array(); |
|
76 | |||
77 | 2 | if ( '' === $current_section ) { |
|
78 | 2 | $settings = apply_filters( |
|
79 | 2 | 'woocommerce_shipping_settings', |
|
80 | array( |
||
81 | array( |
||
82 | 2 | 'title' => __( 'Shipping options', 'woocommerce' ), |
|
83 | 2 | 'type' => 'title', |
|
84 | 2 | 'id' => 'shipping_options', |
|
85 | ), |
||
86 | |||
87 | array( |
||
88 | 2 | 'title' => __( 'Calculations', 'woocommerce' ), |
|
89 | 2 | 'desc' => __( 'Enable the shipping calculator on the cart page', 'woocommerce' ), |
|
90 | 2 | 'id' => 'woocommerce_enable_shipping_calc', |
|
91 | 2 | 'default' => 'yes', |
|
92 | 2 | 'type' => 'checkbox', |
|
93 | 2 | 'checkboxgroup' => 'start', |
|
94 | 'autoload' => false, |
||
95 | ), |
||
96 | |||
97 | array( |
||
98 | 2 | 'desc' => __( 'Hide shipping costs until an address is entered', 'woocommerce' ), |
|
99 | 2 | 'id' => 'woocommerce_shipping_cost_requires_address', |
|
100 | 2 | 'default' => 'no', |
|
101 | 2 | 'type' => 'checkbox', |
|
102 | 2 | 'checkboxgroup' => 'end', |
|
103 | ), |
||
104 | |||
105 | array( |
||
106 | 2 | 'title' => __( 'Shipping destination', 'woocommerce' ), |
|
107 | 2 | 'desc' => __( 'This controls which shipping address is used by default.', 'woocommerce' ), |
|
108 | 2 | 'id' => 'woocommerce_ship_to_destination', |
|
109 | 2 | 'default' => 'billing', |
|
110 | 2 | 'type' => 'radio', |
|
111 | 'options' => array( |
||
112 | 2 | 'shipping' => __( 'Default to customer shipping address', 'woocommerce' ), |
|
113 | 2 | 'billing' => __( 'Default to customer billing address', 'woocommerce' ), |
|
114 | 2 | 'billing_only' => __( 'Force shipping to the customer billing address', 'woocommerce' ), |
|
115 | ), |
||
116 | 'autoload' => false, |
||
117 | 'desc_tip' => true, |
||
118 | 2 | 'show_if_checked' => 'option', |
|
119 | ), |
||
120 | |||
121 | array( |
||
122 | 2 | 'title' => __( 'Debug mode', 'woocommerce' ), |
|
123 | 2 | 'desc' => __( 'Enable debug mode', 'woocommerce' ), |
|
124 | 2 | 'desc_tip' => __( 'Enable shipping debug mode to show matching shipping zones and to bypass shipping rate cache.', 'woocommerce' ), |
|
125 | 2 | 'id' => 'woocommerce_shipping_debug_mode', |
|
126 | 2 | 'default' => 'no', |
|
127 | 2 | 'type' => 'checkbox', |
|
128 | ), |
||
129 | |||
130 | array( |
||
131 | 'type' => 'sectionend', |
||
132 | 'id' => 'shipping_options', |
||
133 | ), |
||
134 | |||
135 | ) |
||
136 | ); |
||
137 | } |
||
138 | |||
139 | 2 | return apply_filters( 'woocommerce_get_settings_' . $this->id, $settings, $current_section ); |
|
140 | } |
||
141 | |||
142 | /** |
||
143 | * Output the settings. |
||
144 | */ |
||
145 | public function output() { |
||
146 | global $current_section, $hide_save_button; |
||
147 | |||
148 | // Load shipping methods so we can show any global options they may have. |
||
149 | $shipping_methods = WC()->shipping()->load_shipping_methods(); |
||
150 | |||
151 | if ( '' === $current_section ) { |
||
152 | $this->output_zones_screen(); |
||
153 | } elseif ( 'options' === $current_section ) { |
||
154 | $settings = $this->get_settings(); |
||
155 | WC_Admin_Settings::output_fields( $settings ); |
||
156 | } elseif ( 'classes' === $current_section ) { |
||
157 | $hide_save_button = true; |
||
158 | $this->output_shipping_class_screen(); |
||
159 | } else { |
||
160 | $is_shipping_method = false; |
||
161 | View Code Duplication | foreach ( $shipping_methods as $method ) { |
|
162 | if ( in_array( $current_section, array( $method->id, sanitize_title( get_class( $method ) ) ), true ) && $method->has_settings() ) { |
||
163 | $is_shipping_method = true; |
||
164 | $method->admin_options(); |
||
165 | } |
||
166 | } |
||
167 | if ( ! $is_shipping_method ) { |
||
168 | $settings = $this->get_settings(); |
||
169 | $settings = apply_filters( 'woocommerce_get_settings_' . $this->id, $settings, $current_section ); |
||
170 | WC_Admin_Settings::output_fields( $settings ); |
||
171 | } |
||
172 | } |
||
173 | } |
||
174 | |||
175 | /** |
||
176 | * Save settings. |
||
177 | */ |
||
178 | public function save() { |
||
179 | global $current_section; |
||
180 | |||
181 | switch ( $current_section ) { |
||
182 | case 'options': |
||
183 | WC_Admin_Settings::save_fields( $this->get_settings() ); |
||
184 | do_action( 'woocommerce_update_options_' . $this->id . '_options' ); |
||
185 | break; |
||
186 | case 'classes': |
||
187 | do_action( 'woocommerce_update_options_' . $this->id . '_classes' ); |
||
188 | break; |
||
189 | case '': |
||
190 | break; |
||
191 | default: |
||
192 | $wc_shipping = WC_Shipping::instance(); |
||
193 | $is_shipping_method = false; |
||
194 | |||
195 | foreach ( $wc_shipping->get_shipping_methods() as $method_id => $method ) { |
||
196 | if ( in_array( $current_section, array( $method->id, sanitize_title( get_class( $method ) ) ), true ) ) { |
||
197 | $is_shipping_method = true; |
||
198 | do_action( 'woocommerce_update_options_' . $this->id . '_' . $method->id ); |
||
199 | } |
||
200 | } |
||
201 | if ( ! $is_shipping_method ) { |
||
202 | WC_Admin_Settings::save_fields( $this->get_settings( $current_section ) ); |
||
203 | } |
||
204 | break; |
||
205 | } |
||
206 | |||
207 | // Increments the transient version to invalidate cache. |
||
208 | WC_Cache_Helper::get_transient_version( 'shipping', true ); |
||
209 | } |
||
210 | |||
211 | /** |
||
212 | * Handles output of the shipping zones page in admin. |
||
213 | */ |
||
214 | protected function output_zones_screen() { |
||
215 | global $hide_save_button; |
||
216 | |||
217 | if ( isset( $_REQUEST['zone_id'] ) ) { // WPCS: input var ok, CSRF ok. |
||
218 | $hide_save_button = true; |
||
219 | $this->zone_methods_screen( wc_clean( wp_unslash( $_REQUEST['zone_id'] ) ) ); // WPCS: input var ok, CSRF ok. |
||
220 | } elseif ( isset( $_REQUEST['instance_id'] ) ) { |
||
221 | $this->instance_settings_screen( absint( wp_unslash( $_REQUEST['instance_id'] ) ) ); // WPCS: input var ok, CSRF ok. |
||
222 | } else { |
||
223 | $hide_save_button = true; |
||
224 | $this->zones_screen(); |
||
225 | } |
||
226 | } |
||
227 | |||
228 | /** |
||
229 | * Show method for a zone |
||
230 | * |
||
231 | * @param int $zone_id Zone ID. |
||
232 | */ |
||
233 | protected function zone_methods_screen( $zone_id ) { |
||
234 | if ( 'new' === $zone_id ) { |
||
235 | $zone = new WC_Shipping_Zone(); |
||
236 | } else { |
||
237 | $zone = WC_Shipping_Zones::get_zone( absint( $zone_id ) ); |
||
238 | } |
||
239 | |||
240 | if ( ! $zone ) { |
||
241 | wp_die( esc_html__( 'Zone does not exist!', 'woocommerce' ) ); |
||
242 | } |
||
243 | |||
244 | $allowed_countries = WC()->countries->get_shipping_countries(); |
||
245 | $shipping_continents = WC()->countries->get_shipping_continents(); |
||
246 | |||
247 | // Prepare locations. |
||
248 | $locations = array(); |
||
249 | $postcodes = array(); |
||
250 | |||
251 | foreach ( $zone->get_zone_locations() as $location ) { |
||
252 | if ( 'postcode' === $location->type ) { |
||
253 | $postcodes[] = $location->code; |
||
254 | } else { |
||
255 | $locations[] = $location->type . ':' . $location->code; |
||
256 | } |
||
257 | } |
||
258 | |||
259 | wp_localize_script( |
||
260 | 'wc-shipping-zone-methods', |
||
261 | 'shippingZoneMethodsLocalizeScript', |
||
262 | array( |
||
263 | 'methods' => $zone->get_shipping_methods( false, 'json' ), |
||
264 | 'zone_name' => $zone->get_zone_name(), |
||
265 | 'zone_id' => $zone->get_id(), |
||
266 | 'wc_shipping_zones_nonce' => wp_create_nonce( 'wc_shipping_zones_nonce' ), |
||
267 | 'strings' => array( |
||
268 | 'unload_confirmation_msg' => __( 'Your changed data will be lost if you leave this page without saving.', 'woocommerce' ), |
||
269 | 'save_changes_prompt' => __( 'Do you wish to save your changes first? Your changed data will be discarded if you choose to cancel.', 'woocommerce' ), |
||
270 | 'save_failed' => __( 'Your changes were not saved. Please retry.', 'woocommerce' ), |
||
271 | 'add_method_failed' => __( 'Shipping method could not be added. Please retry.', 'woocommerce' ), |
||
272 | 'yes' => __( 'Yes', 'woocommerce' ), |
||
273 | 'no' => __( 'No', 'woocommerce' ), |
||
274 | 'default_zone_name' => __( 'Zone', 'woocommerce' ), |
||
275 | ), |
||
276 | ) |
||
277 | ); |
||
278 | wp_enqueue_script( 'wc-shipping-zone-methods' ); |
||
279 | |||
280 | include_once dirname( __FILE__ ) . '/views/html-admin-page-shipping-zone-methods.php'; |
||
281 | } |
||
282 | |||
283 | /** |
||
284 | * Show zones |
||
285 | */ |
||
286 | protected function zones_screen() { |
||
287 | $method_count = wc_get_shipping_method_count(); |
||
288 | |||
289 | wp_localize_script( |
||
290 | 'wc-shipping-zones', |
||
291 | 'shippingZonesLocalizeScript', |
||
292 | array( |
||
293 | 'zones' => WC_Shipping_Zones::get_zones( 'json' ), |
||
294 | 'default_zone' => array( |
||
295 | 'zone_id' => 0, |
||
296 | 'zone_name' => '', |
||
297 | 'zone_order' => null, |
||
298 | ), |
||
299 | 'wc_shipping_zones_nonce' => wp_create_nonce( 'wc_shipping_zones_nonce' ), |
||
300 | 'strings' => array( |
||
301 | 'unload_confirmation_msg' => __( 'Your changed data will be lost if you leave this page without saving.', 'woocommerce' ), |
||
302 | 'delete_confirmation_msg' => __( 'Are you sure you want to delete this zone? This action cannot be undone.', 'woocommerce' ), |
||
303 | 'save_failed' => __( 'Your changes were not saved. Please retry.', 'woocommerce' ), |
||
304 | 'no_shipping_methods_offered' => __( 'No shipping methods offered to this zone.', 'woocommerce' ), |
||
305 | ), |
||
306 | ) |
||
307 | ); |
||
308 | wp_enqueue_script( 'wc-shipping-zones' ); |
||
309 | |||
310 | include_once dirname( __FILE__ ) . '/views/html-admin-page-shipping-zones.php'; |
||
311 | } |
||
312 | |||
313 | /** |
||
314 | * Show instance settings |
||
315 | * |
||
316 | * @param int $instance_id Shipping instance ID. |
||
317 | */ |
||
318 | protected function instance_settings_screen( $instance_id ) { |
||
319 | $zone = WC_Shipping_Zones::get_zone_by( 'instance_id', $instance_id ); |
||
320 | $shipping_method = WC_Shipping_Zones::get_shipping_method( $instance_id ); |
||
321 | |||
322 | if ( ! $shipping_method ) { |
||
323 | wp_die( esc_html__( 'Invalid shipping method!', 'woocommerce' ) ); |
||
324 | } |
||
325 | if ( ! $zone ) { |
||
326 | wp_die( esc_html__( 'Zone does not exist!', 'woocommerce' ) ); |
||
327 | } |
||
328 | if ( ! $shipping_method->has_settings() ) { |
||
329 | wp_die( esc_html__( 'This shipping method does not have any settings to configure.', 'woocommerce' ) ); |
||
330 | } |
||
331 | |||
332 | if ( ! empty( $_POST['save'] ) ) { // WPCS: input var ok, sanitization ok. |
||
333 | |||
334 | if ( empty( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( wp_unslash( $_REQUEST['_wpnonce'] ), 'woocommerce-settings' ) ) { // WPCS: input var ok, sanitization ok. |
||
335 | echo '<div class="updated error"><p>' . esc_html__( 'Edit failed. Please try again.', 'woocommerce' ) . '</p></div>'; |
||
336 | } |
||
337 | |||
338 | $shipping_method->process_admin_options(); |
||
339 | $shipping_method->display_errors(); |
||
340 | } |
||
341 | |||
342 | include_once dirname( __FILE__ ) . '/views/html-admin-page-shipping-zones-instance.php'; |
||
343 | } |
||
344 | |||
345 | /** |
||
346 | * Handles output of the shipping class settings screen. |
||
347 | */ |
||
348 | protected function output_shipping_class_screen() { |
||
349 | $wc_shipping = WC_Shipping::instance(); |
||
350 | wp_localize_script( |
||
351 | 'wc-shipping-classes', |
||
352 | 'shippingClassesLocalizeScript', |
||
353 | array( |
||
354 | 'classes' => $wc_shipping->get_shipping_classes(), |
||
355 | 'default_shipping_class' => array( |
||
356 | 'term_id' => 0, |
||
357 | 'name' => '', |
||
358 | 'description' => '', |
||
359 | ), |
||
360 | 'wc_shipping_classes_nonce' => wp_create_nonce( 'wc_shipping_classes_nonce' ), |
||
361 | 'strings' => array( |
||
362 | 'unload_confirmation_msg' => __( 'Your changed data will be lost if you leave this page without saving.', 'woocommerce' ), |
||
363 | 'save_failed' => __( 'Your changes were not saved. Please retry.', 'woocommerce' ), |
||
364 | ), |
||
365 | ) |
||
366 | ); |
||
367 | wp_enqueue_script( 'wc-shipping-classes' ); |
||
368 | |||
369 | // Extendable columns to show on the shipping classes screen. |
||
370 | $shipping_class_columns = apply_filters( |
||
0 ignored issues
–
show
|
|||
371 | 'woocommerce_shipping_classes_columns', |
||
372 | array( |
||
373 | 'wc-shipping-class-name' => __( 'Shipping class', 'woocommerce' ), |
||
374 | 'wc-shipping-class-slug' => __( 'Slug', 'woocommerce' ), |
||
375 | 'wc-shipping-class-description' => __( 'Description', 'woocommerce' ), |
||
376 | 'wc-shipping-class-count' => __( 'Product count', 'woocommerce' ), |
||
377 | ) |
||
378 | ); |
||
379 | |||
380 | include_once dirname( __FILE__ ) . '/views/html-admin-page-shipping-classes.php'; |
||
381 | } |
||
382 | } |
||
383 | |||
384 | return new WC_Settings_Shipping(); |
||
385 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
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.