Support » Plugin: WordPress Gallery Plugin - NextGEN Gallery » Bug in get_static_url

  • k1sul1

    (@k1sul1)


    I was having an issue with missing leading slashes between the domain and wp-content which eventually led to me finding this:

    https://wordpress.org/support/topic/solutions-to-missing-leading-slash-in-urls/

    This is a legacy project and I do not have a full understanding about how everything works (several years old, just got it today), but I’m sure that there’s no support for root-relative-urls or soil-relative-urls declared, and the slash issue only exists for this plugin.

    I tracked the issue to the following code in get_static_url (package.module.mvc.php):

    
    // For the "Sage" theme and others using the "Soil" plugin "Roots" theme was re-branded to "Sage" theme
    // 2015-02-25; see https://roots.io/new-website-sage-and-the-future/
    if ((current_theme_supports('soil-relative-urls') || current_theme_supports('root-relative-urls')) || strpos($retval, '/') !== 0) {
        $retval = '/' . $retval;
    }
    return $retval;
    

    As I stated, I’ve not declared theme support for either of these, so the condition essentially becomes this:

    
    (false || false) && strpos($retval, '/') !== 0
    

    Which means that the last part of the condition is never executed. One can work around this issue by declaring theme support for either of these, even if support for relative URLs doesn’t exist, but that could break lots of other things so I wouldn’t recommend that.

    Other “solution” is to simply replace && with || directly in the plugin code, but that will eventually break if it isn’t patched directly in the plugin.

    So if anyone else is having this same issue in the near future, you can fix the issue (temporarily) by going to wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/mvc/package.module.mvc.php and editing lines 188 to 193 so that they look like this:

    
    // For the "Sage" theme and others using the "Soil" plugin "Roots" theme was re-branded to "Sage" theme
    // 2015-02-25; see https://roots.io/new-website-sage-and-the-future/
    if ((current_theme_supports('soil-relative-urls') || current_theme_supports('root-relative-urls')) || strpos($retval, '/') !== 0) {
        $retval = '/' . $retval;
    }
    return $retval;
    
    • This topic was modified 3 years ago by k1sul1. Reason: butterfingered the last code block
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author photocrati

    (@photocrati)

    @k1sul1 – Thanks for the feedback and troubleshooting on this issue … I will have our developers review this further.

    – Cais.

    k1sul1

    (@k1sul1)

    Great.

    While the original code was probably meant to check that either of these current_theme_supports is true, and only then check if there’s a need for a leading slash, my issue points out that maybe you should check for the leading slash in any case. If there’s no leading slash for whatever reason, it should be safe to add one.

    Browsers / servers(not sure which, tested with IE/Chrome/FF) don’t seem to care even if there are extra slashes, take this for example: https://ajax.googleapis.com/////ajax/libs/jquery/3.1.1/jquery.min.js

    Plugin Author photocrati

    (@photocrati)

    @k1sul1 – Yes, the existence of extra slashes being ignored in some browsers actually does make this a bit more tricky (and another item we are reviewing) to sort out although we do appreciate the additional feedback related to this problem you are seeing.

    Thanks, again!

    – Cais.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Bug in get_static_url’ is closed to new replies.