Skip to content

Commit

Permalink
Do not attempt to use the asset.php file for cloned assets
Browse files Browse the repository at this point in the history
  • Loading branch information
borkweb committed Sep 27, 2024
1 parent 71d3a46 commit 3e3bb37
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
27 changes: 27 additions & 0 deletions src/Assets/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,15 @@ class Asset {
*/
protected ?string $url = null;

/**
* Whether or not to attempt to load an .asset.php file.
*
* @since 1.3.1
*
* @var bool
*/
protected bool $use_asset_file = true;

/**
* The asset version.
*
Expand Down Expand Up @@ -617,6 +626,7 @@ public function clone_to( string $clone_type, ...$dependencies ) {
$path = $this->get_path();
$min_path = $this->get_min_path();

$clone->use_asset_file( false );
$clone->prefix_asset_directory( $this->should_use_asset_directory_prefix );

if ( $dependencies ) {
Expand Down Expand Up @@ -1005,6 +1015,10 @@ public function get_version(): string {
* @return boolean
*/
public function has_asset_file(): bool {
if ( ! $this->use_asset_file ) {
return false;
}

$asset_file_path = $this->get_asset_file_path();

if ( empty( $asset_file_path ) ) {
Expand Down Expand Up @@ -1665,4 +1679,17 @@ public function set_type( string $type ) {
public function should_print(): bool {
return $this->should_print;
}

/**
* Set whether or not to use an .asset.php file.
*
* @since 1.3.1
*
* @param boolean $use_asset_file Whether to use an .asset.php file.
* @return self
*/
public function use_asset_file( bool $use_asset_file = true ): self {
$this->use_asset_file = $use_asset_file;
return $this;
}
}
2 changes: 1 addition & 1 deletion tests/acceptance/EnqueueCSSCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,6 @@ public function it_should_enqueue_js_when_using_register_with_js( AcceptanceTest

$I->amOnPage( '/' );
$I->seeElement( 'link', [ 'href' => 'http://wordpress.test/wp-content/plugins/assets/tests/_data/build/something.css?ver=12345' ] );
$I->seeElement( 'script', [ 'src' => 'http://wordpress.test/wp-content/plugins/assets/tests/_data/build/something.js?ver=12345' ] );
$I->seeElement( 'script', [ 'src' => 'http://wordpress.test/wp-content/plugins/assets/tests/_data/build/something.js?ver=1.0.0' ] );
}
}
2 changes: 1 addition & 1 deletion tests/acceptance/EnqueueJSCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public function it_should_enqueue_css_when_using_register_with_css( AcceptanceTe


$I->amOnPage( '/' );
$I->seeElement( 'link', [ 'href' => 'http://wordpress.test/wp-content/plugins/assets/tests/_data/build/something.css?ver=12345' ] );
$I->seeElement( 'link', [ 'href' => 'http://wordpress.test/wp-content/plugins/assets/tests/_data/build/something.css?ver=1.0.0' ] );
$I->seeElement( 'script', [ 'src' => 'http://wordpress.test/wp-content/plugins/assets/tests/_data/build/something.js?ver=12345' ] );
}
}

0 comments on commit 3e3bb37

Please sign in to comment.