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

Improve get_asset_relative_path(...) #108

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions include/minit-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,21 +230,17 @@ protected function get_asset_relative_path( $handle ) {
return false;
}

// Remove protocol reference from the local base URL
$base_url = preg_replace( '/^(https?:)/i', '', $this->handler->base_url );
$arr = explode(plugins_url(), $item_url);
Copy link
Owner

Choose a reason for hiding this comment

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

@strarsis What about plugins and WP core files? plugins_url() works only with assets in plugins.

$url_rel = $arr[1];

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

if ( empty( $src_parts ) ) {
if ( empty( $url_rel ) ) {
return false;
}

// Get the trailing part of the local URL
$maybe_relative = array_pop( $src_parts );
$path_abs = WP_PLUGIN_DIR . $url_rel;
Copy link
Owner

Choose a reason for hiding this comment

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

Same here, WP_PLUGIN_DIR is plugin only.


if ( file_exists( ABSPATH . $maybe_relative ) ) {
return $maybe_relative;
if ( file_exists( $path_abs ) ) {
return $path_abs; // TODO: trailing path of the local URL?
}

return false;
Expand Down