Skip to content

Commit

Permalink
Merge pull request #26 from stellarwp/fix/only-prefix-for-relative-paths
Browse files Browse the repository at this point in the history
Prefix Config::set_path() when path is relative
  • Loading branch information
dpanta94 authored Nov 8, 2024
2 parents 579f8aa + 56b6539 commit 1c0b43a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/Assets/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,10 @@ protected static function normalize_path( string $path ): string {
if (
$plugins_content_dir_position === false
&& $themes_content_dir_position === false
&& strpos( $path, '/' ) !== 0
) {
// Default to path.
$path = $path;
// Default to plugins if a relative path is provided.
$path = trailingslashit( $plugin_dir ) . $path;
} elseif ( $plugins_content_dir_position !== false ) {
$path = substr( $path, $plugins_content_dir_position );
} elseif ( $themes_content_dir_position !== false ) {
Expand Down
12 changes: 6 additions & 6 deletions tests/wpunit/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ public function should_set_hook_prefix() {
}

public function paths_provider() {
yield 'plugin' => [ WP_PLUGIN_DIR . '/assets/', '/var/www/html/wp-content/plugins/assets/' ];
yield 'theme' => [ get_theme_file_path() . '/assets/', get_theme_file_path() . '/assets/' ];
yield 'mu-plugin' => [ WPMU_PLUGIN_DIR . '/assets/', '/var/www/html/wp-content/mu-plugins/assets/' ];
yield 'content' => [ WP_CONTENT_DIR . '/assets/', '/var/www/html/wp-content/assets/' ];
yield 'root' => [ ABSPATH . 'assets/', '/var/www/html/assets/' ];
yield 'relative' => [ 'src/resources/', 'src/resources/' ];
yield 'plugin' => [ WP_PLUGIN_DIR . '/my-plugin/', '/var/www/html/wp-content/plugins/my-plugin/' ];
yield 'theme' => [ get_theme_file_path() . '/', get_theme_file_path() . '/' ];
yield 'mu-plugin' => [ WPMU_PLUGIN_DIR . '/my-plugin/', '/var/www/html/wp-content/mu-plugins/my-plugin/' ];
yield 'content' => [ WP_CONTENT_DIR . '/stuff/', '/var/www/html/wp-content/stuff/' ];
yield 'root' => [ ABSPATH . 'stuff/', '/var/www/html/stuff/' ];
yield 'relative' => [ 'my-plugin/', '/var/www/html/wp-content/plugins/my-plugin/' ];
}

/**
Expand Down

0 comments on commit 1c0b43a

Please sign in to comment.