Skip to content

Commit

Permalink
Prevent file hash from being overwritten
Browse files Browse the repository at this point in the history
  • Loading branch information
vjanssens committed Dec 28, 2020
1 parent dd882f3 commit a04a491
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
16 changes: 12 additions & 4 deletions assets/js/woocommerce-dropbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jQuery(function($) {
},

addButtons: function() {
var button = $('<button class="button insert-dropbox">' + woocommerce_dropbox_translation.choose_from_dropbox + '</button>');
var button = $('<button type="button" class="button insert-dropbox">' + woocommerce_dropbox_translation.choose_from_dropbox + '</button>');

$('.downloadable_files').each(function(index) {

Expand Down Expand Up @@ -88,12 +88,20 @@ jQuery(function($) {
afterFileSelected: function(files) {
var table = $(wcdb.lastSelectedButton).closest('.downloadable_files').find('tbody');
var template = $(wcdb.lastSelectedButton).prev('.button.insert').data('row');
var isVariableProduct = template.includes('_wc_variation_file');

_.each(files, function(file) {

var fileRow = $(template);
fileRow.find('.file_name > input').val(file.name).change();
fileRow.find('.file_url > input').val(file.link.replace('dl=0', 'dl=1'));
var searchKey = isVariableProduct ? '_wc_variation_file' : '_wc_file';
var fileNameInput = fileRow.find('.file_name > input[name^="' + searchKey + '_names"]');
var fileUrlInput = fileRow.find('.file_url > input[name^="' + searchKey + '_urls"]');

if (fileNameInput.length === 0 || fileUrlInput.length === 0) {
throw new Error('Could not find input fields');
}

fileNameInput.val(file.name).change();
fileUrlInput.val(file.link.replace('dl=0', 'dl=1'));

table.append(fileRow);
});
Expand Down
11 changes: 9 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Contributors: vadiemjanssens
Tags: woocommerce, dropbox, downloadable, products, downloadable product
Requires at least: 4.5
Tested up to: 5.4
Stable tag: 1.2.3
Tested up to: 5.6
Stable tag: 1.2.4
Requires PHP: 7.2
License: GPL v3

Expand Down Expand Up @@ -69,6 +69,13 @@ Please refer to [this page](https://wordpress.org/plugins/woocommerce-dropbox/)

== Changelog ==

= 1.2.4 =
Release date: December 28th, 2020

* Fixed an issue where long filenames caused issues (thank you @JakePT) [Issue #4](https://github.com/vjanssens/woocommerce-dropbox/issues/4)
* Fixed an issue where file name and url were not populated for variable products
* Tested plugin for WordPress version 5.6 and WooCommerce 4.8.0

= 1.2.3 =
Release date: April 17th, 2020

Expand Down
6 changes: 3 additions & 3 deletions woocommerce-dropbox.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Plugin Name: WooCommerce Dropbox
* Version: 1.2.3
* Version: 1.2.4
* Description: WooCommerce Dropbox integration for downloadable products.
* Author: Vadiem Janssens
* Author URI: https://www.vadiemjanssens.nl
Expand Down Expand Up @@ -36,7 +36,7 @@
define( 'WCDB_PATH', plugin_dir_path(__FILE__) );
define( 'WCDB_BASENAME', plugin_basename(__FILE__) );

define('WCDB_VERSION', '1.2.3');
define('WCDB_VERSION', '1.2.4');

class WC_Dropbox {

Expand Down Expand Up @@ -73,7 +73,7 @@ public function activation_notice() {
$class = 'notice updated notice is-dismissible';
$strings = [
__( 'Great, you\'re almost ready to start using WooCommerce Dropbox! Please go to the', 'woocommerce-dropbox' ),
' <a href="' . admin_url( 'admin.php?page=wc-settings&tab=integration' ) . '" title="' . esc_attr( __( 'View WooCommerce Dropbox Settings', 'woocommerce-dropbox' ) ) . '">',
' <a href="' . admin_url( 'admin.php?page=wc-settings&tab=integration&section=woocommerce-dropbox' ) . '" title="' . esc_attr( __( 'View WooCommerce Dropbox Settings', 'woocommerce-dropbox' ) ) . '">',
__( 'WooCommerce Settings', 'woocommerce-dropbox' ),
'</a> ',
__( 'to configure the plugin.', 'woocommerce-dropbox' ),
Expand Down

0 comments on commit a04a491

Please sign in to comment.