kasparsd / minit

A WordPress plugin to combine CSS and Javascript files.
GNU General Public License v2.0
286 stars 46 forks source link

Support different plugin/theme paths than default ones #107

Open strarsis opened 7 years ago

strarsis commented 7 years ago

A link to minit combined styles and javascript is added but the original script/style links are not removed.

kasparsd commented 7 years ago

I'm not seeing that issue on my personal site, for example. Can you please provide a sample URL?

strarsis commented 7 years ago

I will try to prepare a minimal reproducible example for this issue.

Where are the enqueued styles/scripts removed in minit? I cannot find a wp_dequeue_script(...) invocation.

kasparsd commented 7 years ago

@strarsis We're removing them here where $this->handler is either wp_scripts() or wp_styles().

strarsis commented 7 years ago

@kasparsd: Edit: process($todo) receives indeed an empty array for $todo, but the line $todo = array_merge( $todo, $this->queue ); fills the empty $todo array with all the CSS files that shouldn't be added.

strarsis commented 7 years ago

I found the reason, and the issue is actually not that the original file links aren't removed but those are skipped $src = $this->get_asset_relative_path( $handle );. For most handles, src is actually empty. The reason for this is probably that WordPress Bedrock is used which has custom paths. It should still be possible to get the right path with the WordPress core functions nonetheless.

kasparsd commented 7 years ago

Thank you @strarsis. That should only happen with "pseudo" packages or external scripts/styles. Does it fail at expanding the relative path in your case? Can you please debug it further?

strarsis commented 7 years ago

@kasparsd: Yes, this also fails with "regular" assets.

        // Check if this is a local asset which we can include
        $src_parts = explode( $base_url, $item_url );

The variables are set like this:

$base_url = '//<hostname>/wp';
$item_url = 'http://<hostname>/app/plugins/flowplayer5/frontend/assets/flowplayer-v6/flowplayer.js';

The explode(...) fails, hence $maybe_relative will also contain a full URL and then file_exists(...) will fail.

strarsis commented 7 years ago

@kasparsd: I modified the get_asset_relative_path(...) function in PR https://github.com/kasparsd/minit/pull/108 . What is meant with the "trailing part of the local URL"? - The URL to a plugin assets without the plugin URL prefix (e.g. "/plugins/")?

strarsis commented 7 years ago

@kasparsd: An alternative approach would be requesting the resources from itself (the server), localhost with Hostname or even over its public facing IP address. This would guarantee 100% path resolution in all situation and even finding out issues with resources (404, not found).