Skip to content

Commit

Permalink
Allow for chaining in register methods
Browse files Browse the repository at this point in the history
  • Loading branch information
borkweb committed Sep 28, 2024
1 parent 75db32e commit 86e25d2
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/Assets/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -1334,9 +1334,13 @@ public function print_before( $thing ) {
* Enqueue the asset.
*
* @since 1.0.0
*
* @return static
*/
public function register() {
public function register(): self {
Assets::init()->register_in_wp( $this );

return $this;
}

/**
Expand All @@ -1346,13 +1350,15 @@ public function register() {
*
* @param string|callable ...$dependencies The dependencies to add to the cloned asset.
*
* @return void
* @return static
*/
public function register_with_css( ...$dependencies ) {
public function register_with_css( ...$dependencies ): self {
$this->prefix_asset_directory( false );
$this->register();
$asset = $this->clone_to( 'css', ...$dependencies );
$asset->register();

return $this;
}

/**
Expand All @@ -1362,13 +1368,15 @@ public function register_with_css( ...$dependencies ) {
*
* @param string|callable ...$dependencies The dependencies to add to the cloned asset.
*
* @return void
* @return static
*/
public function register_with_js( ...$dependencies ) {
public function register_with_js( ...$dependencies ): self {
$this->prefix_asset_directory( false );
$this->register();
$asset = $this->clone_to( 'js', ...$dependencies );
$asset->register();

return $this;
}

/**
Expand Down

0 comments on commit 86e25d2

Please sign in to comment.