Template overwrite doesn’t work

Viewing 7 posts - 1 through 7 (of 7 total)
#135736

Joffrey
Participant

Hello,

using WP 5.5 / WP DM 3.1.08

I’m trying to change one link template (link-template-default-ext).
I’m following rules as described in https://www.wpdownloadmanager.com/doc/template-files/

Here is where I put updated file :
wp-content/themes/mychildtheme/download-manager/link-templates/link-template-default-ext.php
It doesn’t work.

What is weird is that I also updated one other template but this one works… (wp-content/themes/mychildtheme/download-manager/shortcodes/category.php)

Thanks for your help.

PS : I’m working in local environment, so I can’t provide link to the website.

Best regards.
Joffrey

#135820

Nayeem Riddhi
Moderator

It is working fine from my side. it will be better if I can see through login your site and see what you have done.

Thanks.

#136012

Joffrey
Participant

Hello,

unfortunatly, as I mentioned, I’m working in local environment, so I can’t provide login to the website now.

I’ve overwritten one page template and its working… but page template is only overwritten if I put the file in /download-manager/ directory and not in /download-manager/page-templates/.

There is only link templates that don’t work. I tried to for link-templates but its not working…

Resume :
wp-content/themes/mychildtheme/download-manager/link-templates/link-template-default-ext.php NOT WORKING
wp-content/themes/mychildtheme/download-manager/link-template-default-ext.php NOT WORKING

wp-content/themes/mychildtheme/download-manager/shortcodes/category.php WORKING
wp-content/themes/mychildtheme/download-manager/page-templates/page-template-default.php NOT WORKING
wp-content/themes/mychildtheme/download-manager/page-template-default.php WORKING

Shortcodes I’m using to display links :
[wpdm_category id="mycategory" toolbar="0" paging="1" order="desc" item_per_page="10" template="link-template-default-ext" cols=4 colspad=2 colsphone=1]
[wpdm_package id='16001' template="link-template-default-ext"]

I tried to reinstall plugin without success. Same issue…

#136014

Joffrey
Participant

Something weird.

When I test the preview in dashboard, it’s the overwritten file that is used. (hum)…

#136016

Joffrey
Participant

I think the issue comes from 2 things :
1) (my config only) owner file config : when it is correctly www-data, file in stylesheet_directory can be found BUT still not overwritten
2) condition in line 1064 in wp-content/plugins/download-manager/libs/class.Package.php should be && not || right ?

When I change this condition as follow :
if(!file_exists($ltpldir) && !file_exists($ltpldir.$template))

It’s working. I also test without overwritten files in childtheme to check if its working correctly with default plugin templates : it’s OK.

Have look please on this. Maybe I could be wrong.

  • This reply was modified 3 years, 7 months ago by Joffrey.
#136070

Nayeem Riddhi
Moderator

Okay if this issue creating frequently we shall adjust on your point. however, it is working fine in our side and server-side too.

Thanks.

#136236

Joffrey
Participant

After plugin update, issue reappear.

— HERE IS A FUNCTIONAL AND TEMPORARILY FIX FOR USERS —
I have to put the “.php” extension in the shortcode template tag to it works as follow :
[wpdm_category ... template="link-template-default-ext.php" ...]
— END OF FIX —

I think there is something not optimised in this part of code :
wp-content/plugins/download-manager/libs/class.Package.php from line 1060

$ltpldir = get_stylesheet_directory().'/download-manager/'.$type.'-templates/';
$pthemeltpldir = get_template_directory().'/download-manager/'.$type.'-templates/';

if(!file_exists($ltpldir) || !file_exists($ltpldir.$template))
    $ltpldir = WPDM_BASE_DIR.'tpls/'.$type.'-templates/';

if (file_exists($ltpldir . $template)) $template = file_get_contents($ltpldir . $template);
else if (file_exists($pthemeltpldir . '/' . $template)) $template = file_get_contents($pthemeltpldir . '/' . $template);
else if (file_exists($ltpldir . $template . '.php')) $template = file_get_contents($ltpldir . $template . '.php');
else if (file_exists($pthemeltpldir . $template . '.php')) $template = file_get_contents($pthemeltpldir . $template . '.php');
else if (file_exists($ltpldir. $type . "-template-" . $template . '.php')) $template = file_get_contents($ltpldir. $type . "-template-" . $template . '.php');
else $template = file_get_contents(wpdm_tpl_path($default[$type], $ltpldir));

If a dev can have a look on this part to improve it.

I suggest to replace above code by something like this :

$directories = [
    get_stylesheet_directory().'/download-manager/'.$type.'-templates/',
    get_template_directory().'/download-manager/'.$type.'-templates/',
    WPDM_BASE_DIR.'tpls/'.$type.'-templates/'
];

$getTemplateContent = function() use ($directories, $template, $type, $default) {
    foreach ($directories as $dir) {
        if (file_exists($dir . $template)) {
            return file_get_contents($dir . $template);
        } 
        if (file_exists($dir . '/' . $template)) {
            return file_get_contents($dir . '/' . $template);
        } 
        if (file_exists($dir . $template . '.php')) {
            return file_get_contents($dir . $template . '.php');
        } 
        if (file_exists($dir . $type . "-template-" . $template . '.php')) {
            return file_get_contents($dir . $type . "-template-" . $template . '.php');
        }
    }

    return file_get_contents(wpdm_tpl_path($default[$type], $dir));
};

$template = $getTemplateContent();

Best regards.

  • This reply was modified 3 years, 7 months ago by Joffrey.
Viewing 7 posts - 1 through 7 (of 7 total)

The topic ‘Template overwrite doesn’t work’ is closed to new replies.