[Patch] Can’t download ‘public’ files

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

Stefano Cardinale
Participant

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

#165545

Nayeem Riddhi
Moderator

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

#165553

Stefano Cardinale
Participant

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

#165587

Nayeem Riddhi
Moderator

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

#165604

Stefano Cardinale
Participant

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

#165627

Nayeem Riddhi
Moderator

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.