• Resolved bresciauc

    (@bresciauc)


    Hi — and thanks for this great modern plugin!

    We are experimenting with using Delightful Downloads to manage PDF files on our site, and would like the files to open directly in a new browser tab when the link is clicked.

    Is there an easy way we can modify or configure the plugin code to open files in the browser? (We understand that this would require turning off the deep-linking prevention, which in our case we do not need.)

    Thanks for any help you can give.

    https://www.ads-software.com/plugins/delightful-downloads/

Viewing 15 replies - 1 through 15 (of 20 total)
  • Plugin Author A5hleyRich

    (@a5hleyrich)

    Hi there,

    It is possible to achieve what you want with Delightful Downloads but its going to require a bit of custom code. In order to stop the PDFs from downloading you are going to have to hook into the download process and send the user to the file, opposed to forcing the download. Something like this should work:

    function download_custom_redirect( $download_id ) {
    
    	// Get path
    	$download_url = get_post_meta( $download_id, '_dedo_file_url', true );
    
    	// Send to file
    	header( "Location: $download_url" );
    	exit();
    
    }
    add_action( 'ddownload_download_before', 'download_custom_redirect', 20, 1 );

    Then to open the links in a new tab you can add a new output:

    function download_new_tab( $styles ) {
    
    	$styles['new_tab'] = array(
     		'name'		=> __( 'New Tab', 'delightful-downloads' ),
     		'format'	=> '<a href="%url%" title="%title%" target="_blank" rel="nofollow">%title%</a>'
    	);
    
    	return $styles;
    }
    add_filter( 'dedo_get_styles', 'download_new_tab' );

    All of the above code should be put into your theme’s functions.php file. The beauty of this is that plugin updates will not break your custom functionality and you can use all other Delightful Downloads features – statistics, members only and agent blocking should still work. I haven’t tested the code but that should be enough to get you started.

    Finally, to embed the download you would use the following shortcode:

    [ddownload id="123" style="new_tab"]

    Ashley

    Thread Starter bresciauc

    (@bresciauc)

    Thanks Ashley — I really appreciate you giving us this great start!

    You might find that this is a feature worth adding to a future release future as a configurable plugin option.

    I’d guess that 20% or so of DD’s potential users are looking for a well-organized way to manage PDFs that open in the browser so they can maintain a very simple user experience for both authors and users.

    (In our case we are a university, so we have a lot of informational PDFs, and I am really liking Delightful Downloads as a clean and easy way to manage these files.)

    I’ll see what I can do with the sample code, and will post any modifications we do in case others find it useful. Cheers, Dan

    Thread Starter bresciauc

    (@bresciauc)

    Just a follow-up note that I’m using Ashley’s code above, and it is working fine on my test server. I expect I’ll go into production with it exactly as-is. Thanks again!

    Plugin Author A5hleyRich

    (@a5hleyrich)

    Excellent, glad it’s working for you. I’ll add this feature to the to-do list.

    Once you’ve had chance to fully test the plugin and have a quick minute, a plugin review would be greatly appreciated.

    Ashley

    I’d just like to add a second request that this be a feature for future releases! Just launched a new site and the client requested that the documents open in the browser rather than be saved directly to their computer – it’s going to take some time to add the code to every document (there are dozens)!

    Thread Starter bresciauc

    (@bresciauc)

    Hi Ashley — Is it possible to make text customization work with the ‘New Tab’ format?

    Currently doing something like this:
    [ddownload id=”446″ style=”new_tab” text=”Download this file…”]
    does not display the custom text as the link text.

    Also… do you have a tip jar or similar where Delightful Download fans can chip in a bit of cash to thank you for the great support you give this plugin?

    Plugin Author A5hleyRich

    (@a5hleyrich)

    If you change the new tab code to the following, you should be able to manually set the text:

    function download_new_tab( $styles ) {
    
    	$styles['new_tab'] = array(
     		'name'		=> __( 'New Tab', 'delightful-downloads' ),
     		'format'	=> '<a href="%url%" title="%text%" target="_blank" rel="nofollow">%text%</a>'
    	);
    
    	return $styles;
    }
    add_filter( 'dedo_get_styles', 'download_new_tab' );

    If you would like to donate to the plugin, you can do so here. Donations are greatly appreciated! ??

    Ashley

    Thread Starter bresciauc

    (@bresciauc)

    Hi Ashley,

    The revised code works, but unfortunately it overwrites the %title% with a generic ‘Download’ if %text% does not exist. For this to work for our site, which has a lot of existing downloads with no %text% set, it would have to default to %title% if %text% does not exist.

    Cheers, Dan [PS: The PayPal link is not working.]

    Plugin Author A5hleyRich

    (@a5hleyrich)

    Dan,

    You can set the default text in Settings > Shortcodes, which allows you to use the wildcards. Adding %title% to the default text field should do the job.

    Sorry, try this one.

    Ashley

    Thread Starter bresciauc

    (@bresciauc)

    Thanks — Deployed and working well!

    Thread Starter bresciauc

    (@bresciauc)

    Hi Ashley — A followup question:

    My new downloads are not working, giving a file-not-found error. I’m trying to figure out why…

    In the functions.php code above I see this line:

    ‘name’ => __( ‘New Tab’, ‘delightful-downloads’ ),

    In Download Settings the default Download Address directory is ‘ddownload’.

    In the file system of my multisite, the directories are named as shown below:

    ‘/public_html/wp-content/uploads/sites/8/delightful-downloads’ with 755 permissions.

    I have two questions about this:

    Should all three of these locations be the same? ‘delightful-downloads’ or ‘ddownload’, but not a mix of both?

    Also, since the issue seems to have started after a migration to a new server and new IP number yesterday, should I be raising it with my hosting service, as perhaps being permissions- or server-related?

    Thanks — Dan

    PS: We just donated $30 as a thanks for your hero-level support of this great plugin!

    Plugin Author A5hleyRich

    (@a5hleyrich)

    Hi Dan,

    The locations do not have to be the same. If you go into one of the downloads and check the URL, does the location actually exist on the new server? If it doesn’t then you will need to update the location of each download. If you have a large amount of downloads, I have an SQL query you can run to update them all. If the location does exist then check the permissions on the individual files. The permission of the folder is correct.

    Let me know how you get on. Thanks immensely for the donation!

    Ashley

    Thread Starter bresciauc

    (@bresciauc)

    Hi Ashley. I wonder if the issue may have something to do with the fact that the plug-in is being used on a sub-directory multisite, though there woulds also have to be some other factor in play.

    As an example the direct URL of one of the downloads is https://bresciau.ca/life/wp-content/uploads/sites/8/delightful-downloads/2014/07/TheFOURRulesforResumeWriting3.pdf

    The actual file is located at /public_html/wp-content/uploads/sites/8/delightful-downloads/2014/07/TheFOURRulesforResumeWriting3.pdf and has 644 permissions.

    Can you see anything in the relationship between the URL and the path that might give us a clue as to what is up?

    Plugin Author A5hleyRich

    (@a5hleyrich)

    Thread Starter bresciauc

    (@bresciauc)

    One more thought… we just started using a CDN. Could this be be a possible factor?

Viewing 15 replies - 1 through 15 (of 20 total)
  • The topic ‘Changing behavior to 'Open in tab'’ is closed to new replies.