Completed
Push — master ( 963c79...0bf4fb )
by Justin
05:31
created

wpsc-functions.php ➔ wpsc_is_theme_engine()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * WP eCommerce core functions
5
 *
6
 * These are core functions for wp-eCommerce
7
 * Things like registering custom post types and taxonomies, rewrite rules, wp_query modifications, link generation and some basic theme finding code is located here
8
 *
9
 * @package wp-e-commerce
10
 * @since 3.8
11
 */
12
13
if ( is_admin() ) {
14
	add_filter( 'term_name', 'wpsc_term_list_levels', 10, 2 );
15
}
16
17
/**
18
 * When doing variation and product category drag&drop sort, we want to restrict
19
 * drag & drop to the same level (children of a category cannot be dropped under
20
 * another parent category). To do this, we need to be able to specify depth level
21
 * of the term items being output to the term list table.
22
 *
23
 * Unfortunately, there's no way we can do that with WP hooks. So this is a work around.
24
 * This function is added to "term_name" filter. Its job is to record the depth level of
25
 * each terms into a global variable. This global variable will later be output to JS in
26
 * wpsc_print_term_list_levels_script().
27
 *
28
 * Not an elegant solution, but it works.
29
 *
30
 * @param  string $term_name
31
 * @param  object $term
32
 * @return string
33
 */
34
function wpsc_term_list_levels( $term_name, $term ) {
35
36
	global $wp_list_table, $wpsc_term_list_levels;
37
38
	$screen = get_current_screen();
39
40
	if ( ! is_object( $screen ) || ! in_array( $screen->id, array( 'edit-wpsc-variation', 'edit-wpsc_product_category' ) ) ) {
41
		return $term_name;
42
	}
43
44
	if ( ! isset( $wpsc_term_list_levels ) ) {
45
		$wpsc_term_list_levels = array();
46
	}
47
48
	if ( is_numeric( $term ) ) {
49
		$term = get_term_by( 'id', $term, str_replace( 'edit-', '', $screen->id ) );
50
	}
51
52
	if ( isset( $wp_list_table->level ) ) {
53
		$wpsc_term_list_levels[ $term->term_id ] = $wp_list_table->level;
54
	}
55
56
	return $term_name;
57
}
58
59
add_filter( 'admin_footer', 'wpsc_print_term_list_levels_script' );
60
61
/**
62
 * Print $wpsc_term_list_levels as JS.
63
 * @see wpsc_term_list_levels()
64
 * @return void
65
 */
66
function wpsc_print_term_list_levels_script() {
67
	global $wpsc_term_list_levels;
68
	$screen = get_current_screen();
69
	if ( ! in_array( $screen->id, array( 'edit-wpsc-variation', 'edit-wpsc_product_category' ) ) )
70
		return;
71
72
	?>
73
	<script type="text/javascript">
74
	//<![CDATA[
75
	var WPSC_Term_List_Levels = <?php echo json_encode( $wpsc_term_list_levels ); ?>;
76
	//]]>
77
	</script>
78
	<?php
79
}
80
81
/**
82
 * Determines whether or not a current user has the capability to do administrative actions in the store.
83
 *
84
 * @since  3.8.14.4
85
 *
86
 * @return  bool  Whether or not current user can administrate the store.
87
 */
88
function wpsc_is_store_admin() {
89
	return current_user_can( apply_filters( 'wpsc_store_admin_capability', 'manage_options' ) );
90
}
91
92
/**
93
 * wpsc_core_load_checkout_data()
94
 *
95
 * @return none
96
 */
97
function wpsc_core_load_checkout_data() {
98
	wpsc_checkout_form_fields();
99
	wpsc_checkout_unique_names();
100
}
101
102
/**
103
 * Get the checkout form fields and types
104
 *
105
 * @since 3.8.14
106
 *
107
 * @return array of strings     each key value being a checkout item's
108
 *                          	user presentable name, the value being the
109
 *                              checkout item type
110
 */
111
function wpsc_checkout_form_fields() {
112
	$form_types = array(
113
			__( 'Text', 'wp-e-commerce' )             => 'text',
114
			__( 'Email Address', 'wp-e-commerce' )    => 'email',
115
			__( 'Street Address', 'wp-e-commerce' )   => 'address',
116
			__( 'City', 'wp-e-commerce' )             => 'city',
117
			__( 'Country', 'wp-e-commerce' )          => 'country',
118
			__( 'Delivery Address', 'wp-e-commerce' ) => 'delivery_address',
119
			__( 'Delivery City', 'wp-e-commerce' )    => 'delivery_city',
120
			__( 'Delivery Country', 'wp-e-commerce' ) => 'delivery_country',
121
			__( 'Text Area', 'wp-e-commerce' )        => 'textarea',
122
			__( 'Heading', 'wp-e-commerce' )          => 'heading',
123
			__( 'Select', 'wp-e-commerce' )           => 'select',
124
			__( 'Radio Button', 'wp-e-commerce' )     => 'radio',
125
			__( 'Checkbox', 'wp-e-commerce' )         => 'checkbox',
126
	);
127
128
	$form_types = apply_filters( 'wpsc_add_form_types', $form_types );
129
130
	// TODO: there really isn't a good reason to save this as an option becuase it is recomputed
131
	// every time WPEC is reloaded.  Deprecate the option and replace any references to the option
132
	// with a call to this function
133
	update_option( 'wpsc_checkout_form_fields', $form_types );
134
135
	return $form_types;
136
}
137
138
139
/**
140
 * Get the unique names used in checkout forms
141
 *
142
 * @since 3.8.14
143
 *
144
 * @return array of strings, each string value being a checkout item's unique name
145
 */
146
function wpsc_checkout_unique_names() {
147
148
	static $unique_names = null;
149
150
	if ( empty( $unique_names ) ) {
151
		$unique_names = array(
152
				'billingfirstname',
153
				'billinglastname',
154
				'billingaddress',
155
				'billingcity',
156
				'billingstate',
157
				'billingcountry',
158
				'billingemail',
159
				'billingphone',
160
				'billingpostcode',
161
				'billingregion',
162
				'shippingSameBilling',
163
				'shippingfirstname',
164
				'shippinglastname',
165
				'shippingaddress',
166
				'shippingcity',
167
				'shippingstate',
168
				'shippingcountry',
169
				'shippingpostcode',
170
				'shippingregion',
171
		);
172
173
		$unique_names = apply_filters( 'wpsc_add_unique_names' , $unique_names );
174
175
		// TODO: there really isn't a good reason to save this as an option becuase it is recomputed
176
		// every time WPEC is reloaded.  Deprecate the option and replace any references to the option
177
		// with a call to this function
178
		update_option( 'wpsc_checkout_unique_names', $unique_names );
179
	}
180
181
	return $unique_names;
182
}
183
184
/**
185
 * Get the unique names used in checkout forms
186
 *
187
 * @since 3.8.14
188
 * @access private
189
 *
190
 * @return array  local variables to add to both admin and front end WPEC javascript
191
 */
