Completed
Pull Request — master (#2237)
by Justin
05:32
created

init.php ➔ wpsc_purchlogs_update_notes()   C

Complexity

Conditions 7
Paths 9

Size

Total Lines 22
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 13
nc 9
nop 2
dl 0
loc 22
rs 6.9811
c 0
b 0
f 0
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
	$notes->add( $purchlog_notes )->save();
564
565
	return $notes;
566
}
567
568
/**
569
 * Delete a purchase log
570
 *
571
 * @deprecated  Use WPSC_Purchase_Log->delete() instead.
572
 *
573
 * @param   int|string  $purchlog_id  Required. Purchase log ID (empty string is deprecated).
574
 * @return  boolean                   Deleted successfully.
575
 */
576
function wpsc_delete_purchlog( $purchlog_id = '' ) {
577
578
	global $wpdb;
579
580
	// Deprecate empty purchase log ID parameter.
581
	if ( $purchlog_id == '' ) {
582
		_wpsc_doing_it_wrong( 'wpsc_delete_purchlog', __( '$purchlog_id parameter requires a numeric purchase log ID.', 'wp-e-commerce' ), '3.9.0' );
583
		return false;
584
	}
585
586
	$log = new WPSC_Purchase_Log( $purchlog_id );
587
588
	return $log->delete();
589
590
}
591
592
// Deprecate deleting purchase log via URL query
593
if ( isset( $_REQUEST['wpsc_admin_action'] ) && ( $_REQUEST['wpsc_admin_action'] == 'delete_purchlog' ) ) {
594
	_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' );
595
}
596
597
function _wpsc_action_flush_rewrite_rules() {
598
	flush_rewrite_rules( false );
599
}
600
601
function wpsc_update_option_product_category_hierarchical_url() {
602
	_wpsc_action_flush_rewrite_rules();
603
}
604
605
add_action( 'update_option_product_category_hierarchical_url', 'wpsc_update_option_product_category_hierarchical_url' );
606
607
function _wpsc_action_sanitize_option_grid_number_per_row( $value, $option ) {
608
	$value = (int) $value;
609
	if ( $value === 0 ) {
610
		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' ) );
611
	}
612
613
	return $value;
614
}
615
add_filter( 'sanitize_option_grid_number_per_row', '_wpsc_action_sanitize_option_grid_number_per_row', 10, 2 );
616
617
/**
618
 * Automatically enable "Anyone can register" if registration before checkout is required.
619
 *
620
 * @since  3.8.9
621
 * @access private
622
 * @param  mixed $old_value Old value
623
 * @param  mixed $new_value New value
624
 */
625
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...
626
	if ( $new_value == 1 && ! get_option( 'users_can_register' ) ) {
627
		update_option( 'users_can_register', 1 );
628
		$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' );
629
		$message = sprintf( $message, admin_url( 'options-general.php' ) );
630
		add_settings_error( 'require_register', 'users_can_register_turned_on', $message, 'updated' );
631
	}
632
}
633
add_action( 'update_option_require_register', '_wpsc_action_update_option_require_register', 10, 2 );
634
635
/**
636
 * Automatically turn off "require registration before checkout" if "Anyone can register" is disabled.
637
 *
638
 * @since  3.8.9
639
 * @access private
640
 * @param  mixed $old_value Old value
641
 * @param  mixed $new_value New value
642
 */
643
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...
644
	if ( ! $new_value && get_option( 'require_register' ) ) {
645
		update_option( 'require_register', 0 );
646
		$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' );
647
		$message = sprintf( $message, admin_url( 'options-general.php?page=wpsc-settings&tab=checkout' ) );
648
		add_settings_error( 'users_can_register', 'require_register_turned_off', $message, 'updated' );
649
	}
650
}
651
add_action( 'update_option_users_can_register', '_wpsc_action_update_option_users_can_register', 10, 2 );
652
653
/**
654
 * wpsc_update_page_urls gets the permalinks for products pages and stores them in the options for quick reference
655
 * @public
656
 *
657
 * @since 3.6
658
 * @param $auto (Boolean) true if coming from WordPress Permalink Page, false otherwise
659
 * @return nothing
660
 */
661
function wpsc_update_page_urls( $auto = false ) {
662
663
	if ( ! wpsc_is_store_admin() ) {
664
		return;
665
	}
666
667
	wpsc_update_permalink_slugs();
668
	wpsc_core_load_page_titles();
669
	wpsc_register_post_types();
670
671
	if ( ! $auto ) {
672
		$sendback = wp_get_referer();
673
		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...
674
			$sendback = add_query_arg( 'updated', $updated, $sendback );
675
676
		if ( isset( $_SESSION['wpsc_settings_curr_page'] ) )
0 ignored issues
show
introduced by
Usage of $_SESSION variable is prohibited.
Loading history...
677
			$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...
678
679
		wp_redirect( esc_url_raw( $sendback ) );
680
		exit();
681
	}
682
}
683
if ( isset( $_REQUEST['wpsc_admin_action'] ) && ($_REQUEST['wpsc_admin_action'] == 'update_page_urls') )
684
	add_action( 'admin_init', 'wpsc_update_page_urls' );
