From 178616506ac8025202820dbfe0b907c55cd1c721 Mon Sep 17 00:00:00 2001 From: Joe Hoyle Date: Thu, 30 Jun 2022 16:37:22 +0200 Subject: [PATCH 1/2] Fix get_file_uri() when using symlinks Fixes #43 --- inc/paths.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/inc/paths.php b/inc/paths.php index d67aea0..a748b5c 100644 --- a/inc/paths.php +++ b/inc/paths.php @@ -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 asbilute 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 ); } /** From 2760fb481259b8b24cbd869b75b99edb949405f5 Mon Sep 17 00:00:00 2001 From: Joe Hoyle Date: Thu, 30 Jun 2022 16:38:34 +0200 Subject: [PATCH 2/2] Update inc/paths.php --- inc/paths.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/paths.php b/inc/paths.php index a748b5c..5192c5f 100644 --- a/inc/paths.php +++ b/inc/paths.php @@ -66,7 +66,7 @@ function get_file_uri( string $path ): string { return get_theme_file_uri( theme_relative_path( $path ) ); } - // If the path is inside WP_CONTENT_DIR then remove the asbilute path, passing to content_url(). + // 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 ) ); }