192
function wpsc_javascript_localizations( $localizations = false ) {
193
194
	if ( ! is_array( $localizations ) ) {
195
		$localizations = array();
196
	}
197
198
	// The default localizations should only be added once per page as we don't want them to be
199
	// defined more than once in the javascript.
200
	static $already_added_default_localizations = false;
201
202
	if ( ! $already_added_default_localizations ) {
203
204
		$localizations['wpsc_ajax'] = array(
205
			'ajaxurl'                 => admin_url( 'admin-ajax.php', 'relative' ),
206
			'spinner'                 => esc_url( wpsc_get_ajax_spinner() ),
207
			'no_quotes'               => __( 'It appears that there are no shipping quotes for the shipping information provided.  Please check the information and try again.', 'wp-e-commerce' ),
208
			'ajax_get_cart_error'     => __( 'There was a problem getting the current contents of the shopping cart.', 'wp-e-commerce' ),
209
			'slide_to_shipping_error' => true,
210
		);
211
212
		$localizations['base_url']  	 	       = site_url();
213
		$localizations['WPSC_URL'] 	               = WPSC_URL;
214
		$localizations['WPSC_IMAGE_URL']           = WPSC_IMAGE_URL;
215
		$localizations['WPSC_CORE_IMAGES_URL']     = WPSC_CORE_IMAGES_URL;
216
		$localizations['fileThickboxLoadingImage'] = WPSC_CORE_IMAGES_URL . '/loadingAnimation.gif';
217
		$localizations['msg_shipping_need_recalc'] = __( 'Please click the <em>Calculate</em> button to refresh your shipping quotes, as your shipping information has been modified.', 'wp-e-commerce' );
218
	}
219
220
	/**
221
	 * a filter for WPeC components, plugins and themes to alter or add to what is localized into the WPeC javascript.
222
	 *
223
	 * @since 3.8.14
224
	 *
225
	 * @access public
226
	 *
227
	 * @param array $localizations array of localizations being sent to the javascript
228
	 *
229
	 */
230
	return apply_filters( 'wpsc_javascript_localizations', $localizations );
231
}
232
233
/**
234
 * wpsc_core_load_purchase_log_statuses()
235
 *
236
 * @global array $wpsc_purchlog_statuses
237
 */
238
function wpsc_core_load_purchase_log_statuses() {
239
	global $wpsc_purchlog_statuses;
240
241
	$wpsc_purchlog_statuses = array(
242
		array(
243
			'internalname' => 'incomplete_sale',
244
			'label'        => __( 'Incomplete Sale', 'wp-e-commerce' ),
245
			'view_label'   => _nx_noop(
246
				'Incomplete Sale <span class="count">(%d)</span>',
247
				'Incomplete Sale <span class="count">(%d)</span>',
248
				'Purchase log view links',
249
				'wp-e-commerce'
250
			),
251
			'order'        => 1,
252
		),
253
		array(
254
			'internalname' => 'order_received',
255
			'label'        => __( 'Order Received', 'wp-e-commerce' ),
256
			'view_label'   => _nx_noop(
257
				'Order Received <span class="count">(%d)</span>',
258
				'Order Received <span class="count">(%d)</span>',
259
				'Purchase log view links',
260
				'wp-e-commerce'
261
			),
262
			'order'        => 2,
263
		),
264
		array(
265
			'internalname'   => 'accepted_payment',
266
			'label'          => __( 'Accepted Payment', 'wp-e-commerce' ),
267
			'view_label'     => _nx_noop(
268
				'Accepted Payment <span class="count">(%d)</span>',
269
				'Accepted Payment <span class="count">(%d)</span>',
270
				'Purchase log view links',
271
				'wp-e-commerce'
272
			),
273
			'is_transaction' => true,
274
			'order'          => 3,
275
		),
276
		array(
277
			'internalname'   => 'job_dispatched',
278
			'label'          => __( 'Job Dispatched', 'wp-e-commerce' ),
279
			'view_label'     => _nx_noop(
280
				'Job Dispatched <span class="count">(%d)</span>',
281
				'Job Dispatched <span class="count">(%d)</span>',
282
				'Purchase log view links',
283
				'wp-e-commerce'
284
			),
285
			'is_transaction' => true,
286
			'order'          => 4,
287
		),
288
		array(
289
			'internalname'   => 'closed_order',
290
			'label'          => __( 'Closed Order', 'wp-e-commerce' ),
291
			'view_label'     => _nx_noop(
292
				'Closed Order <span class="count">(%d)</span>',
293
				'Closed Order <span class="count">(%d)</span>',
294
				'Purchase log view links',
295
				'wp-e-commerce'
296
			),
297
			'is_transaction' => true,
298
			'order'          => 5,
299
		),
300
		array(
301
			'internalname'   => 'declined_payment',
302
			'label'          => __( 'Payment Declined', 'wp-e-commerce' ),
303
			'view_label'     => _nx_noop(
304
				'Payment Declined <span class="count">(%d)</span>',
305
				'Payment Declined <span class="count">(%d)</span>',
306
				'Purchase log view links',
307
				'wp-e-commerce'
308
			),
309
			'order'          => 6,
310
		),
311
	);
312
	$wpsc_purchlog_statuses = apply_filters( 'wpsc_set_purchlog_statuses', $wpsc_purchlog_statuses );
313
}
314
315
/***
316
 * wpsc_core_load_gateways()
317
 *
318
 * Gets the merchants from the merchants directory and eeds to search the
319
 * merchants directory for merchants, the code to do this starts here.
320
 *
321
 * @todo Come up with a better way to do this than a global $num value
322
 */
