Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jdamner committed May 22, 2024
1 parent 2f7c018 commit c1b7ae3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
8 changes: 5 additions & 3 deletions packages/editor-tools/docs/AssetLoader.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ You should typically use these methods in a function tied to `wp_enqueue_scripts

## Advanced Usage

### Base Path
### Base Path & URL
You can specify the base path for the asset loader to load from.
```php
$base_path = WP_CONTENT_DIR . '/plugins/my-plugin/assets';
$loader = new Boxuk\BoxWpEditorTools\AssetLoader( $base_path );
$base_url = WP_CONTENT_URL . '/plugins/my-plugin/build';
$loader = new Boxuk\BoxWpEditorTools\AssetLoader( $base_path, $base_url );

$loader->load( 'index' ); // loads wp-content/plugins/my-plugin/assets/index.js
$loader->load( 'admin' ); // loads wp-content/plugins/my-plugin/assets/admin.js
Expand All @@ -33,7 +34,8 @@ and the name passed to `::load()`. You can modify the prefix:
```php
$prefix = 'my_plugin_asset_';
$base_path = WP_CONTENT_DIR . '/plugins/my-plugin/assets';
$loader = new Boxuk\BoxWpEditorTools\AssetLoader( $base_path, $prefix );
$base_url = WP_CONTENT_URL . '/plugins/my-plugin/build';
$loader = new Boxuk\BoxWpEditorTools\AssetLoader( $base_path, $base_url, $prefix );
$loader->load( 'index' ); // handle will be `my_plugin_asset_index`
```

Expand Down
5 changes: 3 additions & 2 deletions packages/editor-tools/src/AssetLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ class AssetLoader {
* A new instance of an asset loader with the given handle and type.
*
* @param string $base_path The base path to the assets.
* @param string $base_url The base URL to the assets.
* @param string $prefix The prefix to use for the asset.
*/
public function __construct(
private string $base_path = '',
private string $prefix = 'box-',
private string $base_url = ''
private string $base_url = '',
private string $prefix = 'box-'
) {}

/**
Expand Down

0 comments on commit c1b7ae3

Please sign in to comment.