685
686
//change the regions tax settings
687
function wpsc_change_region_tax() {
688
689
	if ( ! wpsc_is_store_admin() ) {
690
		return;
691
	}
692
693
	global $wpdb;
694
	if ( is_array( $_POST['region_tax'] ) ) {
695
		foreach ( $_POST['region_tax'] as $region_id => $tax ) {
696
			if ( is_numeric( $region_id ) && is_numeric( $tax ) ) {
697
				$previous_tax = $wpdb->get_var( $wpdb->prepare( "SELECT `tax` FROM `" . WPSC_TABLE_REGION_TAX . "` WHERE `id` = %d LIMIT 1", $region_id ) );
698
				if ( $tax != $previous_tax ) {
699
					$wpdb->update(
700
						WPSC_TABLE_REGION_TAX,
701
						array(
702
						    'tax' => $tax
703
						),
704
						array(
705
						    'id' => $region_id
706
						),
707
						'%s',
708
						'%d'
709
					    );
710
					$changes_made = true;
711
				}
712
			}
713
		}
714
		$sendback = wp_get_referer();
715
		wp_redirect( $sendback );
716
	}
717
}
718
if ( isset( $_REQUEST['wpsc_admin_action'] ) && ($_REQUEST['wpsc_admin_action'] == 'change_region_tax') )
719
	add_action( 'admin_init', 'wpsc_change_region_tax' );
720
721
function wpsc_product_files_existing() {
722
	//List all product_files, with checkboxes
723
724
	if ( ! wpsc_is_store_admin() ) {
725
		return;
726
	}
727
728
	$product_id = absint( $_GET["product_id"] );
729
	$file_list = wpsc_uploaded_files();
730
731
	$args = array(
732
		'post_type' => 'wpsc-product-file',
733
		'post_parent' => $product_id,
734
		'numberposts' => -1,
0 ignored issues
show
introduced by
Disabling pagination is prohibited in VIP context, do not set numberposts to -1 ever.
Loading history...
735
		'post_status' => 'all'
736
	);
737
	$attached_files = (array)get_posts( $args );
738
739
	$attached_files_by_file = array();
740
	foreach ( $attached_files as $key => $attached_file ) {
741
		$attached_files_by_file[$attached_file->post_title] = & $attached_files[$key];
742
	}
743
744
	$output = "<span class='admin_product_notes select_product_note '>" . esc_html__( 'Choose a downloadable file for this product:', 'wp-e-commerce' ) . "</span><br>";
745
	$output .= "<form method='post' class='product_upload'>";
746
	$output .= '<div class="ui-widget-content multiple-select select_product_file" style="width:100%">';
747
	$num = 0;
748
	foreach ( (array)$file_list as $file ) {
749
		$num++;
750
		$checked_curr_file = "";
751
		if ( isset( $attached_files_by_file[$file['display_filename']] ) ) {
752
			$checked_curr_file = "checked='checked'";
753
		}
754
755
		$output .= "<p " . ((($num % 2) > 0) ? '' : "class='alt'") . " id='select_product_file_row_$num'>\n";
756
		$output .= "  <input type='checkbox' name='select_product_file[]' value='" . $file['real_filename'] . "' id='select_product_file_$num' " . $checked_curr_file . " />\n";
757
		$output .= "  <label for='select_product_file_$num'>" . $file['display_filename'] . "</label>\n";
758
		$output .= "</p>\n";
759
	}
760
761
	$output .= "</div>";
762
	$output .= "<input type='hidden' id='hidden_id' value='$product_id' />";
763
	$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' ) . "' />";
764
	$output .= "</form>";
765
	$output .= "<div class='" . ((is_numeric( $product_id )) ? "edit_" : "") . "select_product_handle'><div></div></div>";
766
	$output .= "<script type='text/javascript'>\n\r";
767
	$output .= "var select_min_height = " . (25 * 3) . ";\n\r";
768
	$output .= "var select_max_height = " . (25 * ($num + 1)) . ";\n\r";
769
	$output .= "</script>";
770
	echo $output;
771
}
772
if ( isset( $_REQUEST['wpsc_admin_action'] ) && ($_REQUEST['wpsc_admin_action'] == 'product_files_existing') )
773
	add_action( 'admin_init', 'wpsc_product_files_existing' );
