From 03a6defba5ddc0ea375726fbade9699eda5e1325 Mon Sep 17 00:00:00 2001 From: Patrick Garman Date: Sun, 29 Jan 2012 02:27:49 +0000 Subject: [PATCH 1/4] option to force login to download files --- admin/woocommerce-admin-settings.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/admin/woocommerce-admin-settings.php b/admin/woocommerce-admin-settings.php index d6f64a0798a..7946d094bb8 100644 --- a/admin/woocommerce-admin-settings.php +++ b/admin/woocommerce-admin-settings.php @@ -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'), From 2f7967b347ac986396fa7c667fcf3fc97982860f Mon Sep 17 00:00:00 2001 From: Patrick Garman Date: Sun, 29 Jan 2012 22:59:18 +0000 Subject: [PATCH 2/4] User check for downloading files. --- woocommerce-functions.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/woocommerce-functions.php b/woocommerce-functions.php index 5d973d00d9e..6f150f4486d 100644 --- a/woocommerce-functions.php +++ b/woocommerce-functions.php @@ -714,7 +714,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 @@ -728,6 +728,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') . ' ' . __('Login →', 'woocommerce') . '' ); + 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 ); @@ -736,7 +751,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') . ' ' . __('Go to homepage →', 'woocommerce') . '' ); else : From 6bdec7216739726af4da10580adf13e95075bf73 Mon Sep 17 00:00:00 2001 From: Patrick Garman Date: Mon, 30 Jan 2012 10:30:29 +0000 Subject: [PATCH 3/4] woocommerce_wp_checkbox was setting value to "on" not "yes" by default --- admin/post-types/writepanels/writepanels-init.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin/post-types/writepanels/writepanels-init.php b/admin/post-types/writepanels/writepanels-init.php index 6542171bf59..447fb2a1c67 100644 --- a/admin/post-types/writepanels/writepanels-init.php +++ b/admin/post-types/writepanels/writepanels-init.php @@ -162,7 +162,7 @@ function woocommerce_wp_checkbox( $field ) { echo '

'; From d0d1cdc24d8fd171cfa0a20872894674cc2b8505 Mon Sep 17 00:00:00 2001 From: Patrick Garman Date: Fri, 3 Feb 2012 04:10:05 +0000 Subject: [PATCH 4/4] http://www.woothemes.com/2012/02/woocommerce-1-4-is-released/#comment-100907 --- admin/woocommerce-admin-init.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin/woocommerce-admin-init.php b/admin/woocommerce-admin-init.php index 0f9ce78ba01..32e908b9671 100644 --- a/admin/woocommerce-admin-init.php +++ b/admin/woocommerce-admin-init.php @@ -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');