323
function wpsc_core_load_gateways() {
324
	global $nzshpcrt_gateways, $num, $wpsc_gateways,$gateway_checkout_form_fields;
325
326
	$gateway_directory      = WPSC_FILE_PATH . '/wpsc-merchants';
327
	$nzshpcrt_merchant_list = wpsc_list_dir( $gateway_directory );
328
329
	$num = 0;
330
	foreach ( $nzshpcrt_merchant_list as $nzshpcrt_merchant ) {
331
		if ( stristr( $nzshpcrt_merchant, '.php' ) ) {
332
			require( WPSC_FILE_PATH . '/wpsc-merchants/' . $nzshpcrt_merchant );
333
		}
334
		$num++;
335
	}
336
	unset( $nzshpcrt_merchant );
337
338
	$nzshpcrt_gateways = apply_filters( 'wpsc_merchants_modules', $nzshpcrt_gateways );
339
	uasort( $nzshpcrt_gateways, 'wpsc_merchant_sort' );
340
341
	// make an associative array of references to gateway data.
342
	$wpsc_gateways = array();
343
	foreach ( (array)$nzshpcrt_gateways as $key => $gateway )
344
		$wpsc_gateways[$gateway['internalname']] = &$nzshpcrt_gateways[$key];
345
346
	unset( $key, $gateway );
347
348
}
349
350
/***
351
 * wpsc_core_load_shipping_modules()
352
 *
353
 * Gets the shipping modules from the shipping directory and needs to search
354
 * the shipping directory for modules.
355
 */
356
function wpsc_core_load_shipping_modules() {
357
	global $wpsc_shipping_modules;
358
359
	$shipping_directory     = WPSC_FILE_PATH . '/wpsc-shipping';
360
	$nzshpcrt_shipping_list = wpsc_list_dir( $shipping_directory );
361
362
	foreach ( $nzshpcrt_shipping_list as $nzshpcrt_shipping ) {
363
		if ( stristr( $nzshpcrt_shipping, '.php' ) ) {
364
			require( WPSC_FILE_PATH . '/wpsc-shipping/' . $nzshpcrt_shipping );
365
		}
366
	}
367
368
	$wpsc_shipping_modules = apply_filters( 'wpsc_shipping_modules', $wpsc_shipping_modules );
369
370
}
371
372
/**
373
 * If shipping is enabled and shipping methods have not been initialized, then
374
 * do so.
375
 *
376
 * @access private
377
 * @since 3.8.13
378
 */
379
function _wpsc_action_get_shipping_method() {
380
	global $wpsc_cart;
381
382
	if ( empty( $wpsc_cart->selected_shipping_method ) ) {
383
		$wpsc_cart->get_shipping_method();
384
	}
385
}
386
387
/**
388
 * Update Notice
389
 *
390
 * Displays an update message below the auto-upgrade link in the WordPress admin
391
 * to notify users that they should check the upgrade information and changelog
392
 * before upgrading in case they need to may updates to their theme files.
393
 *
394
 * @package wp-e-commerce
395
 * @since 3.7.6.1
396
 */
397
function wpsc_update_notice() {
398
	$info_title = __( 'Please backup your website before updating!', 'wp-e-commerce' );
399
	$info_text =  __( 'Before updating please backup your database and files in case anything goes wrong.', 'wp-e-commerce' );
0 ignored issues
show
introduced by
Expected 1 space after "="; 2 found
Loading history...
400
	echo '<div style="border-top:1px solid #CCC; margin-top:3px; padding-top:3px; font-weight:normal;"><strong style="color:#CC0000">' . strip_tags( $info_title ) . '</strong> ' . strip_tags( $info_text, '<br><a><strong><em><span>' ) . '</div>';
401
}
402
403
function wpsc_in_plugin_update_message() {
404
	add_action( 'in_plugin_update_message-' . WPSC_DIR_NAME . '/wp-shopping-cart.php', 'wpsc_update_notice' );
405
}
406
407
if ( is_admin() )
408
	add_action( 'init', 'wpsc_in_plugin_update_message' );
409
410
411
function wpsc_add_product_price_to_rss() {
412
	global $post;
413
	$price = get_post_meta( $post->ID, '_wpsc_price', true );
414
	// Only output a price tag if we have a price
415
	if ( $price )
416
		echo '<price>' . $price . '</price>';
417
}
418
add_action( 'rss2_item', 'wpsc_add_product_price_to_rss' );
419
add_action( 'rss_item', 'wpsc_add_product_price_to_rss' );
420
add_action( 'rdf_item', 'wpsc_add_product_price_to_rss' );
421
422
/**
423
 * wpsc_register_post_types()
424
 *
425
 * The meat of this whole operation, this is where we register our post types
426
 *
427
 * @global array $wpsc_page_titles
428
 */
