• lady_minx

    (@lady_minx)


    We have a WordPress multisite that we need to be able to access with its usual domain, but also through a proxy domain (Azure proxy). I put some code into the wp-config file that fixes most issues with URLs, but it seems like setting WP_SITEURL dynamically isn’t working for calls to the ajaxurl admin-ajax.php in plugins.

    Is it correct that the ajaxurl is dependent on a call to site_url() which is pulling it from the database and ignoring the WP_SITEURL settings in the config file? How can I overcome that?

    Here are the changes in wp-config.php

    /** Sets up WordPress vars and included files. */

    if (isset($_SERVER[‘HTTP_X_MS_PROXY’]) && ($_SERVER[‘HTTP_X_MS_PROXY’] == ‘AzureAD-Application-Proxy’)) {
    $host = ‘proxifieddomain.net’; }
    else {
    $host = $_SERVER[‘HTTP_HOST’]; }

    $protocol = ((!empty($_SERVER[‘HTTPS’]) && $_SERVER[‘HTTPS’] !== ‘off’) || (isset($_SERVER[‘SERVER_PORT’]) && $_SERVER[‘SERVER_PORT’]===443)) ? ‘https://’ : ‘https://’;
    define(‘WP_SITEURL’, $protocol . $host);
    define(‘WP_HOME’, $protocol . $host);

    I also tried to dynamically set the DOMAIN_CURRENT_SITE value for multisite but that didn’t fix it either.

    • This topic was modified 2 months ago by lady_minx.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter lady_minx

    (@lady_minx)

    I was able to _temporarily_ get this to work by modding core. Can someone tell me how I can do this in the theme functions.php instead?

    /wp-includes/link-template.php

    //function admin_url( $path = ”, $scheme = ‘admin’ ) {
    //???????????? return get_admin_url( null, $path, $scheme );
    function admin_url( $path = ”, $scheme = ‘admin’ )
    if (isset($_SERVER[‘HTTP_X_MS_PROXY’]) && ($_SERVER[‘HTTP_X_MS_PROXY’] == ‘AzureAD-Application-Proxy’)) {
    return str_replace(‘internaldomain’, ‘proxydomain’, get_admin_url( null, $path, $scheme )); }
    else {
    return get_admin_url( null, $path, $scheme );}
    }

    Thread Starter lady_minx

    (@lady_minx)

    Created this and put it in my child theme’s functions.php file. Let me know if there are any improvements that can be made to it / if it’s going to cause any issues?

    function modify_admin_url_defaults($url, $path, $blog_id, $scheme) {
    $internal_domain = ‘lm.a.state.gov’; // Replace with your Internal domain
    $host = ‘proxydomain.net’; // Replace with your Proxy domain
    if (isset($_SERVER[‘HTTP_X_MS_PROXY’]) && ($_SERVER[‘HTTP_X_MS_PROXY’] == ‘AzureAD-Application-Proxy’)) {
    return str_replace($internal_domain, $host, $url);
    } else {
    return $url;
    }
    }

    add_filter( “admin_url”, “modify_admin_url_defaults”, 10, 4 );

    Brian Alexander

    (@ironprogrammer)

    Hi, @lady_minx ???? I agree that using a filter is the way to go here.

    The provided code will potentially modify any /wp-admin/... requests (admin pages or AJAX). I presume you have other code in place for frontend requests, which seemed to be covered by the WP_HOME and WP_SITEURL overrides initially shared? E.g. site_url is also filterable, so it’s possible this function could be hooked twice if you wanted the code in one place.

    You mentioned this being a multisite installation, so perhaps the network_site_url hook is also worth a look depending on your use case.

    Regarding adding this logic to a theme’s functions.php, if you’re looking for a more reliable option to retain this code across theme changes, then I would recommend a “must use plugin”. These are inaccessible to users and cannot be deactivated, nor removed without direct filesystem access.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.