PHPackages                             oberonlai/wp-asset - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. oberonlai/wp-asset

ActiveLibrary

oberonlai/wp-asset
==================

Handy tool for wp\_enqueue\_scripts.

v1.0.3(4y ago)030MITPHPPHP &gt;=7.2

Since Jul 12Pushed 4y ago1 watchersCompare

[ Source](https://github.com/oberonlai/wp-asset)[ Packagist](https://packagist.org/packages/oberonlai/wp-asset)[ Docs](https://github.com/oberonlai/wp-asset)[ RSS](/packages/oberonlai-wp-asset/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (5)Used By (0)

WP Asset v1.0
=============

[](#wp-asset-v10)

Simple WordPress class for including scripts and styles which is modifed from [WP\_Register](https://github.com/Josantonius/WP_Register)

Requirements
------------

[](#requirements)

- PHP &gt;=7.2
- [Composer](https://getcomposer.org/)
- [WordPress](https://wordpress.org) &gt;=5.4

Installation
------------

[](#installation)

#### Install with composer

[](#install-with-composer)

Run the following in your terminal to install with [Composer](https://getcomposer.org/).

```
$ composer require oberonlai/wp-asset

```

WP Option [PSR-4](https://www.php-fig.org/psr/psr-4/) autoloading and can be used with the Composer's autoloader. Below is a basic example of getting started, though your setup may be different depending on how you are using Composer.

```
require __DIR__ . '/vendor/autoload.php';

use ODS\Asset;

Asset::addScript();
```

See Composer's [basic usage](https://getcomposer.org/doc/01-basic-usage.md#autoloading) guide for details on working with Composer and autoloading.

Basic Usage
-----------

[](#basic-usage)

Below is a basic example of enqueue JavaScript and CSS.

```
require __DIR__ . '/vendor/autoload.php';

use ODS\Asset;

add_action(
	'init',
	function() {
		Asset::addScript(
			array(
				'name'    => 'my_script',
				'url'     => YOUR_PLUGIN_URL . 'assets/js/script.js',
				'deps'    => array( 'jquery' ),
				'version' => YOUR_PLUGIN_VERSION,
				'footer'  => true,
				'ajax'    => false,
				'admin'   => false,
				'params'  => array()
			)
		)

		Asset::addStyle(
			array(
				'name'    => 'my_style',
				'url'     => YOUR_PLUGIN_URL . 'assets/css/style.css',
				'version' => YOUR_PLUGIN_VERSION,
				'deps'    => array(),
			)
		)
	}
);
```

It is important that call object in the hook of init or WordPress API dosen't work.

Avaiable Attributes
-------------------

[](#avaiable-attributes)

keyDescriptionTypeRequiredDefaultnameUnique IDstringYesurlUrl to filestringYesadminAttach in adminbooleanNofalsedepsDependencesarrayNoversionVersionstringNofalsefooterAttach in footer ( scripts only )booleanNotrueajaxJS for Ajax ( scripts only )booleanNofalseparamsParams available in JS array ( scripts only )arrayNomediaMedia ( styles only )stringNo
Register JavaScript for Ajax
----------------------------

[](#register-javascript-for-ajax)

WP-Asset will help you generate variables ajax\_url and ajax\_nonce automatically when setting the ajax to true.

```
Asset::addScript(
	array(
		'name'    => 'my_ajax',
		'url'     => YOUR_PLUGIN_URL . 'assets/js/ajax.js',
		'deps'    => array( 'jquery' ),
		'version' => YOUR_PLUGIN_VERSION,
		'footer'  => true,
		'ajax'    => true,
		'params'  => array(
			'data1'  => 'my_data_1',
			'data2'  => 'my_data_2',
		)
	)
)
```

After adding script above, you can see JS variables before the scripts.

```

var my_ajax = {"data1":"my_data_1","data2":"my_data_2","ajax_url":"https:\/\/local.test\/wp-admin\/admin-ajax.php?action=my_ajax","ajax_nonce":"fead4137e4"};

```

You can use ajax\_url and ajax\_nonce directly in your scripts.

```
jQuery(function($){
    $(document).ready(function(){
        $('#btn').on('click',function(){
			var data = {
				action: "my_ajax",
				nonce: my_ajax.ajax_nonce,
			};
			$.ajax({
				url: my_ajax.ajax_url,
				data: data,
				type: 'POST',
				dataType: "json",
				success: function(data){
					console.log(data);
				},
				error: function(data){
					console.log(data);
				}
			})
        })
    })
})
```

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~46 days

Total

4

Last Release

1624d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1587136?v=4)[Oberon Lai](/maintainers/oberonlai)[@oberonlai](https://github.com/oberonlai)

---

Top Contributors

[![oberonlai](https://avatars.githubusercontent.com/u/1587136?v=4)](https://github.com/oberonlai "oberonlai (4 commits)")

### Embed Badge

![Health badge](/badges/oberonlai-wp-asset/health.svg)

```
[![Health](https://phpackages.com/badges/oberonlai-wp-asset/health.svg)](https://phpackages.com/packages/oberonlai-wp-asset)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
