Hello WPDM Support,
We’d like to supply you with some further information about an issue reported to you before Xmas last year about your Download Manager Plug In. Yesterday we updated your plugin and the following issue (included below) and previously reported to you occurred again. This time after applying our fix to your code the issue was not resolved with our fix. Therefore, we would like to tell you about our second fix to your code and ask if you can please investigate this issue which is causing your plug n to be incompatible with our WordPress / Themify installation.
Fix 2
——
This fix is similar to the first one but has been applied in this file: class.Package.php.
Around line 1319/1320 we have removed the call to wp_reset_query() and replaced it with: wp_reset_post_data().
The previous reported fault and our fix which incidentally still needs to be applied in addition to this new one follows:
Previously Reported Issue
———————————–
We have identified a fault with Download Manager and are sending you this short report to assist you in resolving the issue which starts with some background information about how it used to work and how we are using WPDM with Themify theme, finally we have fixed the problem but would like to know if our fix is compatible with a future update to WPDM.
1) The expected & actual behaviour prior to a recent update of Themify / WordPress
1.1) We add the [wpdm_package] shortcode in this form: [wpdm_package id="6239" template="55c1e8d58c991”] to posts.
Inline image 2
1.2) We then set Themify to include posts to a page using the Query Posts facility.
Inline image 3
1.3) What we expect to happen.
Prior to a recent update to Themify or WPDM (we’re unsure which one has caused the problem) the short code that was added to the post using the Query Posts facility would render the download package to the screen and the page content would finish. Obviously, because the shortcode is the last item of content in the included post.
The issue
————-
2) After a recent update the content no longer finishes at the end of the last included post and the additional content included via the embedded short code. Instead the content of the page that includes the posts is added to the end of the page after the last post / embedded shortcode.
2.1) Our FIX!
We’ve replaced the call to wp_reset_query() with wp_reset_postdata() and the duplicate page content is no longer added at the end of the page. See below for reference to approx line 360 in class.ShortCodes.php
function Package($params)
{
extract($params);
if(!isset($id)) return ”;
$id = (int)$id;
if(get_post_type($id) != ‘wpdmpro’) return ”;
$postlink = site_url(‘/’);
if (isset($pagetemplate) && $pagetemplate == 1) {
$template = get_post_meta($id,’__wpdm_page_template’, true);
$wpdm_package[‘page_template’] = stripcslashes($template);
$data = wpdm_fetch_template($template, $id, ‘page’);
$siteurl = site_url(‘/’);
return “<div class=’w3eden’>{$data}</div>”;
}
$template = isset($params[‘template’])?$params[‘template’]:get_post_meta($id,’__wpdm_template’, true);
if($template == ”) $template = ‘link-template-calltoaction3.php’;
$html = “<div class=’w3eden’>” . \WPDM\Package::fetchTemplate($template, $id, ‘link’) . “</div>”;
wp_reset_postdata();
//wp_reset_query();
return $html;
}
If this was the source of the problem please can you update your source code so that your next update to WPDM doesn’t remove our fix.
Thanks in advance.
—
Hi there,
I guess I’ve found a problem in your code, regarding JavaScript redirect after downloading single file from files package.
The problem exists in line 347
of class.FileList.php
where you add a <script>
tag with click event for the Download button.
Let’s take a look at your piece of code:
jQuery('.inddl').click(function() {
var tis = this;
jQuery.post('https://someexampleurl.com', {
wpdmfileid: '1234',
wpdmfile: jQuery(this).attr('file'),
actioninddlpvr: 1,
filepass: jQuery(jQuery(this).attr('pass')).val()
}, function(res) {
res = res.split('|');
var ret = res[1];
if (ret == 'error')
jQuery(jQuery(tis).attr('pass')).addClass('input-error');
if (ret == 'ok')
location.href = jQuery(tis).attr('rel') + '&_wpdmkey=' + res[2];
});
});
This is the piece of code that contains an issue:
if (ret == 'ok')
location.href = jQuery(tis).attr('rel') + '&_wpdmkey=' + res[2];
jQuery(tis).attr('rel')
takes rel
attribute value and appends it to current url, so if my package is at https://someexampleurl.com/download/package
and I click the download button which has rel="nofollow"
attribute, I am redirected to:
https://someexampleurl.com/download/package/nofollow&_wpdmkey=WPDMKEY
which gives me a 404 page.
As you can see, ?rel=
is missing in your code where you override location.href
and that redirects to non existing page. You don’t even check whether there is any query variable in the URL or not, which may lead to something like this: https://someexampleurl.com/&_wpdmkey=WPDMKEY
.
Also, if you try to download the file while being connected to slow network, it doesn’t fire the save file dialog
everytime, redirect is fired earlier instead.
I will fix it on my own, but future update will override my fixes. That’s why I’m posting the issue here. I hope you will fix it as soon as possible.