429
function wpsc_register_post_types() {
430
	global $wpsc_page_titles;
431
432
	// Products
433
    $labels = array(
434
		'name'               => _x( 'Products'                  , 'post type name'             , 'wp-e-commerce' ),
435
		'singular_name'      => _x( 'Product'                   , 'post type singular name'    , 'wp-e-commerce' ),
436
		'add_new'            => _x( 'Add New'                   , 'admin menu: add new product', 'wp-e-commerce' ),
437
		'add_new_item'       => __( 'Add New Product'           , 'wp-e-commerce' ),
438
		'edit_item'          => __( 'Edit Product'              , 'wp-e-commerce' ),
439
		'new_item'           => __( 'New Product'               , 'wp-e-commerce' ),
440
		'view_item'          => __( 'View Product'              , 'wp-e-commerce' ),
441
		'search_items'       => __( 'Search Products'           , 'wp-e-commerce' ),
442
		'not_found'          => __( 'No products found'         , 'wp-e-commerce' ),
443
		'not_found_in_trash' => __( 'No products found in Trash', 'wp-e-commerce' ),
444
		'menu_name'          => __( 'Products'                  , 'wp-e-commerce' ),
445
		'parent_item_colon'  => '',
446
      );
447
    $args = array(
448
		'capability_type'      => 'post',
449
		'supports'             => array( 'title', 'editor', 'thumbnail' ),
450
		'hierarchical'         => true,
451
		'exclude_from_search'  => false,
452
		'public'               => true,
453
		'show_ui'              => true,
454
		'show_in_nav_menus'    => true,
455
		'menu_icon'            => version_compare( $GLOBALS['wp_version'], '3.8', '<' ) ? WPSC_CORE_IMAGES_URL . '/credit_cards.png' : 'dashicons-cart',
456
		'labels'               => $labels,
457
		'query_var'            => true,
458
		'register_meta_box_cb' => 'wpsc_meta_boxes',
459
		'rewrite'              => array(
460
			'slug'       => str_replace( basename( home_url() ), '', $wpsc_page_titles['products'] ) . '/%wpsc_product_category%',
461
			'with_front' => false
462
		)
463
	);
464
	$args = apply_filters( 'wpsc_register_post_types_products_args', $args );
465
	register_post_type( 'wpsc-product', $args );
466
467
	// Purchasable product files
468
	$args = array(
469
		'capability_type'     => 'post',
470
		'map_meta_cap'        => true,
471
		'hierarchical'        => false,
472
		'exclude_from_search' => true,
473
		'rewrite'             => false,
474
		'labels'              => array(
475
			'name'          => __( 'Product Files', 'wp-e-commerce' ),
476
			'singular_name' => __( 'Product File' , 'wp-e-commerce' ),
477
		),
478
	);
479
	$args = apply_filters( 'wpsc_register_post_types_product_files_args', $args );
480
	register_post_type( 'wpsc-product-file', $args );
481
482
	// Product tags
483
	$labels = array(
484
		'name'          => _x( 'Product Tags'        , 'taxonomy general name' , 'wp-e-commerce' ),
485
		'singular_name' => _x( 'Product Tag'         , 'taxonomy singular name', 'wp-e-commerce' ),
486
		'search_items'  => __( 'Search Product Tags' , 'wp-e-commerce' ),
487
		'all_items'     => __( 'All Product Tags'    , 'wp-e-commerce' ),
488
		'edit_item'     => __( 'Edit Tag'            , 'wp-e-commerce' ),
489
		'update_item'   => __( 'Update Tag'          , 'wp-e-commerce' ),
490
		'add_new_item'  => __( 'Add New Product Tag' , 'wp-e-commerce' ),
491
		'new_item_name' => __( 'New Product Tag Name', 'wp-e-commerce' ),
492
		'choose_from_most_used' => __('Choose from most used Product Tags', 'wp-e-commerce' ),
493
		'not_found'	=> __('No Product Tags found', 'wp-e-commerce'),
494
	);
495
496
	$args = array(
497
		'hierarchical' => false,
498
		'labels' => $labels,
499
		'rewrite' => array(
500
			'slug' => '/' . sanitize_title_with_dashes( _x( 'tagged', 'slug, part of url', 'wp-e-commerce' ) ),
501
			'with_front' => false )
502
	);
503
	$args = apply_filters( 'wpsc_register_taxonomies_product_tag_args', $args );
504
	register_taxonomy( 'product_tag', 'wpsc-product', $args );
505
506
	// Product categories, is heirarchical and can use permalinks
507
	$labels = array(
508
		'name'              => _x( 'Product Categories'       , 'taxonomy general name' , 'wp-e-commerce' ),
509
		'singular_name'     => _x( 'Product Category'         , 'taxonomy singular name', 'wp-e-commerce' ),
510
		'search_items'      => __( 'Search Product Categories', 'wp-e-commerce' ),
511
		'all_items'         => __( 'All Product Categories'   , 'wp-e-commerce' ),
512
		'parent_item'       => __( 'Parent Product Category'  , 'wp-e-commerce' ),
513
		'parent_item_colon' => __( 'Parent Product Category:' , 'wp-e-commerce' ),
514
		'edit_item'         => __( 'Edit Product Category'    , 'wp-e-commerce' ),
515
		'update_item'       => __( 'Update Product Category'  , 'wp-e-commerce' ),
516
		'add_new_item'      => __( 'Add New Product Category' , 'wp-e-commerce' ),
517
		'new_item_name'     => __( 'New Product Category Name', 'wp-e-commerce' ),
518
		'menu_name'         => _x( 'Categories'               , 'taxonomy general name', 'wp-e-commerce' ),
519
	);
520
	$args = array(
521
		'labels'       => $labels,
522
		'hierarchical' => true,
523
		'rewrite'      => array(
524
			'slug'         => str_replace( basename( home_url() ), '', $wpsc_page_titles['products'] ),
525
			'with_front'   => false,
526
			'hierarchical' => (bool) get_option( 'product_category_hierarchical_url', 0 ),
527
		),
528
	);
529
	$args = apply_filters( 'wpsc_register_taxonomies_product_category_args', $args );
530
531
	register_taxonomy( 'wpsc_product_category', 'wpsc-product', $args );
532
	$labels = array(
533
		'name'              => _x( 'Variations'        , 'taxonomy general name' , 'wp-e-commerce' ),
534
		'singular_name'     => _x( 'Variation'         , 'taxonomy singular name', 'wp-e-commerce' ),
535
		'search_items'      => __( 'Search Variations' , 'wp-e-commerce' ),
536
		'all_items'         => __( 'All Variations'    , 'wp-e-commerce' ),
537
		'parent_item'       => __( 'Parent Variation'  , 'wp-e-commerce' ),
538
		'parent_item_colon' => __( 'Parent Variations:', 'wp-e-commerce' ),
539
		'edit_item'         => __( 'Edit Variation'    , 'wp-e-commerce' ),
540
		'update_item'       => __( 'Update Variation'  , 'wp-e-commerce' ),
541
		'add_new_item'      => __( 'Add New Variation' , 'wp-e-commerce' ),
542
		'new_item_name'     => __( 'New Variation Name', 'wp-e-commerce' ),
543
	);
544
	$args = array(
545
		'hierarchical' => true,
546
		'query_var'    => 'variations',
547
		'rewrite'      => false,
548
		'public'       => true,
549
		'labels'       => $labels
550
	);
551
	$args = apply_filters( 'wpsc_register_taxonomies_product_variation_args', $args );
552
	// Product Variations, is internally heirarchical, externally, two separate types of items, one containing the other
553
	register_taxonomy( 'wpsc-variation', 'wpsc-product', $args );
554
555
	/**
556
	 * Fires after the WPSC post types are registered
557
	 *
558
	 * no params
559
	 */
560
	do_action( 'wpsc_register_post_types_after' );
561
562
	/**
563
	 * Fires after the WPSC taxonomies are registered
564
	 *
565
	 * no params
566
	 */
567
	do_action( 'wpsc_register_taxonomies_after' );
568
}
569
570
add_action( 'init', 'wpsc_register_post_types', 8 );
571
572
/**
573
 * Post Updated Messages
574
 */
