horttcore/wp-assets

This package is abandoned and no longer maintained. The author suggests using the ralfhortt/wp-assets package instead.

A helper package for working with the WordPress assets

Maintainers

Package info

github.com/Horttcore/wp-assets

pkg:composer/horttcore/wp-assets

Transparency log

Statistics

Installs: 1 582

Dependents: 2

Suggesters: 0

Stars: 0

3.1.0 2026-08-07 13:31 UTC

This package is auto-updated.

Last update: 2026-08-07 13:34:36 UTC


README

CI Latest Stable Version License PHP Version Require

A small helper package for registering and enqueuing WordPress scripts and styles.

Requirements

  • PHP >= 8.2
  • WordPress (functions used at runtime)

Installation

composer require ralfhortt/wp-assets

Documentation

Scripts

use RalfHortt\Assets\Script;
use RalfHortt\Assets\AdminScript;
use RalfHortt\Assets\EditorScript;
use RalfHortt\Assets\LoginScript;

new Script(string $handle, string $source = '', array $dependencies = [], string|bool|null $version = null, array|bool $args = []);
new AdminScript(string $handle, string $source = '', array $dependencies = [], string|bool|null $version = null, array|bool $args = []);
new EditorScript(string $handle, string $source = '', array $dependencies = [], string|bool|null $version = null, array|bool $args = []);
new LoginScript(string $handle, string $source = '', array $dependencies = [], string|bool|null $version = null, array|bool $args = []);

Inline scripts

use RalfHortt\Assets\InlineScript;

new InlineScript(string $handle, string $data, string $position = 'after');

Styles

use RalfHortt\Assets\Style;
use RalfHortt\Assets\AdminStyle;
use RalfHortt\Assets\EditorStyle;
use RalfHortt\Assets\LoginStyle;
use RalfHortt\Assets\PrintStyle;

new Style(string $handle, string $source = '', array $dependencies = [], string|bool|null $version = true, string $media = 'all');
new AdminStyle(string $handle, string $source = '', array $dependencies = [], string|bool|null $version = true, string $media = 'all');
new EditorStyle(string $handle, string $source = '', array $dependencies = [], string|bool|null $version = true, string $media = 'all');
new LoginStyle(string $handle, string $source = '', array $dependencies = [], string|bool|null $version = true, string $media = 'all');
new PrintStyle(string $handle, string $source = '', array $dependencies = [], string|bool|null $version = true, string $media = 'all');

Pass absolute asset URLs as $source (for example from get_stylesheet_directory_uri() or plugins_url()). Local URL detection supports multisite, home/siteurl mismatches, and http/https differences so cache-busting via filemtime keeps working.

Usage

use RalfHortt\Assets\Style;
use RalfHortt\Assets\InlineScript;
use RalfHortt\Assets\LoginStyle;

(new Style('my-theme', get_stylesheet_directory_uri() . '/theme.css'))->register();

(new InlineScript('my-theme', 'const ThemeName = "Awesome";'))->register();

// Reuse a registered handle on another hook
(new Style('my-theme'))->register();
(new LoginStyle('my-theme'))->register();
use RalfHortt\Assets\Script;

(new Script(
    'my-theme',
    get_stylesheet_directory_uri() . '/app.js',
    dependencies: ['wp-element'],
    version: true,
    args: ['strategy' => 'defer'],
))->register();

Development

composer install
composer lint
composer test
  • composer lint — PHPStan (level max) with WordPress stubs
  • composer test — Pest suite for URL/path/version resolution