• Resolved Gahapati

    (@gahapati)


    Goedendag Rogier,

    thank you very much for this outstanding plugin!

    I found (and possibly fixed) the following bug:
    File: class-admin.php
    Function: get_plugin_url()
    Lines: 1232 - 1239

    $this->plugin_url returns a malformed URL like:
    sub.example.comwp-content/plugins/really-simple-ssl/.

    In Multisite sub-sites this breaks the SSL in the Configuration tab and causes an extended delay until the request times out.

    I found the use of home_url() instead of network_home_url() to be the main culprit. In addition, the final str_replace() appears to be mixed up.

    The original code reads:

    if (is_multisite() && ( !is_main_site(get_current_blog_id()) ) && (!$this->is_multisite_subfolder_install()) ) {
           $mainsiteurl = str_replace("https://","https://",network_site_url());
    
           $home = str_replace("https://","https://",home_url());
           $this->plugin_url = str_replace($mainsiteurl,home_url(), $this->plugin_url);
    
           //return http link if original url is http.
           if (strpos(home_url(), "https://")===FALSE) $this->plugin_url = str_replace("https://","https://",$this->plugin_url);

    The proposed replacement code reads:

    if (is_multisite() && ( !is_main_site(get_current_blog_id()) ) && (!$this->is_multisite_subfolder_install()) ) {
           $mainsiteurl = str_replace("https://","https://",network_site_url());
    
           $home = str_replace("https://","https://",network_home_url());
           $this->plugin_url = str_replace($mainsiteurl,network_home_url(), $this->plugin_url);
    
           //return http link if original url is http.
           if (strpos(network_home_url(), "https://")===FALSE) $this->plugin_url = str_replace("https://","https://",$this->plugin_url);

    This at least works on my server. I wasn’t able to test out the last line of code in particular, because I have SSL configured to be always on, and I cannot turn it off easily.

    Kind regards

Viewing 1 replies (of 1 total)
  • Plugin Author Rogier Lankhorst

    (@rogierlankhorst)

    Thanks for reporting the issue, and for taking the time to investigate. Your fix is not entirely correct though. The network_home_url returns the home_url of the main site, but that is not what is needed here, because the plugin needs to validate the SSL on this specific subdomain url, not on the main url. So the home_url is good. This is probably caused by the fact that the network_homeurl in your case ends with a slash, but the sub-site does not. So when the plugin_url, which points to the main site plugin directory, is replaced, there is a slash missing. This explains why this issue doesn’t occur in most cases. It can be fixed by using the trailingslashit function on both variables.

    I also now notice that the $home variable, that is meant to use for replacement, is not used.

    Finally, the last line you mention, is meant to return http when the home_url is http, and should return only https when the home_url is https. So what happens here is that when the home_url does not contain https, the plugin_url gets replaced back to http.

    So I would propose the following code:

    if (is_multisite() && ( !is_main_site(get_current_blog_id()) ) && (!$this->is_multisite_subfolder_install()) ) {
           $mainsiteurl = trailingslashit(str_replace("https://","https://",network_site_url()));
    
           $home = trailingslashit(str_replace("https://","https://",home_url()));
           $this->plugin_url = str_replace($mainsiteurl, $home, $this->plugin_url);
    
           //return http link if original url is http.
           if (strpos(home_url(), "https://")===FALSE) $this->plugin_url = str_replace("https://","https://",$this->plugin_url);

    Let me know if this code works for you.

Viewing 1 replies (of 1 total)
  • The topic ‘Bug in class-admin.php / function get_plugin_url()’ is closed to new replies.