Merge pull request #547 from patrickgarman/master

Force user login to download files
This commit is contained in:
Mike Jolley 2012-02-06 09:33:22 -08:00
commit 4fe038d48e
4 changed files with 27 additions and 4 deletions

View File

@ -162,7 +162,7 @@ function woocommerce_wp_checkbox( $field ) {
echo '<p class="form-field '.$field['id'].'_field '.$field['wrapper_class'].'"><label for="'.$field['id'].'">'.$field['label'].'</label><input type="checkbox" class="'.$field['class'].'" name="'.$field['id'].'" id="'.$field['id'].'" ';
checked($field['value'], 'yes');
checked($field['value'], 'on');
echo ' /> ';

View File

@ -218,7 +218,7 @@ function woocommerce_admin_css() {
if ( $typenow == '' || $typenow=="product" || $typenow=="shop_order" || $typenow=="shop_coupon" ) :
wp_enqueue_style( 'thickbox' );
wp_enqueue_style( 'woocommerce_admin_styles', $woocommerce->plugin_url() . '/assets/css/admin.css' );
wp_enqueue_style( 'jquery-ui-style', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css' );
wp_enqueue_style( 'jquery-ui-style', ($_SERVER['HTTPS'] != "on") ? 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css' : 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css' );
endif;
wp_enqueue_style('farbtastic');

View File

@ -241,6 +241,14 @@ $woocommerce_settings['general'] = apply_filters('woocommerce_general_settings',
)
),
array(
'name' => __('Require Login to Download', 'woocommerce'),
'desc' => __('Do not allow downloads if a user is not logged in.', 'woocommerce'),
'id' => 'woocommerce_downloads_require_login',
'type' => 'checkbox',
'std' => 'no',
),
array(
'name' => __('Localisation', 'woocommerce'),
'desc' => __('Use informal localisation file if it exists', 'woocommerce'),

View File

@ -718,7 +718,7 @@ function woocommerce_download_product() {
endif;
$download_result = $wpdb->get_row( $wpdb->prepare("
SELECT order_id, downloads_remaining
SELECT order_id, downloads_remaining,user_id
FROM ".$wpdb->prefix."woocommerce_downloadable_product_permissions
WHERE user_email = %s
AND order_key = %s
@ -732,6 +732,21 @@ function woocommerce_download_product() {
$order_id = $download_result->order_id;
$downloads_remaining = $download_result->downloads_remaining;
$user_id = $download_result->user_id;
if (get_option('woocommerce_downloads_require_login')=='yes'):
if(is_user_logged_in()==false):
wp_die( __('You must be logged in to download files.', 'woocommerce') . ' <a href="'.wp_login_url(get_permalink(woocommerce_get_page_id('myaccount'))).'">' . __('Login &rarr;', 'woocommerce') . '</a>' );
exit;
else:
$current_user = wp_get_current_user();
if($user_id != $current_user->ID):
wp_die( __('This is not your download link.', 'woocommerce'));
exit;
endif;
endif;
endif;
if ($order_id) :
$order = new WC_Order( $order_id );
@ -740,7 +755,7 @@ function woocommerce_download_product() {
exit;
endif;
endif;
if ($downloads_remaining=='0') :
wp_die( __('Sorry, you have reached your download limit for this file', 'woocommerce') . ' <a href="'.home_url().'">' . __('Go to homepage &rarr;', 'woocommerce') . '</a>' );
else :