From fdc1434afaa4d977b24111a595b42259d09baa91 Mon Sep 17 00:00:00 2001 From: Skylar Bolton Date: Fri, 5 Mar 2021 08:42:26 -0700 Subject: [PATCH 1/4] Enqueue needs URL not path --- class/class-wp-scss.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/class/class-wp-scss.php b/class/class-wp-scss.php index e3576c4..16ffc19 100644 --- a/class/class-wp-scss.php +++ b/class/class-wp-scss.php @@ -211,15 +211,17 @@ public function style_url_enqueued($url){ * so it can be used in a url, not path */ public function enqueue_files($base_folder_path, $css_folder) { - $relative_path = explode(get_home_path(), $base_folder_path)[1]; + $enqueue_url = get_home_url() . '/' . $relative_path; + foreach( new DirectoryIterator($this->css_dir) as $stylesheet ) { if ( pathinfo($stylesheet->getFilename(), PATHINFO_EXTENSION) == 'css' ) { $name = $stylesheet->getBasename('.css') . '-style'; - $uri = '/'.$relative_path.$css_folder.$stylesheet->getFilename(); + $uri = $enqueue_url . $css_folder . $stylesheet->getFilename(); $ver = $stylesheet->getMTime(); + wp_register_style( $name, $uri, From ccd9cfb750b8ff82ce7624008fa6b0dd3e743266 Mon Sep 17 00:00:00 2001 From: Skylar Bolton Date: Fri, 5 Mar 2021 16:57:54 -0700 Subject: [PATCH 2/4] Testing encoded URI --- class/class-wp-scss.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/class/class-wp-scss.php b/class/class-wp-scss.php index 16ffc19..f461a4d 100644 --- a/class/class-wp-scss.php +++ b/class/class-wp-scss.php @@ -212,15 +212,15 @@ public function style_url_enqueued($url){ */ public function enqueue_files($base_folder_path, $css_folder) { $relative_path = explode(get_home_path(), $base_folder_path)[1]; - $enqueue_url = get_home_url() . '/' . $relative_path; + $enqueue_base_url = get_home_url() . '/' . $relative_path; foreach( new DirectoryIterator($this->css_dir) as $stylesheet ) { if ( pathinfo($stylesheet->getFilename(), PATHINFO_EXTENSION) == 'css' ) { $name = $stylesheet->getBasename('.css') . '-style'; - $uri = $enqueue_url . $css_folder . $stylesheet->getFilename(); + $uri = $enqueue_base_url . $css_folder . $stylesheet->getFilename(); $ver = $stylesheet->getMTime(); - + var_dump($uri); wp_register_style( $name, From 6534f31cff98cbcf4c72da289dbe695ba64f3dfc Mon Sep 17 00:00:00 2001 From: Mark McEver Date: Thu, 11 Mar 2021 19:24:56 +0000 Subject: [PATCH 3/4] Windows enqueue path/url fix --- class/class-wp-scss.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/class/class-wp-scss.php b/class/class-wp-scss.php index f461a4d..2098dce 100644 --- a/class/class-wp-scss.php +++ b/class/class-wp-scss.php @@ -211,7 +211,12 @@ public function style_url_enqueued($url){ * so it can be used in a url, not path */ public function enqueue_files($base_folder_path, $css_folder) { - $relative_path = explode(get_home_path(), $base_folder_path)[1]; + // We use realpath() to normalize any forward, backward, or trailing slack inconsistencies. + $relative_path = explode(realpath(get_home_path()), realpath($base_folder_path))[1]; + + // In case we're on a Windows machine + $relative_path = str_replace('\\', '/', $relative_path); + $enqueue_base_url = get_home_url() . '/' . $relative_path; foreach( new DirectoryIterator($this->css_dir) as $stylesheet ) { @@ -220,8 +225,6 @@ public function enqueue_files($base_folder_path, $css_folder) { $uri = $enqueue_base_url . $css_folder . $stylesheet->getFilename(); $ver = $stylesheet->getMTime(); - var_dump($uri); - wp_register_style( $name, $uri, From 6a88391c638f357ef9caa047c3998ce82bf364ff Mon Sep 17 00:00:00 2001 From: Skylar Bolton Date: Thu, 11 Mar 2021 20:01:51 -0700 Subject: [PATCH 4/4] Version bump --- readme.md | 2 ++ wp-scss.php | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index ff4bdc0..03522bd 100644 --- a/readme.md +++ b/readme.md @@ -89,6 +89,8 @@ Alternatively, you can include [Bourbon](https://github.com/thoughtbot/bourbon) This plugin will only work with .scss format. ## Changelog +* 2.1.5 + * Enqueue CSS files using `realpath` function. Addition by [mmcev106](https://github.com/ConnectThink/WP-SCSS/pull/179) * 2.1.4 * Set source URL to be home_url('/') not simply `/`. Issue found by [realjjaveweb](https://github.com/ConnectThink/WP-SCSS/issues/128) * 2.1.3 diff --git a/wp-scss.php b/wp-scss.php index 55b1a63..58cc4cf 100644 --- a/wp-scss.php +++ b/wp-scss.php @@ -3,7 +3,7 @@ * Plugin Name: WP-SCSS * Plugin URI: https://github.com/ConnectThink/WP-SCSS * Description: Compiles scss files live on WordPress. - * Version: 2.1.4 + * Version: 2.1.5 * Author: Connect Think * Author URI: http://connectthink.com * License: GPLv3 @@ -44,7 +44,7 @@ define('WPSCSS_VERSION_KEY', 'wpscss_version'); if (!defined('WPSCSS_VERSION_NUM')) - define('WPSCSS_VERSION_NUM', '2.1.4'); + define('WPSCSS_VERSION_NUM', '2.1.5'); // Add version to options table if ( get_option( WPSCSS_VERSION_KEY ) !== false ) {