• I’m testing our site locally on localhost:8000.

    In the past, adding our live domain via the as3cf_local_domains filter made everything work correctly, as per the help page Filtering URLs for multiple domains.

    This has stopped working in the latest release. If I host my local version on port 80 (i.e. no port in the URL), it works again.

    Doing a quick bit of debugging, the list of URLs coming from AS3CF_Local_To_S3::get_bare_upload_base_urls() is:

    array(3) { 
      [0]=> string(30) "//localhost:8000/wp-content/uploads" 
      [1]=> string(30) "//localhost:8000/wp-content/uploads" 
      [2]=> string(49) "//www.mydomain.com:8000/wp-content/uploads"
    }

    This is with the filter is as follows:

    function as3cf_local_domains( $domains ) {
    
        $domains[] = 'www.mydomain.com';
    
        return $domains;
    }
    
    add_filter( 'as3cf_local_domains', 'as3cf_local_domains', 10, 1 );

    The port number should not be added to our live domain.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Contributor ianmjones

    (@ianmjones)

    I can’t see anything having changed in that area of the plugin for quite some time, and manipulating port number in the context of recognizing local domains has never been a thing as far as I can see.

    What version were you using prior to 2.3+?

    Why do you need your production domain to be recognized as local? When you clone to local from production surely you search/replace production domain to local domain (plus port) anyway?

    Thread Starter ncdb

    (@ncdb)

    Thanks for the reply.

    We’re on 2.2.1 but on reflection, perhaps this has always happened and we just used the workaround (serve on port 80) before. But with the email about breaking changes / one-way upgrade, this time it’s getting a more thorough test than I’d usually do!

    We need the production domain to be recognised as local because we don’t make any changes to the database when cloning to local and staging sites.

    By simply adding the production domain with the as3cf_local_domains filter, the plugin can replace all our productiondomain.com/wp-content/uploads images with their CDN URLs – regardless of whatever hostname and whatever port the developer has chosen to serve their local test copy under, and without the need to run any migration scripts on the database.

    Thread Starter ncdb

    (@ncdb)

    If it helps, this is where it seems to go wrong:

    $base_urls[] = substr_replace( $base_url, $match_domain, 2, strlen( $curr_domain ) );

    https://github.com/deliciousbrains/wp-amazon-s3-and-cloudfront/blob/2.3.2/classes/filters/as3cf-local-to-s3.php#L164

    In my case:
    $base_url is “//localhost:8000/wp-content/uploads”
    $match_domain is “www.mydomain.com”
    $curr_domain is “localhost”`

    So the result is “//www.mydomain.com:8000/wp-content/uploads”

    did You try to change as3cf_local_domains to as3cf_local_domain

    function as3cf_local_domain( $domains ) {
    $domains[] = ‘wibble.example.com’;
    $domains[] = ‘wobble.example.com’;

    return $domains;
    }
    add_filter( ‘as3cf_local_domains’, ‘as3cf_local_domain’, 10, 1 );

    above fix is wrong.

    I treid this plugin(https://github.com/deliciousbrains/wp-amazon-s3-and-cloudfront-tweaks) but not work as3cf_local_domains.

    What is fix?

    Plugin Contributor ianmjones

    (@ianmjones)

    @ncdb I’ve added a feature request to our to-do list to handle mapping ports as well as domains as part of that local domains mechanism.

    @erdalaltin To keep this thread on subject, please post a new thread if you have issues related to using the as3cf_local_domains filter that are not related to mapping port numbers. I’ve replied to your thread regarding using a domain mapping plugin.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘2.3 as3cf_local_domains filter not working when current URL has port number’ is closed to new replies.