575
function wpsc_post_updated_messages( $messages ) {
576
	global $post, $post_ID;
577
578
	$messages['wpsc-product'] = array(
579
		0  => '', // Unused. Messages start at index 1.
580
		1  => sprintf( __( 'Product updated. <a href="%s">View product</a>', 'wp-e-commerce' ), esc_url( get_permalink( $post_ID ) ) ),
581
		2  => __( 'Custom field updated.', 'wp-e-commerce' ),
582
		3  => __( 'Custom field deleted.', 'wp-e-commerce' ),
583
		4  => __( 'Product updated.', 'wp-e-commerce' ),
584
		// translators: %s: date and time of the revision
585
		5  => isset( $_GET['revision'] ) ? sprintf( __('Product restored to revision from %s', 'wp-e-commerce' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
586
		6  => sprintf( __( 'Product published. <a href="%s">View product</a>', 'wp-e-commerce' ), esc_url( get_permalink( $post_ID ) ) ),
587
		7  => __( 'Product saved.', 'wp-e-commerce' ),
588
		8  => sprintf( __( 'Product submitted. <a target="_blank" href="%s">Preview product</a>', 'wp-e-commerce' ), esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ) ),
589
		9  => sprintf( __( 'Product scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview product</a>', 'wp-e-commerce' ),
590
			// translators: Publish box date format, see http://php.net/date
591
			date_i18n( __( 'M j, Y @ G:i', 'wp-e-commerce' ), strtotime( $post->post_date ) ), esc_url( get_permalink( $post_ID ) ) ),
592
		10 => sprintf( __( 'Product draft updated. <a target="_blank" href="%s">Preview product</a>', 'wp-e-commerce' ), esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ) ),
593
	);
594
595
	return $messages;
596
}
597
add_filter( 'post_updated_messages', 'wpsc_post_updated_messages' );
598
599
600
/**
601
 * This serializes the shopping cart variable as a backup in case the
602
 * unserialized one gets butchered by various things
603
 */
604
function wpsc_serialize_shopping_cart() {
605
	global $wpsc_cart;
606
607
	if ( is_admin() && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) )
608
		return;
609
610
	if ( is_object( $wpsc_cart ) ) {
611
		$wpsc_cart->errors = array();
612
	}
613
614
	// need to prevent set_cookie from being called at this stage in case the user just logged out
615
	// because by now, some output must have been printed out
616
	$customer_id = wpsc_get_current_customer_id();
617
618
	if ( $customer_id ) {
619
		wpsc_update_customer_cart( $wpsc_cart, $customer_id );
620
	}
621
622
	return true;
623
}
624
625
add_action( 'shutdown', 'wpsc_serialize_shopping_cart' );
626
627
/**
628
 * Changes default "Enter title here" placeholder
629
 *
630
 * @param string $title Default Title Placeholder
631
 * @return string $title New Title Placeholder
632
 */
633
function wpsc_change_title_placeholder( $title ) {
634
	$screen = get_current_screen();
635
636
	if  ( 'wpsc-product' == $screen->post_type ) {
637
		$title =  __( 'Enter product title here', 'wp-e-commerce' );
0 ignored issues
show
introduced by
Expected 1 space after "="; 2 found
Loading history...
638
	}
639
	return $title;
640
}
641
642
add_filter( 'enter_title_here', 'wpsc_change_title_placeholder' );
643
644
/**
645
 * wpsc_get_page_post_names function.
646
 *
647
 * @since 3.8
648
 * @access public
649
 * @return void
650
 */
651
function wpsc_get_page_post_names() {
652
	$wpsc_page['products'] = basename( get_option( 'product_list_url' ) );
0 ignored issues
show
Coding Style Comprehensibility introduced by
$wpsc_page was never initialized. Although not strictly required by PHP, it is generally a good practice to add $wpsc_page = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
653
654
	if ( empty( $wpsc_page['products'] ) || false !== strpos( $wpsc_page['products'], '?page_id=' ) ) {
655
		// Products page either doesn't exist, or is a draft
656
		// Default to /product/xyz permalinks for products
657
		$wpsc_page['products'] = 'product';
658
	}
659
660
	$wpsc_page['checkout']            = basename( get_option( 'checkout_url' ) );
661
	$wpsc_page['transaction_results'] = basename( get_option( 'transact_url' ) );
662
	$wpsc_page['userlog']             = basename( get_option( 'user_account_url' ) );
663
664
	return $wpsc_page;
665
}
666
667
668
/**
669
 * wpsc_cron()
670
 *
671
 * Schedules wpsc worpress cron tasks
672
 *
673
 * @param none
674
 * @return void
675
 */
676
function wpsc_cron() {
677
	$default_schedules = array( 'hourly', 'twicedaily', 'daily', 'weekly');
678
679
	/*
680
	 * Create a cron event for each likely cron schedule.  The likely cron schedules
681
	 * are the default WordPress cron intervals (hourly, twicedaily and daily are
682
	 * defined in wordpress 3.5.1) and any cron schedules added by our plugin or
683
	 * it's related plugins.  We recognize these by checking if the schedule
684
	 * name is prefixed by 'wpsc_'.
685
	 */
686
	foreach ( wp_get_schedules() as $cron => $schedule ) {
687
		if ( in_array($cron, $default_schedules) || ( stripos($cron, 'wpsc_', 0) === 0 ) ) {
688
			if ( ! wp_next_scheduled( "wpsc_{$cron}_cron_task" ) )
689
				wp_schedule_event( time(), $cron, "wpsc_{$cron}_cron_task" );
690
		}
691
	}
692
}
693
add_action( 'init', 'wpsc_cron' );
694
695
/**
696
 * wpsc_add_weekly_schedule()
697
 *
698
 * Creates a weekly schedule event
699
 *
700
 * @param none
701
 * @return void
702
 */
703
function wpsc_add_weekly_schedule( $schedules = array()) {
704
    $schedules['weekly'] = array(
705
        'interval' => 604800,
706
        'display'  => __( 'Once Weekly', 'wp-e-commerce' )
707
    );
708
    return $schedules;
709
}
710
add_filter( 'cron_schedules', 'wpsc_add_weekly_schedule' );
711
712
/**
713
 * Updates permalink slugs
714
 *
715
 * @since 3.8.9
716
 * @return type
717
 */
