Joffrey

Forum Replies Created

Viewing 4 posts - 1 through 4 (of 4 total)
in reply to: Template overwrite doesn’t work #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, 8 months ago by Joffrey.
in reply to: Template overwrite doesn’t work #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, 8 months ago by Joffrey.
in reply to: Template overwrite doesn’t work #136014

Joffrey
Participant

Something weird.

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

in reply to: Template overwrite doesn’t work #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…

Viewing 4 posts - 1 through 4 (of 4 total)