Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for subdirectory multisites #28

Merged
merged 18 commits into from
Mar 3, 2017
Merged

Support for subdirectory multisites #28

merged 18 commits into from
Mar 3, 2017

Conversation

mjangda
Copy link
Member

@mjangda mjangda commented Feb 13, 2017

Properly handle subdirectory sites on a multisite install. The original code for this plugin was written for WordPress.com which only supports domains and has many related assumptions that fail when running in a subdirectory (either as part of a multisite or on its own).

To allow us to work with the css URL directly if needed
Incluse util function to test if two url matches a specified site url
To support siteurls with subdirectories
@david-binda
Copy link
Contributor

Thanks for working on this @mjangda !

When testing the patch in VIP Quickstart, I have noticed that the WPCOM_Concat_Utils::is_internal_url is wrongly evaluating admin styles.

For instance : /wp-includes/css/dashicons.min.css are being concatenated on the blog with ID = 1, but not on blog ID 2 in subdirectory install, as the conditional on https://github.com/Automattic/nginx-http-concat/pull/28/files#diff-b510983752630cb415db4b4533552daeR13 is being evaluated as true and thus returns false.

I'm still digging into this and will look into possible solutions, but wanted to flag that here in order to share the findings.

Some scripts, eg /wp-includes/css/admin-bar.min.css, are being enqueued w/o the protocol and host, and as relative, they should be evaluated as internal ones.

This commit adds check agains `'host'` in parsed tested URL in order to figure out whether the URL is or is not relative and does not let the `WPCOM_Concat_Utils::is_internal_url` method retuning `false` for those URLs.
'subdir_site__internal_absolute_url' => array(
'/wp-content/plugins/plugin/style.css',
'https://example.com/mysite',
false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mjangda why we should be evaluating /wp-content/plugins/plugin/style.css as external in subdirectory site case?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the use case I was thinking of was WordPress being installed a subdirectory. Probably just a mistake though :)

david-binda and others added 9 commits February 14, 2017 19:00
On subdirectory multisite install, the style's path begins with blog's path, eg: /mysite/, and this is breaking the `realpath` check which is being performed.

This commit checks whether the current instance is a subdirectory multisite, and whether the path is set to something other than `Ã'/'. If so, it's being trimmed from the path before performing the realpath check.
The `get_blog_details` function only exists in multisite installation, which leads to PHP fatal errors on single site.

This commit is addressing the issue by moving the `get_blog_details` to inside `is_multisite` conditional
…ct realpath on both, standard installations and subbir MS installations

The body of the method is a copy of the code which has been added in previous commits. Since we need the same code on multiple places, it's better if we abstract it this way.
When the `$js_url` war replaced by `$js_url_parsed`, I forgot to create the `$js_url` variable, which is being used later in the code.

This commit fixes JS concatenation on standard as well as on MS subdir installs.
This commit is taking advantage of WPCOM_Concat_Utils::realpath method for figuring out the last modified date
/wp-content/plugins/plugin/style.css on subdirectory install should be evaluated as internal URL.

Discussion: #28 (comment)
@david-binda
Copy link
Contributor

Note: the tests are failing "just" because of PHPCS, which is not working properly.

@david-binda
Copy link
Contributor

@mjangda I'm done with this PR. I have successfully tested the updates on 1) a single site installation 2) MS domain setup 3) MS directory setup.

I have used following scenario for my tests:

  1. I have disabled debug bar and query monitor
  2. loaded the site with old version of this mu-plugin in place and captured the HTML source
  3. loaded the site with this branch in place and diffed the HTML source against the previously captured one

The diff was clean (JS and CSS wise) in all cases mentioned above.

Could you, please, have a look at the changes I have done and eventually proceed with merging this PR?

@mjangda
Copy link
Member Author

mjangda commented Feb 25, 2017

Haven't tested it yet, but the code looks solid. Will run through on my test site and follow-up.

emrikol and others added 3 commits March 2, 2017 11:41
Since the original `style_loader_tag` filters against a _single_ handle, this can cause problems when the concatenated file contains multiple handles worth of CSS.

This produced a bug where the `Jetpack::concat_remove_style_loader_tag()` filter would remove an _entire_ concatenated file's worth of CSS just because it contained one handle.

The new filter will allow the concatenated tag to still be adjusted if necessary, but it's not at the mercy of one handle removing all of the file.
@david-binda
Copy link
Contributor

@mjangda I have nerfed the PHPCS checks for good and tests are now passing. How are the changes looking on your test site?

If this is a subdirectory site, we need to strip off the subdir from the URL before trying to determine its realpath.

This is because in a multisite install, the subdir is virtual and therefore not needed in the path(For `example.com/subdir/file.css`, `file.css` is actually served from `/`).

In a single-site subdir install, the subdir is included in the ABSPATH and therefore ends up duplicated (ABSPATH: /var/www/wp | URL: example.com/wp/file.css).
@mjangda mjangda changed the title [WIP] Support for subdirectory multisites Support for subdirectory multisites Mar 3, 2017
@mjangda
Copy link
Member Author

mjangda commented Mar 3, 2017

Tested across a bunch of different configurations and looks pretty good. The only issue I spotted is that concat was broken for single site subdirectory installs (i.e. site installed and served from example.com/subdir or when installed in /subdir but served from /).

Pushed a fix for this 8396984 and re-tested and seems to be working well. If you agree, I can look at merging/deploying sometime today (Friday).

@david-binda
Copy link
Contributor

@mjangda the patch looks good and it tests out during my testing.

Ship it!

@mjangda
Copy link
Member Author

mjangda commented Mar 3, 2017

💥

@mjangda mjangda merged commit cea04c4 into master Mar 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants