API Reference
Complete API for all Assets classes.
Asset (Abstract)
Base class for all assets.
| Method | Return | Description |
|---|---|---|
src(string $path) | static | Set source path relative to plugin |
url(string $url) | static | Set absolute URL |
dependencies(array $deps) | static | Set WP dependency handles |
version(string $ver) | static | Set asset version |
condition(callable $cb) | static | Conditional enqueue |
admin() | static | Admin pages only |
front() | static | Frontend only |
onPage(string $hook) | static | Specific admin page |
inline(string $code) | static | Add inline code after asset |
shouldEnqueue(string $hook) | bool | Check if asset should load |
getHandle() | string | Get prefixed handle |
getLocation() | string | Get location (front/admin/both) |
enqueue() | void | Register and enqueue |
register() | void | Register without enqueueing |
deregister() | void | Deregister asset |
ScriptAsset
Extends Asset for JavaScript files.
| Method | Return | Description |
|---|---|---|
inFooter() | static | Load in footer |
async() | static | Add async attribute |
defer() | static | Add defer attribute |
module() | static | Set type="module" |
noModule() | static | Set nomodule attribute |
localize(string $name, array $data) | static | wp_localize_script |
StyleAsset
Extends Asset for CSS stylesheets.
| Method | Return | Description |
|---|---|---|
media(string $media) | static | Set media attribute |
preload() | static | Add preload link hint |
AssetManager
Central asset factory and registry.
| Method | Return | Description |
|---|---|---|
script(string $handle) | ScriptAsset | Create a script asset |
style(string $handle) | StyleAsset | Create a style asset |
enqueueAll(string $loc, string $hook) | void | Enqueue matching assets |
getRegistered() | Asset[] | Get all registered assets |
ViteAssetResolver
Vite manifest reader and dev server integration.
| Method | Return | Description |
|---|---|---|
isDev() | bool | Check if dev server is running |
getDevServerUrl() | string | Get dev server URL |
resolve(string $entry) | array|null | Resolve manifest entry |
enqueueEntry(string $entry, string $handle, array $deps) | void | Enqueue entry (auto dev/prod) |
resolve() Return Format
[
'url' => 'https://example.com/dist/assets/main-abc123.js',
'css' => [
'https://example.com/dist/assets/main-def456.css',
],
'imports' => [
'https://example.com/dist/assets/vendor-ghi789.js',
],
]
AssetsServiceProvider
| Method | Description |
|---|---|
register(ApplicationInterface $app) | Registers AssetManager, ViteAssetResolver, aliases |
boot(ApplicationInterface $app) | Hooks into wp_enqueue_scripts and admin_enqueue_scripts |