Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle Diff URL and Path for wp-content #12

Merged
merged 11 commits into from
Jun 13, 2024
2 changes: 1 addition & 1 deletion assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Plugin Name: Assets
* Description: Asset library with a plugin bootstrap file for automated testing.
* Version: 1.0.0
* Version: 1.2.3
* Author: StellarWP
* Author URI: https://stellarwp.com
*/
10 changes: 4 additions & 6 deletions src/Assets/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static function get_relative_asset_path(): string {
*/
public static function get_url( $path ): string {
if ( empty( static::$path_urls[ $path ] ) ) {
static::$path_urls[ $path ] = trailingslashit( get_site_url() . $path );
static::$path_urls[ $path ] = trailingslashit( str_replace( WP_CONTENT_DIR, WP_CONTENT_URL, $path ) );
}

return static::$path_urls[ $path ];
Expand Down Expand Up @@ -127,17 +127,15 @@ public static function set_relative_asset_path( string $path ) {
* @return void
*/
public static function set_path( string $path ) {
$content_dir = str_replace( get_site_url(), '', WP_CONTENT_URL );

$plugins_content_dir_position = strpos( $path, $content_dir . '/plugins' );
$themes_content_dir_position = strpos( $path, $content_dir . '/themes' );
$plugins_content_dir_position = strpos( $path, WP_PLUGIN_DIR );
$themes_content_dir_position = strpos( $path, get_theme_root() );

if (
$plugins_content_dir_position === false
&& $themes_content_dir_position === false
) {
// Default to plugins.
$path = $content_dir . '/plugins/' . $path;
$path = WP_PLUGIN_DIR . $path;
} elseif ( $plugins_content_dir_position !== false ) {
$path = substr( $path, $plugins_content_dir_position );
} elseif ( $themes_content_dir_position !== false ) {
Expand Down
2 changes: 1 addition & 1 deletion tests/wpunit/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function should_set_hook_prefix() {
public function should_set_path() {
Config::set_path( dirname( dirname( __DIR__ ) ) );

$this->assertEquals( '/wp-content/plugins/assets/', Config::get_path() );
$this->assertEquals( WP_PLUGIN_DIR . '/assets/', Config::get_path() );
}

/**
Expand Down
Loading