Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wpbones/actions-and-filters-js
WordPress actions and filters in Javascript
https://github.com/wpbones/actions-and-filters-js
javascript wordpress wordpress-actions wordpress-development wp-bones wp-bones-packages
Last synced: 3 months ago
JSON representation
WordPress actions and filters in Javascript
- Host: GitHub
- URL: https://github.com/wpbones/actions-and-filters-js
- Owner: wpbones
- License: bsd-2-clause
- Created: 2016-11-02T14:22:50.000Z (about 8 years ago)
- Default Branch: main
- Last Pushed: 2024-10-01T15:58:30.000Z (3 months ago)
- Last Synced: 2024-10-01T16:17:12.196Z (3 months ago)
- Topics: javascript, wordpress, wordpress-actions, wordpress-development, wp-bones, wp-bones-packages
- Language: JavaScript
- Homepage:
- Size: 13.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# WordPress actions and filters implementation for Javascript
A Javascript version of the actions and filters used in PHP in WordPress for WP Bones.
## Requirements
This package works with a WordPress plugin written with [WP Bones framework library](https://github.com/wpbones/WPBones).
## Installation
You can install third party packages by using:
```sh copy
php bones require wpbones/actions-and-filters-js
```I advise to use this command instead of `composer require` because doing this an automatic renaming will done.
You can use composer to install this package:
```sh copy
composer require wpbones/actions-and-filters-js
```You may also to add `"wpbones/actions-and-filters-js": "^1.0"` in the `composer.json` file of your plugin:
```json copy filename="composer.json" {4}
"require": {
"php": ">=7.4",
"wpbones/wpbones": "~0.8",
"wpbones/actions-and-filters-js": "~1.0"
},
```and run
```sh copy
composer install
```Alternatively, you can get the single files `src/resources/assets/js/actions-and-filters.js` in your WP Bones plugin and compile it with `gulp`.
Also, you can get pre-compiled minified version `src/public/js/actions-and-filters.min.js`.## Enqueue for Controller
You can use the provider to enqueue the styles.
```php copy
public function index()
{
// enqueue the minified version
ActionsAndFiltersJSProvider::enqueueScripts();// ...
}
```## ActionsAndFiltersJSProvider
This is a static class autoloaded by composer. You can use it to enqueue or get the styles path:
```php copy
// enqueue the minified version
ActionsAndFiltersJSProvider::enqueueScripts();// enqueue the flat version
ActionsAndFiltersJSProvider::enqueueScripts( false );// return the absolute path of the minified css
ActionsAndFiltersJSProvider::js();// return the absolute path of the flat css
ActionsAndFiltersJSProvider::js();
```## Usage
Let's an example:
```js copy
wpbones_add_action( 'my-action', function() { alert( "Hello" ) } );
...
wpbones_do_action( 'my-action' );
```
This Javascript version works in the same way than PHP version in WordPress.