718
function wpsc_update_permalink_slugs() {
719
	global $wpdb;
720
721
	$wpsc_pageurl_option = array(
722
		'product_list_url'  => '[productspage]',
723
		'shopping_cart_url' => '[shoppingcart]',
724
		'checkout_url'      => '[shoppingcart]',
725
		'transact_url'      => '[transactionresults]',
726
		'user_account_url'  => '[userlog]'
727
	);
728
729
	$ids = array();
730
731
	foreach ( $wpsc_pageurl_option as $option_key => $page_string ) {
732
		$id = $wpdb->get_var( "SELECT `ID` FROM `{$wpdb->posts}` WHERE `post_type` = 'page' AND `post_content` LIKE '%$page_string%' LIMIT 1" );
733
734
		if ( ! $id )
735
			continue;
736
737
		$ids[ $page_string ] = $id;
738
739
		$the_new_link = _get_page_link( $id );
740
741
		if ( stristr( get_option( $option_key ), "https://" ) )
742
			$the_new_link = str_replace( 'http://', "https://", $the_new_link );
743
744
		if ( $option_key == 'shopping_cart_url' )
745
			update_option( 'checkout_url', $the_new_link );
746
747
		update_option( $option_key, $the_new_link );
748
	}
749
750
	update_option( 'wpsc_shortcode_page_ids', $ids );
751
}
752
753
/**
754
 * Return an array of terms assigned to a product.
755
 *
756
 * This function is basically a wrapper for get_the_terms(), and should be used
757
 * instead of get_the_terms() and wp_get_object_terms() because of two reasons:
758
 *
759
 * - wp_get_object_terms() doesn't utilize object cache.
760
 * - get_the_terms() returns false when no terms are found. We want something
761
 *   that returns an empty array instead.
762
 *
763
 * @since 3.8.10
764
 * @param  int    $product_id Product ID
765
 * @param  string $tax        Taxonomy
766
 * @param  string $field      If you want to return only an array of a certain field, specify it here.
767
 * @return stdObject[]
768
 */
769
function wpsc_get_product_terms( $product_id, $tax, $field = '' ) {
770
	$terms = get_the_terms( $product_id, $tax );
771
772
	if ( ! $terms )
773
		$terms = array();
774
775
	if ( $field )
776
		$terms = wp_list_pluck( $terms, $field );
777
778
	// remove the redundant array keys, could cause issues in loops with iterator
779
	$terms = array_values( $terms );
780
	return $terms;
781
}
782
783
/**
784
 * Abstracts Suhosin check into a function.  Used primarily in relation to target markets.
785
 *
786
 * @since 3.8.9
787
 * @return boolean
788
 */
789
function wpsc_is_suhosin_enabled() {
790
	return @ extension_loaded( 'suhosin' ) && @ ini_get( 'suhosin.post.max_vars' ) > 0 && @ ini_get( 'suhosin.post.max_vars' ) < 500;
0 ignored issues
show
Coding Style introduced by
Silencing errors is discouraged
Loading history...
791
}
792
793
/**
794
 * wpsc_core_load_page_titles()
795
 *
796
 * Load the WPEC page titles
797
 *
798
 * @global array $wpsc_page_titles
799
 */
800
function wpsc_core_load_page_titles() {
801
	global $wpsc_page_titles;
802
	$wpsc_page_titles = apply_filters( 'wpsc_page_titles', false );
803
804
	if ( empty( $wpsc_page_titles ) )
805
		$wpsc_page_titles = wpsc_get_page_post_names();
806
}
807
808
/**
809
 * get the global checkout object, will create it
810
 *
811
 * @return wpsc_checkout       the global checkout object
812
 */
813
function wpsc_core_get_checkout() {
814
	global $wpsc_checkout;
815
816
	if ( empty( $wpsc_checkout ) || ! is_a( $wpsc_checkout, 'wpsc_checkout' ) ) {
817
		$wpsc_checkout = new wpsc_checkout();
818
	}
819
820
	$wpsc_checkout->rewind_checkout_items();
821
822
	return $wpsc_checkout;
823
824
}
825
826
/**
827
 * get the current WPeC database version
828
 *
829
 * @return int current database version
830
 */
831
function wpsc_core_get_db_version() {
832
	return intval( get_option( 'wpsc_db_version', 0 ) );
833
}
834
835
/**
836
 * get the current WPeC database version
837
 *
838
 * @return int current database version
839
 */
840
function wpsc_core_shipping_enabled() {
841
	$shipping_disabled = get_option( 'do_not_use_shipping', -1 );
842
843
	if ( $shipping_disabled === -1 ) {
844
		// if shipping enabled comes back as -1 we want to set it to the default value, this is
845
		// because unset WordPress options are not cached.  That means if this option isn't in the database
846
		// we could make a trip to the database every time this option is looked at.  This variable
847
		// can be tested many times per page view, so let's make it clean
848
		update_option( 'do_not_use_shipping', false );
849
		$shipping_disabled = false;
850
	}
851
852
	$shipping_disabled = _wpsc_make_value_into_bool( $shipping_disabled );
853
854
	return ! $shipping_disabled;
855
}
856
857
/**
858
 *  flush all WPeC temporary stored data
859
 *
860
 * WordPress generallay has two places it stores temporary data, the object cache and the transient store.  When
861
 * an object cache is configured for WordPress transients are stored in the object cache.  When there isn't an
862
 * object cache available transients are stored in the WordPress options table.  When clearing temporary data
863
 * we need to consider both places.
864
 *
865
 * @since 3.8.14.1
866
 *
867
 */
868
function wpsc_core_flush_temporary_data() {
869
870
	//
871
	/**
872
	 * Tell the the rest of the WPeC world it's time to flush all cache data
873
	 *
874
	 * @since 3.8.14.1
875
	 *
876
	 * no params
877
	 */
878
	do_action( 'wpsc_core_flush_transients' );
879
880
	$our_saved_transients = _wpsc_remembered_transients();
881
882
	// strip off the WordPress transient prefix to get the transient name used when storing the transient, then delete it
883
	foreach ( $our_saved_transients as $transient_name => $timestamp ) {
884
		delete_transient( $transient_name );
885
	}
886
887
	/**
888
	 * Tell the the rest of the WPeC world we have just flushed all temporary data,
889
	 *
890
	 * @since 3.8.14.1
891
	 *
892
	 * no params
893
	 */
894
	do_action( 'wpsc_core_flushed_transients' );
895
}
896
897
/**
898
 * Rememeber whenever WPeC saves data in a transient
899
 *
900
 * @param string $transient
901
 * @param varies|null $value
902
 * @param int|null $expiration
903
 * @return array[string]|false  names of transients saved, false when nothing has been stored
0 ignored issues
show
Documentation introduced by
The doc-type array[string]|false could not be parsed: Expected "]" at position 2, but found "string". (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
904
 */
