• Resolved amarama

    (@amarama)


    WP CORE msblogs.php has a known issue when using HTTPS for multisites. When adding newsites the http gets appended to the url then it manually has to be updated to work correctly.

    This was the core fix I found in WP Support force-https-or-relative-urls-for-media-in-posts. But this issue has been around for a while. My question is what approach would be best when upgrading WordPress since this fix has not been added to the core.

    Can I use a plugin to override this functionality?

    Using this core function:

    function get_blogaddress_by_id( $blog_id ) {
    $bloginfo = get_blog_details( (int) $blog_id, false ); // only get bare details!
    return esc_url( ‘https://’ . $bloginfo->domain . $bloginfo->path );
    }
    and apply the fix above to override the core upon creating new subsites.

    Any help would be greatly appreciated thanks.

Viewing 10 replies - 1 through 10 (of 10 total)
  • Thread Starter amarama

    (@amarama)

    Also I wanted to know if I could modify this fix via github HERE so it is included in future releases.

    I dont see how this is a bug. Most people use http for their web sites, so that is the default setting. If your sites are https by default, then you should try figuring out how to change it automatically via plugin. I wouldnt recommending changing core.

    Thread Starter amarama

    (@amarama)

    The reason why I stated it as a bugs is because the tools should be able to detect if the site is either based on a condition.

    Also I tried to edit by creating a plugin here is the code:

    if ( !function_exists(‘get_blogaddress_by_id’) ) {

    function get_blogaddress_by_id( $blog_id, $scheme = null ) {
    if ( ! in_array ( $scheme, array( ‘http’, ‘https’ ) ))
    $scheme = is_ssl() ? ‘https’ : ‘http’;
    $bloginfo = get_blog_details( (int) $blog_id, false ); // only get bare details!
    return esc_url( “$scheme://” . $bloginfo->domain . $bloginfo->path );
    }

    }
    add_filter(‘blogaddress_by_id’, ‘get_blogaddress_by_id’, 1);

    I used this code to hook into the core but it is not working. I am working on a multi-site setup in IIS and I did find a URL rewrite fix for redirection. But the site upon creation is not taking this code as the code it should use to correct the subsite name.

    I looked everywhere and have not found an exact answer or fix to this issue any suggestions to fix my code.

    Thanks

    First off, your code with the scheme checking may work for you but not everyone else. For example, our wp-admin is always accessed via https. If your modified get_blogaddress_by_id() is called, then all my new sites will be https when that is not what we would want.

    Second, I do not think get_blogaddress_by_id is called when the blog/site is first created (I may be wrong). This is a function called after a site exists.

    Third, get_blogaddress_by_id is not pluggable nor is it an action or filter.

    If you wanted to change the siteurl when you create a new site, then you would use a hook like wpmu_new_blog – https://codex.www.ads-software.com/Plugin_API/Action_Reference/wpmu_new_blog
    Inside that hook you can change the siteurl and home (they should typically be set the same) with update_blog_option

    Thread Starter amarama

    (@amarama)

    Right now without submitting it as a bug I would like to just get it to work within my plugin referencing the “get_blogaddress_by_id” is a function that in in the ms-blogs.php in the includes folder what I am trying to do is find the correct filter to hook into or override the core functionality of this core file. So the behavior works in the plugin as it does when I embed inside the ms-blogs file.

    I don’t know what I am doing wrong but it works in the core file but once it has been pulled out and added it separate plugin file it then does not work.

    Again I fixed the redirect inside of the IIS web.config file now I just need to upon creating a new website get the protocol to read write and I thought you have to use add_filter (not add_action) to hook into core functionality.

    I don’t know if I am missing the correct tag for the filter. This can remain an issue I just need to fix it for our environment. I have not seen a fix nowhere and other have had the same issue. Most edited config files and core file no resolutions I have seen done in plugin form.

    Better yet, how can I get this core function embeded inside of my plugin to call (filter) before the site is created?

    Thanks

    Thread Starter amarama

    (@amarama)

    Also I tried adding the action as you suggested with some changes and that did not work in my plugin.

    if ( !function_exists(‘get_blogaddress_by_id’) ) {
    function get_blogaddress_by_id( $blog_id ) {
    $protocol = is_ssl() ? ‘https://’ : ‘https://’;
    $bloginfo = get_blog_details( (int) $blog_id, false ); // only get bare details!
    return esc_url( $protocol . $bloginfo->domain . $bloginfo->path );
    }
    add_action( ‘wpmu_new_blog’, ‘get_blogaddress_by_id’ );
    }

    Thread Starter amarama

    (@amarama)

    Ok I saw that the wpmu_create_blog() function hooks into the wpmu_new_blog() function which is initialize upon creation of blogs. If I can interject my plugin code in during this add_action then I can get the results I am looking for. Yet I have never had to do or have done this before and need help. Everything so far has been trial and error. Outside of adding it to the core.

    I really would like to get this working.

    Any ideas WordPress community? If I figure it out I will post my results I think it would be really helpful for future multisite developers and the community.

    Thanks.

    Did you read the plugin page? It is a simple hook with an example. I dont know why you keep trying to modify get_blogaddress_by_id(). It is not a modifyable function/hook. IMO even if you were able to modify it, it would not work the way you think.
    https://codex.www.ads-software.com/Plugin_API/Action_Reference/wpmu_new_blog

    Here is some example code. You need to add this to a plugin or theme. Warning: I did not test out the code.

    function my_wpmu_new_blog( $blog_id, $user_id, $domain, $path, $site_id, $meta ) {
        $url = 'https://' . $domain;
        update_blog_option( $blog_id, "siteurl", $url);
        update_blog_option( $blog_id, "home", $url);
    }
    add_action( 'wpmu_new_blog', 'my_wpmu_new_blog', 10, 6 );
    Thread Starter amarama

    (@amarama)

    Yes I did and thanks for all of the help. However a colleague with more experience did help and he used the get_blog_option for the $blog id, then used and str_replace to replace the protocol and lastly used the update_blog_option to set it in the database so the field reads correctly when you edit the site setting.

    Then the wmpu_new_blog hook what used when calling the function. It is always something simple but when you don’t know the method of how then you will dance all around the answer.

    I will also try your code to I will mark this as resolved.

    Thread Starter amarama

    (@amarama)

    jkhongusc I tried your code it didn’t work but as I said this is resolved and thanks for the help again.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Multisite bug with WP CORE ms-blogs’ is closed to new replies.