Skip to content

Commit

Permalink
Merge pull request #44 from humanmade/fix-plugins-url-symlink
Browse files Browse the repository at this point in the history
Fix get_file_uri() when using symlinks
  • Loading branch information
joehoyle authored Jun 30, 2022
2 parents e90aae0 + 2760fb4 commit 9fdb74d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion inc/paths.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,14 @@ function get_file_uri( string $path ): string {
return get_theme_file_uri( theme_relative_path( $path ) );
}

return content_url( str_replace( WP_CONTENT_DIR, '', $path ) );
// If the path is inside WP_CONTENT_DIR then remove the absolute path, passing to content_url().
if ( strpos( $path, WP_CONTENT_DIR ) === 0 ) {
return content_url( str_replace( WP_CONTENT_DIR, '', $path ) );
}

// Attempt to use plugins_url on the path, if it's a plugin. This will also handle cases
// while $path is inside a symlink.
return plugins_url( basename( $path ), $path );
}

/**
Expand Down

0 comments on commit 9fdb74d

Please sign in to comment.