[Patch] Can’t download ‘public’ files

in Download Manager Free

Viewing 6 posts - 1 through 6 (of 6 total)
Dec 10, 2021 at 2:10 pm
#165541
Participant
Stefano Cardinale
OP

Hi, I don’t know if is a problem of my setup but can’t download files defined as public.
I found a workaround:
just add a line to src/MediaLibrary/MediaAccessControl.php

Current Code:

   function protectMediaLibrary(){
        if(isset($_REQUEST['wpdmmediaid'])){
            global $wpdb;
            $current_user = wp_get_current_user();
            $ID = wpdm_query_var('wpdmmediaid', 'int');
            $media = get_post($ID);
            if(!$media) Messages::fullPage('404', esc_attr__( 'Media not found!', WPDM_TEXT_DOMAIN ));
            $media_meta = wp_get_attachment_metadata($ID);
            //wpdmdd($media_meta);
            //wpdmdd($media);
            $media->path = str_replace(home_url('/'), ABSPATH.'/', $media->guid);
            $media->filesize = wpdm_file_size($media->path);

            $access = get_post_meta($media->ID, '__wpdm_media_access', true);
	    $password = get_post_meta($media->ID, '__wpdm_media_pass', true);
            ...

My patch

   function protectMediaLibrary(){
        if(isset($_REQUEST['wpdmmediaid'])){
            global $wpdb;
            $current_user = wp_get_current_user();
            $ID = wpdm_query_var('wpdmmediaid', 'int');
            $media = get_post($ID);
            if(!$media) Messages::fullPage('404', esc_attr__( 'Media not found!', WPDM_TEXT_DOMAIN ));
            $media_meta = wp_get_attachment_metadata($ID);
            //wpdmdd($media_meta);
            //wpdmdd($media);
            $media->path = str_replace(home_url('/'), ABSPATH.'/', $media->guid);
            $media->filesize = wpdm_file_size($media->path);

            $access = get_post_meta($media->ID, '__wpdm_media_access', true);
=====►>    if(!is_array($access)) $access = array('public');
	    $password = get_post_meta($media->ID, '__wpdm_media_pass', true);
            ...

Please make this change or tell me how to fix my setup and why is not working.
Thanks in advance

Dec 10, 2021 at 2:37 pm
#165545
Moderator
Nayeem Riddhi
Staff

Hello Stefano,

Hope you are well. Can you please elaborate on the issue, what you are trying to do? please elaborate on your requirements

Thank you and regards

Dec 10, 2021 at 3:42 pm
#165553
Participant
Stefano Cardinale
OP

Hi, I’m trying to have files that are free to download for all

when the system executes this instruction $access = get_post_meta($media->ID, '__wpdm_media_access', true); the result is not an array because the __wpdm_media_access value is blank
I selected ‘All visitors’ into my download definition.
The line of code I added just check if the value for that meta is empty and in case initialize the access right array with a ‘Public’ value. In this way the following checks will be succesful and the visitor can get his file.

I Hope this can describe the issue better than before
I apologize for my english

Dec 12, 2021 at 7:30 am
#165587
Moderator
Nayeem Riddhi
Staff

Hello Stefano,

The meta key for file Allow Access is by default for All Visitor and Public. You don’t need to patch any portion of the code. I hope you have understood

Thank you and regards

Dec 12, 2021 at 7:24 pm
#165604
Participant
Stefano Cardinale
OP

I’m sorry to inform you that on my system the meta key stored on db is empty for that value (All Visitors), I’m mount a test site without any other plugin to make another test, but I’m pretty sure that there is a problem

Dec 13, 2021 at 7:15 am
#165627
Moderator
Nayeem Riddhi
Staff

Hello Stefano,

Please let us know about the issue. The feature is working fine from our side

Thank you and regards

Viewing 6 posts - 1 through 6 (of 6 total)

The topic "[Patch] Can’t download ‘public’ files" is closed to new replies.