Domain Mapping Issue

Gotta problem, its kinda complicated, but involves the following set up: network set up, subfolder install and involves using the Divi Theme (with a child theme i created), involves the following plugin: WPMU Domain Mapping and Amazon S3 plugin, however I explained it better:

https://github.com/deliciousbrains/wp-amazon-s3-and-cloudfront/issues/467

I have made some modifications to domain mapping to eliminate the HTTP/HTTPs bug it has for editing pages with the visual builder. Also, used this filter in my child theme: https://deliciousbrains.com/wp-offload-s3/doc/filtering-urls-in-custom-content/

I am left with ONE bug...when domain mapping is active, it is causing the filtering to not work for the customizer css background image paths.I dont know why, it happens when the content is "posted" to save and only in the customizer css, so somewhere it is hooking in and causing an issue.

Do you possibly know where in the code it is rewriting these paths so that I can make the proper modifications?

I think this is a domainmapping/customizer/s3 issue, so somehow Domain Mapping needs to not do its rewrites and get in the way of things

  • Luís

    Hi Ben ,

    Hope you're doing well today!

    After the live chat, I tried to replicate the issue, but I was not able. It's possible that I have missed something about the procedure, however, I made a video about the tests I made, please let me know!

    https://www.screencast.com/t/nLcmz36MYxiA

    Or maybe there is a setting interfering with this, can you give me access to your WordPress admin panel, so I can check your settings and compare with mine?

    If you don't already know, please, follow the link below, to see how enable the staff login:
    https://premium.wpmudev.org/docs/getting-started/getting-support/#chapter-5

    Cheers, Luís

  • Ben

    This is bad not only causing issues with divi (as I pointed out in many many months ago that there is a problem, but seems to also be the culprit of a lot of unnecessary unchecked unncessary load on the database.
    every time admin_url() is called...it appears to be running a query...instead of the result being queried once and then used.....YIKES? You can confirm this using Query Monitor plugin. Not happy guys...can we get this fixed today? And please do QA on the ultimate branding plugin

    Please inform the dev asap shouldn't be hard fix :slight_smile:

    /**
             * Returns current mapping type.
             *
             * @since 4.1.0
             *
             * @access private
             * @param string $option The option name to check.
             * @return string Mapping type.
             */
            private function _get_current_mapping_type( $option ) {
                    $mapping = $this->_plugin->get_option( $option );
                    if ( $mapping != 'original' && $mapping != 'mapped' ) {
                            $original = $this->_wpdb->get_var( sprintf(
                                    "SELECT option_value FROM %s WHERE option_name = 'siteurl'",
                                    $this->_wpdb->options
                            ) );
    
                            if ( $original ) {
                                    $components = self::utils()->parse_mb_url( $original );
                                    $mapping = isset( $components['host'] ) && $_SERVER['HTTP_HOST'] == $components['host']
                                            ? 'original'
                                            : 'mapped';
                            }
                    }
    
                    return apply_filters("dm_current_mapping_type", $mapping, $option);
            }

    I

  • Ben

    What does developer think about this:

    private function _get_current_mapping_type( $option ) {
              if($_SERVER['HTTP_HOST'] != 'mynetworkdomain.com') {
                    $mapping = $this->_plugin->get_option( $option );
                    if ( $mapping != 'original' && $mapping != 'mapped' ) {
                            $original = $this->_wpdb->get_var( sprintf(
                                    "SELECT option_value FROM %s WHERE option_name = 'siteurl'",
                                    $this->_wpdb->options
                            ) );
    
                            if ( $original ) {
                                    $components = self::utils()->parse_mb_url( $original );
                                    $mapping = isset( $components['host'] ) && $_SERVER['HTTP_HOST'] == $components['host']
                                            ? 'original'
                                            : 'mapped';
                            }
                    }
                } else {
                           $mapping = 'original';
    
                 }
                 return apply_filters("dm_current_mapping_type", $mapping, $option);
            }

    Next question if $mapping = $this->_plugin->get_option( $option );
    is expecting something, then not finding anything, after you run the query should you be setting that to something so that "get_option" response can possibly be cached by wordpress automagically during the page load or possibly set to some variable during the page to be checked?

    PLEASE get developer in the thread soon...thanks!

  • Leonidas

    Hello there Ben ,

    I want to thank you for your thorough reports and apologize for any inconvenience Domain Mapping has caused in your project. So, about your issues:

    Initially, for the Domain Mapping/Divi compatibility, we have already produced a beta (4.4.3.3- beta1) that deals with this and was supposed to pass the QA tests soon, in order to be released.

    Secondly, about the unnecessary db load caused by the admin_url function, you are right. DM shouldn't repeatedly run that SELECT query and since you mentioned it, we have built a fix for that. This fix was not included initially in the current beta, but considering the urgency of the issue, we decided it's best to include it for the next release. With this fix applied, my setup ran 2 queries of said query instead of 127 ran queries with the previous DM version.

    I'm attaching the new DM beta (4.4.3.3- beta2) with both the DM/Divi fix and the duplicate query fix applied. Mind you that this beta hasn't been properly QA tested yet, so I'd recommend a site backup before installing it. If you want to wait for Domain Mapping to release its next version, my estimations are that it's not going to be too long before we release it, but you can try with the attached beta nevertheless and let us know what that goes.

    Best regards,
    Leonidas

  • Ben

    Leonidas really appreciate the quick response. I can test that beta, is possible to also send me the files you changed and i can run diff-compare to quickly evaluate the changes you made? I wish i had access to a git repo for your guys dev would make my life much easier.

    Secondly, can you please connect with the person in charge of ultimate branding. I dont know how much was shared from the chat operators, but i sent a bunch of screenshots trailing the series of functions that led up to the database query. I found that while the select statement was being repeated and could have been handled differently, it also revealed that ultimate branding was looping through data requests of other subblogs that it shouldnt be making higher up the chain. So while your plugin made the query, the ultimate branding plugin was responsible for triggering your plugin when it shouldn't be making certain requests at all...which exposes that it is creating much more cpu which can ramp up to much much more significant cpu load in larger network sites. This was revealed by the queries, but if the query problem is gone it will not be so easy to find the run away requests. So in addition to your fix, can you please make sure to work with the developer of ultimate branding to get rid of the looping through all blogs on the network for every request? I have another post about it but hopefully you guys working together can make it easier to resolve.

  • Ash

    Hello Ben

    When we will have the release beta from the developer, I will try to give you a copy so that you can test it :slight_smile:

    UB developer can be connected from your other thread here: https://premium.wpmudev.org/forums/topic/ultima-branding-creating-multiple-queries-on-backend-wp-multisite#post-1343269

    I believe Predrag or Jorge will contact the developer if needed.

    And again, thanks a lot Ben for chiming in and making some suggestions. Sending some cookies on your way :slight_smile:

    Have a nice day!

    Cheers,
    Ash

  • Ben

    Leonidas

    still more opportunities for speed...because this plugin touching things on almost every page load...we need to think about opportunities to set things up differently to reduce database calls.

    IE...unnecessary https checking. The norm for most people is https, http requests google is on a mission to destroy.

    So for this example...we could create an https domain mapping defined variable and if isset...its used and a database lookup is not performed.

    ie: private function _get_sso_endpoint_url
    is using:
    self::utils()->get_mapped_domain_scheme( $domain );
    and
    self::utils()->get_admin_scheme() ? self::utils()->get_admin_scheme() : "http";

    Could some cpu cycles and database cycles be saved by using wp-config vars directly?

    I believe you have a lot of opportunities to combine database look ups and think about items that could be set in wp-config options in order to speed things up.

    What do you think?

  • Ben

    Leonidas

    Reviewing line 45 of classes/Domainmap/Module/System.php

    $this->_upgrade();

    Should this be here?

    You have an upgrade check running on every sub-site admin page load (maybe front end too) Is that necessary to perform in non network admin page loads?

    Its using the "SHOW TABLE" operation...which runs through the whole database...which is pretty heavy., but maybe I am missing something.

    Let me know !

    Thanks Leonidas

  • Leonidas

    Hello there Ben ,

    the beta I have shared is the latest beta so you can try with that, yes.

    Regarding the db calls optimization, those specific parts of code you mentioned are more or less the areas where we are looking to refactor Domain Mapping next. But this bigger refactor is already scheduled to be a part of the second-to-next release (meaning that it will be in 4.4.4 and not 4.4.3.3).

    So for now, you can test your original issues with the latest beta and as soon as the new DM version is out (which can be as soon as next week), I will be able to further look into those other areas where DM's perfomance can be improved.

    Again thank you for your patience and input here :slight_smile:

    Best regards,
    Leonidas

  • Ben

    Leonidas

    I want to also point out a bug that I really want to be addressed that has been persisting and really deserves your attention.

    I am assuming the customizer css is bring "filtered" through domain mapping to re-write file paths when an domain is being used.

    This filtering is somehow messing up referenced paths from the plugin:

    https://wordpress.org/plugins/amazon-s3-and-cloudfront/

    To replicate the issue is quite simple. References a path in customizer css to remote s3 location. When domain mapping is active the s3 location is remapped to the local location because domain mapping is somehow messing the process up. Try disabling domain mapping and things work fine.

    PLEASE look at that issue before the next release. Very important.

    Thanks!

  • Leonidas

    Hello there Ben ,

    about the issue with the customizer, Divi theme and the WP Offload Media Lite plugin, you didn't mentioned to me if the beta I shared fixed it for you. Now that the new DM version is released, you can try updating it and see if your issue is resolved, since one of the tasks implemented for 4.4.3.3 included a fix for customizer that could help your issue.

    If updating Domain Mapping doesn't do the trick, you can grant us access to the site in question, for us to have a better look at it :slight_smile:

    Since this is a public thread, you can share the credentials, the following way:

    Please visit the Contact page and complete the form with the following information:

    https://premium.wpmudev.org/contact/#i-have-a-different-question

    Option: I have a different Question

    Subject: "Attn: Leonidas Milosis"

    In the Message box, please provide the following:

    - link back to this thread for reference
    - any other relevant urls

    - Admin login:
    Admin username
    Admin password
    Login url

    - Hosting Control Panel Login
    Admin username
    Admin password
    Login url

    ~OR~

    - FTP credentials
    host
    username
    password
    (and port if required)

    I'm looking forward to hearing about your findings.

    Best regards,
    Leonidas

  • Ben

    Leonidas

    I just tested your latest plugin release...and it did not address the customizer css, same issues still occur.

    I don't like giving out access to my server, i have ssh keys set up as the only way to enter the server and run without a "control panel"

    That said you can email and I will be happy to run through your code, perhaps you can show me where your plugin swapping of the css from the customizer is occurring and we can see where this accidental re-filtering is occurring.

    Please note i am NOT using version 2.0 that was released yesterday of media lite, don't want to be their early adopter! :smiley:

    Can you please confirm the following scenario that you have tested:
    1. media lite version 1.4.3
    2. Wordpress network set up with SUBFOLDER site install
    3. Customizer css with:
    .some_class { background-image: url(https://full_s3_path_of_image_in_site_media_library); }
    4. This happens on all themes so feel free to use wordpress twenty seventeen theme for testing
    5. Domain mapping active with primary domain

    Please let me know you are testing this exact scenario before proceeding.

  • Hi Ben ,

    answering your question, DM is dealing with the Customizer's unique infrastructure using mainly these two functions located in the classes/Domainmap/Module/Mapping.php file, use_mapped_for_customizer()and use_ssl_for_customizer(), but the function that most concerns us here is the use_mapped_for_customizer() one.

    That being said, the reported issue, which I haven't been able to reproduce (I'm expanding on this further below), sounds more like an issue with how those CSS values are being saved in the db. For example, if the user is adding
    .testdiv {
    background-image: url(https://s3-us-west-1.amazonaws.com/**********/wp-content/uploads/sites/8/2018/10/21121814/leonidas-ico.png);
    }

    in the Customizer CSS, that value is not supposed to be swapped or edited in any way during its save to the db, even with DM active. That makes me think that somewhere along the way, the Filtering URLs in Custom Content filter you mentioned plays its part in this reported discrepancy. But, until I manage to replicate this, all the above are merely theoretical. I'd feel much better if I was to provide you with exact info on what goes on when this bug appears.

    For this, I'd like you to help me by checking the replication steps you previously shared:

    Can you please confirm the following scenario that you have tested:
    1. media lite version 1.4.3
    2. Wordpress network set up with SUBFOLDER site install
    3. Customizer css with:
    .some_class { background-image: url(https://full_s3_path_of_image_in_site_media_library); }
    4. This happens on all themes so feel free to use wordpress twenty seventeen theme for testing
    5. Domain mapping active with primary domain

    1. media lite version 1.4.3 - CHECK
    2. Wordpress network set up with SUBFOLDER site install - CHECK
    3. Customizer css with:
    .some_class { background-image: url(https://full_s3_path_of_image_in_site_media_library); } - CHECK
    4. This happens on all themes so feel free to use wordpress twenty seventeen theme for testing - CHECK
    5. Domain mapping active with primary domain - CHECK

    Doing the above and trying to put a CSS rule with the S3 path of an image, that path is not being replaced with a local one on my end and after the CSS is saved, that original S3 path is being applied normally in the selected element, both in the customizer and the public side of the site.
    Can you share with me an example of a filtering you apply in your theme, using the filters described here https://deliciousbrains.com/wp-offload-media/doc/filtering-urls-in-custom-content/ ? That way I'll be able to duplicate more closely your setup and hopefully figure this thing out for you.

    Best regards,
    Leonidas

  • Ben

    Leonidas

    Make sure the s3 media lite settings are set to "REMOVE original local path file" in the network settings.
    Additionally I did a new server set up...and didn't see the problem occurring! So I re-examined and there are some additional settings to review to recreate:

    Go to network settings:
    Administration mapping: SET THIS TO ORIGINAL DOMAIN
    Login mapping: SET THIS TO ORIGINAL DOMAIN

    Now go to the customizer css on the sub-site and delete the customizer data, revisit the site, then open the customizer css again and re-create the test by adding the s3 file path.

    You should see the issue now.

    Interestingly enough, changing the network domain mapping settings back to the original default settings doesn't fix the problem for me. So after the problem has been "triggered" it doesn't go away.

    Please let me know if you can see the issue now. I can also give you access to my test server.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.