Skip to content
This repository has been archived by the owner on Sep 2, 2021. It is now read-only.

Limitations of Mlp_Copy_Attachments::real_upload_base_url #133

Open
dnaber-de opened this issue Jul 7, 2015 · 3 comments
Open

Limitations of Mlp_Copy_Attachments::real_upload_base_url #133

dnaber-de opened this issue Jul 7, 2015 · 3 comments

Comments

@dnaber-de
Copy link
Member

The current implementation of
Mlp_Copy_Attachments::real_upload_base_url respects only a strict usage of the WordPress Sub-Domain multisite setup where the sites URLs only differ in the host of the URL.

/**
 * Workaround for broken behavior of wp_upload_dir() in WordPress.
 *
 * After switch_to_blog(), 'baseurl' uses the wrong domain name.
 *
 * @param  string $base_url WordPress base URL
 * @param  string $site_url Result of get_option('siteurl')
 * @return string           Correct string
 */
private function real_upload_base_url( $base_url, $site_url ) {

    if ( ! is_subdomain_install() )
        return $base_url;

    if ( 0 === strpos( $base_url, $site_url ) )
        return $base_url;

    $b_host = parse_url( $base_url, PHP_URL_HOST );
    $s_host = parse_url( $site_url, PHP_URL_HOST );

    return str_replace( $b_host, $s_host, $base_url );
}

As it is possible to set up multisite environments which maps URLs including segments of the path as base URL for a site, we should consider a more flexible implementation of this method. Furthermore the sanitizing of the URLs and paths should go into own classes to follow the single responsibility principle.

(Related WPSE Question)

@thefuxia
Copy link

thefuxia commented Jul 7, 2015

I have the seen the problem that this workaround solves on subdomain installations only. Not on normal subdirectory installations and not when a domain is mapped to a subdirectory. In the latter case, this is a problem of the mapping plugin. If we attempt to fix that while that plugin tries to do the same, strange side effect may appear.

So we need two things:

  1. A reproducable setup for that case.
  2. Contact the authors of the two or three most popular domain mapping plugins.

If I remember that correctly, domain mapping is planned to be included into the WP core. In that case, the responsibility for the problem might change.

And yes, we could move that part to a separate object and pass it as an abstract dependency into this class.

@dnaber-de
Copy link
Member Author

Domain mapping is de facto in core yet. The following setup of sites is possible without any plugin using a sub-domain setup:

Site 1: domain.com/
Site 2: domain.de/
Site 3: domain.ch/fr/

I'll provide the reproducable setup soon.

Also I don't meant to cover popular domain mapping plugins but the possibilities of the core.

@bueltge
Copy link
Member

bueltge commented Jul 7, 2015

Domain Mapping plugins are only necessary, if the user will use alias domain. All other scenarios works with the core. It is also on topic for feature releases of multisite core, that is usable to use alias with the core.

@Dinamiko Dinamiko added this to the v2.11.2 milestone Aug 27, 2018
@Dinamiko Dinamiko modified the milestones: v2.11.2, v2.11.3 Nov 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants