Completed
Pull Request — master (#2165)
by Justin
05:43
created

init.php ➔ wpsc_product_files_existing()   C

Complexity

Conditions 7
Paths 21

Size

Total Lines 51
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 37
nc 21
nop 0
dl 0
loc 51
rs 6.9743
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
function wpsc_ajax_sales_quarterly() {
3
4
	if ( ! wpsc_is_store_admin() ) {
5
		return;
6
	}
7
8
	$lastdate = sanitize_text_field( $_POST['add_start'] );
9
	$date = preg_split( '/-/', $lastdate );
10
	if ( !isset( $date[0] ) )
11
		$date[0] = 0;
12
	if ( !isset( $date[1] ) )
13
		$date[1] = 0;
14
	if ( !isset( $date[2] ) )
15
		$date[2] = 0;
16
	$lastquart = mktime( 0, 0, 0, $date[1], $date[2], $date[0] );
17
	if ( $lastquart != get_option( 'wpsc_last_quarter' ) ) {
18
		update_option( 'wpsc_last_date', $lastdate );
19
		update_option( 'wpsc_fourth_quart', $lastquart );
20
		$thirdquart = mktime( 0, 0, 0, $date[1] - 3, $date[2], $date[0] );
21
		update_option( 'wpsc_third_quart', $thirdquart );
22
		$secondquart = mktime( 0, 0, 0, $date[1] - 6, $date[2], $date[0] );
23
		update_option( 'wpsc_second_quart', $secondquart );
24
		$firstquart = mktime( 0, 0, 0, $date[1] - 9, $date[2], $date[0] );
25
		update_option( 'wpsc_first_quart', $firstquart );
26
		$finalquart = mktime( 0, 0, 0, $date[1], $date[2], $date[0] - 1 );
27
		update_option( 'wpsc_final_quart', $finalquart );
28
	}
29
}
30
31
if ( isset( $_REQUEST['wpsc_admin_action'] ) && ($_REQUEST['wpsc_admin_action'] == 'wpsc_quarterly') )
32
	add_action( 'admin_init', 'wpsc_ajax_sales_quarterly' );
33
34
function wpsc_delete_file() {
35
	$product_id = absint( $_REQUEST['product_id'] );
36
	$file_name  = basename( $_REQUEST['file_name'] );
37
	check_admin_referer( 'delete_file_' . $file_name );
38
39
	_wpsc_delete_file( $product_id, $file_name );
40
41
	$sendback = wp_get_referer();
42
	wp_redirect( $sendback );
43
	exit;
44
}
45
46
47
if ( isset( $_REQUEST['wpsc_admin_action'] ) && ($_REQUEST['wpsc_admin_action'] == 'delete_file') )
48
	add_action( 'admin_init', 'wpsc_delete_file' );
49
50
/**
51
 *  Function and action for publishing or unpublishing single products
52
 */
53
function wpsc_ajax_toggle_published() {
54
	$product_id = absint( $_GET['product'] );
55
	check_admin_referer( 'toggle_publish_' . $product_id );
56
57
	$status = (wpsc_toggle_publish_status( $product_id )) ? ('true') : ('false');
58
	$sendback = add_query_arg( 'flipped', "1", wp_get_referer() );
59
	wp_redirect( esc_url_raw( $sendback ) );
60
	exit();
61
}
62
63
if ( isset( $_REQUEST['wpsc_admin_action'] ) && ($_REQUEST['wpsc_admin_action'] == 'toggle_publish') )
64
	add_action( 'admin_init', 'wpsc_ajax_toggle_published' );
65
66
/**
67
 * Function and action for duplicating products,
68
 * Refactored for 3.8
69
 * Purposely not duplicating stick post status (logically, products are most often duplicated because they share many attributes, where products are generally 'featured' uniquely.)
70
 */
71
function wpsc_duplicate_product() {
72
73
	if ( ! wpsc_is_store_admin() ) {
74
		return;
75
	}
76
77
	// Get the original post
78
	$id = absint( $_GET['product'] );
79
	$post = get_post( $id );
80
81
	// Copy the post and insert it
82
	if ( isset( $post ) && $post != null ) {
83
84
		$duplicate = new WPSC_Duplicate_Product( $post->ID );
85
		$new_id = $duplicate->duplicate_product_process();
86
87
		$duplicated = true;
88
		$sendback = wp_get_referer();
89
		$sendback = add_query_arg( 'duplicated', (int) $duplicated, $sendback );
90
91
		wp_redirect( esc_url_raw( $sendback ) );
92
		exit();
93
	} else {
94
		wp_die( __( 'Sorry, for some reason, we couldn\'t duplicate this product because it could not be found in the database, check there for this ID: ', 'wp-e-commerce' ) . $id );
95
	}
96
}
97
98
if ( isset( $_GET['wpsc_admin_action'] ) && ( $_GET['wpsc_admin_action'] == 'duplicate_product' ) )
99
    add_action( 'admin_init', 'wpsc_duplicate_product' );
100
101
function wpsc_purchase_log_csv() {
102
	if ( 'key' == $_REQUEST['rss_key'] && wpsc_is_store_admin() ) {
103
		_wpsc_download_purchase_log_csv( $_REQUEST );
104
	}
105
}
106
107
function _wpsc_download_purchase_log_csv( $args = array() ) {
108
	global $wpdb, $wpsc_gateways;
109
	get_currentuserinfo();
110
	$count = 0;
111
112
	if ( isset( $args['start_timestamp'] ) && isset( $args['end_timestamp'] ) ) {
113
		$start_timestamp = $args['start_timestamp'];
114
		$end_timestamp   = $args['end_timestamp'];
115
		$start_end_sql = "SELECT * FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `date` BETWEEN '%d' AND '%d' ORDER BY `date` DESC";
116
		$start_end_sql = apply_filters( 'wpsc_purchase_log_start_end_csv', $start_end_sql );
117
		$data = $wpdb->get_results( $wpdb->prepare( $start_end_sql, $start_timestamp, $end_timestamp ), ARRAY_A );
118
		/* translators: %1$s is "start" date, %2$s is "to" date */
119
		$csv_name = _x( 'Purchase Log %1$s to %2$s.csv', 'exported purchase log csv file name', 'wp-e-commerce' );
120
		$csv_name = sprintf( $csv_name, date( "M-d-Y", $start_timestamp ), date( "M-d-Y", $end_timestamp ) );
121
	} elseif ( isset( $args['m'] ) ) {
122
		$year = (int) substr( $args['m'], 0, 4);
123
		$month = (int) substr( $args['m'], -2 );
124
		$month_year_sql = "
125
			SELECT *
126
			FROM " . WPSC_TABLE_PURCHASE_LOGS . "
127
			WHERE YEAR(FROM_UNIXTIME(date)) = %d AND MONTH(FROM_UNIXTIME(date)) = %d
128
			ORDER BY `id` DESC
129
		";
130
		$month_year_sql = apply_filters( 'wpsc_purchase_log_month_year_csv', $month_year_sql );
131
		$data = $wpdb->get_results( $wpdb->prepare( $month_year_sql, $year, $month ), ARRAY_A );
132
		/* translators: %1$s is month, %2$s is year */
133
		$csv_name = _x( 'Purchase Log %1$s/%2$s.csv', 'exported purchase log csv file name', 'wp-e-commerce' );
134
		$csv_name = sprintf( $csv_name, $month, $year );
135
	} else {
136
		$sql = apply_filters( 'wpsc_purchase_log_month_year_csv', "SELECT * FROM " . WPSC_TABLE_PURCHASE_LOGS . " ORDER BY `id` DESC" );
137
		$data = $wpdb->get_results( $sql, ARRAY_A );
138
		$csv_name = _x( "All Purchase Logs.csv", 'exported purchase log csv file name', 'wp-e-commerce' );
139
	}
140
141
	$form_sql = "SELECT * FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `active` = '1' AND `type` != 'heading' ORDER BY `checkout_order` DESC;";
142
	$form_data = $wpdb->get_results( $form_sql, ARRAY_A );
143
144
	$headers_array = array(
145
		_x( 'Purchase ID'   , 'purchase log csv headers', 'wp-e-commerce' ),
146
		_x( 'Purchase Total', 'purchase log csv headers', 'wp-e-commerce' ),
147
	);
148
	$headers2_array = array(
149
		_x( 'Payment Gateway', 'purchase log csv headers', 'wp-e-commerce' ),
150
		_x( 'Payment Status' , 'purchase log csv headers', 'wp-e-commerce' ),
151
		_x( 'Purchase Date'  , 'purchase log csv headers', 'wp-e-commerce' ),
152
	);
153
	$form_headers_array = array();
154
155
	$output = '';
156
157
	foreach ( (array) $form_data as $form_field ) {
158
		if ( empty ( $form_field['unique_name'] ) ) {
0 ignored issues
show
Coding Style introduced by
Space before opening parenthesis of function call prohibited
Loading history...
159
			$form_headers_array[] = $form_field['name'];
160
		} else {
161
			$prefix = false === strstr( $form_field['unique_name'], 'billing' ) ? _x( 'Shipping ', 'purchase log csv header field prefix', 'wp-e-commerce' ) : _x( 'Billing ', 'purchase log csv header field prefix', 'wp-e-commerce' );
162
			$form_headers_array[] = $prefix . $form_field['name'];
163
		}
164
	}
165
166
	foreach ( (array) $data as $purchase ) {
167
		$form_headers = '';
168
		$output .= "\"" . $purchase['id'] . "\","; //Purchase ID
169
		$output .= "\"" . $purchase['totalprice'] . "\","; //Purchase Total
170
		foreach ( (array) $form_data as $form_field ) {
171
			$collected_data_sql = "SELECT * FROM `" . WPSC_TABLE_SUBMITTED_FORM_DATA . "` WHERE `log_id` = '" . $purchase['id'] . "' AND `form_id` = '" . $form_field['id'] . "' LIMIT 1";
172
			$collected_data = $wpdb->get_results( $collected_data_sql, ARRAY_A );
173
			$collected_data = $collected_data[0];
174
175
			if (  ( 'billingstate' == $form_field['unique_name'] || 'shippingstate' == $form_field['unique_name'] ) && is_numeric( $collected_data['value'] ) )
176
				$output .= "\"" . wpsc_get_state_by_id( $collected_data['value'], 'code' ) . "\","; // get form fields
177
			else
178
				$output .= "\"" . str_replace( array( "\r", "\r\n", "\n" ), ' ', $collected_data['value'] ) . "\","; // get form fields
179
		}
180
181
		if ( isset( $wpsc_gateways[$purchase['gateway']] ) && isset( $wpsc_gateways[$purchase['gateway']]['display_name'] ) )
182
			$output .= "\"" . $wpsc_gateways[$purchase['gateway']]['display_name'] . "\","; //get gateway name
183
		else
184
			$output .= "\"\",";
185
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
186
187
		$status_name = wpsc_find_purchlog_status_name( $purchase['processed'] );
188
189
		$output .= "\"" . $status_name . "\","; //get purchase status
190
		$output .= "\"" . date( apply_filters( 'wpsc_purchase_log_csv_date_format', 'jS M Y' ), $purchase['date'] ) . "\","; //date
191
192
		$cartsql = "SELECT `prodid`, `quantity`, `name` FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE `purchaseid`=" . $purchase['id'] . "";
193
		$cart = $wpdb->get_results( $cartsql, ARRAY_A );
194
195
		if ( $count < count( $cart ) )
196
		    $count = count( $cart );
197
198
		$items = count( $cart );
199
		$i     = 1;
200
201
		// Go through all products in cart and display quantity and sku
202
		foreach ( (array) $cart as $item ) {
203
			$skuvalue = get_product_meta( $item['prodid'], 'sku', true );
204
			if( empty( $skuvalue ) )
205
			    $skuvalue = __( 'N/A', 'wp-e-commerce' );
206
			$output .= "\"" . $item['quantity'] . "\",";
207
			$output .= "\"" . str_replace( '"', '\"', $item['name'] ) . "\",";
208
209
			if ( $items <= 1 )
210
				$output .= "\"" . $skuvalue . "\"" ;
211
			elseif ( $items > 1 && $i != $items  )
212
				$output .= "\"" . $skuvalue . "\"," ;
213
			else
214
				$output .= "\"" . $skuvalue . "\"" ;
215
216
			$i++;
217
		}
218
219
		$output .= "\n"; // terminates the row/line in the CSV file
220
	}
221
	// Get the most number of products and create a header for them
222
	$headers3 = array();
223
	for( $i = 0; $i < $count; $i++ ){
224
		$headers3[] = _x( 'Quantity', 'purchase log csv headers', 'wp-e-commerce' );
225
		$headers3[] = _x( 'Product Name', 'purchase log csv headers', 'wp-e-commerce' );
226
		$headers3[] = _x( 'SKU', 'purchase log csv headers', 'wp-e-commerce' );
227
	}
228
229
	$headers      = '"' . implode( '","', $headers_array ) . '",';
230
	$form_headers = '"' . implode( '","', $form_headers_array ) . '",';
231
	$headers2     = '"' . implode( '","', $headers2_array ) . '",';
232
	$headers3     = '"' . implode( '","', $headers3 ) . '"';
233
234
	$headers      = apply_filters( 'wpsc_purchase_log_csv_headers', $headers . $form_headers . $headers2 . $headers3, $data, $form_data );
235
	$output       = apply_filters( 'wpsc_purchase_log_csv_output' , $output, $data, $form_data );
236
237
	/**
238
	 * Fires when the WPSC purchase log is exported as a CSV
239
	 */
240
	do_action( 'wpsc_purchase_log_csv' );
241
242
	header( 'Content-Type: text/csv' );
243
	header( 'Content-Disposition: inline; filename="' . $csv_name . '"' );
244
	echo $headers . "\n". $output;
245
	exit;
246
}
247
248
if ( isset( $_REQUEST['wpsc_admin_action'] ) && ($_REQUEST['wpsc_admin_action'] == 'wpsc_downloadcsv') ) {
249
	add_action( 'admin_init', 'wpsc_purchase_log_csv' );
250
}
251
252
if ( isset( $_GET['purchase_log_csv'] ) && ( 'true' == $_GET['purchase_log_csv'] ) )
253
	add_action( 'admin_init', 'wpsc_purchase_log_csv' );
254
255
function wpsc_admin_sale_rss() {
256
257
	if ( ! wpsc_is_store_admin() ) {
258
		return;
259
	}
260
261
	global $wpdb;
262
	if ( ($_GET['rss'] == "true") && ($_GET['rss_key'] == 'key') && ($_GET['action'] == "purchase_log") ) {
263
		$sql = "SELECT * FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `date`!='' ORDER BY `date` DESC";
264
		$purchase_log = $wpdb->get_results( $sql, ARRAY_A );
265
		header( "Content-Type: application/xml; charset=UTF-8" );
266
		header( 'Content-Disposition: inline; filename="WP_E-Commerce_Purchase_Log.rss"' );
267
		$output = '';
268
		$output .= "<?xml version='1.0'?>\n\r";
269
		$output .= "<rss version='2.0'>\n\r";
270
		$output .= "  <channel>\n\r";
271
		$output .= "    <title>" . _x( 'WP eCommerce Product Log', 'admin rss product feed', 'wp-e-commerce' ) . "</title>\n\r";
272
		$output .= "    <link>" . admin_url( 'admin.php?page=' . WPSC_DIR_NAME . '/display-log.php' ) . "</link>\n\r";
273
		$output .= "    <description>" . _x( 'This is the WP eCommerce Product Log RSS feed', 'admin rss product feed', 'wp-e-commerce' ) . "</description>\n\r";
274
		$output .= "    <generator>" . _x( 'WP eCommerce Plugin', 'admin rss product feed', 'wp-e-commerce' ) . "</generator>\n\r";
275
276
		foreach ( (array)$purchase_log as $purchase ) {
277
			$purchase_link = admin_url( 'admin.php?page=' . WPSC_DIR_NAME . '/display-log.php' ) . "&amp;purchaseid=" . $purchase['id'];
278
			$purchase_title = _x( 'Purchase # %d', 'admin rss product feed', 'wp-e-commerce' );
279
			$purchase_title = sprintf( $purchase_title, $purchase['id'] );
280
			$output .= "    <item>\n\r";
281
			$output .= "      <title>{$purchase_title}</title>\n\r";
282
			$output .= "      <link>$purchase_link</link>\n\r";
283
			$output .= "      <description>" . _x( 'This is an entry in the purchase log', 'admin rss product feed', 'wp-e-commerce' ) . ".</description>\n\r";
284
			$output .= "      <pubDate>" . date( "r", $purchase['date'] ) . "</pubDate>\n\r";
285
			$output .= "      <guid>$purchase_link</guid>\n\r";
286
			$output .= "    </item>\n\r";
287
		}
288
		$output .= "  </channel>\n\r";
289
		$output .= "</rss>";
290
		echo $output;
291
		exit();
292
	}
293
}
294
295
if ( isset( $_GET['action'] ) && ( 'purchase_log' == $_GET['action'] ) ) {
296
	add_action( 'admin_init', 'wpsc_admin_sale_rss' );
297
}
298
299
/**
300
 * Do Purchase Log Actions
301
 *
302
 * All purchase log actions are capability and nonce checked before calling
303
 * the relevent 'wpsc_purchase_log_action-{wpsc_purchase_log_action}' hook.
304
 *
305
 * @since  3.9.0
306
 */
307
function wpsc_do_purchase_log_actions() {
308
309
	if ( ! wpsc_is_store_admin() ) {
310
		return;
311
	}
312
313
	if ( isset( $_GET['wpsc_purchase_log_action'] ) && isset( $_GET['id'] ) && isset( $_GET['_wpnonce'] ) ) {
314
		$wpsc_purchase_log_action = sanitize_key( $_GET['wpsc_purchase_log_action'] );
315
316
		if ( wp_verify_nonce( $_GET['_wpnonce'], 'wpsc_purchase_log_action_' . $wpsc_purchase_log_action ) ) {
317
318
			do_action( 'wpsc_purchase_log_action-' . $wpsc_purchase_log_action, absint( $_GET['id'] ) );
319
320
		}
321
	}
322
323
}
324
add_action( 'admin_init', 'wpsc_do_purchase_log_actions' );
325
326
/**
327
 * Handle clear downloads lock purchase log action
328
 *
329
 * The 'wpsc_purchase_log_action-downloads_lock' action hook which calls this function is nonce and capability checked
330
 * in wpsc_do_purchase_log_actions() before triggering do_action( 'wpsc_purchase_log_action-downloads_lock' ).
331
 *
332
 * @since  3.9.0
333
 *
334
 * @param  int  $log_id  Purchase log ID.
335
 */
336
function wpsc_purchase_log_action_downloads_lock( $log_id ) {
337
338
	wpsc_purchlog_clear_download_items( $log_id );
339
340
	// Redirect back to purchase logs list
341
	$sendback = wp_get_referer();
342
	$sendback = esc_url_raw( add_query_arg( 'cleared', 1, $sendback ) );
343
	wp_redirect( $sendback );
344
	exit();
345
346
}
347
add_action( 'wpsc_purchase_log_action-downloads_lock', 'wpsc_purchase_log_action_downloads_lock' );
348
349
/**
350
 * Handle delete purchase log action
351
 *
352
 * The 'wpsc_purchase_log_action-delete' action hook which calls this function is nonce and capability checked
353
 * in wpsc_do_purchase_log_actions() before triggering do_action( 'wpsc_purchase_log_action-delete' ).
354
 *
355
 * @since  3.9.0
356
 *
357
 * @param  int  $log_id  Purchase log ID.
358
 */
359
function wpsc_purchase_log_action_delete( $log_id ) {
360
361
	$log = new WPSC_Purchase_Log( $log_id );
362
	$deleted = $log->delete();
363
364
	// Redirect back to purchase logs list
365
	$sendback = wp_get_referer();
366
	$sendback = remove_query_arg( array( 'c', 'id' ), $sendback );
367
	$sendback = esc_url_raw( add_query_arg( 'deleted', absint( $deleted ), $sendback ) );
368
	wp_redirect( $sendback );
369
	exit();
370
371
}
372
add_action( 'wpsc_purchase_log_action-delete', 'wpsc_purchase_log_action_delete' );
373
374
/**
375
 * Handle email receipt purchase log action
376
 *
377
 * The 'wpsc_purchase_log_action-email_receipt' action hook which calls this function is nonce and capability checked
378
 * in wpsc_do_purchase_log_actions() before triggering do_action( 'wpsc_purchase_log_action-email_receipt' ).
379
 *
380
 * @since  3.9.0
381
 *
382
 * @param  int  $log_id  Purchase log ID.
383
 */
384
function wpsc_purchase_log_action_email_receipt( $log_id ) {
385
386
	$sent = wpsc_purchlog_resend_email( $log_id );
387
388
	// Redirect back to purchase logs list
389
	$sendback = wp_get_referer();
390
	$sendback = esc_url_raw( add_query_arg( 'sent', absint( $sent ), $sendback ) );
391
	wp_redirect( $sendback );
392
	exit();
393
394
}
395
add_action( 'wpsc_purchase_log_action-email_receipt', 'wpsc_purchase_log_action_email_receipt' );
396
397
/**
398
 * Resend Purchase Log Email
399
 *
400
 * @param   int|string  $log_id  Required. Purchase log ID (empty string is deprecated).
401
 * @return  boolean              Sent successfully.
402
 */
403
function wpsc_purchlog_resend_email( $log_id = '' ) {
404
405
	if ( ! wpsc_is_store_admin() ) {
406
		return;
407
	}
408
409
	global $wpdb;
410
411
	// Deprecate empty purchase log ID parameter.
412
	if ( $log_id == '' ) {
413
		_wpsc_doing_it_wrong( 'wpsc_purchlog_resend_email', __( '$log_id parameter requires a numeric purchase log ID.', 'wp-e-commerce' ), '3.9.0' );
414
415
		// Support redirect for legacy purposes for the moment
416
		$sendback = esc_url_raw( add_query_arg( 'sent', 0, wp_get_referer() ) );
417
		wp_redirect( $sendback );
418
		exit();
419
420
	}
421
422
	$log_id = absint( $log_id );
423
424
	if ( $log_id > 0 ) {
425
426
		$wpec_taxes_controller = new wpec_taxes_controller();
427
428
		if ( is_numeric( $log_id ) ) {
429
			$purchase_log = new WPSC_Purchase_Log( $log_id );
430
			return wpsc_send_customer_email( $purchase_log );
431
		}
432
	}
433
434
	return false;
435
}
436
437
// Deprecate resending purchase log email receipt via URL query
438
if ( isset( $_REQUEST['email_buyer_id'] ) && is_numeric( $_REQUEST['email_buyer_id'] ) ) {
439
	_wpsc_doing_it_wrong( 'wpsc_purchlog_resend_email', __( 'Do not trigger resend purchase log email action via email_buyer_id URL query. Instead use the Purchase Log Action Links API.', 'wp-e-commerce' ), '3.9.0' );
440
}
441
442
/**
443
 * Clear Purchase Log Download Locks
444
 *
445
 * @param   string   $log_id  Required. Purchase log ID (empty string is deprecated).
446
 * @return  boolean
447
 */
448
function wpsc_purchlog_clear_download_items( $log_id = '' ) {
449
450
	if ( ! wpsc_is_store_admin() ) {
451
		return;
452
	}
453
454
	global $wpdb;
455
456
	// Deprecate empty purchase log ID parameter.
457
	if ( $log_id == '' ) {
458
		_wpsc_doing_it_wrong( 'wpsc_purchlog_clear_download_items', __( '$log_id parameter requires a numeric purchase log ID.', 'wp-e-commerce' ), '3.9.0' );
459
		return false;
460
	}
461
462
	$log_id = absint( $log_id );
463
464
	if ( $log_id > 0 ) {
465
466
		$downloadable_items = (array) $wpdb->get_results( $wpdb->prepare( "SELECT * FROM `" . WPSC_TABLE_DOWNLOAD_STATUS . "` WHERE `purchid` = %d", $log_id ), ARRAY_A );
467
468
		$wpdb->update( WPSC_TABLE_DOWNLOAD_STATUS, array( 'ip_number' => '' ), array( 'purchid' => $log_id ), '%s', '%d' );
469
470
		$email_form_field = $wpdb->get_var( "SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type` IN ('email') AND `active` = '1' ORDER BY `checkout_order` ASC LIMIT 1" );
471
		$email_address = $wpdb->get_var( $wpdb->prepare( "SELECT `value` FROM `" . WPSC_TABLE_SUBMITTED_FORM_DATA . "` WHERE `log_id` = %d AND `form_id` = '{$email_form_field}' LIMIT 1", $log_id ) );
472
473
		foreach ( $downloadable_items as $downloadable_item ) {
474
			$download_links .= add_query_arg( 'downloadid', $downloadable_item['uniqueid'], home_url() )  . "\n";
0 ignored issues
show
Bug introduced by
The variable $download_links does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
475
		}
476
477
		wp_mail( $email_address, __( 'The administrator has unlocked your file', 'wp-e-commerce' ), str_replace( "[download_links]", $download_links, __( 'Dear Customer, We are pleased to advise you that your order has been updated and your downloads are now active. Please download your purchase using the links provided below. [download_links] Thank you for your order.', 'wp-e-commerce' ) ), "From: " . get_option( 'return_email' )  );
478
479
		return true;
480
481
	}
482
483
	return false;
484
485
}
486
487
// Deprecate clearing purchase log download locks via URL query
488
if ( isset( $_REQUEST['wpsc_admin_action'] ) && ($_REQUEST['wpsc_admin_action'] == 'clear_locks') ) {
489
	_wpsc_doing_it_wrong( 'wpsc_purchlog_clear_download_items', __( 'Do not trigger clear purchase log download locks action via wpsc_admin_action = clear_locks URL query. Instead use the Purchase Log Action Links API.', 'wp-e-commerce' ), '3.9.0' );
490
}
491
492
//bulk actions for purchase log
493
function wpsc_purchlog_bulk_modify() {
494
495
	if ( ! wpsc_is_store_admin() ) {
496
		return;
497
	}
498
499
	if ( $_POST['purchlog_multiple_status_change'] != -1 ) {
500
		if ( is_numeric( $_POST['purchlog_multiple_status_change'] ) && $_POST['purchlog_multiple_status_change'] != 'delete' ) {
501
			foreach ( (array)$_POST['purchlogids'] as $purchlogid ) {
502
				wpsc_purchlog_edit_status( $purchlogid, $_POST['purchlog_multiple_status_change'] );
503
				$updated++;
0 ignored issues
show
Bug introduced by
The variable $updated does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
504
			}
505
		} elseif ( $_POST['purchlog_multiple_status_change'] == 'delete' ) {
506
			foreach ( (array)$_POST['purchlogids'] as $purchlogid ) {
507
508
				$log = new WPSC_Purchase_Log( $purchlogid );
509
				$deleted_log = $log->delete();
510
				if ( $deleted_log ) {
511
					$deleted++;
0 ignored issues
show
Bug introduced by
The variable $deleted does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
512
				}
513
			}
514
		}
515
	}
516
	$sendback = wp_get_referer();
517
	if ( isset( $updated ) ) {
518
		$sendback = add_query_arg( 'updated', $updated, $sendback );
519
	}
520
	if ( isset( $deleted ) ) {
521
		$sendback = add_query_arg( 'deleted', $deleted, $sendback );
522
	}
523
	if ( isset( $_POST['view_purchlogs_by'] ) ) {
524
		$sendback = add_query_arg( 'view_purchlogs_by', $_POST['view_purchlogs_by'], $sendback );
525
	}
526
	if ( isset( $_POST['view_purchlogs_by_status'] ) ) {
527
		$sendback = add_query_arg( 'view_purchlogs_by_status', $_POST['view_purchlogs_by_status'], $sendback );
528
	}
529
	wp_redirect( esc_url_raw( $sendback ) );
530
	exit();
531
}
532
533
if ( isset( $_REQUEST['wpsc_admin_action2'] ) && ($_REQUEST['wpsc_admin_action2'] == 'purchlog_bulk_modify') ) {
534
	add_action( 'admin_init', 'wpsc_purchlog_bulk_modify' );
535
}
536
537
/**
538
 * Update Purchase Log Notes
539
 *
540
 * @param  int     $purchlog_id    Purchase log ID.
541
 * @param  string  $purchlog_notes Notes.
542
 *
543
 * @return mixed                   Result of save.
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use null|WPSC_Purchase_Log_Notes.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
544
 */
545
function wpsc_purchlogs_update_notes( $purchlog_id = 0, $purchlog_notes = '' ) {
546
	if ( empty( $purchlog_id ) && isset( $_POST['purchlog_id'] ) && '' == $purchlog_notes ) {
547
		$purchlog_id = absint( $_POST['purchlog_id'] );
548
549
		if ( isset( $_POST['purchlog_notes'] ) ) {
550
			$purchlog_notes = wp_unslash( $_POST['purchlog_notes'] );
551
		}
552
	}
553
554
	if ( ! $purchlog_id ) {
555
		return;
556
	}
557
558
	$purchase_log = $purchlog_id instanceof WPSC_Purchase_Log
559
		? $purchlog_id
560
		: wpsc_get_order( $purchlog_id );
561
562
	$notes = wpsc_get_order_notes( $purchase_log );
563
564
	return $notes->add( $purchlog_notes )->save();
565
}
566
567
/**
568
 * Delete a purchase log
569
 *
570
 * @deprecated  Use WPSC_Purchase_Log->delete() instead.
571
 *
572
 * @param   int|string  $purchlog_id  Required. Purchase log ID (empty string is deprecated).
573
 * @return  boolean                   Deleted successfully.
574
 */
575
function wpsc_delete_purchlog( $purchlog_id = '' ) {
576
577
	global $wpdb;
578
579
	// Deprecate empty purchase log ID parameter.
580
	if ( $purchlog_id == '' ) {
581
		_wpsc_doing_it_wrong( 'wpsc_delete_purchlog', __( '$purchlog_id parameter requires a numeric purchase log ID.', 'wp-e-commerce' ), '3.9.0' );
582
		return false;
583
	}
584
585
	$log = new WPSC_Purchase_Log( $purchlog_id );
586
587
	return $log->delete();
588
589
}
590
591
// Deprecate deleting purchase log via URL query
592
if ( isset( $_REQUEST['wpsc_admin_action'] ) && ( $_REQUEST['wpsc_admin_action'] == 'delete_purchlog' ) ) {
593
	_wpsc_doing_it_wrong( 'wpsc_delete_purchlog', __( 'Do not trigger delete purchase log action via wpsc_admin_action = delete_purchlog URL query. Instead use the Purchase Log Action Links API.', 'wp-e-commerce' ), '3.9.0' );
594
}
595
596
function _wpsc_action_flush_rewrite_rules() {
597
	flush_rewrite_rules( false );
598
}
599
600
function wpsc_update_option_product_category_hierarchical_url() {
601
	_wpsc_action_flush_rewrite_rules();
602
}
603
604
add_action( 'update_option_product_category_hierarchical_url', 'wpsc_update_option_product_category_hierarchical_url' );
605
606
function _wpsc_action_sanitize_option_grid_number_per_row( $value, $option ) {
607
	$value = (int) $value;
608
	if ( $value === 0 ) {
609
		add_settings_error( $option, 'invalid_grid_number_per_row', __( 'You just set the number of item per row for the grid view to 0. This means the column width will fall back to using whatever CSS you have for it. This could break your theme layout, so please make sure you have adjusted your theme\'s CSS accordingly.', 'wp-e-commerce' ) );
610
	}
611
612
	return $value;
613
}
614
add_filter( 'sanitize_option_grid_number_per_row', '_wpsc_action_sanitize_option_grid_number_per_row', 10, 2 );
615
616
/**
617
 * Automatically enable "Anyone can register" if registration before checkout is required.
618
 *
619
 * @since  3.8.9
620
 * @access private
621
 * @param  mixed $old_value Old value
622
 * @param  mixed $new_value New value
623
 */
624
function _wpsc_action_update_option_require_register( $old_value, $new_value ) {
0 ignored issues
show
Unused Code introduced by
The parameter $old_value is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
625
	if ( $new_value == 1 && ! get_option( 'users_can_register' ) ) {
626
		update_option( 'users_can_register', 1 );
627
		$message = __( 'You wanted to require your customers to log in before checking out. However, the WordPress setting <a href="%s">"Anyone can register"</a> was disabled. WP eCommerce has enabled that setting for you automatically.', 'wp-e-commerce' );
628
		$message = sprintf( $message, admin_url( 'options-general.php' ) );
629
		add_settings_error( 'require_register', 'users_can_register_turned_on', $message, 'updated' );
630
	}
631
}
632
add_action( 'update_option_require_register', '_wpsc_action_update_option_require_register', 10, 2 );
633
634
/**
635
 * Automatically turn off "require registration before checkout" if "Anyone can register" is disabled.
636
 *
637
 * @since  3.8.9
638
 * @access private
639
 * @param  mixed $old_value Old value
640
 * @param  mixed $new_value New value
641
 */
642
function _wpsc_action_update_option_users_can_register( $old_value, $new_value ) {
0 ignored issues
show
Unused Code introduced by
The parameter $old_value is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
643
	if ( ! $new_value && get_option( 'require_register' ) ) {
644
		update_option( 'require_register', 0 );
645
		$message = __( 'You just disabled the "Anyone can register" setting. As a result, the <a href="%s">"Require registration before checking out"</a> setting has been disabled.', 'wp-e-commerce' );
646
		$message = sprintf( $message, admin_url( 'options-general.php?page=wpsc-settings&tab=checkout' ) );
647
		add_settings_error( 'users_can_register', 'require_register_turned_off', $message, 'updated' );
648
	}
649
}
650
add_action( 'update_option_users_can_register', '_wpsc_action_update_option_users_can_register', 10, 2 );
651
652
/**
653
 * wpsc_update_page_urls gets the permalinks for products pages and stores them in the options for quick reference
654
 * @public
655
 *
656
 * @since 3.6
657
 * @param $auto (Boolean) true if coming from WordPress Permalink Page, false otherwise
658
 * @return nothing
659
 */
660
function wpsc_update_page_urls( $auto = false ) {
661
662
	if ( ! wpsc_is_store_admin() ) {
663
		return;
664
	}
665
666
	wpsc_update_permalink_slugs();
667
	wpsc_core_load_page_titles();
668
	wpsc_register_post_types();
669
670
	if ( ! $auto ) {
671
		$sendback = wp_get_referer();
672
		if ( isset( $updated ) )
0 ignored issues
show
Bug introduced by
The variable $updated seems to never exist, and therefore isset should always return false. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
673
			$sendback = add_query_arg( 'updated', $updated, $sendback );
674
675
		if ( isset( $_SESSION['wpsc_settings_curr_page'] ) )
0 ignored issues
show
introduced by
Usage of $_SESSION variable is prohibited.
Loading history...
676
			$sendback = add_query_arg( 'tab', $_SESSION['wpsc_settings_curr_page'], $sendback );
0 ignored issues
show
introduced by
Usage of $_SESSION variable is prohibited.
Loading history...
677
678
		wp_redirect( esc_url_raw( $sendback ) );
679
		exit();
680
	}
681
}
682
if ( isset( $_REQUEST['wpsc_admin_action'] ) && ($_REQUEST['wpsc_admin_action'] == 'update_page_urls') )
683
	add_action( 'admin_init', 'wpsc_update_page_urls' );
684
685
//change the regions tax settings
686
function wpsc_change_region_tax() {
687
688
	if ( ! wpsc_is_store_admin() ) {
689
		return;
690
	}
691
692
	global $wpdb;
693
	if ( is_array( $_POST['region_tax'] ) ) {
694
		foreach ( $_POST['region_tax'] as $region_id => $tax ) {
695
			if ( is_numeric( $region_id ) && is_numeric( $tax ) ) {
696
				$previous_tax = $wpdb->get_var( $wpdb->prepare( "SELECT `tax` FROM `" . WPSC_TABLE_REGION_TAX . "` WHERE `id` = %d LIMIT 1", $region_id ) );
697
				if ( $tax != $previous_tax ) {
698
					$wpdb->update(
699
						WPSC_TABLE_REGION_TAX,
700
						array(
701
						    'tax' => $tax
702
						),
703
						array(
704
						    'id' => $region_id
705
						),
706
						'%s',
707
						'%d'
708
					    );
709
					$changes_made = true;
710
				}
711
			}
712
		}
713
		$sendback = wp_get_referer();
714
		wp_redirect( $sendback );
715
	}
716
}
717
if ( isset( $_REQUEST['wpsc_admin_action'] ) && ($_REQUEST['wpsc_admin_action'] == 'change_region_tax') )
718
	add_action( 'admin_init', 'wpsc_change_region_tax' );
719
720
function wpsc_product_files_existing() {
721
	//List all product_files, with checkboxes
722
723
	if ( ! wpsc_is_store_admin() ) {
724
		return;
725
	}
726
727
	$product_id = absint( $_GET["product_id"] );
728
	$file_list = wpsc_uploaded_files();
729
730
	$args = array(
731
		'post_type' => 'wpsc-product-file',
732
		'post_parent' => $product_id,
733
		'numberposts' => -1,
0 ignored issues
show
introduced by
Disabling pagination is prohibited in VIP context, do not set numberposts to -1 ever.
Loading history...
734
		'post_status' => 'all'
735
	);
736
	$attached_files = (array)get_posts( $args );
737
738
	$attached_files_by_file = array();
739
	foreach ( $attached_files as $key => $attached_file ) {
740
		$attached_files_by_file[$attached_file->post_title] = & $attached_files[$key];
741
	}
742
743
	$output = "<span class='admin_product_notes select_product_note '>" . esc_html__( 'Choose a downloadable file for this product:', 'wp-e-commerce' ) . "</span><br>";
744
	$output .= "<form method='post' class='product_upload'>";
745
	$output .= '<div class="ui-widget-content multiple-select select_product_file" style="width:100%">';
746
	$num = 0;
747
	foreach ( (array)$file_list as $file ) {
748
		$num++;
749
		$checked_curr_file = "";
750
		if ( isset( $attached_files_by_file[$file['display_filename']] ) ) {
751
			$checked_curr_file = "checked='checked'";
752
		}
753
754
		$output .= "<p " . ((($num % 2) > 0) ? '' : "class='alt'") . " id='select_product_file_row_$num'>\n";
755
		$output .= "  <input type='checkbox' name='select_product_file[]' value='" . $file['real_filename'] . "' id='select_product_file_$num' " . $checked_curr_file . " />\n";
756
		$output .= "  <label for='select_product_file_$num'>" . $file['display_filename'] . "</label>\n";
757
		$output .= "</p>\n";
758
	}
759
760
	$output .= "</div>";
761
	$output .= "<input type='hidden' id='hidden_id' value='$product_id' />";
762
	$output .= "<input data-nonce='" . _wpsc_create_ajax_nonce( 'upload_product_file' ) . "' type='submit' name='save' name='product_files_submit' class='button-primary prdfil' value='" . esc_html__( 'Save Product Files', 'wp-e-commerce' ) . "' />";
763
	$output .= "</form>";
764
	$output .= "<div class='" . ((is_numeric( $product_id )) ? "edit_" : "") . "select_product_handle'><div></div></div>";
765
	$output .= "<script type='text/javascript'>\n\r";
766
	$output .= "var select_min_height = " . (25 * 3) . ";\n\r";
767
	$output .= "var select_max_height = " . (25 * ($num + 1)) . ";\n\r";
768
	$output .= "</script>";
769
	echo $output;
770
}
771
if ( isset( $_REQUEST['wpsc_admin_action'] ) && ($_REQUEST['wpsc_admin_action'] == 'product_files_existing') )
772
	add_action( 'admin_init', 'wpsc_product_files_existing' );
773
774
function wpsc_update_variations() {
775
	$product_id = absint( $_POST["product_id"] );
776
	$product_type_object = get_post_type_object('wpsc-product');
777
	if (!current_user_can($product_type_object->cap->edit_post, $product_id))
778
		return;
779
780
	//Setup postdata
781
	$post_data = array();
782
	$post_data['edit_var_val'] = isset( $_POST['edit_var_val'] ) ? $_POST["edit_var_val"] : '';
783
784
	//Add or delete variations
785
	wpsc_edit_product_variations( $product_id, $post_data );
786
}
787
788
if ( isset($_POST["edit_var_val"]) )
789
	add_action( 'admin_init', 'wpsc_update_variations', 50 );
790
791
function wpsc_delete_variation_set() {
792
	check_admin_referer( 'delete-variation' );
793
794
	if ( is_numeric( $_GET['deleteid'] ) ) {
795
		$variation_id = absint( $_GET['deleteid'] );
796
797
		$variation_set = get_term( $variation_id, 'wpsc-variation', ARRAY_A );
798
799
		$variations = get_terms( 'wpsc-variation', array(
800
					'hide_empty' => 0,
801
					'parent' => $variation_id
802
				) );
803
804
		foreach ( (array) $variations as $variation ) {
805
			$return_value = wp_delete_term( $variation->term_id, 'wpsc-variation' );
806
		}
807
808
		if ( !empty( $variation_set ) ) {
809
			$return_value = wp_delete_term( $variation_set['term_id'], 'wpsc-variation' );
810
		}
811
		$deleted = 1;
812
	}
813
814
	$sendback = wp_get_referer();
815
	if ( isset( $deleted ) ) {
816
		$sendback = add_query_arg( 'deleted', $deleted, $sendback );
817
	}
818
	$sendback = remove_query_arg( array(
819
				'deleteid',
820
				'variation_id'
821
					), $sendback );
822
823
	wp_redirect( esc_url_raw( $sendback ) );
824
	exit();
825
}
826
827
if ( isset( $_REQUEST['wpsc_admin_action'] ) && ( 'wpsc-delete-variation-set' == $_REQUEST['wpsc_admin_action'] ) )
828
	add_action( 'admin_init', 'wpsc_delete_variation_set' );
829
830
function wpsc_backup_theme() {
831
832
	if ( ! wpsc_is_store_admin() ) {
833
		return;
834
	}
835
836
	$wp_theme_path = get_stylesheet_directory();
837
	wpsc_recursive_copy( $wp_theme_path, WPSC_THEME_BACKUP_DIR );
838
	$_SESSION['wpsc_themes_backup'] = true;
0 ignored issues
show
introduced by
Usage of $_SESSION variable is prohibited.
Loading history...
839
	$sendback = wp_get_referer();
840
	wp_redirect( $sendback );
841
842
	exit();
843
}
844
if ( isset( $_REQUEST['wpsc_admin_action'] ) && ( $_REQUEST['wpsc_admin_action'] == 'backup_themes' ) )
845
	add_action( 'admin_init', 'wpsc_backup_theme' );
846
847
/**
848
 * Delete a coupon
849
 *
850
 * @since 3.8
851
 */
852
function wpsc_delete_coupon(){
853
854
	global $wpdb;
855
856
	check_admin_referer( 'delete-coupon' );
857
858
	if ( ! function_exists( 'wpsc_is_store_admin' ) || ! wpsc_is_store_admin() ) {
859
		return;
860
	}
861
862
	$deleted = 0;
863
864
	if ( isset( $_GET['delete_id'] ) ) {
865
		$coupon = new WPSC_Coupon( $_GET['delete_id'] );
866
		$coupon->delete();
867
		$deleted = 1;
868
	}
869
870
	$sendback = wp_get_referer();
871
872
	if ( $deleted ) {
873
		$sendback = add_query_arg( 'deleted', $deleted, $sendback );
874
	}
875
876
	$sendback = remove_query_arg( array( 'deleteid', 'wpsc_admin_action' ), $sendback );
877
	wp_redirect( esc_url_raw( $sendback ) );
878
	exit();
879
880
}
881
882
// Delete Coupon
883
if ( isset( $_REQUEST['wpsc_admin_action'] ) && ( 'wpsc-delete-coupon' == $_REQUEST['wpsc_admin_action'] ) ) {
884
	add_action( 'admin_init', 'wpsc_delete_coupon' );
885
}
886
887
function _wpsc_action_update_option_base_country( $old_value, $new_value ) {
0 ignored issues
show
Unused Code introduced by
The parameter $old_value is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
888
	global $wpdb;
889
	$region_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(`regions`.`id`) FROM `" . WPSC_TABLE_REGION_TAX . "` AS `regions` INNER JOIN `" . WPSC_TABLE_CURRENCY_LIST . "` AS `country` ON `country`.`id` = `regions`.`country_id` WHERE `country`.`isocode` IN('%s')",  $new_value ) );
890
	if ( ! $region_count )
891
		update_option( 'base_region', '' );
892
}
893
add_action( 'update_option_base_country', '_wpsc_action_update_option_base_country', 10, 2 );
894