From 9dcc5cc5f14480f02a96a4c43ffc582756ea586b Mon Sep 17 00:00:00 2001 From: Matthew Batchelder Date: Thu, 8 Aug 2024 16:21:29 -0400 Subject: [PATCH] Ensure paths use `/` for Windows compatibility Forward slashes in paths are functional within WP for Windows paths, so let's just convert `\` to `/` for greater compatibility. --- assets.php | 2 +- src/Assets/Config.php | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/assets.php b/assets.php index 9dfb619..061f5e8 100644 --- a/assets.php +++ b/assets.php @@ -2,7 +2,7 @@ /** * Plugin Name: Assets * Description: Asset library with a plugin bootstrap file for automated testing. - * Version: 1.2.6 + * Version: 1.2.8 * Author: StellarWP * Author URI: https://stellarwp.com */ diff --git a/src/Assets/Config.php b/src/Assets/Config.php index 64308bd..291188f 100644 --- a/src/Assets/Config.php +++ b/src/Assets/Config.php @@ -131,7 +131,13 @@ public static function set_relative_asset_path( string $path ) { * @return void */ public static function set_path( string $path ) { - $plugins_content_dir_position = strpos( $path, WP_PLUGIN_DIR ); + $plugin_dir = WP_PLUGIN_DIR; + + if ( DIRECTORY_SEPARATOR !== '/' ) { + $plugin_dir = str_replace( '/', DIRECTORY_SEPARATOR, $plugin_dir ); + } + + $plugins_content_dir_position = strpos( $path, $plugin_dir ); $themes_content_dir_position = strpos( $path, get_theme_root() ); if ( @@ -139,7 +145,7 @@ public static function set_path( string $path ) { && $themes_content_dir_position === false ) { // Default to plugins. - $path = WP_PLUGIN_DIR . $path; + $path = $plugin_dir . $path; } elseif ( $plugins_content_dir_position !== false ) { $path = substr( $path, $plugins_content_dir_position ); } elseif ( $themes_content_dir_position !== false ) {