• Resolved adrianww

    (@adrianww)


    Hi there,

    First of all – great plugin! Currently developing a book review site for someone and this is ideal. Thank you.

    Anyway, we’ve made a custom template for our client (based on your own Inverse template), just adding some extra taxonomy bits and pieces and making a few tweaks. It’s all working well, but in the Admin panel (Reviews->Settings->Templates) the screenshot for our new template isn’t showing properly (it just shows a broken image link). The template is there and it all works fine, it’s just the image link for our template’s screenshot.png in the admin page that is broken.

    I’ve taken a look at the URI that the admin panel is trying to use for the image and I think I can see what might be happening. We pretty much always create and install a child theme on any website we build, but the admin panel is trying to find the image under the parent theme stylesheet/template directory.

    I haven’t checked yet, but I’m guessing that the code to load the image in the admin page is using something like get_template_directory_uri() to build the path to the screenshot.png file. This will work fine for a single root or parent theme, but if a child theme is being used, it returns a URI for the parent. The admin code would need to use get_stylesheet_directory_uri() to get the right path when a child theme is being used.

    Alternatively, since WordPress 4.7, there’s a get_theme_file_uri() call that could be used instead. It could be called with a string parameter something like:

    ‘/rcno_templates/’ . $layout . ‘/screeshot.png’

    to get the URI to the correct screenshot image. The get_theme_file_uri() function works correctly with both parent/root and child themes.

    Thanks again for the great plugin and hope the above is helpful. It’s not a high priority thing to fix in the grand scheme of things (it’s just cosmetic in the admin page) but it’s probably something that you would want to look at.

    Adrian

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter adrianww

    (@adrianww)

    Hi again,

    Just thought I’d take a look at the code and see if I could spot where this is happening.

    I think the culprit is around line 45 in the add_layout_to_list() function in class_rcno_reviews_get_templates.php in the admin/settings directory. When handling a local layout file, it uses:

    $base_url = get_template_directory_uri() . '/rcno_templates/' . $file;

    to set the base URL. This will end up generating a URL for an /rcno_templates/file in the parent/root theme directory. This works fine if there isn’t a child theme, but doesn’t work if a child theme is being used.

    To test this out, I replaced the above line with:

    $base_url = get_theme_file_uri('/rcno_templates/' . $file);

    in the plugin installation on the site that we’re working on and it then picks up the file correctly even with a child theme installed and shows our screenshot.png in the Reviews->Settings->Templates panel.

    Thanks again,

    Adrian

    Plugin Author Kemory Grubb

    (@w33zy)

    Hello @adrianww

    Thanks for catching this issue, it seem I may have never tested this feature with child-theme in my dev setup. I’ll go ahead and implement your suggestion in the next plugin update.

    Thread Starter adrianww

    (@adrianww)

    Hi Kemory

    No problem, you’re welcome. Thank you for coming up with this plugin, it’s great.

    I spent a few minutes searching all the plugin sources for get_template_directory_uri() and that was the only place I found it, so displaying the template screenshot might be the only thing that is really affected by it. It certainly seemed to be the only thing as, apart from the image in the admin panel, our template seemed to get picked up and work perfectly fine.

    All the best

    Adrian.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Plugin not picking up screenshot for custom template’ is closed to new replies.