905
function _wpsc_remembered_transients( $transient = '', $value = null, $expiration = null ) {
0 ignored issues
show
Unused Code introduced by
The parameter $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...
Unused Code introduced by
The parameter $expiration 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...
906
	static $wpsc_transients = false;
907
908
	if ( $wpsc_transients === false ) {
909
910
		// get our saved transients
911
		$wpsc_transients = get_option( __FUNCTION__,  false );
912
913
		if ( $wpsc_transients === false ) {
914
			// look at the database and see if there are WPeC transients in the options table.  Note that it is possible to track these,
915
			// using WordPress hooks, but because we need to check for transients that are stored by prior releases of WPeC we go right
916
			// at the database.
917
			global $wpdb;
918
919
			$wpsc_transients_from_db = $wpdb->get_col( 'SELECT option_name FROM ' . $wpdb->options . ' WHERE `option_name` LIKE "\_transient\_wpsc\_%"' );
920
921
			$wpsc_transients = array();
922
923
			// strip off the WordPress transient prefix to get the transient name used when storing the transient, then delete it
924
			foreach ( $wpsc_transients_from_db as $index => $transient_name ) {
925
				$transient_name = substr( $transient_name, strlen( '_transient_' ) );
926
				$wpsc_transients[$transient_name] = time();
927
			}
928
929
			// we are all initialized, save our known transients list for later
930
			update_option( __FUNCTION__, $wpsc_transients );
931
		}
932
	}
933
934
	// if we are setting a transient, and it is one of ours, and we havn't seen it before, save the name
935
	if ( ! empty ( $transient ) ) {
0 ignored issues
show
Coding Style introduced by
Space before opening parenthesis of function call prohibited
Loading history...
936
		if ( strpos( $transient, 'wpsc_' ) === 0 ||  strpos( $transient, '_wpsc_' ) === 0 ) {
937
			if ( ! isset( $wpsc_transients[$transient] ) ) {
938
				$wpsc_transients[$transient] = time();
939
				update_option( __FUNCTION__, $wpsc_transients );
940
			}
941
		}
942
	}
943
944
	return $wpsc_transients;
945
}
946
947
add_action( 'setted_transient', '_wpsc_remembered_transients' , 10, 3 );
948
949
/**
950
 * When we change versions, aggressively clear temporary data and WordPress cache.
951
 *
952
 * @since 3.8.14.1
953
 *
954
 * @access private
955
 */
956
function _wpsc_clear_wp_cache_on_version_change() {
957
958
	if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
959
		return;
960
	}
961
962
	if ( ! wpsc_is_store_admin() ) {
963
		return;
964
	}
965
966
	$version_we_last_stored = get_option( __FUNCTION__, false );
967
968
	if ( $version_we_last_stored != WPSC_VERSION ) {
969
970
		// version changed, clear temporary data
971
		wpsc_core_flush_temporary_data();
972
973
		// version changed, flush the object cache
974
		wp_cache_flush();
975
976
		if ( false === $version_we_last_stored ) {
977
			// first time through we create the autoload option, we will read it every time
978
			add_option( __FUNCTION__, WPSC_VERSION, null, true );
979
		} else {
980
			update_option( __FUNCTION__, WPSC_VERSION );
981
		}
982
	}
983
}
984
985
add_action( 'admin_init', '_wpsc_clear_wp_cache_on_version_change', 1 );
986
987
/**
988
 * Adds custom WP eCommerce tables to `tables_to_repair` array.
989
 *
990
 * WordPress provides a link, `admin_url( 'maint/repair.php' )`, that allows users to repair database tables.
991
 * We find that this becomes necessary often times when visitor/visitor meta tables become corrupt.
992
 * Symptoms of a corrupt visitor/meta table include disappearing carts, refreshing checkout pages, etc.
993
 *
994
 * In a future version, we will likely have a `System` page that would include a link to the repair.php page.
995
 *
996
 * @since  4.0
997
 *
998
 * @param  array $tables Core tables
999
 *
1000
 * @return array $tables Core + WP eCommerce tables
1001
 */
1002
function wpsc_add_tables_to_repair( $tables ) {
1003
	global $wpec;
1004
1005
	return array_merge( $wpec->setup_table_names(), $tables );
1006
}
1007
1008
add_filter( 'tables_to_repair', 'wpsc_add_tables_to_repair' );
1009
1010
1011
/**
1012
 * Updates a user's digital downloads.
1013
 *
1014
 * @param  integer $user_id [description]
1015
 * @return [type]           [description]
0 ignored issues
show
Documentation introduced by
The doc-type [type] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
1016
 */
