Skip to content

Commit

Permalink
Merge pull request #58 from alleyinteractive/fix/windows-compat
Browse files Browse the repository at this point in the history
Add support for Windows filepaths
  • Loading branch information
kevinfodness authored Dec 18, 2023
2 parents eec2ad5 + 599e9d7 commit 1729343
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
.vscode
tests/php/build
tests/php/wp-unit-test
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Change Log
This project adheres to [Semantic Versioning](http://semver.org/).

## 1.3.6

* Adds support for running the plugin on a Windows hosting environment (#57)

## 1.3.5

* Removes default kses allowed SVG attributes
Expand Down
15 changes: 14 additions & 1 deletion asset-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
Plugin URI: https://github.com/alleyinteractive/wp-asset-manager
Description: Add more robust functionality to enqueuing static assets
Author: Alley Interactive
Version: 1.3.3
Version: 1.3.6
License: GPLv2 or later
Author URI: https://www.alleyinteractive.com/
*/
Expand All @@ -20,6 +20,19 @@
*/
defined( 'AM_BASE_DIR' ) || define( 'AM_BASE_DIR', dirname( __FILE__ ) );

if ( ! function_exists( 'am_validate_path' ) ) {
/**
* Helper function to validate a path before doing something with it.
*
* @param string $path The path to validate.
*
* @return bool True if the path is valid, false otherwise.
*/
function am_validate_path( string $path ) : bool {
return in_array( validate_file( $path ), [ 0, 2 ], true ) && file_exists( $path );
}
}

if ( ! class_exists( 'Asset_Manager' ) ) :
/**
* Load traits.
Expand Down
2 changes: 1 addition & 1 deletion php/class-asset-manager-scripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public function print_asset( $script ) {
esc_js( $script['handle'] ),
wp_json_encode( $script['src'] )
);
} elseif ( 0 === validate_file( $script['src'] ) && file_exists( $script['src'] ) ) {
} elseif ( am_validate_path( $script['src'] ) ) {
$file_contents = file_get_contents( $script['src'] ); // phpcs:ignore WordPressVIPMinimum.Performance.FetchingRemoteData.FileGetContentsUnknown

printf(
Expand Down
2 changes: 1 addition & 1 deletion php/class-asset-manager-styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function print_asset( $stylesheet ) {
if ( ! empty( $stylesheet['src'] ) && ! in_array( $stylesheet['load_method'], $this->wp_enqueue_methods, true ) ) {
if ( 'inline' === $stylesheet['load_method'] ) {
// Validate inline styles.
if ( 0 === validate_file( $stylesheet['src'] ) && file_exists( $stylesheet['src'] ) ) {
if ( am_validate_path( $stylesheet['src'] ) ) {
printf(
'<style class="%1$s" type="text/css">%2$s</style>',
esc_attr( implode( ' ', $classes ) ),
Expand Down
2 changes: 1 addition & 1 deletion php/class-asset-manager-svg-sprite.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ public function get_svg( $path ) {
return '';
}

if ( file_exists( $path ) && 0 === validate_file( $path ) ) {
if ( am_validate_path( $path ) ) {
$file_contents = file_get_contents( $path ); // phpcs:ignore WordPressVIPMinimum.Performance.FetchingRemoteData.FileGetContentsUnknown

if ( ! empty( $file_contents ) ) {
Expand Down

0 comments on commit 1729343

Please sign in to comment.