774
775
function wpsc_update_variations() {
776
	$product_id = absint( $_POST["product_id"] );
777
	$product_type_object = get_post_type_object('wpsc-product');
778
	if (!current_user_can($product_type_object->cap->edit_post, $product_id))
779
		return;
780
781
	//Setup postdata
782
	$post_data = array();
783
	$post_data['edit_var_val'] = isset( $_POST['edit_var_val'] ) ? $_POST["edit_var_val"] : '';
784
785
	//Add or delete variations
786
	wpsc_edit_product_variations( $product_id, $post_data );
787
}
788
789
if ( isset($_POST["edit_var_val"]) )
790
	add_action( 'admin_init', 'wpsc_update_variations', 50 );
791
792
function wpsc_delete_variation_set() {
793
	check_admin_referer( 'delete-variation' );
794
795
	if ( is_numeric( $_GET['deleteid'] ) ) {
796
		$variation_id = absint( $_GET['deleteid'] );
797
798
		$variation_set = get_term( $variation_id, 'wpsc-variation', ARRAY_A );
799
800
		$variations = get_terms( 'wpsc-variation', array(
801
					'hide_empty' => 0,
802
					'parent' => $variation_id
803
				) );
804
805
		foreach ( (array) $variations as $variation ) {
806
			$return_value = wp_delete_term( $variation->term_id, 'wpsc-variation' );
807
		}
808
809
		if ( !empty( $variation_set ) ) {
810
			$return_value = wp_delete_term( $variation_set['term_id'], 'wpsc-variation' );
811
		}
812
		$deleted = 1;
813
	}
814
815
	$sendback = wp_get_referer();
816
	if ( isset( $deleted ) ) {
817
		$sendback = add_query_arg( 'deleted', $deleted, $sendback );
818
	}
819
	$sendback = remove_query_arg( array(
820
				'deleteid',
821
				'variation_id'
822
					), $sendback );
823
824
	wp_redirect( esc_url_raw( $sendback ) );
825
	exit();
826
}
827
828
if ( isset( $_REQUEST['wpsc_admin_action'] ) && ( 'wpsc-delete-variation-set' == $_REQUEST['wpsc_admin_action'] ) )
829
	add_action( 'admin_init', 'wpsc_delete_variation_set' );
830
831
function wpsc_backup_theme() {
832
833
	if ( ! wpsc_is_store_admin() ) {
834
		return;
835
	}
836
837
	$wp_theme_path = get_stylesheet_directory();
838
	wpsc_recursive_copy( $wp_theme_path, WPSC_THEME_BACKUP_DIR );
839
	$_SESSION['wpsc_themes_backup'] = true;
0 ignored issues
show
introduced by
Usage of $_SESSION variable is prohibited.
Loading history...
840
	$sendback = wp_get_referer();
841
	wp_redirect( $sendback );
842
843
	exit();
844
}
845
if ( isset( $_REQUEST['wpsc_admin_action'] ) && ( $_REQUEST['wpsc_admin_action'] == 'backup_themes' ) )
846
	add_action( 'admin_init', 'wpsc_backup_theme' );
847
848
/**
849
 * Delete a coupon
850
 *
851
 * @since 3.8
852
 */
853
function wpsc_delete_coupon(){
854
855
	global $wpdb;
856
857
	check_admin_referer( 'delete-coupon' );
858
859
	if ( ! function_exists( 'wpsc_is_store_admin' ) || ! wpsc_is_store_admin() ) {
860
		return;
861
	}
862
863
	$deleted = 0;
864
865
	if ( isset( $_GET['delete_id'] ) ) {
866
		$coupon = new WPSC_Coupon( $_GET['delete_id'] );
867
		$coupon->delete();
868
		$deleted = 1;
869
	}
870
871
	$sendback = wp_get_referer();
872
873
	if ( $deleted ) {
874
		$sendback = add_query_arg( 'deleted', $deleted, $sendback );
875
	}
876
877
	$sendback = remove_query_arg( array( 'deleteid', 'wpsc_admin_action' ), $sendback );
878
	wp_redirect( esc_url_raw( $sendback ) );
879
	exit();
880
881
}
882
883
// Delete Coupon
884
if ( isset( $_REQUEST['wpsc_admin_action'] ) && ( 'wpsc-delete-coupon' == $_REQUEST['wpsc_admin_action'] ) ) {
885
	add_action( 'admin_init', 'wpsc_delete_coupon' );
886
}
887
888
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...
889
	global $wpdb;
890
	$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 ) );
891
	if ( ! $region_count )
892
		update_option( 'base_region', '' );
893
}
894
add_action( 'update_option_base_country', '_wpsc_action_update_option_base_country', 10, 2 );
895