1017
function wpsc_update_user_downloads( $user_id = 0 ) {
1018
	global $wpdb;
1019
1020
	if ( ! $user_id ) {
1021
		$user_id = get_current_user_id();
1022
	}
1023
1024
	$purchase_ids = $wpdb->get_results( $wpdb->prepare( "SELECT c.prodid, p.id, c.id as cart_id FROM " . WPSC_TABLE_CART_CONTENTS . " as c INNER JOIN " . WPSC_TABLE_PURCHASE_LOGS . " as p ON p.id = c.purchaseid WHERE p.user_ID = %d AND p.processed IN (3,4,5) GROUP BY c.prodid", $user_id ) );
1025
1026
	if ( empty( $purchase_ids ) || apply_filters( 'wpsc_do_not_update_downloads', false ) ) {
1027
		return;
1028
	}
1029
1030
	$downloads = get_option( 'max_downloads' );
1031
1032
	foreach ( $purchase_ids as $key => $id_pairs ) {
1033
		if ( ! apply_filters( "wpsc_update_downloads_{$id_pairs->prodid}", true, $id_pairs ) ) {
1034
			unset( $purchase_ids[ $key ] );
1035
		} else {
1036
1037
			if ( get_post_field( 'post_parent', $id_pairs->prodid ) ) {
1038
				$parents = array( $id_pairs->prodid, get_post_field( 'post_parent', $id_pairs->prodid ) );
1039
			} else {
1040
				$parents = array( $id_pairs->prodid );
1041
			}
1042
1043
			$args = apply_filters( 'wpsc_update_user_downloads_file_args', array(
1044
				'post_type'       => 'wpsc-product-file',
1045
				'post_parent__in' => $parents,
1046
				'numberposts'     => -1,
0 ignored issues
show
introduced by
Disabling pagination is prohibited in VIP context, do not set numberposts to -1 ever.
Loading history...
1047
				'post_status'     => 'inherit'
1048
			), $id_pairs, $user_id );
1049
1050
			$product_files = (array) get_posts( $args );
1051
1052
			foreach ( $product_files as $file ) {
1053
1054
				if ( ! apply_filters( "wpsc_update_downloads_{$id_pairs->prodid}_{$file->ID}", true, $id_pairs, $file ) ) {
1055
					continue;
1056
				}
1057
1058
				$user_has_download = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM " . WPSC_TABLE_DOWNLOAD_STATUS . " WHERE fileid = %d AND purchid = %d AND product_id = %d", $file->ID, $id_pairs->id, $id_pairs->prodid ) );
1059
1060
				if ( $user_has_download ) {
1061
					continue;
1062
				}
1063
1064
				$unique_id = sha1( uniqid( mt_rand(), true ) );
1065
1066
				$wpdb->insert(
1067
					WPSC_TABLE_DOWNLOAD_STATUS,
1068
					array(
1069
							'product_id' => $id_pairs->prodid,
1070
							'fileid'     => $file->ID,
1071
							'purchid'    => $id_pairs->id,
1072
							'cartid'     => $id_pairs->cart_id,
1073
							'uniqueid'   => $unique_id,
1074
							'downloads'  => $downloads,
1075
							'active'     => 1,
1076
							'datetime'   => date( 'Y-m-d H:i:s' )
1077
					),
1078
					array(
1079
							'%d',
1080
							'%d',
1081
							'%d',
1082
							'%d',
1083
							'%s',
1084
							'%s',
1085
							'%d',
1086
							'%s',
1087
					)
1088
				);
1089
			}
1090
		}
1091
	}
1092
}
1093
1094
add_action( 'wpsc_template_before_customer-account-digital-content', 'wpsc_update_user_downloads', 5 );
1095
add_action( 'wpsc_user_profile_section_downloads'                  , 'wpsc_update_user_downloads', 5 );
1096
1097
/**
1098
 * Checks visitor and visitor meta table for corruption.
1099
 *
1100
 * If tables are corrupted, site admins are alerted and given the ability to repair them.
1101
 *
1102
 * @since  3.9.4
1103
 * @return void
1104
 */
1105
function wpsc_check_visitor_tables() {
1106
1107
	// Don't check if current user is not a store admin or if we have checked in the last hour.
1108
	if ( wpsc_is_store_admin() && ! ( $check = get_transient( 'wpsc_tables_intact' ) ) ) {
1109
		global $wpdb;
1110
1111
		$visitor_check      = $wpdb->get_row( "CHECK TABLE {$wpdb->wpsc_visitors}" );
1112
		$visitor_meta_check = $wpdb->get_row( "CHECK TABLE {$wpdb->wpsc_visitormeta}" );
1113
1114
		// If both tables are fine
1115
		if ( 'OK' == $visitor_check->Msg_text && 'OK' == $visitor_meta_check->Msg_text )  {
1116
			set_transient( 'wpsc_tables_intact', true, HOUR_IN_SECONDS );
1117
			return;
1118
		} else {
1119
			set_transient( 'wpsc_tables_intact', false, HOUR_IN_SECONDS );
1120
		}
1121
1122
		add_action( 'all_admin_notices', 'wpsc_visitor_tables_need_repair' );
1123
	}
1124
}
1125
1126
add_action( 'init', 'wpsc_check_visitor_tables' );
1127
1128
/**
1129
 * Adds admin notice to all screens, for store administators, when database tables are in need of repair.
1130
 *
1131
 * @since  3.9.4
1132
 * @return void
1133
 */
1134
function wpsc_visitor_tables_need_repair() {
1135
	echo '<div class="error"><p>' . sprintf( __( 'It appears that your WP eCommerce database tables are in need of repair. This is very important for both security and performance. <a href="%s">Repair your tables now</a>. <br />Note: If you encounter errors upon repairing your tables, simply refresh the page.', 'wp-e-commerce' ), esc_url( admin_url( 'maint/repair.php' ) ) ) . '</p></div>';
1136
}
1137
1138
/**
1139
 * Defines `WP_ALLOW_REPAIR` to true when WP eCommerce tables are in need of repair.
1140
 *
1141
 * @since  3.9.4
1142
 * @return void
1143
 */
1144
function wpsc_repair_tables() {
1145
1146
	$needs_repair = ! get_transient( 'wpsc_tables_intact' );
1147
1148
	if ( ! defined( 'WP_ALLOW_REPAIR' ) && apply_filters( 'wpsc_tables_need_repair', $needs_repair ) && ( defined( 'WP_REPAIRING' ) && WP_REPAIRING ) ) {
1149
		define( 'WP_ALLOW_REPAIR', true );
1150
	}
1151
}
1152
1153
add_action( 'wpsc_init', 'wpsc_repair_tables' );
1154
1155
/**
1156
 * Addes 'wpsc' to the list of Say What aliases after moving to WordPress.org * * language packs.
1157
 *
1158
 * @since  3.11.0
1159
 *
1160
 * @param  array $aliases Say What domain aliases
1161
 * @return array          Say What domain alises with 'wpsc' added
1162
 */
1163
function wpsc_say_what_domain_aliases( $aliases ) {
1164
	$aliases['wp-e-commerce'][] = 'wpsc';
1165
1166
	return $aliases;
1167
}
1168
1169
add_filter( 'say_what_domain_aliases', 'wpsc_say_what_domain_aliases' );
1170
1171
/**
1172
 * Checks if system is using a specific version of the theme engine.
1173
 *
1174
 * Defaults to 1.0.
1175
 *
1176
 * @since 3.11.5
1177
 * @param  string  $version Version number
1178
 * @return boolean          Whether or not this is the theme engine being used.
1179
 */
1180
function wpsc_is_theme_engine( $version = '1.0' ) {
1181
	$te = get_option( 'wpsc_get_active_theme_engine', $version );
1182
1183
	return $version == $te;
1184
}
1185