• Resolved lpedley

    (@lpedley)


    Hey there – love the plugin!

    We’re having difficulty with attachments, the anchor of the link shows correctly (e.g. XXX.pdf) but clicking the link just redirects to the page, rather than being able to view or download the attached file. It looks like the link for the attachments are just the same as the doc link they are attached to.

    Can you please advise?

    Thank you!

Viewing 15 replies - 1 through 15 (of 15 total)
  • Plugin Author David Cavins

    (@dcavins)

    Hi-

    We do some redirects to protect private content (on the web generally, if someone has the address for an image, they can view it). For instance, if I have a BP Doc with the URL http://bptest.local/docs/isnt-it-a-lovely-day/, an attachment might have the URL http://bptest.local/docs/isnt-it-a-lovely-day/?bp-attachment=JD_anchor_1.jpg.

    Lots of browsers don’t show query arguments (the ?bp-attachment=JD_anchor_1.jpg part of the URL) to the user anymore in the location bar or even when hovering over a link, but you should be able to inspect the link.

    Please post here a couple of examples you find while browsing your site.

    -David

    • This reply was modified 8 years, 3 months ago by David Cavins.
    Thread Starter lpedley

    (@lpedley)

    Hi, thanks for getting back to me.

    I have inspected the link and these are a few examples:

    <a href="https://www.squarepeg.online/docs/info-about-the-sheffields-working-programme/" title="Sheffields-Working-Leaflet.pdf">Sheffields-Working-Leaflet.pdf</a>

    <a href="https://www.squarepeg.online/docs/employer-champion-leaflet/" title="Employer-Champion-Leaflet.pdf">Employer-Champion-Leaflet.pdf</a>

    As you can see, the links are just directing back to the docs page of the particular member’s doc. Any ideas?

    Thanks

    Thread Starter lpedley

    (@lpedley)

    Hi there,

    Please can you provide any guidance on this one??

    Thanks

    Plugin Author David Cavins

    (@dcavins)

    Hello. Well, we’ll need to debug bp_docs_get_attachment_url(). So, if you can make a page-test.php file in your theme or similar, and add a <?php ?> block to it, that would be a good start.

    I’d test these items: (You’ll need the ID for an attachment. You can find this by finding Employer-Champion-Leaflet.pdf in your media library and seeing what its ID is.)

    
    var_dump( 'computed url', bp_docs_get_attachment_url( $attachment_id ) );
    // Then, within that function, check a few pieces separately.
    var_dump( 'protection active', bp_docs_attachment_protection() );
    var_dump( '$att_base', wp_basename( get_attached_file( $attachment_id ) ) );
    
    Thread Starter lpedley

    (@lpedley)

    Hey David thanks for your reply. I’ve created a page-test.php in my theme folder and added the php tags. The next bit you lose me a little. How do I test the items? If I had an ID of 163 for example, how to I run the debug (do I visit a specific URL or amend the code)?

    Thanks again

    Plugin Author David Cavins

    (@dcavins)

    OK, if you’ve added a page-test.php file to your theme, then WP will use it when you visit a page called “Test”. (See https://developer.ww.wp.xz.cn/themes/basics/template-hierarchy/#single-page)

    So create a page called test and visit it to execute the code in your page-test.php template part.

    With an attachment ID of 163, you could do this in page-test.php:

    <?php
    $attachment_id = 163;
    var_dump( 'computed url', bp_docs_get_attachment_url( $attachment_id ) );
    // Then, within that function, check a few pieces separately.
    var_dump( 'protection active', bp_docs_attachment_protection() );
    var_dump( '$att_base', wp_basename( get_attached_file( $attachment_id ) ) );
    ?>
    Thread Starter lpedley

    (@lpedley)

    Hi David, thanks for that. Learning a lot!

    This is what was returned after I ran the test on my local copy:

    string(12) "computed url" string(52) "http://localhost:8888/squareroot/test/?bp-attachment" string(17) "protection active" bool(true) string(9) "$att_base" string(0) ""

    Any ideas?

    Plugin Author David Cavins

    (@dcavins)

    Huh. When I use a known BP Docs attachment ID with that code, the output looks like this:

    
    string 'computed url' (length=12)
    string 'http://bptest.local/docs/the-first-of-many/?bp-attachment=vacuum-press_1776.jpg' (length=79)
    string 'protection active' (length=17)
    boolean true
    string '$att_base' (length=9)
    string 'vacuum-press_1776.jpg' (length=21)
    

    Can you double check that 163 is the ID of the attachment and not of the parent doc? If you go to your media library at /wp-admin/upload.php and select the attachment, you’ll see the ID in the URL like /wp-admin/upload.php?item=56.

    Thread Starter lpedley

    (@lpedley)

    Think I finally got there?

    string(12) "computed url" string(104) "https://www.squarepeg.online/docs/employer-champion-leaflet/?bp-attachment=Employer-Champion-Leaflet.pdf" string(17) "protection active" bool(true) string(9) "$att_base" string(29) "Employer-Champion-Leaflet.pdf"

    I am hoping we can find a solution with this πŸ™‚

    Plugin Author David Cavins

    (@dcavins)

    That looks good to me! I even followed the link and the pdf downloaded fine. What did you change? Just the attachment ID, or something else?

    Ok, so we know that the url is being calculated correctly, given the right attachment ID. So, if we can see that the right attachment ID is being passed to the function, then we’ll know that something else (I’m guessing the theme) is shaving off url parameter arguments.

    In /wp-content/plugins/buddypress-docs/includes/templates/docs/single/attachments.php
    , add this line:
    <?php var_dump( 'attachment ID', $attachment->ID ); ?>
    right after this statement.
    <?php foreach ( bp_docs_get_doc_attachments() as $attachment ) : ?>

    If that ID (it’ll be printed out on the page when you visit https://www.squarepeg.online/docs/employer-champion-leaflet/ on your test machine) matches the ID you plugged into your code on page-test.php, then we’ll know that the problem is elsewhere.

    Thread Starter lpedley

    (@lpedley)

    Hi David, I just did the test again but on the live site rather than the test site. The ID was probably incorrect in the original test as well.

    I’ve followed your instructions and the ID displaying on that page is the same that I placed in the code originally so it must be a theme issue. We are using BuddyBoss theme, what should I do next?

    Thank you very much

    Liam

    Plugin Author David Cavins

    (@dcavins)

    Hi Liam-

    I’d follow these steps for troubleshooting code interaction:

    β€’ Switch to a “default” theme like TwentySeventeen. If the problem is fixed, then contact the BuddyBoss authors, who are helpful people.
    β€’ Start disabling plugins to see if one of them is affecting this url.

    If you get down to BuddyPress and BP Docs using TwentySeventeen, then the problem is in BP Docs itself.

    Thread Starter lpedley

    (@lpedley)

    Hey David, thanks for your reply. I did as you advised and it turns out it’s a conflict with W3 Total Cache. Hoping I can change the settings about to resolve – have you experienced this before? Hope you can provide some insight!

    Thanks again, Im really grateful

    Thread Starter lpedley

    (@lpedley)

    Remove query strings for static resources was the culprit if anyone else experiences this issue!

    Plugin Author David Cavins

    (@dcavins)

    Congratulations on finding the root of the issue! I don’t use W3TC myself, I find WP Super Cache easier to set up and similarly effective. I also exclude the docs directory from the cache by path. You might look for something similar in the TC settings. They also may be a setting for allowing url parameter args. It seems like the plug-in would have to allow for meaningful args.

    You’re almost there!

Viewing 15 replies - 1 through 15 (of 15 total)

The topic ‘Attachment links not working’ is closed to new replies.