• Resolved Aldo

    (@ab_lu)


    Hi Stephan

    We have an own function, where we check if a user is allowed to download the file or not. Is there a file we can use, to hook in when a user tries to download a file?

    Then in the filter we could do our stuff and return true/false depending if the user has access.

    Thanks
    Aldo

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author csorbamedia

    (@csorbamedia)

    Dear Aldo,

    The attachment has a meta “is_private” which you could use somewhere in your template. Not sure if you are looking for this.

    <?php if(get_post_meta($file_id, 'is_private', true) == true) && $user_id == '1'){ echo 'Allowed'; } else{ echo 'not allowed' }; ?>

    With the ‘private_media_url_by_array’ filter you can retrieve the download URL by file_id or by passing the file array.

    Stephan

    Thread Starter Aldo

    (@ab_lu)

    Hi Stephan

    Not exactly.
    When a user clicks on the link to download a file (i.e. https://domain.com/download/file/2374/) i would like to hook in before the download is returned to apply my own check.

    Aldo

    Plugin Author csorbamedia

    (@csorbamedia)

    Dear Aldo,

    Ah ok, sorry no there is no way currently.

    Stephan Csorba

    Thread Starter Aldo

    (@ab_lu)

    Any plans for that?

    Thread Starter Aldo

    (@ab_lu)

    Hi Stepahn

    I looked a bit deeper.
    Is there a way to retrieve the current post ID in this hook: PWPF_handle_private_download

    Thanks
    Aldo

    Plugin Author csorbamedia

    (@csorbamedia)

    Hi Aldo,

    I hope you understand that I can’t do every individual request.
    If more people have the same request I can do a change to the plugin.
    How many installations is the plugin installed on your side, and do you need it for every installation?

    Stephan Csorba

    Thread Starter Aldo

    (@ab_lu)

    Hi Stephan

    I understand ??
    It‘s just one Installation.

    If I could just get the page ID from the page the the Download is called.
    Maybe pass it as additional parameter in the rewrite?
    Or can I grab it via get_post_meta mentioned in the beginning to get the post Id the attachment belongs to?
    The rest I can figure out.

    Best, Aldo

    Plugin Author csorbamedia

    (@csorbamedia)

    Dear Aldo,

    The attachment is in the url /download/()/.

    <?php $file = get_query_var('pwpf_file'); ?>

    Thread Starter Aldo

    (@ab_lu)

    Thanks!
    Wouldn’t be possible to pass the post id in the query as well?

    Thread Starter Aldo

    (@ab_lu)

    Hi Stephan

    Ok, I managed to grab the post id. Maybe there is a nicer way to do that, but it does the job.

    In pwf_hooks.php
    After line 157:

    global $post;
    $src_post_id    = $post->ID;
    return $is_private == true ? get_bloginfo( 'url' ) . '/download/file/'.$file['ID'].'/'.$src_post_id.'/' : $file['url'];

    After line 471 add:
    $query_vars[] = 'pwpf_postid';

    Change line 479 (before the change above) to:
    add_rewrite_rule('download/file/([^/]+)/([^/]+)/?$','index.php?pwpf_file=$matches[1]&pwpf_postid=$matches[2]','top');
    And add:
    add_rewrite_tag('%pwpf_postid%','[^&]+');

    Now in PWPF_handle_private_download() you can get the var: get_query_var(‘pwpf_postid’)

    Best,
    Aldo

    Plugin Author csorbamedia

    (@csorbamedia)

    Dear Aldo,

    Thanks for sharing.
    If other people need this, please see Aldo his solution.

    Stephan

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Use own function to define if file protected’ is closed to new replies.